public function replaceVertex($graph, $vertexId, Document $document, array $options = [], $collection = null)
    {
        if ($graph instanceof Graph) {
            $graph = $graph->getKey();
        }

        $parts = explode('/', $vertexId);
        if (count($parts) === 2) {
            list($collection, $vertexId) = $parts;
        }

        if ($collection === null) {
            $vertexCollections      = $this->getVertexCollections($graph);
            $vertexCollectionsCount = count($vertexCollections);
            if ($vertexCollectionsCount !== 1) {
                throw new ClientException('A collection must be provided.');
            }

            if ($vertexCollectionsCount === 1) {
                $collection = $vertexCollections[0];
            }
        }

        $options = array_merge([self::OPTION_REVISION => false], $options);

        $params = $this->includeOptionsInParams(
            $options, [
                'waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
                'policy'      => $this->getConnectionOption(ConnectionOptions::OPTION_REPLACE_POLICY)

            ]
        );

        //Include the revision for conditional updates if required
        if ($options[self::OPTION_REVISION] === true) {

            $revision = $document->getRevision();

            if (null !== $revision) {
                $params[ConnectionOptions::OPTION_REVISION] = $revision;
            }
        } elseif ($options[self::OPTION_REVISION]) {
            $params[ConnectionOptions::OPTION_REVISION] = $options[self::OPTION_REVISION];
        }

        $data = $document->getAll();
        $url  = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_VERTEX, $collection, $vertexId]);
        $url  = UrlHelper::appendParamsUrl($url, $params);

        $response = $this->getConnection()->put($url, $this->json_encode_wrapper($data));

        $jsonArray = $response->getJson();
        $vertex    = $jsonArray['vertex'];

        $document->setInternalId($vertex[Vertex::ENTRY_ID]);
        $document->setRevision($vertex[Vertex::ENTRY_REV]);


        return true;
    }
public function replaceVertex($graph, $vertexId, Document $document, array $options = [], $collection = null)
    {
        if ($graph instanceof Graph) {
            $graph = $graph->getKey();
        }

        $parts = explode('/', $vertexId);
        if (count($parts) === 2) {
            list($collection, $vertexId) = $parts;
        }

        if ($collection === null) {
            $vertexCollections      = $this->getVertexCollections($graph);
            $vertexCollectionsCount = count($vertexCollections);
            if ($vertexCollectionsCount !== 1) {
                throw new ClientException('A collection must be provided.');
            }

            if ($vertexCollectionsCount === 1) {
                $collection = $vertexCollections[0];
            }
        }

        $options = array_merge([self::OPTION_REVISION => false], $options);

        $params = $this->includeOptionsInParams(
            $options, [
                'waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
                'policy'      => $this->getConnectionOption(ConnectionOptions::OPTION_REPLACE_POLICY)

            ]
        );

        //Include the revision for conditional updates if required
        if ($options[self::OPTION_REVISION] === true) {

            $revision = $document->getRevision();

            if (null !== $revision) {
                $params[ConnectionOptions::OPTION_REVISION] = $revision;
            }
        } elseif ($options[self::OPTION_REVISION]) {
            $params[ConnectionOptions::OPTION_REVISION] = $options[self::OPTION_REVISION];
        }

        $data = $document->getAll();
        $url  = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_VERTEX, $collection, $vertexId]);
        $url  = UrlHelper::appendParamsUrl($url, $params);

        $response = $this->getConnection()->put($url, $this->json_encode_wrapper($data));

        $jsonArray = $response->getJson();
        $vertex    = $jsonArray['vertex'];

        $document->setInternalId($vertex[Vertex::ENTRY_ID]);
        $document->setRevision($vertex[Vertex::ENTRY_REV]);


        return true;
    }
public function replaceVertex ( $ graph , $ vertexId , Document $ document , array $ options = [ ] , $ collection = null ) { if ( $ graph instanceof Graph ) { $ graph = $ graph -> getKey ( ) ; } $ parts = explode ( '/' , $ vertexId ) ; if ( count ( $ parts ) === 2 ) { list ( $ collection , $ vertexId ) = $ parts ; } if ( $ collection === null ) { $ vertexCollections = $ this -> getVertexCollections ( $ graph ) ; $ vertexCollectionsCount = count ( $ vertexCollections ) ; if ( $ vertexCollectionsCount !== 1 ) { throw new ClientException ( 'A collection must be provided.' ) ; } if ( $ vertexCollectionsCount === 1 ) { $ collection = $ vertexCollections [ 0 ] ; } } $ options = array_merge ( [ self :: OPTION_REVISION => false ] , $ options ) ; $ params = $ this -> includeOptionsInParams ( $ options , [ 'waitForSync' => $ this -> getConnectionOption ( ConnectionOptions :: OPTION_WAIT_SYNC ) , 'policy' => $ this -> getConnectionOption ( ConnectionOptions :: OPTION_REPLACE_POLICY ) ] ) ; //Include the revision for conditional updates if required if ( $ options [ self :: OPTION_REVISION ] === true ) { $ revision = $ document -> getRevision ( ) ; if ( null !== $ revision ) { $ params [ ConnectionOptions :: OPTION_REVISION ] = $ revision ; } } elseif ( $ options [ self :: OPTION_REVISION ] ) { $ params [ ConnectionOptions :: OPTION_REVISION ] = $ options [ self :: OPTION_REVISION ] ; } $ data = $ document -> getAll ( ) ; $ url = UrlHelper :: buildUrl ( Urls :: URL_GRAPH , [ $ graph , Urls :: URLPART_VERTEX , $ collection , $ vertexId ] ) ; $ url = UrlHelper :: appendParamsUrl ( $ url , $ params ) ; $ response = $ this -> getConnection ( ) -> put ( $ url , $ this -> json_encode_wrapper ( $ data ) ) ; $ jsonArray = $ response -> getJson ( ) ; $ vertex = $ jsonArray [ 'vertex' ] ; $ document -> setInternalId ( $ vertex [ Vertex :: ENTRY_ID ] ) ; $ document -> setRevision ( $ vertex [ Vertex :: ENTRY_REV ] ) ; return true ; }
Replace an existing vertex in a graph, identified graph name and vertex id

This will update the vertex on the server

If policy is set to error (locally or globally through the ConnectionOptions)
and the passed document has a _rev value set, the database will check
that the revision of the to-be-replaced vertex is the same as the one given.<br><br>

@throws Exception

@param mixed    $graph      - graph name as a string or instance of Graph
@param mixed    $vertexId   - the vertex id as string or number
@param Document $document   - the vertex-document to be updated
@param mixed    $options    optional, an array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method):
<p>
<li><b>revision</b> - revision for conditional updates ('some-revision-id' [use the passed in revision id], false or true [use document's revision])</li>
<li><b>policy</b> - update policy to be used in case of conflict ('error', 'last' or NULL [use default])</li>
<li><b>waitForSync</b> - can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection</li>
</p>
@param string   $collection - if one uses a graph with more than one vertex collection one must provide the collection

@return bool - always true, will throw if there is an error
@since 1.2
Replace an existing vertex in a graph identified graph name and vertex id