/**
  * Remove a edge from a graph, identified by the graph name and edge id<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  $revision  - optional revision of the edge to be deleted
  * @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 removal 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 removeEdge($graph, $edgeId, $revision = null, $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];
         }
     }
     // This preserves compatibility for the old policy parameter.
     $params = array();
     $params = $this->validateAndIncludeOldSingleParameterInParams($options, $params, ConnectionOptions::OPTION_DELETE_POLICY);
     $params = $this->includeOptionsInParams($options, $params, array('waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC), 'keepNull' => true));
     if (!is_null($revision)) {
         $params[ConnectionOptions::OPTION_REVISION] = $revision;
     }
     $url = UrlHelper::buildUrl(Urls::URL_GRAPH, array($graph, Urls::URLPART_EDGE, $collection, $edgeId));
     $url = UrlHelper::appendParamsUrl($url, $params);
     $this->getConnection()->delete($url);
     return true;
 }
 /**
  * Get registered user functions
  *
  * The method can optionally be passed a $namespace parameter to narrow the results down to a specific namespace.
  *
  * @param null $namespace
  *
  * @throws Exception throw exception if the request failed
  *
  * @return mixed true if successful without a return value or the return value if one was set in the action
  */
 public function getRegisteredUserFunctions($namespace = null)
 {
     $url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION, array());
     if (!is_null($namespace)) {
         $url = UrlHelper::appendParamsUrl($url, array('namespace' => $namespace));
     }
     $response = $this->_connection->get($url);
     $responseArray = $response->getJson();
     return $responseArray;
 }
 /**
  * Execute the export
  *
  * This will return the results as a Cursor. The cursor can then be used to iterate the results.
  *
  * @throws Exception
  * @return ExportCursor
  */
 public function execute()
 {
     $data = array(self::ENTRY_FLUSH => $this->_flush, self::ENTRY_COUNT => true);
     if ($this->_batchSize > 0) {
         $data[self::ENTRY_BATCHSIZE] = $this->_batchSize;
     }
     if ($this->_limit > 0) {
         $data[self::ENTRY_LIMIT] = $this->_limit;
     }
     if (is_array($this->_restrictions)) {
         $data[self::ENTRY_RESTRICT] = $this->_restrictions;
     }
     $collection = $this->_collection;
     if ($collection instanceof Collection) {
         $collection = $collection->getName();
     }
     $url = UrlHelper::appendParamsUrl(Urls::URL_EXPORT, array("collection" => $collection));
     $response = $this->_connection->post($url, $this->getConnection()->json_encode_wrapper($data));
     return new ExportCursor($this->_connection, $response->getJson(), $this->getCursorOptions());
 }
 /**
  * Import documents into a collection
  *
  * This will throw on all errors except insertion errors
  *
  * @throws Exception
  *
  * @param mixed $collectionId - collection id as string or number
  * @param mixed $importData   - The data to import. This can be a string holding the data according to the type of import, or an array of documents
  * @param array $options      - optional - an array of options.
  *                            <p>Options are :<br>
  *                            <li>
  *                            'type' -  if type is not set or it's set to '' or null, the Header-Value format must be provided in the import file.<br>
  *                            <p>
  *                            <li>                       if set to 'documents', then the file's content must have its documents line by line. Each line will be interpreted as a document.</li>
  *                            <li>                       if set to 'array' then the file's content must provide the documents as a list of documents instead of the above line by line.</li>
  *                            <br>
  *                            More info on how the import functionality works: <a href ="https://github.com/triAGENS/ArangoDB/wiki/HttpImport">https://github.com/triAGENS/ArangoDB/wiki/HttpImport</a>
  *                            </p>
  *                            <br>
  *
  * </li>
  * <li>'createCollection' - If true, create the collection if it doesn't exist. Defaults to false </li>
  * </p>
  *
  * @return int - number of documents that were deleted
  */
 public function import($collectionId, $importData, $options = array('createCollection' => false, 'type' => null))
 {
     $tmpContent = '';
     if (is_array($importData)) {
         foreach ($importData as $document) {
             /** @var $document Document */
             $tmpContent .= $document->toJson() . "\r\n";
         }
         $importData = $tmpContent;
         unset($tmpContent);
         $options['type'] = 'documents';
     }
     $params[self::OPTION_COLLECTION] = $collectionId;
     if (array_key_exists('createCollection', $options)) {
         $params[self::OPTION_CREATE_COLLECTION] = $options['createCollection'] == true ? true : false;
     }
     if (array_key_exists('type', $options)) {
         switch ($options['type']) {
             case "documents":
                 $params[self::OPTION_TYPE] = 'documents';
                 break;
             case "array":
                 $params[self::OPTION_TYPE] = 'array';
                 break;
         }
     }
     $url = UrlHelper::appendParamsUrl(Urls::URL_IMPORT, $params);
     $response = $this->getConnection()->post($url, $importData);
     $responseArray = $response->getJson();
     return $responseArray;
 }
 /**
  * Returns a description of the statistics returned by getServerStatistics().
  * The returned objects contains a list of statistics groups in the attribute groups
  * and a list of statistics figures in the attribute figures.
  * For more information on the statistics returned, please lookup the statistics interface description at
  *
  * @link  http://www.arangodb.com/manuals/1.3.devel/HttpSystem.html#HttpSystemAdminStatistics
  *
  * This will throw if the statistics-description cannot be retrieved
  *
  * @throws Exception
  *
  * @param array $options - an array of options that define the result-set:
  *
  * <p>Options are :<br>
  * <li>'granularity' - use minutes for a granularity of minutes, hours for hours, and days for days. The default is minutes.</li>
  * <li>'figures' - a list of figures, comma-separated. Possible figures are httpConnections. You can use all to get all figures. The default is httpConnections.</li>
  * <li>'length' - If you want a time series, the maximal length of the series as integer. You can use all to get all available information. You can use current to get the latest interval.</li>
  *
  * @return array
  *
  * @see   getServerStatistics()
  *
  * @since 1.3
  */
 public function getServerStatisticsDescription($options = array())
 {
     $url = UrlHelper::appendParamsUrl(Urls::URL_ADMIN_STATISTICS_DESCRIPTION, $options);
     $response = $this->getConnection()->get($url);
     $data = $response->getJson();
     return $data;
 }
 /**
  * Remove a user, identified by the username
  *
  * @throws Exception
  *
  * @param mixed $username - username as a string, of the user that is to be deleted
  *
  * @return bool - always true, will throw if there is an error
  */
 public function removeUser($username)
 {
     // This preserves compatibility for the old policy parameter.
     $params = array();
     $url = UrlHelper::buildUrl(Urls::URL_USER, array($username));
     $url = UrlHelper::appendParamsUrl($url, $params);
     $this->getConnection()->delete($url);
     return true;
 }
 /**
  * Remove a document from a collection (internal method)
  *
  * @throws Exception
  *
  * @param string $url          - the server-side URL being called
  * @param string $collectionId - collection id as string or number
  * @param mixed  $documentId   - document id as string or number
  * @param mixed $revision      - optional revision of the document to be deleted
  * @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>Options are :
  *                             <li>'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])</li>
  *                             <li>'waitForSync' - can be used to force synchronisation of the document removal operation to disk even in case that the waitForSync flag had been disabled for the entire collection</li>
  *                             </p>
  *
  * @return bool - always true, will throw if there is an error
  */
 protected function erase($url, $collectionId, $documentId, $revision = null, $options = array())
 {
     // This preserves compatibility for the old policy parameter.
     $params = array();
     $params = $this->validateAndIncludeOldSingleParameterInParams($options, $params, ConnectionOptions::OPTION_DELETE_POLICY);
     $params = $this->includeOptionsInParams($options, $params, array('waitForSync' => ConnectionOptions::OPTION_WAIT_SYNC));
     if (!is_null($revision)) {
         $params[ConnectionOptions::OPTION_REVISION] = $revision;
     }
     $url = UrlHelper::buildUrl($url, array($collectionId, $documentId));
     $url = UrlHelper::appendParamsUrl($url, $params);
     $this->getConnection()->delete($url);
     return true;
 }
 /**
  * Processes this batch. This sends the captured requests to the server as one batch.
  *
  * @throws ClientException
  * @return bool - true if processing of the batch was  or the HttpResponse object in case of a failure. A successful process just means that tha parts were processed. Each part has it's own response though and should be checked on its own.
  */
 public function process()
 {
     $this->stopCapture();
     $this->setBatchRequest(true);
     $data = '';
     $batchParts = $this->getBatchParts();
     if (count($batchParts) == 0) {
         throw new ClientException('Can\'t process empty batch.');
     }
     /** @var $partValue BatchPart */
     foreach ($batchParts as $partValue) {
         $data .= '--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL;
         $data .= 'Content-Type: application/x-arango-batchpart' . HttpHelper::EOL;
         if (!is_null($partValue->getId())) {
             $data .= 'Content-Id: ' . (string) $partValue->getId() . HttpHelper::EOL . HttpHelper::EOL;
         } else {
             $data .= HttpHelper::EOL;
         }
         $data .= (string) $partValue->getRequest() . HttpHelper::EOL;
     }
     $data .= '--' . HttpHelper::MIME_BOUNDARY . '--' . HttpHelper::EOL . HttpHelper::EOL;
     $params = array();
     $url = UrlHelper::appendParamsUrl(Urls::URL_BATCH, $params);
     $this->_batchResponse = $this->_connection->post($url, $data);
     if ($this->_batchResponse->getHttpCode() !== 200) {
         return $this->_batchResponse;
     }
     $body = $this->_batchResponse->getBody();
     $body = trim($body, '--' . HttpHelper::MIME_BOUNDARY . '--');
     $batchParts = $this->splitWithContentIdKey('--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL, $body);
     foreach ($batchParts as $partKey => $partValue) {
         $response = new HttpResponse($partValue);
         $body = $response->getBody();
         $response = new HttpResponse($body);
         $batchPartResponses[$partKey] = $response;
         $this->getPart($partKey)->setResponse($batchPartResponses[$partKey]);
     }
     return $this;
 }
 /**
  * Get connected edges for a given vertex
  *
  * @throws Exception
  *
  * @param mixed  $collectionId - edge-collection id as string or number
  * @param mixed  $vertexHandle - the vertex involved
  * @param string $direction    - optional defaults to 'any'. Other possible Values 'in' & 'out'
  * @param array $options       - optional, array of options
  *                               <p>Options are :
  *                               <li>'_includeInternals' - true to include the internal attributes. Defaults to false</li>
  *                               <li>'_ignoreHiddenAttributes' - true to show hidden attributes. Defaults to false</li>
  *                               </p>
  *
  * @return array - array of connected edges
  * @since 1.0
  */
 public function edges($collectionId, $vertexHandle, $direction = 'any', array $options = array())
 {
     $params = array(self::OPTION_VERTEX => $vertexHandle, self::OPTION_DIRECTION => $direction);
     $url = UrlHelper::appendParamsUrl(Urls::URL_EDGES . '/' . urlencode($collectionId), $params);
     $response = $this->getConnection()->get($url);
     $json = $response->getJson();
     $edges = array();
     foreach ($json[self::ENTRY_EDGES] as $data) {
         $edges[] = $this->createFromArrayWithContext($data, $options);
     }
     return $edges;
 }
 /**
  * Get edges for a given vertex
  *
  * @throws Exception
  *
  * @param mixed  $collectionId - edge-collection id as string or number
  * @param mixed  $vertexHandle - the vertex involved
  * @param string $direction    - optional defaults to 'any'. Other possible Values 'in' & 'out'
  *
  * @return array - array of cursors
  * @since 1.0
  */
 public function edges($collectionId, $vertexHandle, $direction = 'any')
 {
     $params = array(self::OPTION_COLLECTION => $collectionId, self::OPTION_VERTEX => $vertexHandle, self::OPTION_DIRECTION => $direction);
     $url = UrlHelper::appendParamsUrl(Urls::URL_EDGE, $params);
     $response = $this->getConnection()->get($url);
     $json = $response->getJson();
     return $json;
 }