Example #1
0
 /**
  * @covers Alchemy\Phrasea\Border\File::getUUID
  */
 public function testNewUuid()
 {
     $file = __DIR__ . '/../../../../files/temporay.jpg';
     if (file_exists($file)) {
         unlink($file);
     }
     copy(__DIR__ . '/../../../../files/p4logo.jpg', $file);
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID(true, false);
     $this->assertTrue(Uuid::isValid($uuid));
     $this->assertEquals($uuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $newuuid = $borderFile->getUUID(true, true);
     $this->assertTrue(Uuid::isValid($newuuid));
     $this->assertNotEquals($uuid, $newuuid);
     $this->assertEquals($newuuid, $borderFile->getUUID());
     $borderFile = new File(self::$DI['app'], self::$DI['app']['mediavorus']->guess($file), self::$DI['collection']);
     $uuid = $borderFile->getUUID();
     $this->assertTrue(Uuid::isValid($uuid));
     $this->assertEquals($uuid, $newuuid);
     $this->assertEquals($uuid, $borderFile->getUUID());
     if (file_exists($file)) {
         unlink($file);
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function check(EntityManager $em, File $file)
 {
     $boolean = !count(\record_adapter::get_record_by_uuid($this->app, $file->getCollection()->get_databox(), $file->getUUID()));
     return new Response($boolean, $this);
 }
Example #3
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::uuid4();
     try {
         $media = $this->app['mediavorus']->guess($pathfile);
         $collection = \collection::get_from_coll_id($this->{$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 #4
0
 /**
  * {@inheritdoc}
  */
 public function check(EntityManager $em, File $file)
 {
     $boolean = !count($file->getCollection()->get_databox()->getRecordRepository()->findByUuid($file->getUUID()));
     return new Response($boolean, $this);
 }
Example #5
0
 /**
  *
  * @param File        $file
  * @param Application $app
  *
  * @return \record_adapter
  */
 public static function createFromFile(File $file, Application $app)
 {
     $databox = $file->getCollection()->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' => $file->getCollection()->get_coll_id(), ':parent_record_id' => 0, ':type' => $file->getType() ? $file->getType()->getType() : 'unknown', ':sha256' => $file->getMedia()->getHash('sha256'), ':uuid' => $file->getUUID(true), ':originalname' => $file->getOriginalName(), ':mime' => $file->getFile()->getMimeType()]);
     $record_id = $databox->get_connection()->lastInsertId();
     $record = new self($app, $databox->get_sbas_id(), $record_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' => $record_id, ':coll_id' => $file->getCollection()->get_coll_id()]);
         $stmt->closeCursor();
     } catch (\Exception $e) {
         unset($e);
     }
     $pathhd = databox::dispatch($app['filesystem'], trim($databox->get_sxml_structure()->path));
     $newname = $record->get_record_id() . "_document." . pathinfo($file->getOriginalName(), PATHINFO_EXTENSION);
     $app['filesystem']->copy($file->getFile()->getRealPath(), $pathhd . $newname, true);
     $media = $app['mediavorus']->guess($pathhd . $newname);
     media_subdef::create($app, $record, 'document', $media);
     $record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS);
     $record->insertTechnicalDatas($app['mediavorus']);
     $record->rebuild_subdefs();
     return $record;
 }
Example #6
0
 /**
  * Send a package file to lazaret
  *
  * @param File           $file    The package file
  * @param Visa           $visa    The visa related to the package file
  * @param LazaretSession $session The current LazaretSession
  * @param Boolean        $forced  True if the file has been forced to quarantine
  *
  * @return LazaretFile
  */
 protected function createLazaret(File $file, Visa $visa, LazaretSession $session, $forced)
 {
     $date = new \DateTime();
     $file->addAttribute(new MetadataAttr(new Metadata(new TfQuarantine(), new MonoValue($date->format('Y/m/d H:i:s')))));
     $lazaretPathname = $this->bookLazaretPathfile($file->getOriginalName());
     $lazaretPathnameThumb = $this->bookLazaretPathfile($file->getOriginalName(), 'thumb');
     $this->app['filesystem']->copy($file->getFile()->getRealPath(), $lazaretPathname, true);
     $spec = new ImageSpec();
     $spec->setResizeMode(ImageSpec::RESIZE_MODE_INBOUND_FIXEDRATIO);
     $spec->setDimensions(375, 275);
     try {
         $this->app['media-alchemyst']->turnInto($file->getFile()->getPathname(), $lazaretPathnameThumb, $spec);
     } catch (MediaAlchemystException $e) {
     }
     $lazaretFile = new LazaretFile();
     $lazaretFile->setBaseId($file->getCollection()->get_base_id());
     $lazaretFile->setSha256($file->getSha256());
     $lazaretFile->setUuid($file->getUUID());
     $lazaretFile->setOriginalName($file->getOriginalName());
     $lazaretFile->setForced($forced);
     $lazaretFile->setFilename(pathinfo($lazaretPathname, PATHINFO_BASENAME));
     $lazaretFile->setThumbFileName(pathinfo($lazaretPathnameThumb, PATHINFO_BASENAME));
     $lazaretFile->setSession($session);
     $this->app['orm.em']->persist($lazaretFile);
     foreach ($file->getAttributes() as $fileAttribute) {
         $attribute = new LazaretAttribute();
         $attribute->setName($fileAttribute->getName());
         $attribute->setValue($fileAttribute->asString());
         $attribute->setLazaretFile($lazaretFile);
         $lazaretFile->addAttribute($attribute);
         $this->app['orm.em']->persist($attribute);
     }
     foreach ($visa->getResponses() as $response) {
         if (!$response->isOk()) {
             $check = new LazaretCheck();
             $check->setCheckClassname(get_class($response->getChecker()));
             $check->setLazaretFile($lazaretFile);
             $lazaretFile->addCheck($check);
             $this->app['orm.em']->persist($check);
         }
     }
     $this->app['orm.em']->flush();
     return $lazaretFile;
 }