/**
  * test for getting the , true, true for a collection
  */
 public function testGetRevision()
 {
     $collectionHandler = $this->collectionHandler;
     $documentHandler = $this->documentHandler;
     $collection = new Collection();
     $collection->setName("ArangoDB_PHP_TestSuite_TestCollection_01");
     $collection->setId($collectionHandler->create($collection));
     $revision = $collectionHandler->getRevision($collection->getName());
     $this->assertArrayHasKey('revision', $revision);
     $document = Document::createFromArray(array('someAttribute' => 'someValue1', 'someOtherAttribute' => 'someOtherValue'));
     $documentHandler->save($collection->getId(), $document);
     $revision2 = $collectionHandler->getRevision($collection->getName());
     $this->assertNotEquals($revision2['revision'], $revision['revision']);
     $collectionHandler->drop($collection);
 }
 /**
  * Test export as Edge object
  */
 public function testExportEdgeObjects()
 {
     if (!$this->hasExportApi) {
         return;
     }
     try {
         $this->collectionHandler->drop('ArangoDB_PHP_TestSuite_TestEdge');
     } catch (\Exception $e) {
     }
     $edgeCollection = new Collection();
     $edgeCollection->setName('ArangoDB_PHP_TestSuite_TestEdge');
     $edgeCollection->setType(Collection::TYPE_EDGE);
     $this->collectionHandler->add($edgeCollection);
     $edgeHandler = new EdgeHandler($this->connection);
     $vertexCollection = $this->collection->getName();
     for ($i = 0; $i < 100; ++$i) {
         $edgeHandler->saveEdge($edgeCollection, $vertexCollection . "/1", $vertexCollection . "/2", array("value" => $i));
     }
     $export = new Export($this->connection, $edgeCollection, array("_flat" => false));
     $cursor = $export->execute();
     $this->assertEquals(1, $cursor->getFetches());
     $this->assertNull($cursor->getId());
     $this->assertEquals(100, $cursor->getCount());
     $this->assertEquals(1, $cursor->getFetches());
     $all = $cursor->getNextBatch();
     $this->assertEquals(100, count($all));
     foreach ($all as $doc) {
         $this->assertTrue($doc instanceof Document);
         $this->assertTrue($doc instanceof Edge);
     }
     $this->assertFalse($cursor->getNextBatch());
     $this->collectionHandler->drop('ArangoDB_PHP_TestSuite_TestEdge');
 }
Example #3
0
} catch (Exception $e) {
    // do nothing
}
/* drop edge if it exists */
try {
    $edge = $collections->get("edges");
    $collections->drop($edge);
} catch (Exception $e) {
    // do nothing
}
$vertex = new Collection();
$vertex->setName("vertices");
$collections->add($vertex);
$vertex = $vertex->getId();
$edge = new Collection();
$edge->setName("edges");
$edge->setType(3);
$collections->add($edge);
$edge = $edge->getId();
print "Reading graph file...\n";
$graphfilename = $argv[1];
$actionsfilename = $argv[2];
$fp = fopen($graphfilename, "rb");
if (0x1234abcd != get_next_int64($fp)) {
    print "Endianness check failed.  Endianness swap not implemented.";
    exit;
}
$nv = get_next_int64($fp);
$ne = get_next_int64($fp);
$off = get_int64_array($fp, $nv + 1);
$ind = get_int64_array($fp, $ne);
<?php

namespace triagens\ArangoDb;

