示例#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);
 }
 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()]);
     }
 }
示例#3
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);
 }
示例#4
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);
 }
 public function testSelectCollectionInheritsReadPreferenceAndWriteConcern()
 {
     $databaseOptions = ['readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
     $database = new Database($this->manager, $this->getDatabaseName(), $databaseOptions);
     $collection = $database->selectCollection($this->getCollectionName());
     $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());
 }
 /**
  * @return \MongoDB\Collection
  */
 private function newQuery()
 {
     return $this->database->selectCollection($this->collection);
 }
示例#7
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;
 }
 /**
  * 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' => '*****@*****.**']);
 }
 public function testSelectCollectionInheritsOptions()
 {
     $databaseOptions = ['readConcern' => new ReadConcern(ReadConcern::LOCAL), 'readPreference' => new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED), 'typeMap' => ['root' => 'array'], 'writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
     $database = new Database($this->manager, $this->getDatabaseName(), $databaseOptions);
     $collection = $database->selectCollection($this->getCollectionName());
     $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());
 }
示例#10
0
 /**
  * @param Database $db
  * @param string $collectionName
  * @return Collection
  */
 protected function getMongoCollection(Database $db, $collectionName)
 {
     return $db->selectCollection($collectionName);
 }
 /**
  * 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)]);
 }
示例#12
0
 /**
  * Get a MongoDB collection.
  *
  * @param  string   $name
  * @return Collection
  */
 public function getCollection($name)
 {
     return new Collection($this, $this->db->selectCollection($name));
 }
 /**
  * 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']]);
 }
示例#14
0
 public function selectCollection($collectionName, array $options = [])
 {
     return new Collection($this->database->selectCollection($collectionName, $options), $this->client);
 }