Skip to content

Commit b65085c

Browse files
author
Jan Steemann
committed
INCOMPATIBLE CHANGE: changed behavior of edge retrieval methods
The methods EdgeHandler::edges(), EdgeHandler::inEdges() and EdgeHandler::outEdges() previously returned a list of edge ids in the specified edge collection. This was in contrast to the methods' signatures and documentation, which suggested that the methods would return the edges connected to the specified vertex. However, passing in a vertex or a direction parameter never had an effect because internally the methods called a server API which did not take these parameters into account. With the fix, the parameters are taken into account so only connected edges are returned as documented. Additionally, the return value of the methods change from an array of edge ids (i.e. strings) to an array of edge objects. This is not compatible with the behavior of the methods prior to version 2.6, but staying compatible with the old methods does not make much sense here, as they did not do what the documentation suggested.
1 parent b42502f commit b65085c

File tree

7 files changed

+428
-60
lines changed

7 files changed

+428
-60
lines changed

lib/triagens/ArangoDb/Document.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public function setInternalId($id)
502502
}
503503

504504

505-
if (!preg_match('/^[a-zA-Z0-9_-]{1,64}\/[a-zA-Z0-9_:-]{1,254}$/', $id)) {
505+
if (!preg_match('/^[a-zA-Z0-9_-]{1,64}\/[a-zA-Z0-9_:\.@-]{1,254}$/', $id)) {
506506
throw new ClientException('Invalid format for document id');
507507
}
508508

@@ -526,7 +526,7 @@ public function setInternalKey($key)
526526
throw new ClientException('Should not update the key of an existing document');
527527
}
528528

