/**
  * Get the collection associated to a model class
  *
  * @param string $class
  *
  * @return Collection
  */
 public function getCollection($class)
 {
     if (!isset($this->collections[$class])) {
         $info = $this->resolver->resolve($class);
         $this->collections[$class] = $this->client->selectCollection($info['database'], $info['collection']);
     }
     return $this->collections[$class];
 }
Example #2
0
 /**
  * Open session
  *
  * @param string $savePath
  * @param string $name
  * @return bool
  */
 public function open($savePath, $name)
 {
     // Note: session save path is not used
     $this->sessionName = $name;
     $this->lifetime = (int) ini_get('session.gc_maxlifetime');
     $this->mongoCollection = $this->mongoClient->selectCollection($this->options->getDatabase(), $this->options->getCollection());
     $this->mongoCollection->createIndex([$this->options->getModifiedField() => 1], $this->options->useExpireAfterSecondsIndex() ? ['expireAfterSeconds' => $this->lifetime] : []);
     return true;
 }
 /**
  * Return a "MongoCollection" instance.
  *
  * @return \MongoCollection
  */
 private function getCollection()
 {
     if (null === $this->collection) {
         $this->collection = $this->mongo->selectCollection($this->options['database'], $this->options['collection']);
     }
     return $this->collection;
 }
 /**
  * Delete a reserved job from the queue.
  *
  * @param  string $queue
  * @param  string $id
  * @return void
  */
 public function deleteReserved($queue, $id)
 {
     // original query: $this->database->table($this->table)->where('_id', $id)->delete();
     try {
         $result = $this->client->selectCollection($this->databaseName, $this->table)->deleteOne(['_id' => $id], ['$isolated' => 1]);
     } catch (Exception $e) {
         printf("Other error: %s\n", $e->getMessage());
         exit;
     }
 }
 public function testSelectCollectionPassesReadPreferenceAndWriteConcern()
 {
     $collectionOptions = ['readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
     $client = new Client($this->getUri());
     $collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName(), $collectionOptions);
     $debug = $collection->__debugInfo();
     $this->assertInstanceOf('MongoDB\\Driver\\ReadPreference', $debug['readPreference']);
     $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
     $this->assertInstanceOf('MongoDB\\Driver\\WriteConcern', $debug['writeConcern']);
     $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
 }
Example #6
0
 /**
  * Constructor.
  *
  * @param Client|Manager $mongodb    MongoDB library or driver client
  * @param string         $database   Database name
  * @param string         $collection Collection name
  * @param int            $level      The minimum logging level at which this handler will be triggered
  * @param Boolean        $bubble     Whether the messages that are handled can bubble up the stack or not
  */
 public function __construct($mongodb, $database, $collection, $level = Logger::DEBUG, $bubble = true)
 {
     if (!($mongodb instanceof Client || $mongodb instanceof Manager)) {
         throw new \InvalidArgumentException('MongoDB\\Client or MongoDB\\Driver\\Manager instance required');
     }
     if ($mongodb instanceof Client) {
         $this->collection = $mongodb->selectCollection($database, $collection);
     } else {
         $this->manager = $mongodb;
         $this->namespace = $database . '.' . $collection;
     }
     parent::__construct($level, $bubble);
 }
Example #7
0
 public function testSelectCollectionPassesOptions()
 {
     $collectionOptions = ['readConcern' => new ReadConcern(ReadConcern::LOCAL), 'readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'typeMap' => ['root' => 'array'], 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
     $client = new Client($this->getUri());
     $collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName(), $collectionOptions);
     $debug = $collection->__debugInfo();
     $this->assertInstanceOf('MongoDB\\Driver\\ReadConcern', $debug['readConcern']);
     $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
     $this->assertInstanceOf('MongoDB\\Driver\\ReadPreference', $debug['readPreference']);
     $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
     $this->assertInternalType('array', $debug['typeMap']);
     $this->assertSame(['root' => 'array'], $debug['typeMap']);
     $this->assertInstanceOf('MongoDB\\Driver\\WriteConcern', $debug['writeConcern']);
     $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
 }
 public function testUpsertedIds()
 {
     $client = new \MongoDB\Client(Config::get('mongolab.uri') . '/' . Config::get('mongolab.database_name'));
     $preaggregated_collection = $client->selectCollection(Config::get('mongolab.database_name'), "update_many_test");
     $preaggregated_collection->drop();
     $preaggregated_collection->insertOne(['_id' => 'i1', "views" => 1]);
     $preaggregated_collection->insertOne(['_id' => 'i2', "views" => 1]);
     $preaggregated_collection->insertOne(['_id' => 'i3', "views" => 1]);
     $preaggregated_collection->insertOne(['_id' => 'i4', "views" => 1]);
     //        $update_result = $preaggregated_collection->updateMany(
     //            ['_id' => ['$in' => ['i1', 'i2', 'i10']]],
     //            ['$inc' => ["views" => 1]],
     //            ['upsert' => true]
     //        );
     $update_result = $preaggregated_collection->updateOne(['_id' => 'i10'], ['$inc' => ["views" => 1]], ['upsert' => true]);
 }
