Skip to content

Commit 2f40e4e

Browse files
committed
Added support for deleting all registered functions in a namespace.
1 parent 986a959 commit 2f40e4e

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/triagens/ArangoDb/AqlUserFunction.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,25 @@ public function register($name = null, $code = null)
145145
*
146146
* If $name is passed, it will override the object's property with the passed one
147147
*
148-
* @param null $name
148+
* @param string $name
149+
* @param boolean $namespace
149150
*
150151
* @throws Exception throw exception if the request fails
151152
*
152153
* @return mixed true if successful without a return value or the return value if one was set in the action
153154
*/
154-
public function unregister($name = null)
155+
public function unregister($name = null, $namespace = false)
155156
{
156157
if (is_null($name)) {
157158
$name = $this->getName();
158159
}
160+
159161
$url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION, $name);
160162

163+
if($namespace){
164+
$url = UrlHelper::appendParamsUrl($url, array('group' => true));
165+
}
166+
161167
$response = $this->_connection->delete($url);
162168
$responseArray = $response->getJson();
163169

tests/AqlUserFunctionTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,40 @@ public function testGetAQLFunctionsWithNamespaceFilter()
290290
$userFunction->unregister($name2);
291291
}
292292

293+
/**
294+
* Unregister all AQL functions on a namespace.
295+
*/
296+
public function testUnregisterAQLFunctionsOnNamespace()
297+
{
298+
299+
$name1 = 'myFunctions:myFunction1';
300+
$name2 = 'myFunctions:myFunction2';
301+
$code = 'function (celsius) { return celsius * 1.8 + 32; }';
302+
303+
//Setup
304+
$userFunction = new AqlUserFunction($this->connection);
305+
306+
$userFunction->name = $name1;
307+
$userFunction->code = $code;
308+
309+
$result = $userFunction->register();
310+
311+
$userFunction = new AqlUserFunction($this->connection);
312+
313+
$userFunction->name = $name2;
314+
$userFunction->code = $code;
315+
316+
$result = $userFunction->register();
317+
318+
$functions = $userFunction->getRegisteredUserFunctions('myFunctions');
319+
$this->assertCount(2, $functions, "myFunctions namespace should only contain 2 functions.");
320+
321+
$userFunction->unregister('myFunctions', true);
322+
323+
$functions = $userFunction->getRegisteredUserFunctions('myFunctions');
324+
$this->assertEmpty($functions, "myFunctions namespace should only contain no functions.");
325+
}
326+
293327
public function tearDown()
294328
{
295329

0 commit comments

Comments
 (0)