From 6b237ec7b72b75fa51ee948575136d9a20bade07 Mon Sep 17 00:00:00 2001 From: Andrei Shapiro Date: Tue, 12 Nov 2024 10:07:11 +0300 Subject: [PATCH] chore: rename event and listener --- ...tao.php => Version202411111300522235_tao.php} | 16 ++++++++-------- ...ngedEvent.php => TranslationTouchedEvent.php} | 7 +------ ...r.php => TranslationTouchedEventListener.php} | 6 +++--- .../Service/TranslationCreationService.php | 4 ++-- .../Service/TranslationDeletionService.php | 4 ++-- .../Service/TranslationSyncService.php | 4 ++-- .../TranslationServiceProvider.php | 4 ++-- 7 files changed, 20 insertions(+), 25 deletions(-) rename migrations/{Version202410100711422234_tao.php => Version202411111300522235_tao.php} (61%) rename models/classes/Translation/Event/{ResourceTranslationChangedEvent.php => TranslationTouchedEvent.php} (89%) rename models/classes/Translation/Listener/{ResourceTranslationChangedEventListener.php => TranslationTouchedEventListener.php} (90%) diff --git a/migrations/Version202410100711422234_tao.php b/migrations/Version202411111300522235_tao.php similarity index 61% rename from migrations/Version202410100711422234_tao.php rename to migrations/Version202411111300522235_tao.php index d60f201094..7d07fa163c 100644 --- a/migrations/Version202410100711422234_tao.php +++ b/migrations/Version202411111300522235_tao.php @@ -6,26 +6,26 @@ use Doctrine\DBAL\Schema\Schema; use oat\oatbox\event\EventManager; -use oat\tao\model\Translation\Event\ResourceTranslationChangedEvent; -use oat\tao\model\Translation\Listener\ResourceTranslationChangedEventListener; +use oat\tao\model\Translation\Event\TranslationTouchedEvent; +use oat\tao\model\Translation\Listener\TranslationTouchedEventListener; use oat\tao\scripts\tools\migrations\AbstractMigration; /** * phpcs:disable Squiz.Classes.ValidClassName */ -final class Version202410100711422234_tao extends AbstractMigration +final class Version202411111300522235_tao extends AbstractMigration { public function getDescription(): string { - return 'Register new event to detect translation changes'; + return 'Register new event to detect when translations are touched (created, deleted, updated, synchronized)'; } public function up(Schema $schema): void { $eventManager = $this->getEventManager(); $eventManager->attach( - ResourceTranslationChangedEvent::class, - [ResourceTranslationChangedEventListener::class, 'onResourceTranslationChanged'] + TranslationTouchedEvent::class, + [TranslationTouchedEventListener::class, 'onTranslationTouched'], ); $this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager); } @@ -34,8 +34,8 @@ public function down(Schema $schema): void { $eventManager = $this->getEventManager(); $eventManager->detach( - ResourceTranslationChangedEvent::class, - [ResourceTranslationChangedEventListener::class, 'onResourceTranslationChanged'] + TranslationTouchedEvent::class, + [TranslationTouchedEventListener::class, 'onTranslationTouched'] ); $this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager); } diff --git a/models/classes/Translation/Event/ResourceTranslationChangedEvent.php b/models/classes/Translation/Event/TranslationTouchedEvent.php similarity index 89% rename from models/classes/Translation/Event/ResourceTranslationChangedEvent.php rename to models/classes/Translation/Event/TranslationTouchedEvent.php index d16e3bb179..1647a78387 100644 --- a/models/classes/Translation/Event/ResourceTranslationChangedEvent.php +++ b/models/classes/Translation/Event/TranslationTouchedEvent.php @@ -24,7 +24,7 @@ use oat\oatbox\event\Event; -class ResourceTranslationChangedEvent implements Event +class TranslationTouchedEvent implements Event { private string $resourceUri; @@ -42,9 +42,4 @@ public function getResourceUri(): string { return $this->resourceUri; } - - public function getLanguage(): string - { - return $this->language; - } } diff --git a/models/classes/Translation/Listener/ResourceTranslationChangedEventListener.php b/models/classes/Translation/Listener/TranslationTouchedEventListener.php similarity index 90% rename from models/classes/Translation/Listener/ResourceTranslationChangedEventListener.php rename to models/classes/Translation/Listener/TranslationTouchedEventListener.php index 34bd768cec..029db2ece5 100644 --- a/models/classes/Translation/Listener/ResourceTranslationChangedEventListener.php +++ b/models/classes/Translation/Listener/TranslationTouchedEventListener.php @@ -25,11 +25,11 @@ use oat\generis\model\data\Ontology; use oat\tao\model\TaoOntology; use oat\tao\model\Translation\Entity\AbstractResource; -use oat\tao\model\Translation\Event\ResourceTranslationChangedEvent; +use oat\tao\model\Translation\Event\TranslationTouchedEvent; use oat\tao\model\Translation\Query\ResourceTranslationQuery; use oat\tao\model\Translation\Repository\ResourceTranslationRepository; -class ResourceTranslationChangedEventListener +class TranslationTouchedEventListener { private Ontology $ontology; private ResourceTranslationRepository $resourceTranslationRepository; @@ -40,7 +40,7 @@ public function __construct(Ontology $ontology, ResourceTranslationRepository $r $this->resourceTranslationRepository = $resourceTranslationRepository; } - public function onResourceTranslationChanged(ResourceTranslationChangedEvent $event): void + public function onTranslationTouched(TranslationTouchedEvent $event): void { $resource = $this->ontology->getResource($event->getResourceUri()); $property = $this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATED_INTO_LANGUAGES); diff --git a/models/classes/Translation/Service/TranslationCreationService.php b/models/classes/Translation/Service/TranslationCreationService.php index d69da74c66..3c6fff8c15 100644 --- a/models/classes/Translation/Service/TranslationCreationService.php +++ b/models/classes/Translation/Service/TranslationCreationService.php @@ -32,7 +32,7 @@ use oat\tao\model\TaoOntology; use oat\tao\model\Translation\Command\CreateTranslationCommand; use oat\tao\model\Translation\Entity\ResourceTranslatable; -use oat\tao\model\Translation\Event\ResourceTranslationChangedEvent; +use oat\tao\model\Translation\Event\TranslationTouchedEvent; use oat\tao\model\Translation\Exception\ResourceTranslationException; use oat\tao\model\Translation\Query\ResourceTranslatableQuery; use oat\tao\model\Translation\Query\ResourceTranslationQuery; @@ -194,7 +194,7 @@ public function create(CreateTranslationCommand $command): core_kernel_classes_R $callable($clonedInstance); } - $this->eventManager->trigger(new ResourceTranslationChangedEvent($resourceUri)); + $this->eventManager->trigger(new TranslationTouchedEvent($resourceUri)); return $clonedInstance; } catch (Throwable $exception) { diff --git a/models/classes/Translation/Service/TranslationDeletionService.php b/models/classes/Translation/Service/TranslationDeletionService.php index 4b2d4355b0..d9f2a6211b 100644 --- a/models/classes/Translation/Service/TranslationDeletionService.php +++ b/models/classes/Translation/Service/TranslationDeletionService.php @@ -27,7 +27,7 @@ use oat\generis\model\resource\Contract\ResourceDeleterInterface; use oat\oatbox\event\EventManager; use oat\tao\model\Translation\Entity\AbstractResource; -use oat\tao\model\Translation\Event\ResourceTranslationChangedEvent; +use oat\tao\model\Translation\Event\TranslationTouchedEvent; use oat\tao\model\Translation\Exception\ResourceTranslationException; use oat\tao\model\Translation\Query\ResourceTranslationQuery; use oat\tao\model\Translation\Repository\ResourceTranslationRepository; @@ -92,7 +92,7 @@ public function deleteByRequest(ServerRequestInterface $request): core_kernel_cl $this->resourceDeleter->delete($resource); } - $this->eventManager->trigger(new ResourceTranslationChangedEvent($resourceUri)); + $this->eventManager->trigger(new TranslationTouchedEvent($resourceUri)); return $resource; } catch (Throwable $exception) { diff --git a/models/classes/Translation/Service/TranslationSyncService.php b/models/classes/Translation/Service/TranslationSyncService.php index 7c853e8c2a..2811e83b89 100644 --- a/models/classes/Translation/Service/TranslationSyncService.php +++ b/models/classes/Translation/Service/TranslationSyncService.php @@ -27,7 +27,7 @@ use oat\oatbox\event\EventManager; use oat\tao\model\TaoOntology; use oat\tao\model\Translation\Entity\ResourceTranslation; -use oat\tao\model\Translation\Event\ResourceTranslationChangedEvent; +use oat\tao\model\Translation\Event\TranslationTouchedEvent; use oat\tao\model\Translation\Exception\ResourceTranslationException; use oat\tao\model\Translation\Query\ResourceTranslationQuery; use oat\tao\model\Translation\Repository\ResourceTranslationRepository; @@ -82,7 +82,7 @@ public function syncByRequest(ServerRequestInterface $request): core_kernel_clas } } - $this->eventManager->trigger(new ResourceTranslationChangedEvent($id)); + $this->eventManager->trigger(new TranslationTouchedEvent($id)); return $resource; } diff --git a/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php b/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php index 8064899353..8e2a27cec2 100644 --- a/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php +++ b/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php @@ -34,7 +34,7 @@ use oat\tao\model\Translation\Factory\ResourceTranslatableFactory; use oat\tao\model\Translation\Factory\ResourceTranslationFactory; use oat\tao\model\Translation\Form\Modifier\TranslationFormModifier; -use oat\tao\model\Translation\Listener\ResourceTranslationChangedEventListener; +use oat\tao\model\Translation\Listener\TranslationTouchedEventListener; use oat\tao\model\Translation\Repository\ResourceTranslatableRepository; use oat\tao\model\Translation\Repository\ResourceTranslationRepository; use oat\tao\model\Translation\Service\ResourceLanguageRetriever; @@ -182,7 +182,7 @@ public function __invoke(ContainerConfigurator $configurator): void ]); $services - ->set(ResourceTranslationChangedEventListener::class, ResourceTranslationChangedEventListener::class) + ->set(TranslationTouchedEventListener::class, TranslationTouchedEventListener::class) ->args([ service(Ontology::SERVICE_ID), service(ResourceTranslationRepository::class),