Example #9
0
 /**
  * Get mongo db stream collection
  *
  * @param StreamName $streamName
  * @return Collection
  */
 private function getCollection(StreamName $streamName)
 {
     return $this->client->selectCollection($this->dbName, (string) $streamName);
 }
Example #10
0
 /**
  * Test including an rdf sequence in a view
  */
 public function testGenerateViewContainingRdfSequence()
 {
     // get the view - this should trigger generation
     $this->tripodViews->getViewForResource("http://talisaspire.com/resources/filter1", "v_resource_rdfsequence");
     $expectedView = array("_id" => array(_ID_RESOURCE => "http://talisaspire.com/resources/filter1", _ID_CONTEXT => 'http://talisaspire.com/', "type" => "v_resource_rdfsequence"), "value" => array(_GRAPHS => array(array("_id" => array("r" => "http://talisaspire.com/works/filter1", "c" => 'http://talisaspire.com/'), "dct:subject" => array("u" => "http://talisaspire.com/disciplines/physics"), "rdf:type" => array(array(VALUE_URI => "bibo:Book"), array(VALUE_URI => "acorn:Work"))), array("_id" => array("r" => "http://talisaspire.com/works/filter2", "c" => 'http://talisaspire.com/'), "dct:subject" => array("u" => "http://talisaspire.com/disciplines/physics"), "rdf:type" => array(array(VALUE_URI => "bibo:Book"), array(VALUE_URI => "acorn:Work"))), array("_id" => array("r" => "http://talisaspire.com/works/filter3", "c" => 'http://talisaspire.com/'), "dct:subject" => array("u" => "http://talisaspire.com/disciplines/physics"), "rdf:type" => array(array(VALUE_URI => "bibo:Chapter"), array(VALUE_URI => "acorn:Work"))), array("_id" => array("r" => "http://talisaspire.com/resources/filter1", "c" => 'http://talisaspire.com/'), "rdf:type" => array(array(VALUE_URI => "bibo:Book"), array(VALUE_URI => "acorn:Resource"), array(VALUE_URI => "rdf:Seq")), "dct:isVersionOf" => array(array(VALUE_URI => "http://talisaspire.com/works/filter1"), array(VALUE_URI => "http://talisaspire.com/works/filter2"), array(VALUE_URI => "http://talisaspire.com/works/filter3")), "rdf:_1" => array("u" => "http://talisaspire.com/1"), "rdf:_2" => array("u" => "http://talisaspire.com/2"), "rdf:_3" => array("u" => "http://talisaspire.com/3"))), _IMPACT_INDEX => array(array(_ID_RESOURCE => "http://talisaspire.com/resources/filter1", _ID_CONTEXT => 'http://talisaspire.com/'), array(_ID_RESOURCE => "http://talisaspire.com/works/filter1", _ID_CONTEXT => 'http://talisaspire.com/'), array(_ID_RESOURCE => "http://talisaspire.com/works/filter2", _ID_CONTEXT => 'http://talisaspire.com/'), array(_ID_RESOURCE => "http://talisaspire.com/works/filter3", _ID_CONTEXT => 'http://talisaspire.com/'))));
     // get the view direct from mongo
     $mongo = new Client(\Tripod\Mongo\Config::getInstance()->getConnStr('tripod_php_testing'), [], ['typeMap' => ['root' => 'array', 'document' => 'array', 'array' => 'array']]);
     $actualView = $mongo->selectCollection('tripod_php_testing', 'views')->findOne(array('_id' => array("r" => 'http://talisaspire.com/resources/filter1', "c" => 'http://talisaspire.com/', "type" => 'v_resource_rdfsequence')));
     $this->assertEquals($expectedView, $actualView);
 }
