Replace calls to mediavorus to getMediaFromUri

This commit is contained in:
Benoît Burnichon
2015-05-12 18:12:02 +02:00
parent 81e8fcb606
commit 61206fd517
15 changed files with 40 additions and 41 deletions

View File

@@ -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

View File

@@ -9,7 +9,6 @@
*/
namespace Alchemy\Phrasea\Application\Helper;
use Alchemy\Phrasea\Application;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

View File

@@ -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));
}

View File

@@ -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);

View File

@@ -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');

View File

@@ -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,

View File

@@ -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
*/

View File

@@ -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);

View File

@@ -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(

View File

@@ -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,

View File

@@ -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();

View File

@@ -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);

View File

@@ -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']);

View File

@@ -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);

View File

@@ -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();
}