From a9a52e10e21d6c9406e2a60b14c3986337f81129 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Mon, 15 Jun 2020 10:40:45 +0200 Subject: [PATCH 01/15] extending the events with extra info and make them available for webhooks --- manifest.php | 2 +- models/events/TestTakerCreatedEvent.php | 25 +++++++++++++++++++++- models/events/TestTakerImportedEvent.php | 25 +++++++++++++++++++++- models/events/TestTakerRemovedEvent.php | 27 +++++++++++++++++++++++- scripts/update/Updater.php | 2 +- 5 files changed, 76 insertions(+), 5 deletions(-) diff --git a/manifest.php b/manifest.php index 7eeeaf6c..4ce59697 100755 --- a/manifest.php +++ b/manifest.php @@ -34,7 +34,7 @@ 'label' => 'Test-taker core extension', 'description' => 'TAO TestTaker extension', 'license' => 'GPL-2.0', - 'version' => '7.5.0', + 'version' => '7.6.0', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => [ 'generis' => '>=12.15.0', diff --git a/models/events/TestTakerCreatedEvent.php b/models/events/TestTakerCreatedEvent.php index 80ecfeee..1cebffbd 100644 --- a/models/events/TestTakerCreatedEvent.php +++ b/models/events/TestTakerCreatedEvent.php @@ -22,11 +22,34 @@ namespace oat\taoTestTaker\models\events; +use oat\tao\model\webhooks\WebhookSerializableEventInterface; + /** * Class TestTakerCreatedEvent * @package oat\taoTestTaker\models\events */ -class TestTakerCreatedEvent extends AbstractTestTakerEvent +class TestTakerCreatedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface { + /** + * @inheritDoc + */ + public function getWebhookEventName() + { + return 'test-taker-created'; + } + /** + * @inheritDoc + */ + public function serializeForWebhook() + { + return [ + 'name' => $this->getWebhookEventName(), + 'payload' => [ + 'testTakerUri' => $this->testTakerUri, + 'unit' => 1, + 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, + ], + ]; + } } diff --git a/models/events/TestTakerImportedEvent.php b/models/events/TestTakerImportedEvent.php index 2e0b8f29..e8af249f 100644 --- a/models/events/TestTakerImportedEvent.php +++ b/models/events/TestTakerImportedEvent.php @@ -22,11 +22,34 @@ namespace oat\taoTestTaker\models\events; +use oat\tao\model\webhooks\WebhookSerializableEventInterface; + /** * Class TestTakerImportedEvent * @package oat\taoTestTaker\models\events */ -class TestTakerImportedEvent extends AbstractTestTakerEvent +class TestTakerImportedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface { + /** + * @inheritDoc + */ + public function getWebhookEventName() + { + return 'test-taker-created'; + } + /** + * @inheritDoc + */ + public function serializeForWebhook() + { + return [ + 'name' => $this->getWebhookEventName(), + 'payload' => [ + 'testTakerUri' => $this->testTakerUri, + 'unit' => 1, + 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL + ], + ]; + } } diff --git a/models/events/TestTakerRemovedEvent.php b/models/events/TestTakerRemovedEvent.php index 83047c09..de6f5833 100644 --- a/models/events/TestTakerRemovedEvent.php +++ b/models/events/TestTakerRemovedEvent.php @@ -22,11 +22,36 @@ namespace oat\taoTestTaker\models\events; +use oat\tao\model\webhooks\WebhookSerializableEventInterface; + /** * Class TestTakerRemovedEvent * @package oat\taoTestTaker\models\events */ -class TestTakerRemovedEvent extends AbstractTestTakerEvent +class TestTakerRemovedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface { const EVENT_NAME = __CLASS__; + + /** + * @inheritDoc + */ + public function getWebhookEventName() + { + return 'test-taker-removed'; + } + + /** + * @inheritDoc + */ + public function serializeForWebhook() + { + return [ + 'name' => $this->getWebhookEventName(), + 'payload' => [ + 'testTakerUri' => $this->testTakerUri, + 'unit' => 1, + 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, + ], + ]; + } } diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index f6c7fac5..5ac102c7 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -99,6 +99,6 @@ public function update($initialVersion) $this->setVersion('3.11.0'); } - $this->skip('3.11.0', '7.5.0'); + $this->skip('3.11.0', '7.6.0'); } } From 3854a4ee5b92376da60af19038908c2bae93874c Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Mon, 15 Jun 2020 11:54:11 +0200 Subject: [PATCH 02/15] fix manifest and event name --- manifest.php | 14 ++++++++++---- models/events/TestTakerImportedEvent.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/manifest.php b/manifest.php index 4ce59697..6ed9dbb1 100755 --- a/manifest.php +++ b/manifest.php @@ -26,6 +26,12 @@ * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php * */ + +use oat\taoTestTaker\models\routing\ApiRoute; +use oat\taoTestTaker\models\TestTakerService; +use oat\taoTestTaker\scripts\install\SetupConfig; +use oat\taoTestTaker\scripts\install\SetupTesttakerCsvImporter; + $extpath = dirname(__FILE__) . DIRECTORY_SEPARATOR; $taopath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'tao' . DIRECTORY_SEPARATOR; @@ -49,17 +55,17 @@ dirname(__FILE__) . '/models/ontology/taosubject.rdf' ], 'php' => [ - \oat\taoTestTaker\scripts\install\SetupConfig::class, - \oat\taoTestTaker\scripts\install\SetupTesttakerCsvImporter::class, + SetupConfig::class, + SetupTesttakerCsvImporter::class, ] ], 'update' => "oat\\taoTestTaker\\scripts\\update\\Updater", 'managementRole' => 'http://www.tao.lu/Ontologies/TAOSubject.rdf#SubjectsManagerRole', 'acl' => [ - ['grant', \oat\taoTestTaker\models\TestTakerService::ROLE_SUBJECT_MANAGER, ['ext' => 'taoTestTaker']] + ['grant', TestTakerService::ROLE_SUBJECT_MANAGER, ['ext' => 'taoTestTaker']] ], 'routes' => [ - '/taoTestTaker/api' => ['class' => \oat\taoTestTaker\models\routing\ApiRoute::class], + '/taoTestTaker/api' => ['class' => ApiRoute::class], '/taoTestTaker' => 'oat\\taoTestTaker\\actions' ], 'constants' => [ diff --git a/models/events/TestTakerImportedEvent.php b/models/events/TestTakerImportedEvent.php index e8af249f..f446318f 100644 --- a/models/events/TestTakerImportedEvent.php +++ b/models/events/TestTakerImportedEvent.php @@ -35,7 +35,7 @@ class TestTakerImportedEvent extends AbstractTestTakerEvent implements WebhookSe */ public function getWebhookEventName() { - return 'test-taker-created'; + return 'test-taker-imported'; } /** From 19152e71e3bca55cd59d6c26a76022348c7a6986 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 16 Jun 2020 09:14:48 +0200 Subject: [PATCH 03/15] make RDF import dispatch events --- actions/Import.php | 23 ++++++++--------- models/RdfImporter.php | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 models/RdfImporter.php diff --git a/actions/Import.php b/actions/Import.php index 4c30a7c2..25a1b009 100644 --- a/actions/Import.php +++ b/actions/Import.php @@ -23,14 +23,11 @@ namespace oat\taoTestTaker\actions; -use common_report_Report; -use core_kernel_classes_Resource; -use oat\generis\Helper\UserHashForEncryption; -use oat\generis\model\GenerisRdf; use oat\taoTestTaker\models\CsvImporter; -use oat\taoTestTaker\models\events\TestTakerImportedEvent; -use oat\taoTestTaker\models\TestTakerSavePasswordInMemory; -use tao_helpers_form_FormFactory; +use oat\taoTestTaker\models\RdfImporter; +use tao_actions_Import; +use tao_models_classes_import_CsvImporter; +use tao_models_classes_import_RdfImporter; /** * Extends the common Import class to exchange the generic @@ -38,22 +35,26 @@ * * @author Bertrand Chevrier, */ -class Import extends \tao_actions_Import +class Import extends tao_actions_Import { /** - * (non-PHPdoc) - * @see tao_actions_Import::getAvailableImportHandlers() + * @inheritDoc */ public function getAvailableImportHandlers() { $returnValue = parent::getAvailableImportHandlers(); foreach (array_keys($returnValue) as $key) { - if ($returnValue[$key] instanceof \tao_models_classes_import_CsvImporter) { + if ($returnValue[$key] instanceof tao_models_classes_import_CsvImporter) { $importer = new CsvImporter(); $importer->setValidators($this->getValidators()); $returnValue[$key] = $importer; } + + if ($returnValue[$key] instanceof tao_models_classes_import_RdfImporter) { + $importer = new RdfImporter(); + $returnValue[$key] = $importer; + } } return $returnValue; diff --git a/models/RdfImporter.php b/models/RdfImporter.php new file mode 100644 index 00000000..92536cbe --- /dev/null +++ b/models/RdfImporter.php @@ -0,0 +1,56 @@ +getSuccesses() as $success) { + $resource = $success->getData(); + + try { + $this->getEventManager()->trigger( + new TestTakerImportedEvent($resource->getUri(), $this->getProperties($resource)) + ); + } catch (Exception $e) { + common_Logger::e($e->getMessage()); + } + } + + return $report; + } + + protected function getProperties(core_kernel_classes_Resource $resource): array + { + return []; + } +} From 451b3590faf36318520685d863a684528162babf Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Tue, 16 Jun 2020 16:54:43 +0200 Subject: [PATCH 04/15] simplify payload --- models/events/TestTakerCreatedEvent.php | 9 +++------ models/events/TestTakerImportedEvent.php | 9 +++------ models/events/TestTakerRemovedEvent.php | 9 +++------ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/models/events/TestTakerCreatedEvent.php b/models/events/TestTakerCreatedEvent.php index 1cebffbd..ba038ea1 100644 --- a/models/events/TestTakerCreatedEvent.php +++ b/models/events/TestTakerCreatedEvent.php @@ -44,12 +44,9 @@ public function getWebhookEventName() public function serializeForWebhook() { return [ - 'name' => $this->getWebhookEventName(), - 'payload' => [ - 'testTakerUri' => $this->testTakerUri, - 'unit' => 1, - 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, - ], + 'testTakerUri' => $this->testTakerUri, + 'unit' => 1, + 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, ]; } } diff --git a/models/events/TestTakerImportedEvent.php b/models/events/TestTakerImportedEvent.php index f446318f..25e7d616 100644 --- a/models/events/TestTakerImportedEvent.php +++ b/models/events/TestTakerImportedEvent.php @@ -44,12 +44,9 @@ public function getWebhookEventName() public function serializeForWebhook() { return [ - 'name' => $this->getWebhookEventName(), - 'payload' => [ - 'testTakerUri' => $this->testTakerUri, - 'unit' => 1, - 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL - ], + 'testTakerUri' => $this->testTakerUri, + 'unit' => 1, + 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL ]; } } diff --git a/models/events/TestTakerRemovedEvent.php b/models/events/TestTakerRemovedEvent.php index de6f5833..9d9f6b3f 100644 --- a/models/events/TestTakerRemovedEvent.php +++ b/models/events/TestTakerRemovedEvent.php @@ -46,12 +46,9 @@ public function getWebhookEventName() public function serializeForWebhook() { return [ - 'name' => $this->getWebhookEventName(), - 'payload' => [ - 'testTakerUri' => $this->testTakerUri, - 'unit' => 1, - 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, - ], + 'testTakerUri' => $this->testTakerUri, + 'unit' => 1, + 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, ]; } } From 5ae88c7a5b82a6a78a1b53e062688caf62fd3b80 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Wed, 17 Jun 2020 12:06:04 +0200 Subject: [PATCH 05/15] remove unnecessary tenant information --- models/events/TestTakerCreatedEvent.php | 3 +-- models/events/TestTakerImportedEvent.php | 3 +-- models/events/TestTakerRemovedEvent.php | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/models/events/TestTakerCreatedEvent.php b/models/events/TestTakerCreatedEvent.php index ba038ea1..eb33fc45 100644 --- a/models/events/TestTakerCreatedEvent.php +++ b/models/events/TestTakerCreatedEvent.php @@ -45,8 +45,7 @@ public function serializeForWebhook() { return [ 'testTakerUri' => $this->testTakerUri, - 'unit' => 1, - 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, + 'unit' => 1 ]; } } diff --git a/models/events/TestTakerImportedEvent.php b/models/events/TestTakerImportedEvent.php index 25e7d616..ff0898d6 100644 --- a/models/events/TestTakerImportedEvent.php +++ b/models/events/TestTakerImportedEvent.php @@ -45,8 +45,7 @@ public function serializeForWebhook() { return [ 'testTakerUri' => $this->testTakerUri, - 'unit' => 1, - 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL + 'unit' => 1 ]; } } diff --git a/models/events/TestTakerRemovedEvent.php b/models/events/TestTakerRemovedEvent.php index 9d9f6b3f..84209e04 100644 --- a/models/events/TestTakerRemovedEvent.php +++ b/models/events/TestTakerRemovedEvent.php @@ -47,8 +47,7 @@ public function serializeForWebhook() { return [ 'testTakerUri' => $this->testTakerUri, - 'unit' => 1, - 'tenant' => defined('LOCAL_NAMESPACE') ? LOCAL_NAMESPACE : ROOT_URL, + 'unit' => 1 ]; } } From 810a043abd38ad91c4d9d2cd0b9ec07fbb913917 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Wed, 17 Jun 2020 16:57:05 +0200 Subject: [PATCH 06/15] constants added and switch case added --- actions/Import.php | 19 +++++++++++-------- models/events/TestTakerCreatedEvent.php | 4 +++- models/events/TestTakerImportedEvent.php | 4 +++- models/events/TestTakerRemovedEvent.php | 5 +++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/actions/Import.php b/actions/Import.php index 25a1b009..9d76c8b4 100644 --- a/actions/Import.php +++ b/actions/Import.php @@ -45,15 +45,18 @@ public function getAvailableImportHandlers() $returnValue = parent::getAvailableImportHandlers(); foreach (array_keys($returnValue) as $key) { - if ($returnValue[$key] instanceof tao_models_classes_import_CsvImporter) { - $importer = new CsvImporter(); - $importer->setValidators($this->getValidators()); - $returnValue[$key] = $importer; - } + switch (get_class($returnValue[$key])) { + case tao_models_classes_import_CsvImporter::class: + $importer = new CsvImporter(); + $importer->setValidators($this->getValidators()); + $returnValue[$key] = $importer; + + break; + case tao_models_classes_import_RdfImporter::class: + $importer = new RdfImporter(); + $returnValue[$key] = $importer; - if ($returnValue[$key] instanceof tao_models_classes_import_RdfImporter) { - $importer = new RdfImporter(); - $returnValue[$key] = $importer; + break; } } diff --git a/models/events/TestTakerCreatedEvent.php b/models/events/TestTakerCreatedEvent.php index eb33fc45..3ff98629 100644 --- a/models/events/TestTakerCreatedEvent.php +++ b/models/events/TestTakerCreatedEvent.php @@ -30,12 +30,14 @@ */ class TestTakerCreatedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface { + private const WEBHOOK_EVENT_NAME = 'test-taker-created'; + /** * @inheritDoc */ public function getWebhookEventName() { - return 'test-taker-created'; + return self::WEBHOOK_EVENT_NAME; } /** diff --git a/models/events/TestTakerImportedEvent.php b/models/events/TestTakerImportedEvent.php index ff0898d6..10caf997 100644 --- a/models/events/TestTakerImportedEvent.php +++ b/models/events/TestTakerImportedEvent.php @@ -30,12 +30,14 @@ */ class TestTakerImportedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface { + private const WEBHOOK_EVENT_NAME = 'test-taker-imported'; + /** * @inheritDoc */ public function getWebhookEventName() { - return 'test-taker-imported'; + return self::WEBHOOK_EVENT_NAME; } /** diff --git a/models/events/TestTakerRemovedEvent.php b/models/events/TestTakerRemovedEvent.php index 84209e04..c6847f57 100644 --- a/models/events/TestTakerRemovedEvent.php +++ b/models/events/TestTakerRemovedEvent.php @@ -30,14 +30,15 @@ */ class TestTakerRemovedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface { - const EVENT_NAME = __CLASS__; + private const WEBHOOK_EVENT_NAME = 'test-taker-removed'; + public const EVENT_NAME = __CLASS__; /** * @inheritDoc */ public function getWebhookEventName() { - return 'test-taker-removed'; + return self::WEBHOOK_EVENT_NAME; } /** From 46b98720a94307e10aaa755431184c1d46103be1 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Thu, 18 Jun 2020 09:32:43 +0200 Subject: [PATCH 07/15] added unit test as possible --- models/CsvImporter.php | 26 +++-- models/RdfImporter.php | 27 +++--- .../TestTakerImportEventDispatcher.php | 51 ++++++++++ .../TestTakerImportEventDispatcherTest.php | 94 +++++++++++++++++++ 4 files changed, 167 insertions(+), 31 deletions(-) create mode 100644 models/events/dispatcher/TestTakerImportEventDispatcher.php create mode 100755 test/unit/models/events/dispatcher/TestTakerImportEventDispatcherTest.php diff --git a/models/CsvImporter.php b/models/CsvImporter.php index bcfb9bcf..e3af097b 100644 --- a/models/CsvImporter.php +++ b/models/CsvImporter.php @@ -22,15 +22,12 @@ namespace oat\taoTestTaker\models; -use common_Logger; -use common_report_Report; use core_kernel_classes_Resource; use oat\generis\Helper\UserHashForEncryption; use oat\oatbox\service\ServiceManager; -use oat\oatbox\user\UserLanguageService; use oat\tao\model\TaoOntology; use oat\generis\model\GenerisRdf; -use oat\taoTestTaker\models\events\TestTakerImportedEvent; +use oat\taoTestTaker\models\events\dispatcher\TestTakerImportEventDispatcher; /** * A custom subject CSV importer @@ -46,17 +43,11 @@ public function import($class, $form, $userId = null) { $report = parent::import($class, $form); - /** @var common_report_Report $success */ - foreach ($report->getSuccesses() as $success) { - $resource = $success->getData(); - try { - $this->getEventManager()->trigger( - new TestTakerImportedEvent($resource->getUri(), $this->getProperties($resource)) - ); - } catch (\Exception $e) { - common_Logger::e($e->getMessage()); - } - } + $this->getTestTakerImportEventDispatcher() + ->dispatch( + $report, + [$this, 'getProperties'] + ); return $report; } @@ -164,4 +155,9 @@ public static function taoSubjectsPasswordEncode($value) { return \core_kernel_users_Service::getPasswordHash()->encrypt($value); } + + private function getTestTakerImportEventDispatcher(): TestTakerImportEventDispatcher + { + return $this->getServiceLocator()->get(TestTakerImportEventDispatcher::class); + } } diff --git a/models/RdfImporter.php b/models/RdfImporter.php index 92536cbe..2a8d960d 100644 --- a/models/RdfImporter.php +++ b/models/RdfImporter.php @@ -20,11 +20,8 @@ namespace oat\taoTestTaker\models; -use common_Logger; -use common_report_Report; use core_kernel_classes_Resource; -use Exception; -use oat\taoTestTaker\models\events\TestTakerImportedEvent; +use oat\taoTestTaker\models\events\dispatcher\TestTakerImportEventDispatcher; use tao_models_classes_import_RdfImporter; class RdfImporter extends tao_models_classes_import_RdfImporter @@ -33,18 +30,11 @@ public function import($class, $form, $userId = null) { $report = parent::import($class, $form); - /** @var common_report_Report $success */ - foreach ($report->getSuccesses() as $success) { - $resource = $success->getData(); - - try { - $this->getEventManager()->trigger( - new TestTakerImportedEvent($resource->getUri(), $this->getProperties($resource)) - ); - } catch (Exception $e) { - common_Logger::e($e->getMessage()); - } - } + $this->getTestTakerImportEventDispatcher() + ->dispatch( + $report, + [$this, 'getProperties'] + ); return $report; } @@ -53,4 +43,9 @@ protected function getProperties(core_kernel_classes_Resource $resource): array { return []; } + + private function getTestTakerImportEventDispatcher(): TestTakerImportEventDispatcher + { + return $this->getServiceLocator()->get(TestTakerImportEventDispatcher::class); + } } diff --git a/models/events/dispatcher/TestTakerImportEventDispatcher.php b/models/events/dispatcher/TestTakerImportEventDispatcher.php new file mode 100644 index 00000000..a6b3db86 --- /dev/null +++ b/models/events/dispatcher/TestTakerImportEventDispatcher.php @@ -0,0 +1,51 @@ + + */ + +namespace oat\taoTestTaker\models\events\dispatcher; + +use common_Logger; +use common_report_Report; +use oat\oatbox\event\EventManagerAwareTrait; +use oat\oatbox\service\ConfigurableService; +use oat\taoTestTaker\models\events\TestTakerImportedEvent; +use Throwable; + +class TestTakerImportEventDispatcher extends ConfigurableService +{ + use EventManagerAwareTrait; + + public function dispatch(common_report_Report $report, callable $processResource): void + { + /** @var common_report_Report $success */ + foreach ($report->getSuccesses() as $success) { + $resource = $success->getData(); + + try { + $this->getEventManager()->trigger( + new TestTakerImportedEvent($resource->getUri(), $processResource($resource)) + ); + } catch (Throwable $e) { + common_Logger::e($e->getMessage()); + } + } + } +} diff --git a/test/unit/models/events/dispatcher/TestTakerImportEventDispatcherTest.php b/test/unit/models/events/dispatcher/TestTakerImportEventDispatcherTest.php new file mode 100755 index 00000000..fdbd896f --- /dev/null +++ b/test/unit/models/events/dispatcher/TestTakerImportEventDispatcherTest.php @@ -0,0 +1,94 @@ +eventManager = $this->createMock(EventManager::class); + $this->subject = new TestTakerImportEventDispatcher(); + $this->subject->setServiceLocator( + $this->getServiceLocatorMock( + [ + EventManager::SERVICE_ID => $this->eventManager + ] + ) + ); + } + + public function testDispatch(): void + { + $resourceUri = 'abc123'; + $report = $this->createMock(common_report_Report::class); + $successReport = $this->createMock(common_report_Report::class); + $resource = $this->createMock(core_kernel_classes_Resource::class); + + $report->method('getSuccesses') + ->willReturn( + [ + $successReport + ] + ); + + $successReport->method('getData') + ->willReturn($resource); + + $resource->method('getUri') + ->willReturn($resourceUri); + + $this->eventManager + ->expects($this->once()) + ->method('trigger') + ->with( + new TestTakerImportedEvent( + $resourceUri, + [ + 'uri' => $resourceUri + ] + ) + ); + + $this->subject->dispatch( + $report, + function (core_kernel_classes_Resource $resource) { + return [ + 'uri' => $resource->getUri() + ]; + } + ); + } +} From 5edeb3170bc9168399ac0011a53336a9676f4e2d Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Thu, 18 Jun 2020 12:05:32 +0200 Subject: [PATCH 08/15] use proper callback --- models/CsvImporter.php | 5 ++++- models/RdfImporter.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/models/CsvImporter.php b/models/CsvImporter.php index e3af097b..669cfdd4 100644 --- a/models/CsvImporter.php +++ b/models/CsvImporter.php @@ -46,7 +46,10 @@ public function import($class, $form, $userId = null) $this->getTestTakerImportEventDispatcher() ->dispatch( $report, - [$this, 'getProperties'] + function ($resource) + { + return $this->getProperties($resource); + } ); return $report; diff --git a/models/RdfImporter.php b/models/RdfImporter.php index 2a8d960d..91dbddb1 100644 --- a/models/RdfImporter.php +++ b/models/RdfImporter.php @@ -33,7 +33,10 @@ public function import($class, $form, $userId = null) $this->getTestTakerImportEventDispatcher() ->dispatch( $report, - [$this, 'getProperties'] + function ($resource) + { + return $this->getProperties($resource); + } ); return $report; From fffe67a87e36304219110c85f06269425411dc38 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Thu, 18 Jun 2020 13:41:56 +0200 Subject: [PATCH 09/15] Update models/events/dispatcher/TestTakerImportEventDispatcher.php Co-authored-by: Mikhail Kamarouski <4569734+boajer@users.noreply.github.com> --- models/events/dispatcher/TestTakerImportEventDispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/events/dispatcher/TestTakerImportEventDispatcher.php b/models/events/dispatcher/TestTakerImportEventDispatcher.php index a6b3db86..50e16de3 100644 --- a/models/events/dispatcher/TestTakerImportEventDispatcher.php +++ b/models/events/dispatcher/TestTakerImportEventDispatcher.php @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2016 (original work) Open Assessment Technologies SA; + * Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA; * * @author Ivan klimchuk */ From ed82f4bdd41f911a4f4694819acecb0b0f645399 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Thu, 18 Jun 2020 14:28:13 +0200 Subject: [PATCH 10/15] adding strict type --- actions/Import.php | 2 ++ manifest.php | 2 ++ models/CsvImporter.php | 6 +++--- models/RdfImporter.php | 2 ++ models/events/TestTakerCreatedEvent.php | 4 +++- models/events/TestTakerImportedEvent.php | 4 +++- models/events/TestTakerRemovedEvent.php | 4 +++- .../dispatcher/TestTakerImportEventDispatcher.php | 4 +++- scripts/update/Updater.php | 14 ++++---------- 9 files changed, 25 insertions(+), 17 deletions(-) diff --git a/actions/Import.php b/actions/Import.php index 9d76c8b4..fd9d9a4b 100644 --- a/actions/Import.php +++ b/actions/Import.php @@ -21,6 +21,8 @@ * */ +declare(strict_types=1); + namespace oat\taoTestTaker\actions; use oat\taoTestTaker\models\CsvImporter; diff --git a/manifest.php b/manifest.php index 6ed9dbb1..f1ecb4d0 100755 --- a/manifest.php +++ b/manifest.php @@ -27,6 +27,8 @@ * */ +declare(strict_types=1); + use oat\taoTestTaker\models\routing\ApiRoute; use oat\taoTestTaker\models\TestTakerService; use oat\taoTestTaker\scripts\install\SetupConfig; diff --git a/models/CsvImporter.php b/models/CsvImporter.php index 669cfdd4..f3e27fd7 100644 --- a/models/CsvImporter.php +++ b/models/CsvImporter.php @@ -15,11 +15,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); - * - * + * Copyright (c) 2013-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); */ +declare(strict_types=1); + namespace oat\taoTestTaker\models; use core_kernel_classes_Resource; diff --git a/models/RdfImporter.php b/models/RdfImporter.php index 91dbddb1..1e61fda6 100644 --- a/models/RdfImporter.php +++ b/models/RdfImporter.php @@ -18,6 +18,8 @@ * Copyright (c) 2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); */ +declare(strict_types=1); + namespace oat\taoTestTaker\models; use core_kernel_classes_Resource; diff --git a/models/events/TestTakerCreatedEvent.php b/models/events/TestTakerCreatedEvent.php index 3ff98629..2d693b5f 100644 --- a/models/events/TestTakerCreatedEvent.php +++ b/models/events/TestTakerCreatedEvent.php @@ -15,11 +15,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2016 (original work) Open Assessment Technologies SA; + * Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA; * * @author Ivan klimchuk */ +declare(strict_types=1); + namespace oat\taoTestTaker\models\events; use oat\tao\model\webhooks\WebhookSerializableEventInterface; diff --git a/models/events/TestTakerImportedEvent.php b/models/events/TestTakerImportedEvent.php index 10caf997..8bbb8c6f 100644 --- a/models/events/TestTakerImportedEvent.php +++ b/models/events/TestTakerImportedEvent.php @@ -15,11 +15,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2016 (original work) Open Assessment Technologies SA; + * Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA; * * @author Ivan klimchuk */ +declare(strict_types=1); + namespace oat\taoTestTaker\models\events; use oat\tao\model\webhooks\WebhookSerializableEventInterface; diff --git a/models/events/TestTakerRemovedEvent.php b/models/events/TestTakerRemovedEvent.php index c6847f57..f9b44ebf 100644 --- a/models/events/TestTakerRemovedEvent.php +++ b/models/events/TestTakerRemovedEvent.php @@ -15,11 +15,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2016 (original work) Open Assessment Technologies SA; + * Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA; * * @author Ivan klimchuk */ +declare(strict_types=1); + namespace oat\taoTestTaker\models\events; use oat\tao\model\webhooks\WebhookSerializableEventInterface; diff --git a/models/events/dispatcher/TestTakerImportEventDispatcher.php b/models/events/dispatcher/TestTakerImportEventDispatcher.php index a6b3db86..d7f38fb4 100644 --- a/models/events/dispatcher/TestTakerImportEventDispatcher.php +++ b/models/events/dispatcher/TestTakerImportEventDispatcher.php @@ -15,11 +15,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2016 (original work) Open Assessment Technologies SA; + * Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA; * * @author Ivan klimchuk */ +declare(strict_types=1); + namespace oat\taoTestTaker\models\events\dispatcher; use common_Logger; diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index 5ac102c7..08bc6a75 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -15,11 +15,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (c) 2015 (original work) Open Assessment Technologies SA; - * - * + * Copyright (c) 2015-2020 (original work) Open Assessment Technologies SA; */ +declare(strict_types=1); + namespace oat\taoTestTaker\scripts\update; use oat\generis\model\GenerisRdf; @@ -28,9 +28,7 @@ use oat\tao\model\user\TaoRoles; use oat\taoTestTaker\actions\Api; use oat\tao\model\user\import\UserCsvImporterFactory; -use oat\taoTestTaker\actions\RestTestTakers; use oat\taoTestTaker\models\TestTakerImporter; -use oat\taoTestTaker\models\TestTakerService; /** * Class Updater @@ -39,11 +37,7 @@ class Updater extends \common_ext_ExtensionUpdater { /** - * @param $initialVersion - * @return string $versionUpdatedTo - * @internal param string $currentVersion - * @throws \common_ext_ExtensionException - * @throws \common_Exception + * @inheritDoc */ public function update($initialVersion) { From 2494db51970d604b29af7effb8ff518ed4be2f8a Mon Sep 17 00:00:00 2001 From: Aleh Hutnikau Date: Mon, 22 Jun 2020 13:58:59 +0300 Subject: [PATCH 11/15] Deprecate updater file --- manifest.php | 2 +- scripts/update/Updater.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/manifest.php b/manifest.php index f1ecb4d0..408fc5e3 100755 --- a/manifest.php +++ b/manifest.php @@ -42,7 +42,7 @@ 'label' => 'Test-taker core extension', 'description' => 'TAO TestTaker extension', 'license' => 'GPL-2.0', - 'version' => '7.6.0', + 'version' => '7.7.0', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => [ 'generis' => '>=12.15.0', diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index 08bc6a75..78806355 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -33,6 +33,7 @@ /** * Class Updater * @package oat\taoTestTaker\scripts\update + * @deprecated use migrations instead. See https://github.com/oat-sa/generis/wiki/Tao-Update-Process */ class Updater extends \common_ext_ExtensionUpdater { @@ -94,5 +95,10 @@ public function update($initialVersion) } $this->skip('3.11.0', '7.6.0'); + + //Updater files are deprecated. Please use migrations. + //See: https://github.com/oat-sa/generis/wiki/Tao-Update-Process + + $this->setVersion($this->getExtension()->getManifest()->getVersion()); } } From a08a236b625f0541e43b32eb15e7b77488222b64 Mon Sep 17 00:00:00 2001 From: gitromba Date: Thu, 25 Jun 2020 13:36:28 +0200 Subject: [PATCH 12/15] chore: prevent composer.lock and vendor folder from being committed. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..1f02b10b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +composer.lock +vendor/ From c3c2580328707dbc4409227a4bc447f699d2145e Mon Sep 17 00:00:00 2001 From: bugalot Date: Fri, 26 Jun 2020 16:08:56 +0200 Subject: [PATCH 13/15] add .idea in .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1f02b10b..51a749cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock vendor/ +.idea/ From 208034ec242f4a2c1e5753f41fd03787b584e824 Mon Sep 17 00:00:00 2001 From: bugalot Date: Fri, 26 Jun 2020 16:09:24 +0200 Subject: [PATCH 14/15] Bump version 7.7.1 --- manifest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.php b/manifest.php index 408fc5e3..2a86c4aa 100755 --- a/manifest.php +++ b/manifest.php @@ -42,7 +42,7 @@ 'label' => 'Test-taker core extension', 'description' => 'TAO TestTaker extension', 'license' => 'GPL-2.0', - 'version' => '7.7.0', + 'version' => '7.7.1', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => [ 'generis' => '>=12.15.0', From 0ade8f074c9549969ed7b3e0be7107ca9785a626 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Fri, 3 Jul 2020 11:29:07 +0200 Subject: [PATCH 15/15] remove strict type breaking build --- manifest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/manifest.php b/manifest.php index 2a86c4aa..10ca5585 100755 --- a/manifest.php +++ b/manifest.php @@ -27,8 +27,6 @@ * */ -declare(strict_types=1); - use oat\taoTestTaker\models\routing\ApiRoute; use oat\taoTestTaker\models\TestTakerService; use oat\taoTestTaker\scripts\install\SetupConfig;