Use mediavorus as core service

This commit is contained in:
Romain Neutron
2012-06-18 15:55:33 +02:00
parent c44f11fc8a
commit 50cf4ab8c8
25 changed files with 66 additions and 49 deletions

View File

@@ -276,8 +276,10 @@ class File
*/
public function buildFromPathfile($pathfile, \collection $collection, $originalName = null)
{
$core = \bootstrap::getCore();
try {
$media = MediaVorus::guess(new \SplFileInfo($pathfile));
$media = $core['mediavorus']->guess(new \SplFileInfo($pathfile));
} catch (\MediaVorus\Exception\FileNotFoundException $e) {
throw new \InvalidArgumentException(sprintf('Unable to build media file from non existant %s', $pathfile));
}

View File

@@ -132,7 +132,7 @@ class Publications implements ControllerProviderInterface
throw new \Exception_BadRequest('Uploaded file is invalid');
}
$media = \MediaVorus\MediaVorus::guess($file);
$media = $app['Core']['mediavorus']->guess($file);
if ($media->getType() !== \MediaVorus\Media\Media::TYPE_IMAGE) {
throw new \Exception_BadRequest('Bad filetype');

View File

@@ -401,7 +401,7 @@ class Lazaret implements ControllerProviderInterface
return self::formatJson($app['Core']['Serializer'], $ret);
}
$media = MediaVorus::guess(new \SplFileInfo($lazaretFile->getPathname()));
$media = $app['Core']['mediavorus']->guess(new \SplFileInfo($lazaretFile->getPathname()));
$record = $lazaretFile->getCollection()->get_databox()->get_record($recordId);
$record->substitute_subdef('document', $media);

View File

@@ -143,7 +143,7 @@ class Tools implements ControllerProviderInterface
, $request->get('record_id')
);
$media = MediaVorus::guess($file);
$media = $app['Core']['mediavorus']->guess($file);
$record->substitute_subdef('document', $media);
@@ -194,7 +194,7 @@ class Tools implements ControllerProviderInterface
, $request->get('record_id')
);
$media = MediaVorus::guess($file);
$media = $app['Core']['mediavorus']->guess($file);
$record->substitute_subdef('thumbnail', $media);
@@ -254,7 +254,7 @@ class Tools implements ControllerProviderInterface
file_put_contents($fileName, $dataUri->getData());
$media = MediaVorus::guess(new \SplFileInfo($fileName));
$media = $app['Core']['mediavorus']->guess(new \SplFileInfo($fileName));
$record->substitute_subdef('thumbnail', $media);

View File

