Skip to content

Commit a9ba3ed

Browse files
committed
various changes
1 parent 4c88529 commit a9ba3ed

13 files changed

+595
-57
lines changed

CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1+
Release notes for the ArangoDB-PHP driver 3.4.x
2+
===============================================
3+
4+
Starting with release 3.4.0, the following constants were removed from the
5+
`CollectionHandler` class:
6+
7+
* `OPTION_IGNORE_NULL`
8+
* `OPTION_CONSTRAINT`
9+
10+
These constants were geo-index related, and the geo-index functionality changes in ArangoDB
11+
3.4 have made these constants obsolete.
12+
13+
For the same reason, the `createGeoIndex` function signature in the same class has
14+
changed from
15+
```
16+
public function createGeoIndex($collectionId, array $fields, $geoJson = null, $constraint = null, $ignoreNull = null)
17+
```
18+
to just
19+
```
20+
public function createGeoIndex($collectionId, array $fields, $geoJson = null)
21+
```
22+
23+
Additionally the 3.4 release of the driver adds support for the following collection
24+
properties:
25+
26+
* replicationFactor: number of replicas to keep per shard in a cluster environment
27+
(a replication factor of 1 will be used if this is not specified)
28+
* shardingStrategy: sharding strategy to be used for the collection
29+
30+
The `Collection` class also got the new methods `setReplicationFactor`, `getReplicationFactor`,
31+
`setShardingStrategy` and `getShardingStrategy`.
32+
33+
A method `getEntries` was added to the `QueryCacheHandler` class, which allows to
34+
peek into the contents of the query cache at runtime.
35+
36+
The single-document APIs in class `DocumentHandler` have been augmented so they support
37+
the attributes `returnOld` and `returnNew`. This allows retrieving the previous version
38+
of documents on update/replace/remove, and returning the new version of documents after
39+
insert/update/replace.
40+
In addition, the `save` method of `DocumentHandler` will now understand the `overwrite`
41+
option, which will turn an insert into a replace operation in case the insert fails with a
42+
unique constraint violation error on the primary key.
43+
44+
The method `insert` was introduced in `DocumentHandler` as an alias for `save` for consistency
45+
with the server-side naming.
46+
47+
148
Release notes for the ArangoDB-PHP driver 3.3.x
249
===============================================
350

lib/ArangoDBClient/AqlUserFunction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public function getRegisteredUserFunctions($namespace = null)
199199
if (isset($data['result'])) {
200200
return $data['result'];
201201
}
202+
// backwards compatibility
202203
return $data;
203204
}
204205

lib/ArangoDBClient/Collection.php

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,23 @@ class Collection
7272
/**
7373
* The collection numberOfShards value (might be NULL for new collections)
7474
*
75-
* @var int - numberOfShards value
75+
* @var mixed - numberOfShards value
7676
*/
7777
private $_numberOfShards;
78+
79+
/**
80+
* The replicationFactor value (might be NULL for new collections)
81+
*
82+
* @var mixed - replicationFactor value
83+
*/
84+
private $_replicationFactor;
85+
86+
/**
87+
* The shardingStrategy value (might be NULL for new collections)
88+
*
89+
* @var mixed - shardingStrategy value
90+
*/
91+
private $_shardingStrategy;
7892

7993
/**
8094
* The collection shardKeys value (might be NULL for new collections)
@@ -146,6 +160,16 @@ class Collection
146160
* Collection 'numberOfShards' index
147161
*/
148162
const ENTRY_NUMBER_OF_SHARDS = 'numberOfShards';
163+
164+
/**
165+
* Collection 'replicationFactor' index
166+
*/
167+
const ENTRY_REPLICATION_FACTOR = 'replicationFactor';
168+
169+
/**
170+
* Collection 'shardingStrategy' index
171+
*/
172+
const ENTRY_SHARDING_STRATEGY = 'shardingStrategy';
149173

