Skip to content

Commit

Permalink
chore: rename event and listener
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed Nov 12, 2024
1 parent ff5e27f commit 6b237ec
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

use oat\oatbox\event\Event;

class ResourceTranslationChangedEvent implements Event
class TranslationTouchedEvent implements Event
{
private string $resourceUri;

Expand All @@ -42,9 +42,4 @@ public function getResourceUri(): string
{
return $this->resourceUri;
}

public function getLanguage(): string
{
return $this->language;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions models/classes/Translation/Service/TranslationSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 6b237ec

Please sign in to comment.