From 77352e59efec63a65ce99f740e8bd295c77641e9 Mon Sep 17 00:00:00 2001 From: Sandeep Date: Mon, 26 Feb 2018 11:30:55 +0400 Subject: [PATCH] PHRAS-1856_PORT-PHRAS-1347 --- .../Command/Developer/RegenerateSqliteDb.php | 4 ++-- .../Phrasea/Controller/Api/V1Controller.php | 18 +++++++++++++++--- .../Controller/Prod/LazaretController.php | 3 +-- .../Controller/Prod/ToolsController.php | 10 +++++++--- .../Controller/Prod/UploadController.php | 2 +- .../Phrasea/TaskManager/Job/ArchiveJob.php | 2 +- .../Tests/Phrasea/Application/OverviewTest.php | 9 ++++++++- .../Phrasea/Controller/Prod/LazaretTest.php | 4 ++-- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php index 1a1c3770b1..a6d9606dee 100644 --- a/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php +++ b/lib/Alchemy/Phrasea/Command/Developer/RegenerateSqliteDb.php @@ -432,8 +432,8 @@ class RegenerateSqliteDb extends Command if ($i < 3) { /** @var SubdefSubstituer $substituer */ $substituer = $this->container['subdef.substituer']; - $substituer->substitute($story, 'preview', $media); - $substituer->substitute($story, 'thumbnail', $media); + $substituer->substituteSubdef($story, 'preview', $media); + $substituer->substituteSubdef($story, 'thumbnail', $media); } $DI['record_story_' . $i] = $story; } diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index c9e6eeb935..e8be1f7d24 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -1010,7 +1010,15 @@ class V1Controller extends Controller return $this->getBadRequestAction($request, 'Missing name parameter'); } - $media = $this->app->getMediaFromUri($file->getPathname()); + // Add file extension + $uploadedFilename = $file->getRealPath(); + + $renamedFilename = $file->getRealPath() . '.' . pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); + + $this->getFilesystem()->rename($uploadedFilename, $renamedFilename); + + $media = $this->app->getMediaFromUri($renamedFilename); + $record = $this->findDataboxById($request->get('databox_id'))->get_record($request->get('record_id')); $base_id = $record->getBaseId(); $collection = \collection::getByBaseId($this->app, $base_id); @@ -1021,7 +1029,11 @@ class V1Controller extends Controller } $adapt = ($request->get('adapt')===null || !(\p4field::isno($request->get('adapt')))); $ret['adapt'] = $adapt; - $this->getSubdefSubstituer()->substitute($record, $request->get('name'), $media, $adapt); + if($request->get('name') == 'document') { + $this->getSubdefSubstituer()->substituteDocument($record, $media, $adapt); + } else { + $this->getSubdefSubstituer()->substituteSubdef($record, $request->get('name'), $media, $adapt); + } foreach ($record->get_embedable_medias() as $name => $media) { if ($name == $request->get('name') && null !== ($subdef = $this->listEmbeddableMedia($request, $record, $media))) { @@ -2623,7 +2635,7 @@ class V1Controller extends Controller continue; } $media = $this->app->getMediaFromUri($value->getRealPath()); - $this->getSubdefSubstituer()->substitute($story, $name, $media); + $this->getSubdefSubstituer()->substituteSubdef($story, $name, $media); // name = thumbnail | preview $this->getDataboxLogger($story->getDatabox())->log( $story, \Session_Logger::EVENT_SUBSTITUTE, diff --git a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php index b9c1d1567b..035476d5fb 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php @@ -225,8 +225,7 @@ class LazaretController extends Controller $media = $this->app->getMediaFromUri($lazaretFileName); $record = $lazaretFile->getCollection($this->app)->get_databox()->get_record($recordId); - $this->getSubDefinitionSubstituer() - ->substitute($record, 'document', $media); + $this->getSubDefinitionSubstituer()->substituteDocument($record, $media); $this->getDataboxLogger($record->getDatabox())->log( $record, \Session_Logger::EVENT_SUBSTITUTE, diff --git a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php index 0139be9586..9971e801ba 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php @@ -192,7 +192,7 @@ class ToolsController extends Controller $media = $this->app->getMediaFromUri($tempoFile); - $this->getSubDefinitionSubstituer()->substitute($record, 'document', $media); + $this->getSubDefinitionSubstituer()->substituteDocument($record, $media); $record->insertTechnicalDatas($this->getMediaVorus()); $this->getMetadataSetter()->replaceMetadata($this->getMetadataReader() ->read($media), $record); @@ -252,7 +252,7 @@ class ToolsController extends Controller $media = $this->app->getMediaFromUri($tempoFile); - $this->getSubDefinitionSubstituer()->substitute($record, 'thumbnail', $media); + $this->getSubDefinitionSubstituer()->substituteSubdef($record, 'thumbnail', $media); $this->getDataboxLogger($record->getDatabox()) ->log($record, \Session_Logger::EVENT_SUBSTITUTE, 'thumbnail', ''); @@ -416,7 +416,11 @@ class ToolsController extends Controller $media = $this->app->getMediaFromUri($fileName); - $this->getSubDefinitionSubstituer()->substitute($record, $subDefName, $media); + if($subDefName == 'document') { + $this->getSubDefinitionSubstituer()->substituteDocument($record, $media); + } else { + $this->getSubDefinitionSubstituer()->substituteSubdef($record, $subDefName, $media); + } $this->getDataboxLogger($record->getDatabox()) ->log($record, \Session_Logger::EVENT_SUBSTITUTE, $subDefName, ''); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php b/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php index a42ba5145c..a56c7d957a 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/UploadController.php @@ -193,7 +193,7 @@ class UploadController extends Controller file_put_contents($fileName, $dataUri->getData()); $media = $this->app->getMediaFromUri($fileName); - $this->getSubDefinitionSubstituer()->substitute($elementCreated, 'thumbnail', $media); + $this->getSubDefinitionSubstituer()->substituteSubdef($elementCreated, 'thumbnail', $media); $this->getDataboxLogger($elementCreated->getDatabox()) ->log($elementCreated, \Session_Logger::EVENT_SUBSTITUTE, 'thumbnail', ''); diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php index 87a5c34e64..c1408d596e 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php @@ -1003,7 +1003,7 @@ class ArchiveJob extends AbstractJob } $story = \record_adapter::createStory($app, $collection); - $app['subdef.substituer']->substitute($story, 'document', $media); + $app['subdef.substituer']->substituteDocument($story, $media); $story->set_metadatas($metadatas->toMetadataArray($metadatasStructure), true); diff --git a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php index 5e2d3ca11a..d98c9d7c61 100644 --- a/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php +++ b/tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php @@ -2,6 +2,7 @@ namespace Alchemy\Tests\Phrasea\Application; +use Alchemy\Phrasea\Media\SubdefSubstituer; use Alchemy\Phrasea\Model\Entities\Feed; use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedItem; @@ -254,7 +255,13 @@ class OverviewTest extends \PhraseanetAuthenticatedWebTestCase ->method('getFile') ->will($this->returnValue($symfoFile)); - self::$DI['app']['subdef.substituer']->substitute($story, $name, $media); + /** @var SubdefSubstituer $substituter */ + $substituter = self::$DI['app']['subdef.substituer']; + if($name == 'document') { + $substituter->substituteDocument($story, $media); + } else { + $substituter->substituteSubdef($story, $name, $media); + } $path = self::$DI['app']['url_generator']->generate('datafile', [ 'sbas_id' => $story->getDataboxId(), diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php index 82c916e197..0430b61b2f 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php @@ -296,8 +296,8 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase //expect one call to substitute the documents self::$DI['app']['subdef.substituer']->expects($this->once()) - ->method('substitute') - ->with($record, $this->equalTo('document')); + ->method('substituteDocument') + ->with($record); $databox = $this->getMock('databox', [], [], '', false);