Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added support for deleting all registered functions in a namespace.
  • Loading branch information
F21 committed May 19, 2013
commit 2f40e4e47ca183c13d667ec79a39963c6c7a7841
10 changes: 8 additions & 2 deletions lib/triagens/ArangoDb/AqlUserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,25 @@ public function register($name = null, $code = null)
*
* If $name is passed, it will override the object's property with the passed one
*
* @param null $name
* @param string $name
* @param boolean $namespace
*
* @throws Exception throw exception if the request fails
*
* @return mixed true if successful without a return value or the return value if one was set in the action
*/
public function unregister($name = null)
public function unregister($name = null, $namespace = false)
{
if (is_null($name)) {
$name = $this->getName();
}

$url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION, $name);

if($namespace){
$url = UrlHelper::appendParamsUrl($url, array('group' => true));
}

$response = $this->_connection->delete($url);
$responseArray = $response->getJson();

Expand Down
34 changes: 34 additions & 0 deletions tests/AqlUserFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,40 @@ public function testGetAQLFunctionsWithNamespaceFilter()
$userFunction->unregister($name2);
}

/**
* Unregister all AQL functions on a namespace.
*/
public function testUnregisterAQLFunctionsOnNamespace()
{

$name1 = 'myFunctions:myFunction1';
$name2 = 'myFunctions:myFunction2';
$code = 'function (celsius) { return celsius * 1.8 + 32; }';

//Setup
$userFunction = new AqlUserFunction($this->connection);

$userFunction->name = $name1;
$userFunction->code = $code;

$result = $userFunction->register();

$userFunction = new AqlUserFunction($this->connection);

$userFunction->name = $name2;
$userFunction->code = $code;

$result = $userFunction->register();

$functions = $userFunction->getRegisteredUserFunctions('myFunctions');
$this->assertCount(2, $functions, "myFunctions namespace should only contain 2 functions.");

$userFunction->unregister('myFunctions', true);

$functions = $userFunction->getRegisteredUserFunctions('myFunctions');
$this->assertEmpty($functions, "myFunctions namespace should only contain no functions.");
}

public function tearDown()
{

Expand Down