Example #1
0
 /**
  * @covers Alchemy\Phrasea\Controller\Admin\Database::emptyDatabase
  */
 public function testPostEmptyBaseWithHighRecordAmount()
 {
     $this->setAdmin(true);
     $base = $this->createDatabox();
     $collection = \collection::create(self::$DI['app'], $base, self::$DI['app']['phraseanet.appbox'], 'TESTTODELETE');
     self::$createdCollections[] = $collection;
     $sql = 'INSERT INTO record
           (coll_id, record_id, parent_record_id, moddate, credate
             , type, sha256, uuid, originalname, mime)
         VALUES
           (:coll_id, null, :parent_record_id, NOW(), NOW()
           , :type, :sha256, :uuid
           , :originalname, :mime)';
     $stmt = $base->get_connection()->prepare($sql);
     $i = 0;
     while ($i < 502) {
         $stmt->execute([':coll_id' => $collection->get_coll_id(), ':parent_record_id' => 0, ':type' => 'unknown', ':sha256' => null, ':uuid' => \uuid::generate_v4(), ':originalname' => null, ':mime' => null]);
         $i++;
     }
     $stmt->closeCursor();
     if ($collection->get_record_amount() < 500) {
         $this->markTestSkipped('No enough records added');
     }
     $this->XMLHTTPRequest('POST', '/admin/databox/' . $base->get_sbas_id() . '/empty/');
     $json = $this->getJson(self::$DI['client']->getResponse());
     $this->assertTrue($json->success);
     if (count(self::$DI['app']['EM']->getRepository('Phraseanet:Task')->findAll()) === 0) {
         $this->fail('Task for empty collection has not been created');
     }
     $base->unmount_databox();
     $base->delete();
 }
Example #2
0
 public function testCompare()
 {
     for ($i = 0; $i < 1000; $i++) {
         $uuid1 = uuid::generate_v4();
         $uuid2 = uuid::generate_v4();
         $this->assertFalse(uuid::compare($uuid1, $uuid2));
     }
 }
Example #3
0
 /**
  *
  * @param Application $app
  * @param \collection $collection
  *
  * @return \record_adapter
  */
 public static function createStory(Application $app, \collection $collection)
 {
     $databox = $collection->get_databox();
     $sql = 'INSERT INTO record
           (coll_id, record_id, parent_record_id, moddate, credate
             , type, sha256, uuid, originalname, mime)
         VALUES
           (:coll_id, null, :parent_record_id, NOW(), NOW()
           , :type, :sha256, :uuid
           , :originalname, :mime)';
     $stmt = $databox->get_connection()->prepare($sql);
     $stmt->execute([':coll_id' => $collection->get_coll_id(), ':parent_record_id' => 1, ':type' => 'unknown', ':sha256' => null, ':uuid' => \uuid::generate_v4(), ':originalname' => null, ':mime' => null]);
     $story_id = $databox->get_connection()->lastInsertId();
     $story = new self($app, $databox->get_sbas_id(), $story_id);
     try {
         $log_id = $app['phraseanet.logger']($databox)->get_id();
         $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment)
         VALUES (null, :log_id, now(),
           :record_id, "add", :coll_id,"")';
         $stmt = $databox->get_connection()->prepare($sql);
         $stmt->execute([':log_id' => $log_id, ':record_id' => $story_id, ':coll_id' => $collection->get_coll_id()]);
         $stmt->closeCursor();
     } catch (\Exception $e) {
         unset($e);
     }
     return $story;
 }
Example #4
0
 /**
  * Update a record with a UUID
  *
  * @param \databox $databox
  * @param array    $record
  */
 protected function updateRecordUUID(\databox $databox, array $record)
 {
     $pathfile = \p4string::addEndSlash($record['path']) . $record['file'];
     $uuid = \uuid::generate_v4();
     try {
         $media = $this->app['mediavorus']->guess($pathfile);
         $collection = \collection::get_from_coll_id($app, $databox, (int) $record['coll_id']);
         $file = new File($this->app, $media, $collection);
         $uuid = $file->getUUID(true, true);
         $sha256 = $file->getSha256();
         $this->app['monolog']->addInfo(sprintf("Upgrading record %d with uuid %s", $record['record_id'], $uuid));
     } catch (\Exception $e) {
         $this->app['monolog']->addError(sprintf("Uuid upgrade for record %s failed", $record['record_id']));
     }
     $sql = 'UPDATE record SET uuid = :uuid, sha256 = :sha256 WHERE record_id = :record_id';
     $params = [':uuid' => $uuid, 'sha256' => $sha256, ':record_id' => $record['record_id']];
     $stmt = $databox->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
 }
Example #5
0
 /**
  *
  * @return Bridge_Api_Youtube
  */
 protected function initialize_transport()
 {
     $http_client = new Zend_Gdata_HttpClient();
     $http_client->setHeaders('Accept', 'application/atom+xml');
     $this->_api = new Zend_Gdata_YouTube($http_client, uuid::generate_v4(), $this->conf->get(['main', 'bridge', 'youtube', 'client_id']), $this->conf->get(['main', 'bridge', 'youtube', 'developer_key']));
     $this->_api->setMajorProtocolVersion(2);
     return $this;
 }
Example #6
0
 /**
  * Checks for UUID in metadatas
  *
  * @todo Check if a file exists with the same checksum
  * @todo Check if an UUID is contained in the attributes, replace It if
  *              necessary
  *
  * @param  boolean $generate if true, if no uuid found, a valid one is generated
  * @param  boolean $write    if true, writes uuid in all available metadatas
  * @return File
  */
 public function getUUID($generate = false, $write = false)
 {
     if ($this->uuid && !$write) {
         return $this->uuid;
     }
     $availableUUIDs = ['XMP-exif:ImageUniqueID', 'SigmaRaw:ImageUniqueID', 'IPTC:UniqueDocumentID', 'ExifIFD:ImageUniqueID', 'Canon:ImageUniqueID'];
     if (!$this->uuid) {
         $metadatas = $this->media->getMetadatas();
         $uuid = null;
         foreach ($availableUUIDs as $meta) {
             if ($metadatas->containsKey($meta)) {
                 $candidate = $metadatas->get($meta)->getValue()->asString();
                 if (\uuid::is_valid($candidate)) {
                     $uuid = $candidate;
                     break;
                 }
             }
         }
         if (!$uuid && $generate) {
             /**
              * @todo Check if a file exists with the same checksum
              */
             $uuid = \uuid::generate_v4();
         }
         $this->uuid = $uuid;
     }
     if ($write) {
         $value = new MonoValue($this->uuid);
         $metadatas = new ExiftoolMetadataBag();
         foreach ($availableUUIDs as $tagname) {
             $metadatas->add(new Metadata(TagFactory::getFromRDFTagname($tagname), $value));
         }
         /**
          * PHPExiftool throws exception on some files not supported
          */
         try {
             $this->app['exiftool.writer']->reset();
             $this->app['exiftool.writer']->write($this->getFile()->getRealPath(), $metadatas);
         } catch (PHPExiftoolException $e) {
         }
     }
     return $this->uuid;
 }