From 89fe434807adadb254a8de72d7e731cc8f5e507d Mon Sep 17 00:00:00 2001 From: Andrei Shapiro Date: Mon, 4 Nov 2024 19:43:15 +0300 Subject: [PATCH 1/2] feat: better handling of unique IDs --- models/classes/Copier/CopierServiceProvider.php | 6 ++++++ .../Translation/Form/Modifier/TranslationFormModifier.php | 4 ++++ models/classes/event/TestDuplicatedEvent.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/models/classes/Copier/CopierServiceProvider.php b/models/classes/Copier/CopierServiceProvider.php index 59bece0e..af9ac28e 100644 --- a/models/classes/Copier/CopierServiceProvider.php +++ b/models/classes/Copier/CopierServiceProvider.php @@ -95,6 +95,12 @@ public function __invoke(ContainerConfigurator $configurator): void [ tagged_iterator('tao.copier.permissions'), ] + ) + ->call( + 'withEventManager', + [ + service(EventManager::class), + ] ); $services diff --git a/models/classes/Translation/Form/Modifier/TranslationFormModifier.php b/models/classes/Translation/Form/Modifier/TranslationFormModifier.php index f370d765..6c0a19fb 100644 --- a/models/classes/Translation/Form/Modifier/TranslationFormModifier.php +++ b/models/classes/Translation/Form/Modifier/TranslationFormModifier.php @@ -59,6 +59,10 @@ public function modify(Form $form, array $options = []): void (string)$translationType : $translationType->getUri(); + $translationTypeUri = $translationType instanceof core_kernel_classes_Literal + ? (string) $translationType + : $translationType->getUri(); + if ( empty($translationType) || $translationTypeUri === TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL diff --git a/models/classes/event/TestDuplicatedEvent.php b/models/classes/event/TestDuplicatedEvent.php index 147e5817..e840a422 100644 --- a/models/classes/event/TestDuplicatedEvent.php +++ b/models/classes/event/TestDuplicatedEvent.php @@ -67,4 +67,9 @@ public function jsonSerialize() 'cloneUri' => $this->cloneUri ]; } + + public function getCloneUri(): string + { + return $this->cloneUri; + } } From ab08f0192487ff79ee7d14183bb2685674050785 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 5 Nov 2024 11:01:14 +0100 Subject: [PATCH 2/2] chore: use new service to clone --- .../Translation/Form/Modifier/TranslationFormModifier.php | 7 ++----- .../ServiceProvider/TranslationServiceProvider.php | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/models/classes/Translation/Form/Modifier/TranslationFormModifier.php b/models/classes/Translation/Form/Modifier/TranslationFormModifier.php index 6c0a19fb..ba53265f 100644 --- a/models/classes/Translation/Form/Modifier/TranslationFormModifier.php +++ b/models/classes/Translation/Form/Modifier/TranslationFormModifier.php @@ -23,6 +23,7 @@ namespace oat\taoTests\models\Translation\Form\Modifier; use core_kernel_classes_Literal; +use core_kernel_classes_Resource; use oat\generis\model\data\Ontology; use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; use oat\tao\model\form\Modifier\AbstractFormModifier; @@ -55,13 +56,9 @@ public function modify(Form $form, array $options = []): void $translationType = $instance->getOnePropertyValue( $this->ontology->getProperty(TaoOntology::PROPERTY_TRANSLATION_TYPE) ); - $translationTypeUri = $translationType instanceof core_kernel_classes_Literal ? - (string)$translationType : - $translationType->getUri(); - $translationTypeUri = $translationType instanceof core_kernel_classes_Literal ? (string) $translationType - : $translationType->getUri(); + : ($translationType instanceof core_kernel_classes_Resource ? $translationType->getUri() : null); if ( empty($translationType) diff --git a/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php b/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php index e2d4b54b..4474628d 100644 --- a/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php +++ b/models/classes/Translation/ServiceProvider/TranslationServiceProvider.php @@ -25,6 +25,7 @@ use oat\generis\model\data\Ontology; use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; use oat\oatbox\log\LoggerService; +use oat\tao\model\resources\Service\InstanceCopier; use oat\tao\model\TaoOntology; use oat\tao\model\featureFlag\FeatureFlagChecker; use oat\tao\model\Translation\Form\Modifier\TranslationFormModifier as TaoTranslationFormModifier; @@ -37,7 +38,6 @@ use oat\taoTests\models\Translation\Listener\TestCreatedEventListener; use oat\taoTests\models\Translation\Service\TranslationPostCreationService; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use taoTests_models_classes_TestsService; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; @@ -102,10 +102,10 @@ public function __invoke(ContainerConfigurator $configurator): void $services ->get(TranslationCreationService::class) ->call( - 'setOntologyClassService', + 'setResourceTransfer', [ TaoOntology::CLASS_URI_TEST, - service(taoTests_models_classes_TestsService::class) + service(InstanceCopier::class . '::TESTS') ] ) ->call(