public function check(EntityManager $em, File $file) { if (0 === count($this->extensions)) { //if empty authorize all extensions $boolean = true; } else { $boolean = in_array(strtolower($file->getFile()->getExtension()), $this->extensions); } 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; }
/** * Add technical Metadata attribute to a package file by reference to add it * to Phraseanet * * @param File $file The file * @return \Doctrine\ORM\EntityManager */ protected function addMediaAttributes(File $file) { if (method_exists($file->getMedia(), 'getWidth')) { $file->addAttribute(new MetadataAttr(new Metadata(new TfWidth(), new MonoValue($file->getMedia()->getWidth())))); } if (method_exists($file->getMedia(), 'getHeight')) { $file->addAttribute(new MetadataAttr(new Metadata(new TfHeight(), new MonoValue($file->getMedia()->getHeight())))); } if (method_exists($file->getMedia(), 'getChannels')) { $file->addAttribute(new MetadataAttr(new Metadata(new TfChannels(), new MonoValue($file->getMedia()->getChannels())))); } if (method_exists($file->getMedia(), 'getColorDepth')) { $file->addAttribute(new MetadataAttr(new Metadata(new TfBits(), new MonoValue($file->getMedia()->getColorDepth())))); } if (method_exists($file->getMedia(), 'getDuration')) { $file->addAttribute(new MetadataAttr(new Metadata(new TfDuration(), new MonoValue($file->getMedia()->getDuration())))); } if ($file->getFile()->getMimeType() == 'application/pdf' && null !== $this->pdfToText) { try { $text = $this->pdfToText->getText($file->getFile()->getRealPath()); if (trim($text)) { $file->addAttribute(new MetadataAttr(new Metadata(new PdfText(), new MonoValue($text)))); } } catch (\XPDF\Exception\Exception $e) { } } $file->addAttribute(new MetadataAttr(new Metadata(new TfMimetype(), new MonoValue($file->getFile()->getMimeType())))); $file->addAttribute(new MetadataAttr(new Metadata(new TfSize(), new MonoValue($file->getFile()->getSize())))); $file->addAttribute(new MetadataAttr(new Metadata(new TfBasename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_BASENAME))))); $file->addAttribute(new MetadataAttr(new Metadata(new TfFilename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_FILENAME))))); $file->addAttribute(new MetadataAttr(new Metadata(new TfExtension(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_EXTENSION))))); return $this; }
/** * 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::getFile */ public function testGetFile() { $this->assertInstanceOf('\\MediaVorus\\File', $this->object->getFile()); $this->assertEquals(realpath(__DIR__ . '/../../../../../tmp/iphone_pic.jpg'), $this->object->getFile()->getRealPath()); }