150174
/**
151175
* Collection 'shardKeys' index
@@ -247,14 +271,16 @@ public static function getDefaultType()
247271
*/
248272
public function __clone()
249273
{
250-
$this->_id = null;
251-
$this->_name = null;
252-
$this->_waitForSync = null;
253-
$this->_journalSize = null;
254-
$this->_isSystem = null;
255-
$this->_isVolatile = null;
256-
$this->_numberOfShards = null;
257-
$this->_shardKeys = null;
274+
$this->_id = null;
275+
$this->_name = null;
276+
$this->_waitForSync = null;
277+
$this->_journalSize = null;
278+
$this->_isSystem = null;
279+
$this->_isVolatile = null;
280+
$this->_numberOfShards = null;
281+
$this->_replicationFactor = null;
282+
$this->_shardingStrategy = null;
283+
$this->_shardKeys = null;
258284
}
259285

260286
/**
@@ -313,6 +339,14 @@ public function getAll()
313339
if (null !== $this->_numberOfShards) {
314340
$result[self::ENTRY_NUMBER_OF_SHARDS] = $this->_numberOfShards;
315341
}
342+
343+
if (null !== $this->_replicationFactor) {
344+
$result[self::ENTRY_REPLICATION_FACTOR] = $this->_replicationFactor;
345+
}
346+
347+
if (null !== $this->_shardingStrategy) {
348+
$result[self::ENTRY_SHARDING_STRATEGY] = $this->_shardingStrategy;
349+
}
316350

317351
if (is_array($this->_shardKeys)) {
318352
$result[self::ENTRY_SHARD_KEYS] = $this->_shardKeys;
@@ -401,6 +435,18 @@ public function set($key, $value)
401435

402436
return;
403437
}
438+
439+
if ($key === self::ENTRY_REPLICATION_FACTOR) {
440+
$this->setReplicationFactor($value);
441+
442+
return;
443+
}
444+
445+
if ($key === self::ENTRY_SHARDING_STRATEGY) {
446+
$this->setShardingStrategy($value);
447+
448+
return;
449+
}
404450

405451
if ($key === self::ENTRY_SHARD_KEYS) {
406452
$this->setShardKeys($value);
@@ -697,12 +743,58 @@ public function setNumberOfShards($value)
697743
/**
698744
* Get the numberOfShards value (if already known)
699745
*
700-
* @return int - numberOfShards value
746+
* @return mixed - numberOfShards value
701747
*/
702748
public function getNumberOfShards()
703749
{
704750
return $this->_numberOfShards;
705751
}
752+
753+
754+
/**
755+
* Set the replicationFactor value
756+
*
757+
* @param int $value - replicationFactor value
758+
*
759+
* @return void
760+
*/
761+
public function setReplicationFactor($value)
762+
{
763+
assert(null === $value || is_numeric($value) || $value === 'satellite');
764+
$this->_replicationFactor = $value;
765+
}
766+
767+
/**
768+
* Get the replicationFactor value (if already known)
769+
*
770+
* @return mixed - replicationFactor value
771+
*/
772+
public function getReplicationFactor()
773+
{
774+
return $this->_replicationFactor;
775+
}
776+
777+
/**
778+
* Set the shardingStragy value
779+
*
780+
* @param string $value - shardingStrategy value
781+
*
782+
* @return void
783+
*/
784+
public function setShardingStrategy($value)
785+
{
786+
$this->_shardingStrategy = $value;
787+
}
788+
789+
/**
790+
* Get the sharding strategy value (if already known)
791+
*
792+
* @return mixed - shardingStrategy value
793+
*/
794+
public function getShardingStrategy()
795+
{
796+
return $this->_shardingStrategy;
797+
}
706798

707799
/**
708800
* Set the shardKeys value

lib/ArangoDBClient/CollectionHandler.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,6 @@ class CollectionHandler extends Handler
132132
*/
133133
const OPTION_GEO_INDEX = 'geo';
134134

