diff --git a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php index a0784a46eb..90012df68e 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/ToolsController.php @@ -10,14 +10,16 @@ namespace Alchemy\Phrasea\Controller\Prod; use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware; +use Alchemy\Phrasea\Application\Helper\DispatcherAware; use Alchemy\Phrasea\Application\Helper\FilesystemAware; use Alchemy\Phrasea\Application\Helper\SubDefinitionSubstituerAware; use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Controller\RecordsRequest; +use Alchemy\Phrasea\Core\Event\Record\RecordEvents; use Alchemy\Phrasea\Exception\RuntimeException; -use Alchemy\Phrasea\Media\SubdefSubstituer; use Alchemy\Phrasea\Metadata\PhraseanetMetadataReader; use Alchemy\Phrasea\Metadata\PhraseanetMetadataSetter; +use Alchemy\Phrasea\Record\RecordWasRotated; use DataURI\Parser; use MediaAlchemyst\Alchemyst; use MediaVorus\MediaVorus; @@ -28,6 +30,7 @@ use Symfony\Component\HttpFoundation\Request; class ToolsController extends Controller { use DataboxLoggerAware; + use DispatcherAware; use FilesystemAware; use SubDefinitionSubstituerAware; @@ -105,6 +108,16 @@ class ToolsController extends Controller { $records = RecordsRequest::fromRequest($this->app, $request, false); $rotation = (int)$request->request->get('rotation', 90); + $rotation %= 360; + + if ($rotation > 180) { + $rotation -= 360; + } + + if ($rotation <= -180) { + $rotation += 360; + } + if (!in_array($rotation, [-90, 90, 180], true)) { $rotation = 90; } @@ -118,8 +131,11 @@ class ToolsController extends Controller try { $subdef->rotate($rotation, $this->getMediaAlchemyst(), $this->getMediaVorus()); } catch (\Exception $e) { + // ignore exception } } + + $this->dispatch(RecordEvents::ROTATE, new RecordWasRotated($record, $rotation)); } return $this->app->json(['success' => true, 'errorMessage' => '']); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php index f6c28d7fc5..103e9aad51 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Tools.php @@ -28,6 +28,7 @@ class Tools implements ControllerProviderInterface, ServiceProviderInterface $app['controller.prod.tools'] = $app->share(function (PhraseaApplication $app) { return (new ToolsController($app)) ->setDataboxLoggerLocator($app['phraseanet.logger']) + ->setDispatcher($app['dispatcher']) ->setFileSystemLocator(new LazyLocator($app, 'filesystem')) ->setSubDefinitionSubstituerLocator(new LazyLocator($app, 'subdef.substituer')) ; diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvent.php index a0355f2968..81b25fd336 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvent.php @@ -1,9 +1,8 @@ record = $record; diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvents.php b/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvents.php index 25e22c3f9a..47db7da5be 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvents.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/RecordEvents.php @@ -20,6 +20,8 @@ final class RecordEvents const METADATA_CHANGED = 'record.metadata_changed'; const ORIGINAL_NAME_CHANGED = 'record.original_name_changed'; const STATUS_CHANGED = 'record.status_changed'; + const ROTATE = 'record.rotate'; + // Sub-definitions const SUB_DEFINITIONS_CREATION = 'record.sub_definitions_creation'; const SUB_DEFINITION_CREATION = 'record.sub_definition_creation'; diff --git a/lib/Alchemy/Phrasea/Record/RecordWasRotated.php b/lib/Alchemy/Phrasea/Record/RecordWasRotated.php new file mode 100644 index 0000000000..4393ee6106 --- /dev/null +++ b/lib/Alchemy/Phrasea/Record/RecordWasRotated.php @@ -0,0 +1,39 @@ +angle = $angle; + } + + public function getAngle() + { + return $this->angle; + } +} diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php index 47257bf198..7e374c44fa 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php @@ -1,9 +1,8 @@ indexer = $indexer; } - /** @return Indexer */ + /** + * @return Indexer + */ public function getIndexer() { if ($this->indexer instanceof Indexer) { @@ -86,6 +86,7 @@ class IndexerSubscriber implements EventSubscriberInterface RecordEvents::STATUS_CHANGED => 'onRecordChange', RecordEvents::SUB_DEFINITIONS_CREATED => 'onRecordChange', RecordEvents::MEDIA_SUBSTITUTED => 'onRecordChange', + RecordEvents::ROTATE => 'onRecordChange', ThesaurusEvents::IMPORTED => 'onThesaurusChange', ThesaurusEvents::FIELD_LINKED => 'onThesaurusChange', ThesaurusEvents::CANDIDATE_ACCEPTED_AS_CONCEPT => 'onThesaurusChange',