@@ -12,7 +12,6 @@
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Border;
use MediaVorus\MediaVorus;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
@@ -177,7 +176,7 @@ class Upload implements ControllerProviderInterface
}
try {
$media = MediaVorus::guess($file);
$media = $app['Core']['mediavorus']->guess($file);
$collection = \collection::get_from_base_id($base_id);
$lazaretSession = new \Entities\LazaretSession();

View File

@@ -145,6 +145,12 @@ class Core extends \Pimple
return new Serializer\Serializer(array(), $encoders);
});
$this['mediavorus'] = $this->share(function() {
return new \MediaVorus\MediaVorus();
});
$this['monolog'] = $this->share(function () use ($core) {
$logger = new \Monolog\Logger('Logger');

View File

@@ -450,7 +450,7 @@ class Edit extends RecordHelper
throw new \Exception('A reg image must come from image data');
foreach ($newsubdef_reg->get_subdefs() as $name => $value) {
$media = MediaVorus::guess(new \SplFileInfo($value->get_pathfile()));
$media = $this->core['mediavorus']->guess(new \SplFileInfo($value->get_pathfile()));
$reg_record->substitute_subdef($name, $media);
}
} catch (\Exception $e) {

View File

@@ -644,7 +644,7 @@ class API_V1_adapter extends API_V1_Abstract
throw new API_V1_exception_forbidden(sprintf('You do not have access to collection %s', $collection->get_name()));
}
$media = \MediaVorus\MediaVorus::guess($file);
$media = $app['Core']['mediavorus']->guess($file);
$Package = new Alchemy\Phrasea\Border\File($media, $collection, $file->getClientOriginalName());

View File

@@ -438,7 +438,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
*/
public function get_size()
{
return filesize($this->get_pathfile());
return @filesize($this->get_pathfile());
}
/**
@@ -563,7 +563,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
return $this;
}
$media = MediaVorus::guess(new SplFileInfo($this->get_pathfile()));
$media = $Core['mediavorus']->guess(new SplFileInfo($this->get_pathfile()));
$sql = "UPDATE subdef
SET height = :height , width = :width, updated_on = NOW()
@@ -601,8 +601,9 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
if ( ! $this->is_physically_present()) {
return array();
}
$media = MediaVorus::guess(new \SplFileInfo($this->get_pathfile()));
$Core = \bootstrap::getCore();
$media = $Core['mediavorus']->guess(new \SplFileInfo($this->get_pathfile()));
$datas = array();

View File

@@ -132,6 +132,7 @@ class p4file
{
throw new Exception('This method is deprecated');
$core = \bootstrap::getCore();
$checks = array();
$system_file = new system_file($filename);
@@ -151,7 +152,7 @@ class p4file
$errors = array();
$media = \MediaVorus\MediaVorus::guess($filename);
$media = $core['mediavorus']->guess($filename);
$width = $height = 0;
$colorSpace = null;

View File

@@ -84,7 +84,7 @@ class patch_370a7 implements patchInterface
$filePath = __DIR__ . '/../../../tmp/lazaret/' . $row['filepath'];
if (file_exists($filePath)) {
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($filePath));
$media = $Core['mediavorus']->guess(new \SplFileInfo($filePath));
$collection = \collection::get_from_base_id($row['base_id']);

View File

@@ -1002,7 +1002,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
}
$core['file-system']->chmod($subdefFile->getRealPath(), 0760);
$media = \MediaVorus\MediaVorus::guess($subdefFile);
$media = $core['mediavorus']->guess($subdefFile);
media_subdef::create($this, $name, $media);
@@ -1348,7 +1348,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$core['file-system']->copy($file->getFile()->getRealPath(), $pathhd . $newname, true);
$media = MediaVorus\MediaVorus::guess(new \SplFileInfo($pathhd . $newname));
$media = $core['mediavorus']->guess(new \SplFileInfo($pathhd . $newname));
$subdef = media_subdef::create($record, 'document', $media);
$record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS);
@@ -1652,6 +1652,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
return;
}
$core = \bootstrap::getCore();
foreach ($subdefs as $subdef) {
$subdefname = $subdef->get_name();
@@ -1676,7 +1678,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$this->generate_subdef($subdef, $pathdest, $logger);
if (file_exists($pathdest)) {
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($pathdest));
$media = $core['mediavorus']->guess(new \SplFileInfo($pathdest));
media_subdef::create($this, $subdef->get_name(), $media);
}

View File

@@ -1531,7 +1531,8 @@ class task_period_archive extends task_abstract
$stat1 = '0';
}
$media = MediaVorus::guess(new \SplFileInfo($pathfile));
$core = \bootstrap::getCore();
$media = $core['mediavorus']->guess(new \SplFileInfo($pathfile));
$databox = $collection->get_databox();
$metadatasStructure = $databox->get_meta_structure();
@@ -1597,7 +1598,7 @@ class task_period_archive extends task_abstract
$core = \bootstrap::getCore();
$status = databox_status::operation_or($stat0, $stat1);
$media = MediaVorus::guess(new \SplFileInfo($pathfile));
$media = $core['mediavorus']->guess(new \SplFileInfo($pathfile));
$databox = $collection->get_databox();
$metadatasStructure = $databox->get_meta_structure();

View File

@@ -42,7 +42,8 @@ class task_period_upgradetov31 extends task_abstract
{
printf("taskid %s starting." . PHP_EOL, $this->getID());
// task can't be stopped here
$appbox = appbox::get_instance(\bootstrap::getCore());
$core = \bootstrap::getCore();
$appbox = appbox::get_instance($core);
$conn = $appbox->get_connection();
$running = true;
@@ -75,7 +76,7 @@ class task_period_upgradetov31 extends task_abstract
$uuid = uuid::generate_v4();
try {
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($pathfile));
$media = $core->guess(new \SplFileInfo($pathfile));
$collection = \collection::get_from_coll_id($databox, $row['coll_id']);
$file = new \Alchemy\Phrasea\Border\File($media, $collection);

View File

@@ -942,7 +942,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
{
$this->setToken(self::$token);
$file = new \Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/../../../testfiles/test001.CR2')), self::$collection);
$file = new \Alchemy\Phrasea\Border\File(self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../../testfiles/test001.CR2')), self::$collection);
$record = \record_adapter::createFromFile($file);
$route = '/records/' . $record->get_sbas_id() . '/' . $record->get_record_id() . '/setmetadatas/';
@@ -1064,7 +1064,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/
public function testMoveRecordToCollection()
{
$file = new \Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/../../../testfiles/test001.CR2')), self::$collection);
$file = new \Alchemy\Phrasea\Border\File(self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../../testfiles/test001.CR2')), self::$collection);
$record = \record_adapter::createFromFile($file);
$this->setToken(self::$token);
@@ -1327,9 +1327,10 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateResponse200($this->client->getResponse());
$this->evaluateMeta200($content);
/**
* check that there is a record or lazaret
*/
$datas = $content['response'];
$this->assertArrayHasKey('entity', $datas);
$this->assertArrayHasKey('url', $datas);
}
/**

View File

@@ -48,7 +48,7 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
$tmp = tempnam(sys_get_temp_dir(), 'testEtag');
copy(__DIR__ . '/../../../testfiles/cestlafete.jpg', $tmp);
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($tmp));
$media = self::$core['mediavorus']->guess(new \SplFileInfo($tmp));
$file = new Alchemy\Phrasea\Border\File($media, self::$collection);
$record = record_adapter::createFromFile($file);

View File

@@ -25,7 +25,7 @@ class FilenameTest extends \PhraseanetPHPUnitAbstract
$this->object = new Filename;
$this->filename = __DIR__ . '/../../../../../tmp/test001.CR2';
copy(__DIR__ . '/../../../../testfiles/test001.CR2', $this->filename);
$this->media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($this->filename));
$this->media = self::$core['mediavorus']->guess(new \SplFileInfo($this->filename));
}
public function tearDown()

View File

@@ -26,7 +26,7 @@ class MediaTypeTest extends \PhraseanetPHPUnitAbstract
*/
public function testCheck()
{
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/../../../../testfiles/test001.CR2'));
$media = self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../../../testfiles/test001.CR2'));
$file = new \Alchemy\Phrasea\Border\File($media, self::$collection);
$response = $this->object->check(self::$core['EM'], $file);
@@ -34,7 +34,7 @@ class MediaTypeTest extends \PhraseanetPHPUnitAbstract
$object = new MediaType(array('mediatypes' => array(MediaType::TYPE_VIDEO, MediaType::TYPE_AUDIO)));
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/../../../../testfiles/test001.CR2'));
$media = self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../../../testfiles/test001.CR2'));
$file = new \Alchemy\Phrasea\Border\File($media, self::$collection);
$response = $object->check(self::$core['EM'], $file);

View File

@@ -21,7 +21,7 @@ class Sha256Test extends \PhraseanetPHPUnitAbstract
$this->object = new Sha256;
$this->filename = __DIR__ . '/../../../../../tmp/test001.CR2';
copy(__DIR__ . '/../../../../testfiles/test001.CR2', $this->filename);
$this->media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($this->filename));
$this->media = self::$core['mediavorus']->guess(new \SplFileInfo($this->filename));
}
public function tearDown()