135-
/**
136-
* ignoreNull option
137-
*/
138-
const OPTION_IGNORE_NULL = 'ignoreNull';
139-
140-
/**
141-
* constraint option
142-
*/
143-
const OPTION_CONSTRAINT = 'constraint';
144-
145135
/**
146136
* geoJson option
147137
*/
@@ -224,13 +214,16 @@ class CollectionHandler extends Handler
224214
* @param mixed $collection - collection object to be created on the server or a string with the name
225215
* @param array $options - an array of options.
226216
* <p>Options are :<br>
227-
* <li>'type' - 2 -> normal collection, 3 -> edge-collection</li>
228-
* <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>
229-
* <li>'journalSize' - journalSize value.</li>
230-
* <li>'isSystem' - false->user collection(default), true->system collection .</li>
231-
* <li>'isVolatile' - false->persistent collection(default), true->volatile (in-memory) collection .</li>
232-
* <li>'numberOfShards' - number of shards for the collection.</li>
233-
* <li>'shardKeys' - list of shard key attributes.</li>
217+
* <li>'type' - 2 -> normal collection, 3 -> edge-collection</li>
218+
* <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>
219+
* <li>'journalSize' - journalSize value.</li>
220+
* <li>'isSystem' - false->user collection(default), true->system collection .</li>
221+
* <li>'isVolatile' - false->persistent collection(default), true->volatile (in-memory) collection .</li>
222+
* <li>'keyOptions' - key options to use.</li>
223+
* <li>'numberOfShards' - number of shards for the collection.</li>
224+
* <li>'shardKeys' - array of shard key attributes.</li>
225+
* <li>'replicationFactor' - number of replicas to keep (default: 1).</li>
226+
* <li>'shardingStrategy' - sharding strategy to use in cluster.</li>
234227
* </p>
235228
*
236229
* @return mixed - id of collection created
@@ -276,6 +269,14 @@ public function create($collection, array $options = [])
276269
if ($collection->getNumberOfShards() !== null) {
277270
$params[Collection::ENTRY_NUMBER_OF_SHARDS] = $collection->getNumberOfShards();
278271
}
272+
273+
if ($collection->getReplicationFactor() !== null) {
274+
$params[Collection::ENTRY_REPLICATION_FACTOR] = $collection->getReplicationFactor();
275+
}
276+
277+
if ($collection->getShardingStrategy() !== null) {
278+
$params[Collection::ENTRY_SHARDING_STRATEGY] = $collection->getShardingStrategy();
279+
}
279280

280281
if (is_array($collection->getShardKeys())) {
281282
$params[Collection::ENTRY_SHARD_KEYS] = $collection->getShardKeys();
@@ -949,30 +950,20 @@ public function createPersistentIndex($collectionId, array $fields, $unique = nu
949950
* @param string $collectionId - the collection id
950951
* @param array $fields - an array of fields
951952
* @param boolean $geoJson - whether to use geoJson or not
952-
* @param boolean $constraint - whether this is a constraint or not
953-
* @param boolean $ignoreNull - whether to ignore null
954953
*
955954
* @link https://docs.arangodb.com/HTTP/Indexes/Geo.html
956955
*
957956
* @return array - server response of the created index
958957
* @throws \ArangoDBClient\Exception
959958
*/
960-
public function createGeoIndex($collectionId, array $fields, $geoJson = null, $constraint = null, $ignoreNull = null)
959+
public function createGeoIndex($collectionId, array $fields, $geoJson = null)
961960
{
962961
$indexOptions = [];
963962

964963
if ($geoJson) {
965964
$indexOptions[self::OPTION_GEOJSON] = (bool) $geoJson;
966965
}
967966

968-
if ($constraint) {
969-
$indexOptions[self::OPTION_CONSTRAINT] = (bool) $constraint;
970-
}
971-
972-
if ($ignoreNull) {
973-
$indexOptions[self::OPTION_IGNORE_NULL] = $ignoreNull;
974-
}
975-
976967
return $this->index($collectionId, self::OPTION_GEO_INDEX, $fields, null, $indexOptions);
977968
}
978969

0 commit comments

Comments
 (0)