public static function setUpBeforeClass()
 {
     if (!class_exists('\\Mongo')) {
         return;
     }
     parent::setUpBeforeClass();
     self::$conn = self::createConnection();
     self::$conn->task_queue->drop();
     self::$conn->createCollection('task_queue');
 }
Exemple #2
0
 protected function setUp()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped('Mongo is not installed');
     }
     $mongo = new \MongoClient();
     $this->module = new MongoDb(make_container());
     $this->module->_setConfig($this->mongoConfig);
     $this->module->_initialize();
     $this->db = $mongo->selectDB('test');
     $this->userCollection = $this->db->createCollection('users');
     $this->userCollection->insert(array('id' => 1, 'email' => '*****@*****.**'));
 }
 protected function setUp()
 {
     if (!class_exists('Mongo')) {
         $this->markTestSkipped('Mongo is not installed');
     }
     $mongo = new \Mongo();
     $this->module = new MongoDb();
     $this->module->_setConfig($this->mongoConfig);
     $this->module->_initialize();
     $this->db = $mongo->selectDB('test');
     $this->userCollection = $this->db->createCollection('users');
     $user_id = $this->userCollection->insert(array('id' => 1, 'email' => '*****@*****.**'));
     $this->assertInternalType('string', $user_id);
 }
Exemple #4
0
 public function __construct(MongoBaseDatabase $database, $database_name, $collection_name)
 {
     $this->database = $database;
     $this->name = $collection_name;
     $mongo_db = $database->getMasterConnection()->selectDB($database_name);
     $collection_names = $mongo_db->getCollectionNames();
     if (!in_array($collection_name, $collection_names)) {
         // create
         $this->masterCollection = $mongo_db->createCollection($collection_name);
     } else {
         $this->masterCollection = $mongo_db->selectCollection($collection_name);
     }
     $this->masterMongoDb = $mongo_db;
     // slave
     $this->slaveMongoDb = $database->getSlaveConnection()->selectDB($database_name);
     $this->slaveCollection = $this->slaveMongoDb->selectCollection($collection_name);
 }
 /**
  * getCollection get a handle to the collection object
  *
  * @access private
  * @return MongoCollection the mongo collection class reffering to the
  *                         appropriate dataset
  */
 private function getCollection()
 {
     // if the collection is not already cached
     if (empty($this->collection)) {
         // selects the collection if it exists
         $this->collection = $this->db->selectCollection(self::COLLECTION);
         // or creates a new one if it doesn't
         if (empty($this->collection)) {
             $this->collection = $this->db->createCollection(self::COLLECTION);
         }
     }
     return $this->collection;
 }
 /**
  * Return the filling percentage of the backend storage
  *
  * @return int integer between 0 and 100
  */
 public function getFillingPercentage()
 {
     $result = $this->_database->execute('db.stats()');
     $total = @$result['retval']['storageSize'] ?: 0;
     $free = $total - @$result['retval']['dataSize'] ?: 0;
     if ($total == 0) {
         Zend_Cache::throwException('can\'t get disk_total_space');
     } else {
         if ($free >= $total) {
             return 100;
         }
         return (int) (100.0 * ($total - $free) / $total);
     }
 }
Exemple #7
0
 /**
  * Create Schema
  *
  * @return DBAL
  */
 public function createSchema()
 {
     $this->connection->selectCollection($this->tableName)->ensureIndex('version', array('unique' => 1));
     return $this;
 }