Skip to content

Commit c213706

Browse files
committed
added isSystem option for CollectionHandler::drop
1 parent 4fe4628 commit c213706

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

lib/triagens/ArangoDb/CollectionHandler.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,18 +659,24 @@ public function truncate($collection)
659659
* @throws Exception
660660
*
661661
* @param mixed $collection - collection id as string or number or collection object
662+
* @param array $options - an array of options for the drop operation
662663
*
663664
* @return bool - always true, will throw if there is an error
664665
*/
665-
public function drop($collection)
666+
public function drop($collection, $options = array())
666667
{
667668
$collectionName = $this->getCollectionName($collection);
668669

669670
if ($this->isValidCollectionId($collectionName)) {
670671
throw new ClientException('Cannot alter a collection without a collection id');
671672
}
672673

673-
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionName]));
674+
$appendix = '';
675+
if (is_array($options) && isset($options['isSystem'])) {
676+
$appendix = '?isSystem=' . UrlHelper::getBoolString($options['isSystem']);
677+
}
678+
679+
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionName]) . $appendix);
674680

675681
return true;
676682
}

tests/CollectionBasicTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public function testCreateAndDeleteSystemCollectionWithoutCreatingObject()
428428
$name = '_ArangoDB_PHP_TestSuite_TestCollection_02';
429429

430430
try {
431-
$collectionHandler->drop($name);
431+
$collectionHandler->drop($name, [ 'isSystem' => true ]);
432432
} catch (Exception $e) {
433433
//Silence the exception
434434
}
@@ -447,7 +447,7 @@ public function testCreateAndDeleteSystemCollectionWithoutCreatingObject()
447447
static::assertTrue($resultingCollectionProperties->getWaitForSync());
448448

449449

450-
$collectionHandler->delete($name);
450+
$collectionHandler->drop($name, [ 'isSystem' => true ]);
451451
}
452452

453453

tests/CollectionExtendedTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function setUp()
3333
$this->documentHandler = new DocumentHandler($this->connection);
3434

3535
try {
36-
$this->collectionHandler->delete('ArangoDB_PHP_TestSuite_TestCollection_01');
36+
$this->collectionHandler->drop('ArangoDB_PHP_TestSuite_TestCollection_01');
3737
} catch (\Exception $e) {
3838
// don't bother us, if it's already deleted.
3939
}
@@ -112,6 +112,11 @@ public function testCreateGetAndDeleteSystemCollection()
112112
$collection->setName($name);
113113
$collection->setIsSystem(true);
114114

115+
try {
116+
$collectionHandler->drop($name, [ 'isSystem' => true ]);
117+
} catch (Exception $e) {
118+
//Silence the exception
119+
}
115120

116121
$response = $collectionHandler->add($collection);
117122

@@ -122,7 +127,7 @@ public function testCreateGetAndDeleteSystemCollection()
122127
$properties = $collectionHandler->getProperties($name);
123128
static::assertTrue($properties->getIsSystem(), '"isSystem" should be true!');
124129

125-
$response = $collectionHandler->delete($collection);
130+
$response = $collectionHandler->drop($collection, [ 'isSystem' => true ]);
126131
static::assertTrue($response, 'Delete should return true!');
127132
}
128133

tests/EdgeExtendedTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ public function setUp()
3131
$this->collection = new Collection();
3232
$this->collection->setName('ArangoDB_PHP_TestSuite_TestEdgeCollection_01');
3333
$this->collectionHandler->add($this->collection);
34+
35+
try {
36+
$this->collectionHandler->drop('ArangoDB_PHP_TestSuite_EdgeCollection_01');
37+
} catch (Exception $e) {
38+
//Silence the exception
39+
}
40+
41+
try {
42+
$this->collectionHandler->drop('ArangoDB_PHP_TestSuite_Collection_01');
43+
} catch (Exception $e) {
44+
//Silence the exception
45+
}
46+
3447
$this->edgeHandler = new EdgeHandler($this->connection);
3548
$this->edgeCollection = new Collection();
3649
$this->edgeCollection->setName('ArangoDBPHPTestSuiteTestEdgeCollection01');

0 commit comments

Comments
 (0)