Example #11
0
 public function __construct(Client $client, $databaseName, $collectionName)
 {
     $this->collection = $client->selectCollection($databaseName, $collectionName);
 }
 public function __construct(Client $mongodb, string $database, string $collection)
 {
     $this->collection = $mongodb->selectCollection($database, $collection);
 }
 public function testTransactionLogIsWrittenToCorrectDBAndCollection()
 {
     $storeName = 'tripod_php_testing';
     $newConfig = \Tripod\Mongo\Config::getConfig();
     $newConfig['transaction_log']['database'] = 'tripod_php_testing_transaction_log';
     $newConfig['transaction_log']['collection'] = 'transaction_log';
     \Tripod\Mongo\Config::setConfig($newConfig);
     $config = \Tripod\Mongo\Config::getInstance();
     // Clear out any old data
     $tlogDB = $config->getTransactionLogDatabase();
     $tlogDB->drop();
     // Make sure the dbs do not exist
     $transactionConnInfo = $newConfig['data_sources'][$newConfig['transaction_log']['data_source']];
     $options = isset($transactionConnInfo['replicaSet']) && !empty($transactionConnInfo['replicaSet']) ? array('replicaSet' => $transactionConnInfo['replicaSet']) : array();
     $transactionMongo = new Client($transactionConnInfo['connection'], $options);
     $transactionDbInfo = $transactionMongo->listDatabases();
     foreach ($transactionDbInfo as $db) {
         $this->assertNotEquals($db->getName(), $newConfig['transaction_log']['database']);
     }
     $tqueuesConnInfo = $newConfig['data_sources'][$newConfig['transaction_log']['data_source']];
     $options = isset($tqueuesConnInfo['replicaSet']) && !empty($tqueuesConnInfo['replicaSet']) ? array('replicaSet' => $tqueuesConnInfo['replicaSet']) : array();
     $queuesMongo = new Client($tqueuesConnInfo['connection'], $options);
     $queuesDbInfo = $queuesMongo->listDatabases();
     foreach ($queuesDbInfo as $db) {
         $this->assertNotEquals($db->getName(), $newConfig['transaction_log']['database']);
     }
     // Start adding some data
     $this->tripod = new \Tripod\Mongo\Driver('CBD_testing', $storeName, array(OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => false, OP_SEARCH => false)));
     $this->loadResourceDataViaTripod();
     $graph = new \Tripod\Mongo\MongoGraph();
     $subject = 'http://example.com/' . uniqid();
     $labeller = new \Tripod\Mongo\Labeller();
     $graph->add_resource_triple($subject, RDF_TYPE, $labeller->qname_to_uri('foaf:Person'));
     $graph->add_literal_triple($subject, FOAF_NAME, "Anne Example");
     $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph);
     $newGraph = $this->tripod->describeResource($subject);
     $newGraph->add_literal_triple($subject, $labeller->qname_to_uri('foaf:email'), '*****@*****.**');
     $this->tripod->saveChanges($graph, $newGraph);
     // Make sure the dbs do now exist
     $transactionDbInfo = $transactionMongo->listDatabases();
     $transactionDbExists = false;
     foreach ($transactionDbInfo as $db) {
         if ($db->getName() === $newConfig['transaction_log']['database']) {
             $transactionDbExists = true;
         }
     }
     $this->assertTrue($transactionDbExists);
     // Make sure the data in the dbs look right
     $transactionColletion = $transactionMongo->selectCollection($newConfig['transaction_log']['database'], $newConfig['transaction_log']['collection']);
     $transactionCount = $transactionColletion->count();
     $transactionExampleDocument = $transactionColletion->findOne();
     $this->assertEquals(24, $transactionCount);
     $this->assertContains('transaction_', $transactionExampleDocument["_id"]);
 }