Esempio n. 1
0
 public function getFeed(Source $source, FeedRequest $feedRequest) : array
 {
     $collection = $this->mongoDB->selectCollection($source->getMongoDBCollection());
     $source->ensureIndexes($this->mongoDB, $collection);
     $stream = $this->streamFactory->getStreamForSource($source);
     return $stream->fetch($feedRequest->getCriteria(), $collection);
 }
Esempio n. 2
0
 /**
  * @param MongoDB\Database                       $database
  * @param MongoDB\Collection                     $collection
  * @param HHPnet\Core\Domain\Videos\VideoFactory $video_factory
  */
 public function let(\MongoDB\Database $database, \MongoDB\Collection $collection, \HHPnet\Core\Domain\Videos\VideoFactory $video_factory)
 {
     $this->collection = $collection;
     $this->video_factory = $video_factory;
     $database->selectCollection(Argument::any())->willReturn($this->collection);
     $this->beConstructedWith($database, $this->video_factory);
 }
Esempio n. 3
0
 /**
  * @param MongoDB\Database                       $database
  * @param MongoDB\Collection                     $collection
  * @param HHPnet\Core\Domain\Albums\AlbumFactory $album_factory
  */
 public function let(\MongoDB\Database $database, \MongoDB\Collection $collection, AlbumFactory $album_factory)
 {
     $this->collection = $collection;
     $this->album_factory = $album_factory;
     $database->selectCollection(Argument::any())->willReturn($this->collection);
     $this->beConstructedWith($database, $this->album_factory);
 }
 /**
  * Drop the collection if it exists.
  *
  * @param Collection $collection
  */
 protected function dropCollectionIfItExists(Collection $collection)
 {
     $database = new Database($this->manager, $collection->getDatabaseName());
     $collections = $database->listCollections(array('filter' => array('name' => $collection->getCollectionName())));
     if (iterator_count($collections) > 0) {
         $this->assertCommandSucceeded($collection->drop());
     }
 }
 public function exclude(IndexedEntity $entity)
 {
     /** @var Profile $entity */
     if ($this->isIndexable($entity)) {
         $source = $this->getSource($entity);
         $collection = $this->mongoDB->selectCollection($source->getMongoDBCollection());
         $collection->deleteOne(['id' => $entity->getId()]);
     }
 }
Esempio n. 6
0
 /**
  * @before
  */
 protected function setUpMongoClient()
 {
     $client = new Client();
     $this->database = $client->selectDatabase('yadm_test');
     foreach ($this->database->listCollections() as $collectionInfo) {
         if ('system.indexes' == $collectionInfo->getName()) {
             continue;
         }
         $this->database->dropCollection($collectionInfo->getName());
     }
 }
Esempio n. 7
0
 /**
  * @return \MongoDB\Database
  */
 private function createDatabaseObject()
 {
     $options = ['readPreference' => $this->readPreference, 'writeConcern' => $this->writeConcern];
     if ($this->db === null) {
         $this->db = $this->connection->getClient()->selectDatabase($this->name, $options);
     } else {
         $this->db = $this->db->withOptions($options);
     }
 }
 /**
  * @return \MongoDB\Collection
  */
 private function newQuery()
 {
     return $this->database->selectCollection($this->collection);
 }
Esempio n. 9
0
 /**
  * @param MongoDB\Database                     $mongo_db
  * @param HHPnet\Core\Domain\Users\UserFactory $factory
  */
 public function __construct(Database $mongo_db, UserFactory $factory)
 {
     $this->collection = $mongo_db->selectCollection('users');
     $this->factory = $factory;
 }
Esempio n. 10
0
 /**
  * Retrieve last error from database
  * @param $db
  * @return array
  */
 protected function getLastDBError(\MongoDB\Database $db)
 {
     return $db->command(['getLastError' => 1])->toArray()[0];
 }
 /**
  * Creates a user collection and it's indexes
  *
  * This migration creates the required user collection to establish an application login and it's required indexes.
  * An overall admin user is created as well.
  *
  * {@inheritdoc}
  */
 public function execute(Database $db)
 {
     $userCollection = $db->selectCollection('user');
     $userCollection->createIndex(['email_address' => 1], ['unique' => true]);
     $userCollection->insertOne(['username' => 'admin', 'password' => password_hash('topsecret', PASSWORD_DEFAULT), 'email_address' => '*****@*****.**']);
 }
Esempio n. 12
0
 /**
  * @param Database $db
  * @param string $collectionName
  * @return Collection
  */
 protected function getMongoCollection(Database $db, $collectionName)
 {
     return $db->selectCollection($collectionName);
 }
 /**
  * Obfuscate all email addresses
  *
  * In case a production backup is restored, all email addresses are going to be obfuscated.
  *
  * {@inheritdoc}
  */
 public function execute(Database $db)
 {
     $userCollection = $db->selectCollection('user');
     $userCollection->updateMany(['email_address' => ['$ne' => 'deleted']], ['$set' => ['email_address' => 'deleted']]);
 }
Esempio n. 14
0
 public function getGridFs($options = [])
 {
     return new Bucket($this->client, $this->database->getDatabaseName(), $options);
 }
 public function testWithOptionsInheritsOptions()
 {
     $databaseOptions = ['readConcern' => new ReadConcern(ReadConcern::LOCAL), 'readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
     $database = new Database($this->manager, $this->getDatabaseName(), $databaseOptions);
     $clone = $database->withOptions();
     $debug = $clone->__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->assertInstanceOf('MongoDB\\Driver\\WriteConcern', $debug['writeConcern']);
     $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
 }
Esempio n. 16
0
 /**
  * (PECL mongo &gt;= 0.9.0)<br/>
  * @deprecated Use MongoCollection::drop() instead.
  * Drops a collection
  * @link http://www.php.net/manual/en/mongodb.dropcollection.php
  * @param MongoCollection|string $coll MongoCollection or name of collection to drop.
  * @return array Returns the database response.
  */
 public function dropCollection($coll)
 {
     return $this->db->dropCollection((string) $coll);
 }
 /**
  * Create one record per release
  *
  * {@inheritdoc}
  */
 public function execute(MongoDB\Database $db)
 {
     $releaseCollection = $db->selectCollection('releases');
     $releaseCollection->insertOne(['created' => new MongoDB\BSON\UTCDatetime((new \DateTime())->getTimestamp() * 1000)]);
 }
Esempio n. 18
0
 /**
  * Get a MongoDB collection.
  *
  * @param  string   $name
  * @return Collection
  */
 public function getCollection($name)
 {
     return new Collection($this, $this->db->selectCollection($name));
 }
Esempio n. 19
0
 /**
  * @see Database::getDBRef()
  */
 public function getDBRef(array $ref)
 {
     $this->log(array('getDBRef' => true, 'reference' => $ref));
     return parent::getDBRef($ref);
 }
Esempio n. 20
0
 /**
  * Database constructor.
  *
  * @param Manager                      $manager
  * @param string                       $databaseName
  * @param array                        $options
  * @param DataCollectorLoggerInterface $logger
  */
 public function __construct(Manager $manager, $databaseName, array $options = [], DataCollectorLoggerInterface $logger)
 {
     parent::__construct($manager, $databaseName, $options);
     $this->logger = $logger;
 }