Author: Christer Edvartsen (cogo@starzinger.net)
Beispiel #1
0
 /**
  * Get details for a given public key
  *
  * @param  string $publicKey
  * @return array
  */
 private function getPublicKeyDetails($publicKey)
 {
     if (isset($this->publicKeys[$publicKey])) {
         return $this->publicKeys[$publicKey];
     }
     // Not in cache, fetch from database
     $pubkeyInfo = $this->getAclCollection()->findOne(['publicKey' => $publicKey]);
     if (!$pubkeyInfo) {
         return [];
     }
     $data = $this->bsonToArray->toArray($pubkeyInfo->getArrayCopy());
     $this->publicKeys[$publicKey] = $data;
     return $data;
 }
Beispiel #2
0
 /**
  * @dataProvider getValues
  * @covers Imbo\Helpers\BSONToArray::toArray
  * @covers Imbo\Helpers\BSONToArray::isBSONModel
  */
 public function testCanConvertValuesToArray($document, $expected)
 {
     $this->assertSame($expected, $this->helper->toArray($document));
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function getImages(array $users, Query $query, Images $model)
 {
     // Initialize return value
     $images = [];
     // Query data
     $queryData = ['user' => ['$in' => $users]];
     $from = $query->from();
     $to = $query->to();
     if ($from || $to) {
         $tmp = [];
         if ($from !== null) {
             $tmp['$gte'] = $from;
         }
         if ($to !== null) {
             $tmp['$lte'] = $to;
         }
         $queryData['added'] = $tmp;
     }
     $imageIdentifiers = $query->imageIdentifiers();
     if (!empty($imageIdentifiers)) {
         $queryData['imageIdentifier']['$in'] = $imageIdentifiers;
     }
     $checksums = $query->checksums();
     if (!empty($checksums)) {
         $queryData['checksum']['$in'] = $checksums;
     }
     $originalChecksums = $query->originalChecksums();
     if (!empty($originalChecksums)) {
         $queryData['originalChecksum']['$in'] = $originalChecksums;
     }
     // Sorting
     $sort = ['added' => -1];
     if ($querySort = $query->sort()) {
         $sort = [];
         foreach ($querySort as $s) {
             $sort[$s['field']] = $s['sort'] === 'asc' ? 1 : -1;
         }
     }
     // Fields to fetch
     $fields = array_fill_keys(['extension', 'added', 'checksum', 'originalChecksum', 'updated', 'user', 'imageIdentifier', 'mime', 'size', 'width', 'height'], true);
     if ($query->returnMetadata()) {
         $fields['metadata'] = true;
     }
     try {
         $options = ['projection' => $fields, 'limit' => $query->limit(), 'sort' => $sort];
         // Skip some images if a page has been set
         if (($page = $query->page()) > 1) {
             $skip = $query->limit() * ($page - 1);
             $options['skip'] = $skip;
         }
         $cursor = $this->getImageCollection()->find($queryData, $options);
         foreach ($cursor as $image) {
             unset($image['_id']);
             $image['added'] = new DateTime('@' . $image['added'], new DateTimeZone('UTC'));
             $image['updated'] = new DateTime('@' . $image['updated'], new DateTimeZone('UTC'));
             $images[] = $this->bsonToArray->toArray($image->getArrayCopy());
         }
         // Update model
         $model->setHits($this->getImageCollection()->count($queryData));
     } catch (MongoException $e) {
         throw new DatabaseException('Unable to search for images', 500, $e);
     }
     return $images;
 }