/** * Update an existing edge in a graph, identified by graph name and edge id * * This will update the edge on the server * * This will throw if the edge cannot be updated * * If policy is set to error (locally or globally through the ConnectionOptions) * and the passed edge-document has a _rev value set, the database will check * that the revision of the to-be-replaced document 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 - patch edge-document which contains the attributes and values to be updated * @param mixed $options optional, array of options (see below) * <p> * <li><b>policy</b> - update policy to be used in case of conflict ('error', 'last' or NULL [use default])</li> * <li><b>keepNull</b> - can be used to instruct ArangoDB to delete existing attributes instead setting their values to null. Defaults to true (keep attributes when set to null)</li> * <li><b>waitForSync</b> - can be used to force synchronisation of the document update 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 updateEdge($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_UPDATE_POLICY); $params = $this->includeOptionsInParams($options, $params, array('waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC), 'keepNull' => true)); $policy = null; //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]; } 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); $result = $this->getConnection()->patch($url, $this->json_encode_wrapper($document->getAll())); $json = $result->getJson(); $edge = $json['edge']; $document->setRevision($edge[Edge::ENTRY_REV]); return true; }