/** * Returns true if the checker should be executed against the current file * * @param File $file A file to check * * @return Boolean */ public function isApplicable(File $file) { if (null === $file->getCollection()) { return true; } $fileDatabox = $file->getCollection()->get_databox(); foreach ($this->databoxes as $databox) { if ($databox->get_sbas_id() === $fileDatabox->get_sbas_id()) { return true; } } foreach ($this->collections as $collection) { if ($collection->get_base_id() === $file->getCollection()->get_base_id()) { return true; } } return false; }
/** * {@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); }
/** * {@inheritdoc} */ public function check(EntityManager $em, File $file) { $boolean = !count($file->getCollection()->get_databox()->getRecordRepository()->findByUuid($file->getUUID())); return new Response($boolean, $this); }
/** * {@inheritdoc} */ public function check(EntityManager $em, File $file) { $boolean = !count(\record_adapter::get_records_by_originalname($file->getCollection()->get_databox(), $file->getOriginalName(), $this->sensitive, 0, 1)); return new Response($boolean, $this); }
/** * * @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; }
/** * 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; }
/** * @covers Alchemy\Phrasea\Border\File::getCollection */ public function testGetCollection() { $this->assertSame(self::$DI['collection'], $this->object->getCollection()); }