/** * Replace an existing edge in a graph, identified graph name and edge id * * This will replace the edge on the server * * This will throw if the edge cannot be Replaced * * 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 edge 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 $edgeId - edge id as string or number * @param mixed $label - label for the edge or '' * @param Edge $document - edge document to be updated * @param mixed $options optional, array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method) * <p> * <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 */ public function replaceEdge($graph, $edgeId, $label, Edge $document, $options = array(), $collection = null) { if ($graph instanceof Graph) { $graph = $graph->getKey(); } $parts = explode("/", $edgeId); if (count($parts) === 2) { $edgeId = $parts[1]; $collection = $parts[0]; } if (count($this->getEdgeCollections($graph)) !== 1 && $collection === null) { throw new ClientException('A collection must be provided.'); } else { if (count($this->getEdgeCollections($graph)) === 1 && $collection === null) { $collection = $this->getEdgeCollections($graph); $collection = $collection[0]; } } $options = array_merge(array(self::OPTION_REVISION => false), $options); // This preserves compatibility for the old policy parameter. $params = array(); $params = $this->validateAndIncludeOldSingleParameterInParams($options, $params, ConnectionOptions::OPTION_REPLACE_POLICY); $params = $this->includeOptionsInParams($options, $params, array('waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC))); //Include the revision for conditional updates if required if ($options[self::OPTION_REVISION] === true) { $revision = $document->getRevision(); if (!is_null($revision)) { $params[ConnectionOptions::OPTION_REVISION] = $revision; } } elseif ($options[self::OPTION_REVISION]) { $params[ConnectionOptions::OPTION_REVISION] = $options[self::OPTION_REVISION]; } $data = $document->getAll(); if (!is_null($label)) { $document->set('$label', $label); } $url = UrlHelper::buildUrl(Urls::URL_GRAPH, array($graph, Urls::URLPART_EDGE, $collection, $edgeId)); $url = UrlHelper::appendParamsUrl($url, $params); $response = $this->getConnection()->PUT($url, $this->json_encode_wrapper($data)); $jsonArray = $response->getJson(); $edge = $jsonArray['edge']; $document->setInternalId($edge[Edge::ENTRY_ID]); $document->setRevision($edge[Edge::ENTRY_REV]); return true; }