Skip to content

Commit a431684

Browse files
committed
cleanup
1 parent c42e98f commit a431684

File tree

5 files changed

+21
-38
lines changed

5 files changed

+21
-38
lines changed

lib/ArangoDBClient/CollectionHandler.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,10 @@ public function import($collection, $importData, array $options = [])
832832
$options['type'] = 'documents';
833833
}
834834

835-
$this->createCollectionIfOptions($collection, $options);
835+
if ((isset($options['createCollection']) && $options['createCollection']) ||
836+
$this->getConnection()->getOption(ConnectionOptions::OPTION_CREATE)) {
837+
$this->lazyCreateCollection($collection, $options);
838+
}
836839

837840
$params = array_merge(
838841
[self::OPTION_COLLECTION => $collection],
@@ -2030,18 +2033,8 @@ public function within($collection, $latitude, $longitude, $radius, array $optio
20302033
* @param $collection
20312034
* @param $options
20322035
*/
2033-
private function createCollectionIfOptions($collection, $options)
2036+
private function lazyCreateCollection($collection, $options)
20342037
{
2035-
if (!array_key_exists(CollectionHandler::OPTION_CREATE_COLLECTION, $options)) {
2036-
return;
2037-
}
2038-
2039-
$value = (bool) $options[CollectionHandler::OPTION_CREATE_COLLECTION];
2040-
2041-
if (!$value) {
2042-
return;
2043-
}
2044-
20452038
$collectionOptions = [];
20462039
if (isset($options['createCollectionType'])) {
20472040
if ($options['createCollectionType'] === 'edge' ||

lib/ArangoDBClient/DocumentHandler.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,16 @@ public function insert($collection, $document, array $options = [])
351351
$options, [
352352
'waitForSync' => null,
353353
'silent' => false,
354-
'createCollection' => $this->getConnection()->getOption(ConnectionOptions::OPTION_CREATE),
355354
'overwrite' => (bool) @$options[self::OPTION_OVERWRITE],
356355
'returnOld' => (bool) @$options[self::OPTION_RETURN_OLD],
357356
'returnNew' => (bool) @$options[self::OPTION_RETURN_NEW],
358357
]
359358
);
360359

361-
$this->createCollectionIfOptions($collection, $params);
360+
if ((isset($options['createCollection']) && $options['createCollection']) ||
361+
$this->getConnection()->getOption(ConnectionOptions::OPTION_CREATE)) {
362+
$this->lazyCreateCollection($collection, $params);
363+
}
362364

363365
$url = UrlHelper::appendParamsUrl(Urls::URL_DOCUMENT . '/' . $collection, $params);
364366

@@ -394,6 +396,7 @@ public function insert($collection, $document, array $options = [])
394396

395397
$id = UrlHelper::getDocumentIdFromLocation($location);
396398

399+
$document->setInternalKey($json[$_documentClass::ENTRY_KEY]);
397400
$document->setInternalId($json[$_documentClass::ENTRY_ID]);
398401
$document->setRevision($json[$_documentClass::ENTRY_REV]);
399402

@@ -683,11 +686,7 @@ protected function put($url, $collection, $documentId, Document $document, array
683686
*/
684687
public function remove(Document $document, array $options = [])
685688
{
686-
$documentId = $this->getDocumentId($document);
687-
688-
$revision = $this->getRevision($document);
689-
690-
return $this->removeById($document, $documentId, $revision, $options);
689+
return $this->removeById($document, $this->getDocumentId($document), $this->getRevision($document), $options);
691690
}
692691

693692

@@ -819,28 +818,16 @@ private function getRevision($document)
819818

820819

821820
/**
822-
* @param $collection mixed collection name or id
821+
* @param mixed $collection collection name or id
823822
* @param array $options - optional, array of options
824823
* <p>Options are :
825-
* <li>'createCollection' - true to create the collection if it does not exist</li>
826824
* <li>'createCollectionType' - "document" or 2 for document collection</li>
827825
* <li> "edge" or 3 for edge collection</li>
828826
* <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>
829827
* </p>
830828
*/
831-
protected function createCollectionIfOptions($collection, $options)
829+
protected function lazyCreateCollection($collection, $options)
832830
{
833-
834-
if (!array_key_exists(CollectionHandler::OPTION_CREATE_COLLECTION, $options)) {
835-
return;
836-
}
837-
838-
$value = (bool) $options[CollectionHandler::OPTION_CREATE_COLLECTION];
839-
840-
if (!$value) {
841-
return;
842-
}
843-
844831
$collectionHandler = new CollectionHandler($this->getConnection());
845832

846833
$params = [];

lib/ArangoDBClient/EdgeHandler.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ public function saveEdge($collection, $from, $to, $document, array $options = []
151151
$params = $this->includeOptionsInParams(
152152
$options, [
153153
'waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
154-
'createCollection' => $this->getConnectionOption(ConnectionOptions::OPTION_CREATE)
155154
]
156155
);
157156

158-
$this->createCollectionIfOptions($collection, $params);
157+
if ((isset($options['createCollection']) && $options['createCollection']) ||
158+
$this->getConnection()->getOption(ConnectionOptions::OPTION_CREATE)) {
159+
$this->lazyCreateCollection($collection, $params);
160+
}
159161

160162
$data = $document->getAllForInsertUpdate();
161163

@@ -265,10 +267,10 @@ public function outEdges($collection, $vertexHandle)
265267
* <li> "edge" or 3 for edge collection</li>
266268
* </p>
267269
*/
268-
protected function createCollectionIfOptions($collection, $options)
270+
protected function lazyCreateCollection($collection, $options)
269271
{
270272
$options['createCollectionType'] = 3;
271-
parent::createCollectionIfOptions($collection, $options);
273+
parent::lazyCreateCollection($collection, $options);
272274
}
273275
}
274276

lib/ArangoDBClient/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function includeOptionsInParams($options, array $includeArray = [])
111111
}
112112
}
113113

114-
foreach ($includeArray as $key => $value) {
114+
foreach ($includeArray as $key => $value) {
115115
if (!array_key_exists($key, $options)) {
116116
if ($key === ConnectionOptions::OPTION_UPDATE_POLICY) {
117117
UpdatePolicy::validate($value);

tests/CollectionExtendedTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ public function testCreateDocumentsWithCreateFromArrayGetAsArrayAndRemoveByExamp
848848
static::assertArrayHasKey('_rev', $array[0]);
849849

850850
unset($array[0]['_key'], $array[0]['_id'], $array[0]['_rev']);
851+
unset($documentArray['_key']);
851852

852853
static::assertSame($documentArray, $array[0]);
853854
}

0 commit comments

Comments
 (0)