require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
try {
    $connection = new Connection($connectionOptions);
    $handler = new CollectionHandler($connection);
    if ($handler->has('example')) {
        $handler->delete('example');
    }
    $col = new Collection();
    $col->setName('example');
    $result = $handler->add($col);
    // create a statement to insert 100 example documents
    $statement = new Statement($connection, array('query' => 'FOR i IN 1..100 INSERT { _key: CONCAT("example", i) } IN example'));
    $statement->execute();
    // print number of documents
    var_dump($handler->getCount('example'));
    // later on, we can assemble a list of document keys
    $keys = array();
    for ($i = 1; $i <= 100; ++$i) {
        $keys[] = 'example' . $i;
    }
    // and fetch all the documents at once by their keys
    $documents = $handler->lookupByKeys('example', $keys);
    var_dump($documents);
    // we can also bulk-remove them:
    $result = $handler->removeByKeys('example', $keys);
    var_dump($result);
    // print number of documents after bulk removal
<?php

namespace triagens\ArangoDb;

require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
try {
    $connection = new Connection($connectionOptions);
    $handler = new CollectionHandler($connection);
    // create a new collection
    $col = new Collection();
    $col->setName("hihi");
    $result = $handler->add($col);
    var_dump($result);
    // check if a collection exists
    $result = $handler->has("foobar");
    var_dump($result);
    // get an existing collection
    $result = $handler->get("hihi");
    var_dump($result);
    // get an existing collection
    $result = $handler->get("hihi");
    var_dump($result);
    // get number of documents from an existing collection
    $result = $handler->getCount("hihi");
    var_dump($result);
    // get figures for an existing collection
    $result = $handler->getFigures("hihi");
    var_dump($result);
    // delete the collection
    $result = $handler->delete("hihi");
    var_dump($result);
 public function testCreateMixedBatchWithPartIds()
 {
     $edgeCollection = $this->edgeCollection;
     $batch = new Batch($this->connection);
     $this->assertInstanceOf('\\triagens\\ArangoDb\\Batch', $batch);
     // Create collection
     $connection = $this->connection;
     $collection = new Collection();
     $collectionHandler = new CollectionHandler($connection);
     $name = 'ArangoDB_PHP_TestSuite_TestCollection_02';
     $collection->setName($name);
     $batch->nextBatchPartId('testCollection1');
     $response = $collectionHandler->add($collection);
     $this->assertTrue(is_numeric($response), 'Did not return a fake numeric id!');
     $batch->process();
     $resultingCollectionId = $batch->getProcessedPartResponse('testCollection1');
     $testCollection1Part = $batch->getPart('testCollection1');
     $this->assertTrue($testCollection1Part->getHttpCode() == 200, 'Did not return an HttpCode 200!');
     $resultingCollection = $collectionHandler->get($batch->getProcessedPartResponse('testCollection1'));
     $resultingAttribute = $resultingCollection->getName();
     $this->assertTrue($name === $resultingAttribute, 'The created collection name and resulting collection name do not match!');
     $this->assertEquals(Collection::getDefaultType(), $resultingCollection->getType());
     $batch = new Batch($this->connection);
     // Create documents
     $documentHandler = $this->documentHandler;
     $batch->nextBatchPartId('doc1');
     $document = Document::createFromArray(array('someAttribute' => 'someValue', 'someOtherAttribute' => 'someOtherValue'));
     $documentId = $documentHandler->add($resultingCollectionId, $document);
     $this->assertTrue(is_numeric($documentId), 'Did not return a fake numeric id!');
     for ($i = 0; $i <= 10; ++$i) {
         $document = Document::createFromArray(array('someAttribute' => 'someValue' . $i, 'someOtherAttribute' => 'someOtherValue2' . $i));
         $documentId = $documentHandler->add($resultingCollectionId, $document);
     }
     $this->assertTrue(is_numeric($documentId), 'Did not return a fake numeric id!');
     $batch->process();
     // try getting processed response through batchpart
     $testDocument1PartResponse = $batch->getPart('doc1')->getProcessedResponse();
     // try getting it from batch
     $testDocument2PartResponse = $batch->getProcessedPartResponse(1);
     $batch = new Batch($this->connection);
     $docId1 = explode('/', $testDocument1PartResponse);
     $docId2 = explode('/', $testDocument2PartResponse);
     $documentHandler->getById($resultingCollectionId, $docId1[1]);
     $documentHandler->getById($resultingCollectionId, $docId2[1]);
     $batch->process();
     $document1 = $batch->getProcessedPartResponse(0);
     $document2 = $batch->getProcessedPartResponse(1);
     $batch = new Batch($this->connection);
     // test edge creation
     $edgeDocument = new Edge();
     $edgeDocumentHandler = new EdgeHandler($connection);
     $edgeDocument->set('label', 'knows');
     $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $document1->getHandle(), $document2->getHandle(), $edgeDocument);
     $batch->process();
     $edge = $batch->getProcessedPartResponse(0);
     $this->assertFalse(is_a($edge, 'triagens\\ArangoDb\\HttpResponse'), 'Edge batch creation did return an error: ' . print_r($edge, true));
     $this->assertTrue($edge == !'', 'Edge batch creation did return empty string: ' . print_r($edge, true));
     $batch = new Batch($this->connection);
     $document = new Document();
     $documentHandler = new DocumentHandler($connection);
     $document->someAttribute = 'someValue';
     $documentHandler->add($resultingCollection->getId(), $document);
     // set the next batchpart id
     $batch->nextBatchPartId('myBatchPart');
     // set cursor options for the next batchpart
     $batch->nextBatchPartCursorOptions(array("sanitize" => true));
     // set batchsize to 10, so we can test if an additional http request is done when we getAll() a bit later
     $statement = new Statement($connection, array("query" => '', "count" => true, "batchSize" => 10, "sanitize" => true));
     $statement->setQuery('FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_02` RETURN a');
     $statement->execute();
     $documentHandler->removeById($resultingCollectionId, $docId1[1]);
     $documentHandler->removeById($resultingCollectionId, $docId2[1]);
     $batch->nextBatchPartId('docsAfterRemoval');
     $collectionHandler->getAllIds($resultingCollectionId);
     $batch->process();
     $stmtCursor = $batch->getProcessedPartResponse('myBatchPart');
     $this->assertTrue(count($stmtCursor->getAll()) == 13, 'At the time of statement execution there should be 13 documents found! Found: ' . count($stmtCursor->getAll()));
     // This fails but we'll just make a note because such a query is not needed to be batched.
     // $docsAfterRemoval=$batch->getProcessedPartResponse('docsAfterRemoval');
     // $this->assertTrue(count($docsAfterRemoval) == 1, 'At the time of statement execution there should be 3 documents found! Found: '.count($stmtCursor->getAll()));
     // Get previously created collection and delete it, from inside a batch
     $batch = new Batch($this->connection);
     $collectionHandler->delete($resultingCollectionId);
     $batch->process();
 }
 /**
  * Try to create and delete an edge collection
  */
 public function testCreateAndDeleteEdgeCollection()
 {
     $connection = $this->connection;
     $collection = new Collection();
     $collectionHandler = new CollectionHandler($connection);
     $name = 'ArangoDB_PHP_TestSuite_TestCollection_02';
     try {
         $collectionHandler->drop($name);
     } catch (Exception $e) {
         //Silence the exception
     }
     $collection->setName($name);
     $collection->setType(3);
     $collectionHandler->add($collection);
     $resultingCollection = $collectionHandler->get($name);
     $resultingAttribute = $resultingCollection->getName();
     $this->assertTrue($name === $resultingAttribute, 'The created collection name and resulting collection name do not match!');
     $this->assertEquals(Collection::TYPE_EDGE, $resultingCollection->getType());
     $collectionHandler->delete($collection);
 }
 /**
  * Creates a new collection on the server
  *
  * This will add the collection on the server and return its id
  * The id is mainly returned for backwards compatibility, but you should use the collection name for any reference to the collection.   *
  * This will throw if the collection cannot be created
  *
  * @throws Exception
  *
  * @param mixed $collection - collection object to be created on the server or a string with the name
  * @param array $options    - an array of options.
  *                          <p>Options are :<br>
  *                          <li>'type'            - 2 -> normal collection, 3 -> edge-collection</li>
  *                          <li>'waitForSync'     -  if set to true, then all removal operations will instantly be synchronised to disk / If this is not specified, then the collection's default sync behavior will be applied.</li>
  *                          <li>'journalSize'     -  journalSize value.</li>
  *                          <li>'isSystem'        -  false->user collection(default), true->system collection .</li>
  *                          <li>'isVolatile'      -  false->persistent collection(default), true->volatile (in-memory) collection .</li>
  *                          <li>'numberOfShards'  -  number of shards for the collection.</li>
  *                          <li>'shardKeys'       -  list of shard key attributes.</li>
  *                          </p>
  *
  * @return mixed - id of collection created
  */
 public function create($collection, $options = array())
 {
     if (is_string($collection)) {
         $name = $collection;
         $collection = new Collection();
         $collection->setName($name);
         foreach ($options as $key => $value) {
             $collection->{'set' . ucfirst($key)}($value);
         }
     }
     if ($collection->getWaitForSync() === null) {
         $collection->setWaitForSync($this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC));
     }
     if ($collection->getJournalSize() === null) {
         $collection->setJournalSize($this->getConnectionOption(ConnectionOptions::OPTION_JOURNAL_SIZE));
     }
     if ($collection->getIsSystem() === null) {
         $collection->setIsSystem($this->getConnectionOption(ConnectionOptions::OPTION_IS_SYSTEM));
     }
     if ($collection->getIsVolatile() === null) {
         $collection->setIsVolatile($this->getConnectionOption(ConnectionOptions::OPTION_IS_VOLATILE));
     }
     $type = $collection->getType() ? $collection->getType() : Collection::getDefaultType();
     $params = array(Collection::ENTRY_NAME => $collection->getName(), Collection::ENTRY_TYPE => $type, Collection::ENTRY_WAIT_SYNC => $collection->getWaitForSync(), Collection::ENTRY_JOURNAL_SIZE => $collection->getJournalSize(), Collection::ENTRY_IS_SYSTEM => $collection->getIsSystem(), Collection::ENTRY_IS_VOLATILE => $collection->getIsVolatile(), Collection::ENTRY_KEY_OPTIONS => $collection->getKeyOptions());
     // set extra cluster attributes
     if ($collection->getNumberOfShards() !== null) {
         $params[Collection::ENTRY_NUMBER_OF_SHARDS] = $collection->getNumberOfShards();
     }
     if (is_array($collection->getShardKeys())) {
         $params[Collection::ENTRY_SHARD_KEYS] = $collection->getShardKeys();
     }
     $response = $this->getConnection()->post(Urls::URL_COLLECTION, $this->json_encode_wrapper($params));
     //    $location = $response->getLocationHeader();
     //    if (!$location) {
     //      throw new ClientException('Did not find location header in server response');
     //    }
     $jsonResponse = $response->getJson();
     $id = $jsonResponse['id'];
     $collection->setId($id);
     return $id;
 }