arangodb / arangodb-php

PHP ODM for ArangoDB
https://www.arangodb.com
Apache License 2.0
182 stars 46 forks source link

Add non-existing options keys to return parameters in includeOptionsInParams #261

Closed ivanignatiev closed 5 years ago

ivanignatiev commented 5 years ago

Hello,

The code from tutorial https://www.arangodb.com/tutorials/tutorial-php/ without collection creation will throw an error :

$connectionOptions = array(
    ArangoDBClient\ConnectionOptions::OPTION_DATABASE => 'database',
    // server endpoint to connect to
    ArangoDBClient\ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529',
    // authorization type to use (currently supported: 'Basic')
    ArangoDBClient\ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
    // user for basic authorization
    ArangoDBClient\ConnectionOptions::OPTION_AUTH_USER => 'root',
    // password for basic authorization
    ArangoDBClient\ConnectionOptions::OPTION_AUTH_PASSWD => '',
    // connection persistence on server. can use either 'Close' (one-time connections) or 'Keep-Alive' (re-used connections)
    ArangoDBClient\ConnectionOptions::OPTION_CONNECTION => 'Close',
    // connect timeout in seconds
    ArangoDBClient\ConnectionOptions::OPTION_TIMEOUT => 3,
    // whether or not to reconnect when a keep-alive connection has timed out on server
    ArangoDBClient\ConnectionOptions::OPTION_RECONNECT => true,
    // optionally create new collections when inserting documents
    ArangoDBClient\ConnectionOptions::OPTION_CREATE => true,
    // optionally create new collections when inserting documents
    ArangoDBClient\ConnectionOptions::OPTION_UPDATE_POLICY => ArangoDBClient\UpdatePolicy::LAST
);

$connection = new ArangoDBClient\Connection($connectionOptions);
$documentHandler = new ArangoDBClient\DocumentHandler($connection);
$document = new ArangoDBClient\Document();
$document->set('title', 'title');

$documentId = $documentHandler->save('collection', $document);
Fatal error: Uncaught ArangoDBClient\ServerException: 1203 collection or view not found

The issue cause in Handler::includeOptionsInParams. $options parameter of Document::save function by default is empty object [] but Handler::includeOptionsInParams only replaces parameters with existing $options keys. As $options is empty, all parameters are ignored and OPTION_CREATE = true is ignored as well.

Other way to solve this issue is to assign correct default value to $options parameter of functions.

Please note that for legal reasons we require you to sign the Contributor Agreement before we can accept your pull requests.

jsteemann commented 5 years ago

Hi @ivanignatiev

Many thanks for your improvements, they look good! We are using an Apache 2 contributor license agreement (CLA) for ArangoDB and its companion projects, which for legal reasons we require to get signed once by each contributor. The CLA can be found here: https://www.arangodb.com/documents/cla.pdf In order to accept your changes may you just fill in the form, sign and send a scanned copy over to cla[at]arangodb[.]com or via fax to +49-221-2722999-88 Thanks very much!

ivanignatiev commented 5 years ago

@jsteemann Thank you ! I have signed the agreement and sent the scan by email

jsteemann commented 5 years ago

Thanks!