View File

@@ -21,7 +21,7 @@ class UUIDTest extends \PhraseanetPHPUnitAbstract
$this->object = new UUID;
$this->filename = __DIR__ . '/../../../../../tmp/test001.CR2';
copy(__DIR__ . '/../../../../testfiles/test001.CR2', $this->filename);
$this->media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($this->filename));
$this->media = self::$core['mediavorus']->guess(new \SplFileInfo($this->filename));
}
public function tearDown()

View File

@@ -22,7 +22,7 @@ class FileTest extends \PhraseanetPHPUnitAbstract
$this->filename = __DIR__ . '/../../../../tmp/iphone_pic.jpg';
copy(__DIR__ . '/../../../testfiles/iphone_pic.jpg', $this->filename);
$this->media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($this->filename));
$this->media = self::$core['mediavorus']->guess(new \SplFileInfo($this->filename));
$this->object = new File($this->media, self::$collection, 'originalName.txt');
}
@@ -60,20 +60,20 @@ class FileTest extends \PhraseanetPHPUnitAbstract
copy(__DIR__ . '/../../../testfiles/p4logo.jpg', $file);
$borderFile = new File(\MediaVorus\MediaVorus::guess(new \SplFileInfo($file)), self::$collection);
$borderFile = new File(self::$core['mediavorus']->guess(new \SplFileInfo($file)), self::$collection);
$uuid = $borderFile->getUUID(true, false);
$this->assertTrue(\uuid::is_valid($uuid));
$this->assertEquals($uuid, $borderFile->getUUID());
$borderFile = new File(\MediaVorus\MediaVorus::guess(new \SplFileInfo($file)), self::$collection);
$borderFile = new File(self::$core['mediavorus']->guess(new \SplFileInfo($file)), self::$collection);
$newuuid = $borderFile->getUUID(true, true);
$this->assertTrue(\uuid::is_valid($newuuid));
$this->assertNotEquals($uuid, $newuuid);
$this->assertEquals($newuuid, $borderFile->getUUID());
$borderFile = new File(\MediaVorus\MediaVorus::guess(new \SplFileInfo($file)), self::$collection);
$borderFile = new File(self::$core['mediavorus']->guess(new \SplFileInfo($file)), self::$collection);
$uuid = $borderFile->getUUID();
$this->assertTrue(\uuid::is_valid($uuid));
@@ -139,7 +139,7 @@ class FileTest extends \PhraseanetPHPUnitAbstract
*/
public function testOriginalNameAuto()
{
$object = new File(\MediaVorus\MediaVorus::guess(new \SplFileInfo($this->filename)), self::$collection);
$object = new File(self::$core['mediavorus']->guess(new \SplFileInfo($this->filename)), self::$collection);
$this->assertSame('iphone_pic.jpg', $object->getOriginalName());
}
@@ -180,7 +180,7 @@ class FileTest extends \PhraseanetPHPUnitAbstract
*/
public function testBuildFromPathfile()
{
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($this->filename));
$media = self::$core['mediavorus']->guess(new \SplFileInfo($this->filename));
$file1 = new File($media, self::$collection);
$file2 = File::buildFromPathfile($this->filename, self::$collection);
@@ -188,7 +188,7 @@ class FileTest extends \PhraseanetPHPUnitAbstract
$this->assertEquals($file1, $file2);
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($this->filename));
$media = self::$core['mediavorus']->guess(new \SplFileInfo($this->filename));
$file3 = new File($media, self::$collection, 'coco lapin');
$file4 = File::buildFromPathfile($this->filename, self::$collection, 'coco lapin');

