コード例 #1
0
 /**
  * @param string $databaseName
  * @return bool
  */
 public static function hasDB($databaseName)
 {
     foreach (static::$_mongoClient->listDatabases() as $databaseInfo) {
         if ($databaseInfo->getName() == $databaseName) {
             return true;
         }
     }
     return false;
 }
コード例 #2
0
 public function getDatabases()
 {
     $result = [];
     /** @var DatabaseInfo $item */
     foreach ($this->client->listDatabases() as $item) {
         $result[] = new SchemaObject($item->getName(), $item->getSizeOnDisk(), $item->isEmpty());
     }
     return $result;
 }
コード例 #3
0
 /**
  * Lists all of the databases available
  *
  * @link http://php.net/manual/en/mongoclient.listdbs.php
  * @return array Returns an associative array containing three fields. The first field is databases, which in turn contains an array. Each element of the array is an associative array corresponding to a database, giving the database's name, size, and if it's empty. The other two fields are totalSize (in bytes) and ok, which is 1 if this method ran successfully.
  */
 public function listDBs()
 {
     $databaseInfoIterator = $this->client->listDatabases();
     $databases = ['databases' => [], 'totalSize' => 0, 'ok' => 1.0];
     foreach ($databaseInfoIterator as $databaseInfo) {
         $databases['databases'][] = $databaseInfo->getName();
         $databases['totalSize'] += $databaseInfo->getSizeOnDisk();
     }
     return $databases;
 }
コード例 #4
0
 /**
  * Lists all of the databases available
  *
  * @link http://php.net/manual/en/mongoclient.listdbs.php
  * @return array Returns an associative array containing three fields. The first field is databases, which in turn contains an array. Each element of the array is an associative array corresponding to a database, giving the database's name, size, and if it's empty. The other two fields are totalSize (in bytes) and ok, which is 1 if this method ran successfully.
  */
 public function listDBs()
 {
     try {
         $databaseInfoIterator = $this->client->listDatabases();
     } catch (\MongoDB\Driver\Exception\Exception $e) {
         throw ExceptionConverter::toLegacy($e);
     }
     $databases = ['databases' => [], 'totalSize' => 0, 'ok' => 1.0];
     foreach ($databaseInfoIterator as $databaseInfo) {
         $databases['databases'][] = ['name' => $databaseInfo->getName(), 'empty' => $databaseInfo->isEmpty(), 'sizeOnDisk' => $databaseInfo->getSizeOnDisk()];
         $databases['totalSize'] += $databaseInfo->getSizeOnDisk();
     }
     return $databases;
 }
コード例 #5
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     if (!class_exists('MongoDB\\Client')) {
         self::$supported = false;
         return;
     }
     try {
         $client = new Client();
         $client->listDatabases();
         self::$supported = true;
     } catch (Exception $e) {
         self::$supported = false;
     }
 }
コード例 #6
0
 /**
  * Lists all of the databases available
  *
  * @link http://php.net/manual/en/mongoclient.listdbs.php
  * @return array Returns an associative array containing three fields. The first field is databases, which in turn contains an array. Each element of the array is an associative array corresponding to a database, giving the database's name, size, and if it's empty. The other two fields are totalSize (in bytes) and ok, which is 1 if this method ran successfully.
  */
 public function listDBs()
 {
     return $this->client->listDatabases();
 }
コード例 #7
0
 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"]);
 }