diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index c005520ef5..2d9a787cf8 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -109,6 +109,8 @@ use Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider; use FFMpeg\FFMpegServiceProvider; use Gedmo\DoctrineExtensions as GedmoExtension; use MediaAlchemyst\MediaAlchemystServiceProvider; +use MediaVorus\Media\MediaInterface; +use MediaVorus\MediaVorus; use MediaVorus\MediaVorusServiceProvider; use Monolog\Handler\NullHandler; use Monolog\Logger; @@ -706,6 +708,21 @@ class Application extends SilexApplication return static::$flashTypes; } + /** + * Get Media instance given a file uri. + * + * @param string $uri + * + * @return MediaInterface + */ + public function getMediaFromUri($uri) + { + /** @var MediaVorus $mediavorus */ + $mediavorus = $this['mediavorus']; + + return $mediavorus->guess($uri); + } + private function setupApplicationPaths() { // app root path diff --git a/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php b/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php index 8053008468..93c316abb5 100644 --- a/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php +++ b/lib/Alchemy/Phrasea/Application/Helper/DispatcherAware.php @@ -9,7 +9,6 @@ */ namespace Alchemy\Phrasea\Application\Helper; -use Alchemy\Phrasea\Application; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; diff --git a/lib/Alchemy/Phrasea/Border/File.php b/lib/Alchemy/Phrasea/Border/File.php index 2a9e5de76f..abe8ec0f23 100644 --- a/lib/Alchemy/Phrasea/Border/File.php +++ b/lib/Alchemy/Phrasea/Border/File.php @@ -41,7 +41,7 @@ class File /** * - * @var \MediaVorus\Media\MediaInterface + * @var MediaInterface */ protected $media; protected $uuid; @@ -54,7 +54,7 @@ class File /** * Constructor * - * @param Applciation $app Application context + * @param Application $app Application context * @param MediaInterface $media The media * @param \collection $collection The destination collection * @param string $originalName The original name of the file @@ -227,7 +227,7 @@ class File /** * Returns an instance of MediaVorus\Media\MediaInterface corresponding to the file * - * @return MediaVorus\Media\MediaInterface + * @return MediaInterface */ public function getMedia() { @@ -282,7 +282,7 @@ class File public static function buildFromPathfile($pathfile, \collection $collection, Application $app, $originalName = null) { try { - $media = $app['mediavorus']->guess($pathfile); + $media = $app->getMediaFromUri($pathfile); } catch (FileNotFoundException $e) { throw new \InvalidArgumentException(sprintf('Unable to build media file from non existant %s', $pathfile)); } diff --git a/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php b/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php index 1b0132908b..7ad99d418a 100644 --- a/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php +++ b/lib/Alchemy/Phrasea/Command/Upgrade/Step31.php @@ -124,7 +124,7 @@ class Step31 implements DatasUpgraderInterface $uuid = Uuid::uuid4(); try { - $media = $this->app['mediavorus']->guess($pathfile); + $media = $this->app->getMediaFromUri($pathfile); $collection = \collection::get_from_coll_id($this->$app, $databox, (int) $record['coll_id']); $file = new File($this->app, $media, $collection); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/FeedController.php b/lib/Alchemy/Phrasea/Controller/Admin/FeedController.php index 87d5ce405b..33becac80e 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/FeedController.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/FeedController.php @@ -152,9 +152,7 @@ class FeedController extends Controller throw new BadRequestHttpException('Uploaded file is invalid'); } - /** @var MediaVorus $mediavorus */ - $mediavorus = $this->app['mediavorus']; - $media = $mediavorus->guess($file->getPathname()); + $media = $this->app->getMediaFromUri($file->getPathname()); if ($media->getType() !== MediaInterface::TYPE_IMAGE) { throw new BadRequestHttpException('Bad filetype'); diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index da589ab770..1bcd6339d6 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -771,9 +771,7 @@ class V1Controller extends Controller ))->createResponse(); } - /** @var MediaVorus $mediavorus */ - $mediavorus = $this->app['mediavorus']; - $media = $mediavorus->guess($file->getPathname()); + $media = $this->app->getMediaFromUri($file->getPathname()); $Package = new File($this->app, $media, $collection, $file->getClientOriginalName()); @@ -860,9 +858,7 @@ class V1Controller extends Controller return $this->getBadRequestAction($request, 'Missing name parameter'); } - /** @var MediaVorus $mediavorus */ - $mediavorus = $this->app['mediavorus']; - $media = $mediavorus->guess($file->getPathname()); + $media = $this->app->getMediaFromUri($file->getPathname()); $record = $this->findDataboxById($request->get('databox_id'))->get_record($request->get('record_id')); $base_id = $record->get_base_id(); $collection = \collection::get_from_base_id($this->app, $base_id); @@ -2101,9 +2097,7 @@ class V1Controller extends Controller if (!in_array($name, array('thumbnail', 'preview'))) { continue; } - /** @var MediaVorus $mediavorus */ - $mediavorus = $this->app['mediavorus']; - $media = $mediavorus->guess($value->get_pathfile()); + $media = $this->app->getMediaFromUri($value->get_pathfile()); $story->substitute_subdef($name, $media, $this->app); $this->app['phraseanet.logger']($story->get_databox())->log( $story, diff --git a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php index d19b8f5c12..be416d2f14 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php @@ -16,7 +16,6 @@ use Alchemy\Phrasea\Core\Event\RecordEdit; use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Media\SubdefSubstituer; use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController; -use MediaVorus\MediaVorus; use Symfony\Component\HttpFoundation\Request; class EditController extends Controller @@ -290,7 +289,7 @@ class EditController extends Controller continue; } - $media = $this->getMediaVorus()->guess($value->get_pathfile()); + $media = $this->app->getMediaFromUri($value->get_pathfile()); $this->getSubDefinitionSubstituer()->substitute($reg_record, $name, $media); $this->getDispatcher()->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($reg_record)); $this->getDataboxLogger($reg_record->get_databox())->log( @@ -382,14 +381,6 @@ class EditController extends Controller return $this->app['phraseanet.logger']($databox); } - /** - * @return MediaVorus - */ - private function getMediaVorus() - { - return $this->app['mediavorus']; - } - /** * @return SubdefSubstituer */ diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php index 3a6d6bd8dc..a65fe86fae 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php @@ -425,7 +425,7 @@ class Lazaret implements ControllerProviderInterface $lazaretThumbFileName = $app['tmp.lazaret.path'].'/'.$lazaretFile->getThumbFilename(); try { - $media = $app['mediavorus']->guess($lazaretFileName); + $media = $app->getMediaFromUri($lazaretFileName); $record = $lazaretFile->getCollection($app)->get_databox()->get_record($recordId); $app['subdef.substituer']->substitute($record, 'document', $media); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php index f59deffcdb..eff75eedcd 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php @@ -142,7 +142,7 @@ class Tools implements ControllerProviderInterface $request->get('record_id') ); - $media = $app['mediavorus']->guess($tempoFile); + $media = $app->getMediaFromUri($tempoFile); $app['subdef.substituer']->substitute($record, 'document', $media); $record->insertTechnicalDatas($app['mediavorus']); @@ -202,7 +202,7 @@ class Tools implements ControllerProviderInterface $request->get('record_id') ); - $media = $app['mediavorus']->guess($tempoFile); + $media = $app->getMediaFromUri($tempoFile); $app['subdef.substituer']->substitute($record, 'thumbnail', $media); $app['phraseanet.logger']($record->get_databox())->log( @@ -265,7 +265,7 @@ class Tools implements ControllerProviderInterface file_put_contents($fileName, $dataUri->getData()); - $media = $app['mediavorus']->guess($fileName); + $media = $app->getMediaFromUri($fileName); $app['subdef.substituer']->substitute($record, 'thumbnail', $media); $app['phraseanet.logger']($record->get_databox())->log( diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php index 78e88ebc0f..3b1b10d74f 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Upload.php @@ -172,7 +172,7 @@ class Upload implements ControllerProviderInterface $app['filesystem']->rename($uploadedFilename, $renamedFilename); - $media = $app['mediavorus']->guess($renamedFilename); + $media = $app->getMediaFromUri($renamedFilename); $collection = \collection::get_from_base_id($app, $base_id); $lazaretSession = new LazaretSession(); @@ -233,7 +233,7 @@ class Upload implements ControllerProviderInterface $fileName = $app['temporary-filesystem']->createTemporaryFile('base_64_thumb', null, "png"); file_put_contents($fileName, $dataUri->getData()); - $media = $app['mediavorus']->guess($fileName); + $media = $app->getMediaFromUri($fileName); $app['subdef.substituer']->substitute($elementCreated, 'thumbnail', $media); $app['phraseanet.logger']($elementCreated->get_databox())->log( $elementCreated, diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php index f7a22d0649..7c971805ac 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php @@ -987,7 +987,7 @@ class ArchiveJob extends AbstractJob { $status = \databox_status::operation_or($stat0, $stat1); - $media = $app['mediavorus']->guess($pathfile); + $media = $app->getMediaFromUri($pathfile); $databox = $collection->get_databox(); $metadatasStructure = $databox->get_meta_structure(); @@ -1035,7 +1035,7 @@ class ArchiveJob extends AbstractJob { $status = \databox_status::operation_or($stat0, $stat1); - $media = $app['mediavorus']->guess($pathfile); + $media = $app->getMediaFromUri($pathfile); $databox = $collection->get_databox(); $metadatasStructure = $databox->get_meta_structure(); diff --git a/lib/classes/appbox.php b/lib/classes/appbox.php index 4ccc70bfc8..ae6491ae47 100644 --- a/lib/classes/appbox.php +++ b/lib/classes/appbox.php @@ -66,7 +66,7 @@ class appbox extends base //resize collection logo $imageSpec = new ImageSpecification(); - $media = $this->app['mediavorus']->guess($filename); + $media = $this->app->getMediaFromUri($filename); if ($media->getWidth() > 120 || $media->getHeight() > 24) { $imageSpec->setResizeMode(ImageSpecification::RESIZE_MODE_INBOUND_FIXEDRATIO); diff --git a/lib/classes/patch/370alpha7a.php b/lib/classes/patch/370alpha7a.php index 8790908f01..f728e2132b 100644 --- a/lib/classes/patch/370alpha7a.php +++ b/lib/classes/patch/370alpha7a.php @@ -108,7 +108,7 @@ class patch_370alpha7a extends patchAbstract } - $media = $app['mediavorus']->guess($filePath); + $media = $app->getMediaFromUri($filePath); $collection = \collection::get_from_base_id($app, $row['base_id']); diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index d00cb63374..20ecf9e2d6 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -915,7 +915,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } $app['filesystem']->chmod($subdefFile, 0760); - $media = $app['mediavorus']->guess($subdefFile); + $media = $app->getMediaFromUri($subdefFile); $subdef = media_subdef::create($app, $this, $name, $media); $subdef->set_substituted(true); @@ -1274,7 +1274,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $app['filesystem']->copy($file->getFile()->getRealPath(), $pathhd . $newname, true); - $media = $app['mediavorus']->guess($pathhd . $newname); + $media = $app->getMediaFromUri($pathhd . $newname); media_subdef::create($app, $record, 'document', $media); $record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS); diff --git a/lib/classes/recordutils/image.php b/lib/classes/recordutils/image.php index a160c56494..4dbae124bc 100644 --- a/lib/classes/recordutils/image.php +++ b/lib/classes/recordutils/image.php @@ -61,7 +61,7 @@ class recordutils_image $rotation = null; try { - $image = $app['mediavorus']->guess($subdef->get_pathfile()); + $image = $app->getMediaFromUri($subdef->get_pathfile()); if (MediaInterface::TYPE_IMAGE === $image->getType()) { $rotation = $image->getOrientation(); }