Skip to content

Commit 9a7dfea

Browse files
committed
Fix collection creation options if trying insert new document in non-existing collection
1 parent 7e3124c commit 9a7dfea

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lib/ArangoDBClient/DocumentHandler.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,17 +806,20 @@ private function getRevision($document)
806806
return $revision;
807807
}
808808

809+
809810
/**
810811
* @param $collection mixed collection name or id
811812
* @param array $options - optional, array of options
812813
* <p>Options are :
813814
* <li>'createCollection' - true to create the collection if it does not exist</li>
814815
* <li>'createCollectionType' - "document" or 2 for document collection</li>
815816
* <li> "edge" or 3 for edge collection</li>
817+
* <li>'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk / If this is not specified, then the collection's default sync behavior will be applied.</li>
816818
* </p>
817819
*/
818820
protected function createCollectionIfOptions($collection, $options)
819821
{
822+
820823
if (!array_key_exists(CollectionHandler::OPTION_CREATE_COLLECTION, $options)) {
821824
return;
822825
}
@@ -829,18 +832,25 @@ protected function createCollectionIfOptions($collection, $options)
829832

830833
$collectionHandler = new CollectionHandler($this->getConnection());
831834

835+
$params = [];
836+
832837
if (array_key_exists('createCollectionType', $options)) {
833-
$options['type'] = $options['createCollectionType'];
834-
unset($options['createCollectionType']);
838+
$params['type'] = $options['createCollectionType'];
839+
}
840+
841+
if (array_key_exists('waitForSync', $options)) {
842+
$params['waitForSync'] = $options['waitForSync'];
835843
}
836-
unset($options['createCollection']);
844+
837845
try {
838846
// attempt to create the collection
839-
$collectionHandler->create($collection, $options);
847+
$collectionHandler->create($collection, $params);
840848
} catch (Exception $e) {
841849
// collection may have existed already
842850
}
843851
}
844852
}
845853

854+
}
855+
846856
class_alias(DocumentHandler::class, '\triagens\ArangoDb\DocumentHandler');

0 commit comments

Comments
 (0)