529-
if (!preg_match('/^[a-zA-Z0-9_:-]{1,254}$/', $key)) {
529+
if (!preg_match('/^[a-zA-Z0-9_:\.@-]{1,254}$/', $key)) {
530530
throw new ClientException('Invalid format for document key');
531531
}
532532

lib/triagens/ArangoDb/EdgeHandler.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class EdgeHandler extends
3030
* documents array index
3131
*/
3232
const ENTRY_DOCUMENTS = 'edge';
33+
34+
/**
35+
* edges array index
36+
*/
37+
const ENTRY_EDGES = 'edges';
3338

3439
/**
3540
* collection parameter
@@ -192,57 +197,65 @@ public function saveEdge($collectionId, $from, $to, $document, $options = array(
192197

193198

194199
/**
195-
* Get edges for a given vertex
200+
* Get connected edges for a given vertex
196201
*
197202
* @throws Exception
198203
*
199204
* @param mixed $collectionId - edge-collection id as string or number
200205
* @param mixed $vertexHandle - the vertex involved
201206
* @param string $direction - optional defaults to 'any'. Other possible Values 'in' & 'out'
207+
* @param array $options - optional, array of options
208+
* <p>Options are :
209+
* <li>'_includeInternals' - true to include the internal attributes. Defaults to false</li>
210+
* <li>'_ignoreHiddenAttributes' - true to show hidden attributes. Defaults to false</li>
211+
* </p>
202212
*
203-
* @return array - array of cursors
213+
* @return array - array of connected edges
204214
* @since 1.0
205215
*/
206-
public function edges($collectionId, $vertexHandle, $direction = 'any')
216+
public function edges($collectionId, $vertexHandle, $direction = 'any', array $options = array())
207217
{
208-
209218
$params = array(
210-
self::OPTION_COLLECTION => $collectionId,
211219
self::OPTION_VERTEX => $vertexHandle,
212220
self::OPTION_DIRECTION => $direction
213221
);
214-
$url = UrlHelper::appendParamsUrl(Urls::URL_EDGE, $params);
222+
$url = UrlHelper::appendParamsUrl(Urls::URL_EDGES . '/' . urlencode($collectionId), $params);
215223
$response = $this->getConnection()->get($url);
216224
$json = $response->getJson();
225+
226+
$edges = array();
227+
foreach ($json[self::ENTRY_EDGES] as $data) {
228+
$edges[] = $this->createFromArrayWithContext($data, $options);
229+
}
217230

218-
return $json;
231+
return $edges;
219232
}
220233

221234

222235
/**
223-
* Get inbound edges for a given vertex
236+
* Get connected inbound edges for a given vertex
224237
*
225238
* @throws Exception
226239
*
227240
* @param mixed $collectionId - edge-collection id as string or number
228241
* @param mixed $vertexHandle - the vertex involved
229242
*
230-
* @return array - array of cursors
243+
* @return array - array of connected edges
231244
*/
232245
public function inEdges($collectionId, $vertexHandle)
233246
{
234247
return $this->edges($collectionId, $vertexHandle, 'in');
235248
}
236249

237250
/**
238-
* Get outbound edges for a given vertex
251+
* Get connected outbound edges for a given vertex
239252
*
240253
* @throws Exception
241254
*
242255
* @param mixed $collectionId - edge-collection id as string or number
243256
* @param mixed $vertexHandle - the vertex involved
244257
*
245-
* @return array - array of cursors
258+
* @return array - array of connected edges
246259
*/
247260
public function outEdges($collectionId, $vertexHandle)
248261
{

lib/triagens/ArangoDb/GraphHandler.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,8 @@ public function getDistanceTo($graph,
19491949
$options['objectType'] = 'distanceTo';
19501950
$data = array_merge($options, $this->getCursorOptions($options));
19511951
$statement = new Statement($this->getConnection(), array(
1952-
"query" => ''
1952+
"query" => '',
1953+
"_flat" => true
19531954
));
19541955
$statement->setResultType($options['objectType']);
19551956
$aql = "FOR a IN GRAPH_DISTANCE_TO(@graphName, @start, @end , @options) ";
@@ -2466,7 +2467,6 @@ public function getAbsoluteBetweenness($graph,
24662467
/**
24672468
* Get the <a href="http://en.wikipedia.org/wiki/Betweenness_centrality">betweenness</a> of a graph.
24682469
*
2469-
* This will throw if the list cannot be fetched from the server
24702470
* This does not support 'batchsize', 'limit' and 'count'.<br><br>
24712471
*
24722472
* @throws Exception
@@ -2487,8 +2487,7 @@ public function getAbsoluteBetweenness($graph,
24872487
*
24882488
* @return array
24892489
*/
2490-
public function getBetweenness($graph,
2491-
$options = array())
2490+
public function getBetweenness($graph, $options = array())
24922491
{
24932492
if ($graph instanceof Graph) {
24942493
$graph = $graph->getKey();
@@ -2497,7 +2496,8 @@ public function getBetweenness($graph,
24972496
$options['objectType'] = 'figure';
24982497
$data = array_merge($options, $this->getCursorOptions($options));
24992498
$statement = new Statement($this->getConnection(), array(
2500-
"query" => ''
2499+
"query" => '',
2500+
"_flat" => true
25012501
));
25022502
$statement->setResultType($options['objectType']);
25032503
$aql = "RETURN GRAPH_BETWEENNESS(@graphName, @options) ";
@@ -2515,7 +2515,9 @@ public function getBetweenness($graph,
25152515
$statement->bind('options', $options);
25162516

25172517
$statement->setQuery($aql);
2518-
return $statement->execute()->getAll();
2518+
$result = $statement->execute()->getAll();
2519+
2520+
return $result[0];
25192521
}
25202522

25212523
/**

lib/triagens/ArangoDb/UrlHelper.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,23 @@ abstract class UrlHelper
2929
*/
3030
public static function getDocumentIdFromLocation($location)
3131
{
32-
@list(, , , , , , $id) = explode('/', $location);
32+
if (!is_string($location)) {
33+
// can't do anything about it if location is not even a string
34+
return null;
35+
}
3336

34-
return $id;
35-
}
37+
if (substr($location, 0, 5) === '/_db/') {
38+
// /_db/<dbname>/_api/document/<collection>/<key>
39+
@list(, , , , , , $id) = explode('/', $location);
40+
}
41+
else {
42+
// /_api/document/<collection>/<key>
43+
@list(, , , , $id) = explode('/', $location);
44+
}
3645

37-
/**
38-
* Get the collection id from a location header
39-
*
40-
* @param string $location - HTTP response location header
41-
*
42-
* @return string - collection id parsed from header
43-
*/
44-
public static function getCollectionIdFromLocation($location)
45-
{
46-
@list(, , , $id) = explode('/', $location);
46+
if (is_string($id)) {
47+
$id = urldecode($id);
48+
}
4749

4850
return $id;
4951
}

lib/triagens/ArangoDb/Urls.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,35 @@
2121
abstract class Urls
2222
{
2323
/**
24-
* URL base part for all document-related REST calls
24+
* URL base part for document-related CRUD operations REST calls
2525
*/
2626
const URL_DOCUMENT = '/_api/document';
2727

2828
/**
29-
* URL base part for all document-related REST calls
29+
* URL base part for edge-related CRUD operations REST calls
3030
*/
3131
const URL_EDGE = '/_api/edge';
32-
32+
3333
/**
34-
* URL base part for all document-related REST calls
34+
* URL base part for all retrieving connected edges
3535
*/
36-
const URL_GRAPH = '/_api/gharial';
36+
const URL_EDGES = '/_api/edges';
3737

3838
/**
39-
* URL base part for all document-related REST calls
39+
* URL base part for all graph-related REST calls
4040
*/
41-
const URLPART_VERTEX = 'vertex';
41+
const URL_GRAPH = '/_api/gharial';
4242

4343
/**
44-
* URL base part for all document-related REST calls
44+
* URL part vertex-related graph REST calls
4545
*/
46-
const URLPART_VERTICES = 'vertices';
46+
const URLPART_VERTEX = 'vertex';
4747

4848
/**
49-
* URL base part for all document-related REST calls
49+
* URL part for edge-related graph REST calls
5050
*/
5151
const URLPART_EDGE = 'edge';
5252

53-
/**
54-
* URL base part for all document-related REST calls
55-
*/
56-
const URLPART_EDGES = 'edges';
57-
5853
/**
5954
* URL base part for all collection-related REST calls
6055
*/

tests/DocumentBasicTest.php

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,36 @@ public function testCreateAndDeleteDocumentWithSeveralKeys()
114114
$collection = $this->collection;
115115
$documentHandler = new DocumentHandler($connection);
116116

117-
$keys = array("foo", "bar", "bar:bar", "baz", "1", "0", "a-b-c", "a:b", "this-is-a-test", "FOO", "BAR", "Bar", "bAr");
117+
$keys = array(
118+
"_",
119+
"foo",
120+
"bar",
121+
"bar:bar",
122+
"baz",
123+
"1",
124+
"0",
125+
"a-b-c",
126+
"a:b",
127+
"this-is-a-test",
128+
"FOO",
129+
"BAR",
130+
"Bar",
131+
"bAr"
132+
);
133+
134+
$adminHandler = new AdminHandler($this->connection);
135+
$version = preg_replace("/-[a-z0-9]+$/", "", $adminHandler->getServerVersion());
136+
137+
if (version_compare($version, '2.6.0') >= 0) {
138+
// 2.6 will also allow the following document keys, while 2.5 will not
139+
$keys[] = ".";
140+
$keys[] = ":";
141+
$keys[] = "@";
142+
$keys[] = "-.:@";
143+
$keys[] = "foo@bar.baz.com";
144+
$keys[] = ":.foo@bar-bar_bar.baz.com.:";
145+
}
146+
118147
foreach ($keys as $key) {
119148
$document = new Document();
120149
$document->someAttribute = 'someValue';
@@ -148,10 +177,27 @@ public function testCreateDocumentWithInvalidKeys()
148177
$collection = $this->collection;
149178
$documentHandler = new DocumentHandler($connection);
150179

151-
$keys = array("", " ", " bar", "bar ", "/", "?", "abcdef gh", "abcxde&", "mötörhead", "this-key-will-be-too-long-to-be-processed-successfully-would-you-agree-with-me-sure-you-will-because-there-is-a-limit-of-254-characters-per-key-which-this-string-will-not-conform-to-if-you-are-still-reading-this-you-should-probably-do-something-else-right-now-REALLY");
180+
$keys = array(
181+
"",
182+
" ",
183+
" bar",
184+
"bar ",
185+
"/",
186+
"?",
187+
"abcdef gh",
188+
"abcxde&",
189+
"mötörhead",
190+
"this-key-will-be-too-long-to-be-processed-successfully-would-you-agree-with-me-sure-you-will-because-there-is-a-limit-of-254-characters-per-key-which-this-string-will-not-conform-to-if-you-are-still-reading-this-you-should-probably-do-something-else-right-now-REALLY",
191+
"#",
192+
"|",
193+
"ü",
194+
"~",
195+
"<>",
196+
"µµ"
197+
);
152198

153199
foreach ($keys as $key) {
154-
$document = new Document();
200+
$document = new Document();
155201
$document->someAttribute = 'someValue';
156202

157203
$caught = false;

0 commit comments

Comments
 (0)