View File

@@ -731,13 +731,15 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
throw new Exception(sprintf('File %d not found', $i));
};
$core = self::$core;
foreach (range(1, 24) as $i) {
static::$records['record_' . $i] = static::$records->share(function() use ($logger, $collection, $resolvePathfile, $i) {
static::$records['record_' . $i] = static::$records->share(function() use ($logger, $collection, $resolvePathfile, $i, $core) {
PhraseanetPHPUnitAbstract::$recordsInitialized[] = $i;
$file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess($resolvePathfile($i)), $collection);
$file = new Alchemy\Phrasea\Border\File($core['mediavorus']->guess($resolvePathfile($i)), $collection);
$record = record_adapter::createFromFile($file);
@@ -757,11 +759,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
$collection_no_access = self::$collection_no_access;
static::$records['record_no_access'] = static::$records->share(function()use($collection_no_access) {
static::$records['record_no_access'] = static::$records->share(function()use($collection_no_access, $core) {
PhraseanetPHPUnitAbstract::$recordsInitialized[] = 'no_access';
$file = new Alchemy\Phrasea\Border\File(MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/testfiles/test001.CR2')), $collection_no_access);
$file = new Alchemy\Phrasea\Border\File($core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/testfiles/test001.CR2')), $collection_no_access);
return record_adapter::createFromFile($file);
});

View File

@@ -82,7 +82,7 @@ class collectionTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_record_amount()
{
self::$object->empty_collection();
$file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg')), self::$object);
$file = new Alchemy\Phrasea\Border\File(self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg')), self::$object);
record_adapter::createFromFile($file);
$this->assertTrue(self::$object->get_record_amount() === 1);
self::$object->empty_collection();
@@ -129,7 +129,7 @@ class collectionTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_record_details()
{
$file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg')), self::$object);
$file = new Alchemy\Phrasea\Border\File(self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/testfiles/cestlafete.jpg')), self::$object);
$record = record_adapter::createFromFile($file);
$details = self::$object->get_record_details();

View File

@@ -27,7 +27,8 @@ class media_subdefTest extends \PhraseanetPHPUnitAbstract
{
parent::setUpBeforeClass();
$file = new Alchemy\Phrasea\Border\File(\MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . "/../testfiles/iphone_pic.jpg")), self::$collection);
$mediavorus = new \MediaVorus\MediaVorus();
$file = new Alchemy\Phrasea\Border\File($mediavorus->guess(new \SplFileInfo(__DIR__ . "/../testfiles/iphone_pic.jpg")), self::$collection);
$logger = new \Monolog\Logger('test');
$logger->pushHandler(new \Monolog\Handler\NullHandler());

View File

@@ -417,7 +417,7 @@ class task_period_archiveTest extends \PhraseanetPHPUnitAbstract
public function testGetIndexByFieldName()
{
$meta_struct = self::$collection->get_databox()->get_meta_structure();
$media = \MediaVorus\MediaVorus::guess(new \SplFileInfo(__DIR__ . '/../../testfiles/test001.CR2'));
$media = self::$core['mediavorus']->guess(new \SplFileInfo(__DIR__ . '/../../testfiles/test001.CR2'));
$bagByName = self::$object->getIndexByFieldNameTester($meta_struct, $media->getEntity()->getMetadatas());