/**
  * Updater
  *
  * @param string $initialVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $this->skip('0.1', '0.2.4');
     if ($this->isVersion('0.2.4')) {
         $setupPortableElementFileStorage = new SetupPortableElementFileStorage();
         $setupPortableElementFileStorage->setServiceLocator($this->getServiceManager());
         $setupPortableElementFileStorage([]);
         $registerPicModel = new RegisterPicModel();
         $registerPicModel->setServiceLocator($this->getServiceManager());
         $registerPicModel([]);
         $setQtiCreatorConfig = new SetQtiCreatorConfig();
         $setQtiCreatorConfig([]);
         $registerClientProvider = new RegisterClientProvider();
         $registerClientProvider([]);
         $testManagerRole = $this->getResource('http://www.tao.lu/Ontologies/TAOItem.rdf#ItemsManagerRole');
         $QTIManagerRole = $this->getResource('http://www.tao.lu/Ontologies/TAOItem.rdf#QTIManagerRole');
         $testTakerRole = $this->getResource(INSTANCE_ROLE_DELIVERY);
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantModuleAccess($testManagerRole, 'qtiItemPic', 'PciLoader');
         $accessService->grantModuleAccess($QTIManagerRole, 'qtiItemPic', 'PciLoader');
         $accessService->grantModuleAccess($testTakerRole, 'qtiItemPic', 'PciLoader');
         HookRegistry::getRegistry()->remove('picCreator');
         $this->setVersion('1.0.0');
     }
     $this->skip('1.0.0', '1.1.0');
     if ($this->isVersion('1.1.0')) {
         call_user_func(new RegisterPicStudentToolbar(), ['0.2.0']);
         call_user_func(new RegisterPicStudentToolSample(), ['0.2.0']);
         $this->setVersion('1.2.0');
     }
 }
 /**
  * 
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     if ($currentVersion == '1.0') {
         $currentVersion = '1.0.1';
     }
     if ($currentVersion == '1.0.1') {
         $currentVersion = '1.1.0';
     }
     if ($currentVersion == '1.1.0') {
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $anonymous = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/generis.rdf#AnonymousRole');
         $accessService->grantModuleAccess($anonymous, 'taoClientDiagnostic', 'CompatibilityChecker');
         $currentVersion = '1.1.1';
     }
     if ($currentVersion == '1.1.1') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoClientDiagnostic');
         $extension->setConfig('clientDiag', array('footer' => ''));
         $currentVersion = '1.2.0';
     }
     if ($currentVersion == '1.2.0') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoClientDiagnostic');
         $config = $extension->getConfig('clientDiag');
         $extension->setConfig('clientDiag', array_merge($config, array('performances' => array('samples' => array('taoClientDiagnostic/tools/performances/data/sample1/', 'taoClientDiagnostic/tools/performances/data/sample2/', 'taoClientDiagnostic/tools/performances/data/sample3/'), 'occurrences' => 10, 'timeout' => 30, 'optimal' => 0.025, 'threshold' => 0.25), 'bandwidth' => array('unit' => 0.16, 'ideal' => 45, 'max' => 100))));
         $currentVersion = '1.3.0';
     }
     return $currentVersion;
 }
 /**
  * returns the modules of an extension from the ontology
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  string extensionID
  * @return array
  */
 public static function getModules($extensionId)
 {
     $returnValue = array();
     foreach (ControllerHelper::getControllers($extensionId) as $controllerClassName) {
         $shortName = strpos($controllerClassName, '\\') !== false ? substr($controllerClassName, strrpos($controllerClassName, '\\') + 1) : substr($controllerClassName, strrpos($controllerClassName, '_') + 1);
         $uri = funcAcl_models_classes_AccessService::singleton()->makeEMAUri($extensionId, $shortName);
         $returnValue[$uri] = new core_kernel_classes_Resource($uri);
     }
     return (array) $returnValue;
 }
 /**
  *
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     //migrate ACL
     if ($currentVersion == '0.1') {
         $MngrRole = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAODelivery.rdf#DeliveryManagerRole');
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantModuleAccess($MngrRole, 'taoDeliveryRdf', 'DeliveryMgmt');
         $currentVersion = '0.2';
         $this->setVersion($currentVersion);
     }
     if ($this->isVersion('0.2')) {
         OntologyUpdater::syncModels();
         AclProxy::applyRule(new AccessRule('grant', 'http://www.tao.lu/Ontologies/generis.rdf#AnonymousRole', array('controller' => 'oat\\taoDeliveryRdf\\controller\\Guest')));
         $currentService = $this->safeLoadService(AssignmentService::CONFIG_ID);
         if (class_exists('taoDelivery_models_classes_AssignmentService', false) && $currentService instanceof \taoDelivery_models_classes_AssignmentService) {
             $assignmentService = new GroupAssignment();
             $this->getServiceManager()->register(AssignmentService::CONFIG_ID, $assignmentService);
         }
         $this->setVersion('1.0.0');
     }
     if ($this->isVersion('1.0.0')) {
         $this->setVersion('1.0.1');
     }
     if ($this->isVersion('1.0.1')) {
         OntologyUpdater::syncModels();
         $this->setVersion('1.1.0');
     }
     $this->skip('1.1.0', '1.4.0');
     if ($this->isVersion('1.4.0')) {
         AclProxy::applyRule(new AccessRule(AccessRule::GRANT, 'http://www.tao.lu/Ontologies/generis.rdf#taoDeliveryRdfManager', array('ext' => 'taoDeliveryRdf')));
         $this->setVersion('1.5.0');
     }
     $this->skip('1.5.0', '1.6.3');
     if ($this->isVersion('1.6.3')) {
         OntologyUpdater::syncModels();
         $registerService = new RegisterDeliveryContainerService();
         $registerService([]);
         $this->setVersion('1.7.0');
     }
     $this->skip('1.7.0', '1.8.1');
     if ($this->isVersion('1.8.1')) {
         OntologyUpdater::syncModels();
         $registerEvents = new RegisterEvents();
         $registerEvents->setServiceLocator($this->getServiceManager());
         $registerEvents([]);
         $this->setVersion('1.9.0');
     }
 }
 public function testFuncACL()
 {
     $baseRole = $this->testrole;
     $srv = tao_models_classes_UserService::singleton();
     $generisUser = new core_kernel_users_GenerisUser($this->user);
     $this->assertTrue(LoginService::startSession($generisUser));
     // -- Test uri creation
     $emauri = FUNCACL_NS . '#a_tao_Users_add';
     $emaurimod = FUNCACL_NS . '#m_tao_Users';
     $makeemauri = funcAcl_models_classes_AccessService::singleton()->makeEMAUri('tao', 'Users', 'add');
     $makeemaurimod = funcAcl_models_classes_AccessService::singleton()->makeEMAUri('tao', 'Users');
     $this->assertEquals($emauri, $makeemauri);
     $this->assertEquals($emaurimod, $makeemaurimod);
     $funcAclImp = new funcAcl_models_classes_FuncAcl();
     // -- Try to access a restricted action
     $this->assertFalse($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // -- Try to access a unrestricted action
     // (BACKOFFICE has access to the backend login action because it includes the TAO Role)
     $this->assertTrue($funcAclImp->hasAccess('login', 'Main', 'tao'));
     // -- Try to access an action that does not exist.
     $this->assertFalse($funcAclImp->hasAccess('action', 'Unknown', 'tao'));
     // -- Try to access a unrestricted action
     // Add access for this action to the Manager role.
     funcAcl_models_classes_ActionAccessService::singleton()->add($this->testRole->getUri(), $makeemauri);
     // Add the Manager role the the currently tested user
     tao_models_classes_UserService::singleton()->attachRole($this->user, $this->testRole);
     // Logoff/login, to refresh roles cache
     $this->assertTrue(LoginService::startSession($generisUser));
     // Ask for access
     $this->assertTrue($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // Remove the access to this action from the Manager role
     funcAcl_models_classes_ActionAccessService::singleton()->remove($this->testRole->getUri(), $makeemauri);
     // We should not have access anymore to this action with the Manager role
     $this->assertFalse($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // -- Give access to the entire module and try to access the previously tested action
     funcAcl_models_classes_ModuleAccessService::singleton()->add($this->testRole->getUri(), $makeemaurimod);
     $this->assertTrue($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // -- Remove the entire module access and try again
     funcAcl_models_classes_ModuleAccessService::singleton()->remove($this->testRole->getUri(), $makeemaurimod);
     $this->assertFalse($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // reset
     funcAcl_models_classes_ModuleAccessService::singleton()->add($this->testRole->getUri(), $makeemaurimod);
     // Unattach role from user
     tao_models_classes_UserService::singleton()->unnatachRole($this->user, $this->testRole);
 }
 /**
  * (non-PHPdoc)
  * @see common_ext_ExtensionUpdater::update()
  */
 public function update($initialVersion)
 {
     $current = $initialVersion;
     if ($current == '0.0.1' || $current == '0.1.0' || $current == '0.1.1') {
         OntologyUpdater::syncModels();
         $current = '0.1.2';
     }
     if ($current == '0.1.2') {
         OntologyUpdater::syncModels();
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $roleService = \tao_models_classes_RoleService::singleton();
         $testCenterManager = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/generis.rdf#TestCenterManager');
         //revoke access right to test center manager
         $accessService->revokeExtensionAccess($testCenterManager, 'taoTestCenter');
         $roleService->removeRole($testCenterManager);
         $current = '0.2';
     }
     $this->setVersion($current);
     $this->skip('0.2', '0.3.0');
 }
 /**
  *
  * @param string $initialVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     // add testrunner config
     if ($currentVersion == '2.6') {
         \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->setConfig('testRunner', array('progress-indicator' => 'percentage', 'timerWarning' => array('assessmentItemRef' => null, 'assessmentSection' => 300, 'testPart' => null)));
         $currentVersion = '2.6.1';
     }
     if ($currentVersion == '2.6.1') {
         $config = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->getConfig('testRunner');
         $config['exitButton'] = false;
         \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->setConfig('testRunner', $config);
         $currentVersion = '2.6.2';
     }
     // add testrunner review screen config
     if ($currentVersion == '2.6.2') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $extension->setConfig('testRunner', array_merge($config, array('test-taker-review' => false, 'test-taker-review-region' => 'left', 'test-taker-review-section-only' => false, 'test-taker-review-prevents-unseen' => true)));
         $currentVersion = '2.6.3';
     }
     // adjust testrunner config
     if ($currentVersion == '2.6.3') {
         $defaultConfig = array('timerWarning' => array('assessmentItemRef' => null, 'assessmentSection' => null, 'testPart' => null), 'progress-indicator' => 'percentage', 'progress-indicator-scope' => 'testSection', 'test-taker-review' => false, 'test-taker-review-region' => 'left', 'test-taker-review-section-only' => false, 'test-taker-review-prevents-unseen' => true, 'exitButton' => false);
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         foreach ($defaultConfig as $key => $value) {
             if (!isset($config[$key])) {
                 $config[$key] = $value;
             }
         }
         $extension->setConfig('testRunner', $config);
         $currentVersion = '2.6.4';
     }
     if ($currentVersion == '2.6.4') {
         $currentVersion = '2.7.0';
     }
     // add markForReview button
     if ($currentVersion === '2.7.0') {
         $registry = TestRunnerClientConfigRegistry::getRegistry();
         $registry->registerQtiTools('markForReview', array('label' => 'Mark for review', 'icon' => 'anchor', 'hook' => 'taoQtiTest/testRunner/actionBar/markForReview'));
         $currentVersion = '2.8.0';
     }
     // adjust testrunner config: set the review scope
     if ($currentVersion == '2.8.0') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['test-taker-review-scope'] = 'test';
         unset($config['test-taker-review-section-only']);
         $extension->setConfig('testRunner', $config);
         $currentVersion = '2.9.0';
     }
     // add show/hide button
     // adjust testrunner config: set the "can collapse" option
     if ($currentVersion == '2.9.0') {
         $registry = TestRunnerClientConfigRegistry::getRegistry();
         $registry->registerQtiTools('collapseReview', array('title' => 'Show/Hide the review screen', 'label' => 'Review', 'icon' => 'mobile-menu', 'hook' => 'taoQtiTest/testRunner/actionBar/collapseReview', 'order' => -1));
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['test-taker-review-can-collapse'] = false;
         $extension->setConfig('testRunner', $config);
         $currentVersion = '2.10.0';
     }
     // adjust testrunner config: set the item sequence number options
     if ($currentVersion == '2.10.0') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['test-taker-review-force-title'] = false;
         $config['test-taker-review-item-title'] = 'Item %d';
         $extension->setConfig('testRunner', $config);
         $currentVersion = '2.11.0';
     }
     if ($currentVersion == '2.11.0') {
         $currentVersion = '2.11.1';
     }
     // adjust testrunner config: set the force progress indicator display
     if ($currentVersion == '2.11.1') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['progress-indicator-forced'] = false;
         $extension->setConfig('testRunner', $config);
         $currentVersion = '2.12.0';
     }
     // update the test taker review action buttons
     if ($currentVersion == '2.12.0') {
         $registry = TestRunnerClientConfigRegistry::getRegistry();
         $registry->registerQtiTools('collapseReview', array('hook' => 'taoQtiTest/testRunner/actionBar/collapseReview', 'order' => 'first', 'title' => null, 'label' => null, 'icon' => null));
         $registry->registerQtiTools('markForReview', array('hook' => 'taoQtiTest/testRunner/actionBar/markForReview', 'order' => 'last', 'title' => null, 'label' => null, 'icon' => null));
         $currentVersion = '2.13.0';
     }
     // adjust testrunner config: set the next section button display
     if ($currentVersion == '2.13.0') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['next-section'] = false;
         $extension->setConfig('testRunner', $config);
         $currentVersion = '2.14.0';
     }
     if ($currentVersion === '2.14.0') {
         try {
             $this->getServiceManager()->get('taoQtiTest/SessionStateService');
         } catch (ServiceNotFoundException $e) {
             $sessionStateService = new SessionStateService();
             $sessionStateService->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register('taoQtiTest/SessionStateService', $sessionStateService);
         }
         $currentVersion = '2.15.0';
     }
     if ($currentVersion === '2.15.0') {
         $registry = TestRunnerClientConfigRegistry::getRegistry();
         $registry->registerQtiTools('comment', array('hook' => 'taoQtiTest/testRunner/actionBar/comment'));
         $currentVersion = '2.16.0';
     }
     $this->setVersion($currentVersion);
     if ($this->isBetween('2.16.0', '2.17.0')) {
         $proctorRole = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole');
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantModuleAccess($proctorRole, 'taoQtiTest', 'Runner');
         try {
             $this->getServiceManager()->get(QtiRunnerService::CONFIG_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new QtiRunnerService();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(QtiRunnerService::CONFIG_ID, $service);
         }
         $this->setVersion('2.17.0');
     }
     $this->skip('2.17.0', '2.19.1');
     if ($this->isVersion('2.19.1')) {
         // sets default plugin options
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         if (!array_key_exists('plugins', $config)) {
             $config['plugins'] = null;
         }
         $extension->setConfig('testRunner', $config);
         $this->setVersion('2.20.0');
     }
     $this->skip('2.20.0', '2.21.1');
     if ($this->isVersion('2.21.1')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $extension->setConfig('testRunner', array_merge($config, array('csrf-token' => true)));
         $this->setVersion('2.22.0');
     }
     if ($this->isVersion('2.22.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['timer']['target'] = 'server';
         $extension->setConfig('testRunner', $config);
         $this->setVersion('2.23.0');
     }
     $this->skip('2.23.0', '2.24.0');
     if ($this->isVersion('2.24.0')) {
         $className = \taoQtiTest_helpers_SessionManager::DEFAULT_TEST_SESSION;
         try {
             $deliveryConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery')->getConfig('deliveryServer');
             if ($deliveryConfig) {
                 $deliveryContainer = $deliveryConfig->getOption('deliveryContainer');
                 if (false !== strpos($deliveryContainer, 'DeliveryClientContainer')) {
                     $className = 'oat\\taoQtiTest\\models\\runner\\session\\TestSession';
                 }
             }
         } catch (\common_ext_ExtensionException $e) {
         }
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['test-session'] = $className;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('2.25.0');
     }
     if ($this->isVersion('2.25.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['plugins']['overlay']['full'] = false;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('2.26.0');
     }
     $this->skip('2.26.0', '2.27.0');
     if ($this->isVersion('2.27.0')) {
         $serviceExtension = 'taoQtiTest';
         $serviceController = 'Runner';
         try {
             $deliveryConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery')->getConfig('testRunner');
             if ($deliveryConfig) {
                 $serviceExtension = $deliveryConfig['serviceExtension'];
                 $serviceController = $deliveryConfig['serviceController'];
             }
         } catch (\common_ext_ExtensionException $e) {
         }
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['bootstrap'] = ['serviceExtension' => $serviceExtension, 'serviceController' => $serviceController, 'communication' => ['enabled' => false, 'type' => 'poll', 'extension' => null, 'controller' => null, 'action' => 'messages', 'service' => null, 'params' => []]];
         $extension->setConfig('testRunner', $config);
         try {
             $this->getServiceManager()->get(QtiCommunicationService::CONFIG_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new QtiCommunicationService();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(QtiCommunicationService::CONFIG_ID, $service);
         }
         $this->setVersion('2.28.0');
     }
     if ($this->isVersion('2.28.0')) {
         $testRunnerConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->getConfig('testRunner');
         if (array_key_exists('timerWarning', $testRunnerConfig)) {
             foreach ($testRunnerConfig['timerWarning'] as &$value) {
                 if ($value !== null && is_int($value)) {
                     $value = [$value => 'warning'];
                 }
             }
             \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->setConfig('testRunner', $testRunnerConfig);
         }
         $this->setVersion('2.29.0');
     }
     if ($this->isVersion('2.29.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['bootstrap']['timeout'] = 0;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('2.30.0');
     }
     if ($this->isVersion('2.30.0')) {
         try {
             $service = $this->getServiceManager()->get(QtiCommunicationService::CONFIG_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new QtiCommunicationService();
         }
         $service->setServiceManager($this->getServiceManager());
         $service->attachChannel(new TestStateChannel(), QtiCommunicationService::CHANNEL_TYPE_OUTPUT);
         $this->getServiceManager()->register(QtiCommunicationService::CONFIG_ID, $service);
         $this->setVersion('2.31.0');
     }
     if ($this->isVersion('2.31.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         if (!isset($config['bootstrap']) || isset($config['bootstrap']['timeout']) && count($config['bootstrap']) == 1) {
             $config['bootstrap'] = array_merge($config['bootstrap'], ['serviceExtension' => 'taoQtiTest', 'serviceController' => 'Runner', 'communication' => ['enabled' => false, 'type' => 'poll', 'extension' => null, 'controller' => null, 'action' => 'messages', 'service' => null, 'params' => []]]);
             $extension->setConfig('testRunner', $config);
         }
         $this->setVersion('2.31.1');
     }
     $this->skip('2.31.1', '3.0.0');
     if ($this->isVersion('3.0.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['enable-allow-skipping'] = false;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('3.1.0');
     }
     $this->skip('3.1.0', '3.4.0');
     if ($this->isVersion('3.4.0')) {
         $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $uri = $ext->getConfig(\taoQtiTest_models_classes_QtiTestService::CONFIG_QTITEST_FILESYSTEM);
         $dir = new \core_kernel_file_File($uri);
         $fs = $dir->getFileSystem();
         \taoQtiTest_models_classes_QtiTestService::singleton()->setQtiTestFileSystem($fs->getUri());
         $this->setVersion('4.0.0');
     }
     $this->skip('4.0.0', '4.6.0');
     if ($this->isVersion('4.6.0')) {
         $registry = TestRunnerClientConfigRegistry::getRegistry();
         $runnerConfig = $registry->get(TestRunnerClientConfigRegistry::RUNNER);
         if (isset($runnerConfig['plugins']) && is_array($runnerConfig['plugins'])) {
             foreach ($runnerConfig['plugins'] as $plugin) {
                 //if the plugin is registered
                 if ($plugin['module'] == 'taoQtiTest/runner/plugins/controls/disableRightClick') {
                     //we migrate the category
                     $registry->removePlugin('taoQtiTest/runner/plugins/controls/disableRightClick', 'controls', null);
                     $registry->registerPlugin('taoQtiTest/runner/plugins/security/disableRightClick', 'security', null);
                     break;
                 }
             }
         }
         $this->setVersion('4.7.0');
     }
     $this->skip('4.7.0', '4.8.2');
     if ($this->isVersion('4.8.2')) {
         //regsiter the core plugins into taoTests
         $registerCorePlugins = new RegisterTestRunnerPlugins();
         $registerCorePlugins([]);
         $registry = PluginRegistry::getRegistry();
         //list the installed plugins
         $oldRegistry = TestRunnerClientConfigRegistry::getRegistry();
         $runnerConfig = $oldRegistry->get(TestRunnerClientConfigRegistry::RUNNER);
         if (isset($runnerConfig['plugins']) && is_array($runnerConfig['plugins'])) {
             foreach ($runnerConfig['plugins'] as $plugin) {
                 //if they are not yet in the config, migrate them automatically
                 if (!$registry->isRegistered($plugin['module'])) {
                     $pluginId = basename($plugin['module']);
                     $pluginName = ucfirst(join(preg_split('/(?=[A-Z])/', $pluginId), ' '));
                     $registry->register(TestPlugin::fromArray(['id' => $pluginId, 'name' => $pluginName, 'module' => $plugin['module'], 'category' => $plugin['category'], 'position' => $plugin['position'], 'active' => true]));
                 }
             }
         }
         //then remove the old config
         $registry->remove(TestRunnerClientConfigRegistry::RUNNER);
         $registry->remove(TestRunnerClientConfigRegistry::RUNNER_PROD);
         $this->setVersion('5.0.0');
     }
     $this->skip('5.0.0', '5.4.0');
     if ($this->isVersion('5.4.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['plugins']['collapser'] = ['collapseTools' => true, 'collapseNavigation' => false, 'hover' => false];
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.5.0');
     }
     $this->skip('5.5.0', '5.5.3');
     if ($this->isVersion('5.5.3')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['force-branchrules'] = false;
         $config['force-preconditions'] = false;
         $config['path-tracking'] = false;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.6.0');
     }
     if ($this->isVersion('5.6.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['always-allow-jumps'] = false;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.7.0');
     }
     $this->skip('5.7.0', '5.8.4');
     if ($this->isVersion('5.8.4')) {
         OntologyUpdater::syncModels();
         $testModelService = new TestModelService(array('exportHandlers' => array(new \taoQtiTest_models_classes_export_TestExport(), new \taoQtiTest_models_classes_export_TestExport22()), 'importHandlers' => array(new \taoQtiTest_models_classes_import_TestImport())));
         $testModelService->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(TestModelService::SERVICE_ID, $testModelService);
         $this->setVersion('5.9.0');
     }
     $this->skip('5.9.0', '5.10.2');
     if ($this->isVersion('5.10.2')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['check-informational'] = false;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.11.0');
     }
     if ($this->isVersion('5.11.0')) {
         $registry = PluginRegistry::getRegistry();
         $registry->register(TestPlugin::fromArray(['id' => 'modalFeedback', 'name' => 'QTI modal feedbacks', 'module' => 'taoQtiTest/runner/plugins/content/modalFeedback/modalFeedback', 'description' => 'Display Qti modalFeedback element', 'category' => 'content', 'active' => true, 'tags' => ['core', 'qti', 'required']]));
         $this->setVersion('5.12.0');
     }
     $this->skip('5.12.0', '5.16.2');
     if ($this->isVersion('5.16.2')) {
         $service = new TestExporter();
         $service->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(TestMetadataExporter::SERVICE_ID, $service);
         $this->setVersion('5.17.0');
     }
     $this->skip('5.17.0', '5.17.3');
     if ($this->isVersion('5.17.3')) {
         \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->setConfig('TestCompiler', array('enable-category-rules-generation' => false));
         $categoryRulesService = new TestCategoryRulesService(array('score-variable-identifier' => 'SCORE', 'weight-identifier' => 'WEIGHT', 'category-exclusions' => array('/x-tao-/'), 'flags' => TestCategoryRulesGenerator::COUNT | TestCategoryRulesGenerator::CORRECT | TestCategoryRulesGenerator::SCORE));
         $categoryRulesService->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(TestCategoryRulesService::SERVICE_ID, $categoryRulesService);
         $this->setVersion('5.18.0');
     }
     $this->skip('5.18.0', '5.23.0');
     if ($this->isVersion('5.23.0')) {
         $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $uri = $ext->getConfig(\taoQtiTest_models_classes_QtiTestService::CONFIG_QTITEST_FILESYSTEM);
         if (!is_string($uri)) {
             if (is_object($uri) && $uri instanceof \core_kernel_classes_Resource) {
                 \taoQtiTest_models_classes_QtiTestService::singleton()->setQtiTestFileSystem($uri->getUri());
             } else {
                 throw new \common_exception_InconsistentData('Invalid qti test storage directory configuration');
             }
         }
         $this->setVersion('5.23.1');
     }
     $this->skip('5.23.1', '5.25.1');
     if ($this->isVersion('5.25.1')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['test-taker-unanswered-items-message'] = true;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.26.0');
     }
     if ($this->isVersion('5.26.0')) {
         $registry = PluginRegistry::getRegistry();
         $registry->register(TestPlugin::fromArray(['id' => 'documentViewer', 'name' => 'Document Viewer', 'module' => 'taoQtiTest/runner/plugins/tools/documentViewer/documentViewer', 'description' => 'Display a document as requested by an event', 'category' => 'tools', 'active' => false, 'tags' => []]));
         $this->setVersion('5.27.0');
     }
     if ($this->isVersion('5.27.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['keep-timer-up-to-timeout'] = false;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.28.0');
     }
     $this->skip('5.28.0', '5.30.1');
     if ($this->isVersion('5.30.1')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['allow-shortcuts'] = true;
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.31.0');
     }
     $this->skip('5.31.0', '5.31.1');
     if ($this->isVersion('5.31.1')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['shortcuts'] = ['calculator' => ['toggle' => 'C'], 'zoom' => ['in' => 'I', 'out' => 'O'], 'comment' => ['toggle' => 'A'], 'itemThemeSwitcher' => ['toggle' => 'T'], 'review' => ['toggle' => 'R', 'flag' => 'M']];
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.32.0');
     }
     $this->skip('5.32.0', '5.32.1');
     if ($this->isVersion('5.32.1')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['shortcuts']['next'] = ['trigger' => 'J'];
         $config['shortcuts']['previous'] = ['trigger' => 'K'];
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.33.0');
     }
     if ($this->isVersion('5.33.0')) {
         $registry = PluginRegistry::getRegistry();
         $registry->register(TestPlugin::fromArray(['id' => 'responsesAccess', 'name' => 'Shortcuts to access the item responses', 'module' => 'taoQtiTest/runner/plugins/content/accessibility/responsesAccess', 'description' => 'Provide a way to navigate between item responses using the keyboard', 'category' => 'content', 'active' => true, 'tags' => ['core', 'qti']]));
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['shortcuts']['responsesAccess'] = ['previous' => 'Shift+Tab', 'next' => 'Tab'];
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.34.0');
     }
     $this->skip('5.34.0', '5.36.0');
     if ($this->isVersion('5.36.0')) {
         $registry = PluginRegistry::getRegistry();
         $registry->register(TestPlugin::fromArray(['id' => 'highlighter', 'name' => 'Text Highlighter', 'module' => 'taoQtiTest/runner/plugins/tools/highlighter/plugin', 'description' => 'Allows the test taker to highlight text', 'category' => 'tools', 'active' => true, 'tags' => []]));
         $this->setVersion('5.37.0');
     }
     if ($this->isVersion('5.37.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest');
         $config = $extension->getConfig('testRunner');
         $config['shortcuts']['itemThemeSwitcher'] = ['toggle' => 'T', 'loop' => 'Y', 'select' => 'U'];
         $extension->setConfig('testRunner', $config);
         $this->setVersion('5.37.1');
     }
     $this->skip('5.37.1', '5.38.1');
     if ($this->isVersion('5.38.1')) {
         $registry = PluginRegistry::getRegistry();
         $registry->register(TestPlugin::fromArray(['id' => 'highlighter', 'name' => 'Text Highlighter', 'module' => 'taoQtiTest/runner/plugins/tools/highlighter/plugin', 'description' => 'Allows the test taker to highlight text', 'category' => 'tools', 'active' => false, 'tags' => []]));
         $this->setVersion('5.38.2');
     }
     $this->skip('5.38.2', '5.39.1');
 }
 /**
  * 
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     //migrate from 2.6 to 2.6.1
     if ($currentVersion == '2.6') {
         //data upgrade
         OntologyUpdater::syncModels();
         $currentVersion = '2.6.1';
     }
     if ($currentVersion == '2.6.1') {
         $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery');
         $className = $ext->getConfig(\taoDelivery_models_classes_execution_ServiceProxy::CONFIG_KEY);
         if (is_string($className)) {
             $impl = null;
             switch ($className) {
                 case 'taoDelivery_models_classes_execution_OntologyService':
                     $impl = new \taoDelivery_models_classes_execution_OntologyService();
                     break;
                 case 'taoDelivery_models_classes_execution_KeyValueService':
                     $impl = new \taoDelivery_models_classes_execution_KeyValueService(array(\taoDelivery_models_classes_execution_KeyValueService::OPTION_PERSISTENCE => 'deliveryExecution'));
                     break;
                 default:
                     \common_Logger::w('Unable to migrate custom execution service');
             }
             if (!is_null($impl)) {
                 $proxy = \taoDelivery_models_classes_execution_ServiceProxy::singleton();
                 $proxy->setImplementation($impl);
                 $currentVersion = '2.6.2';
             }
         }
     }
     if ($currentVersion == '2.6.2') {
         $currentVersion = '2.6.3';
     }
     if ($currentVersion == '2.6.3') {
         //data upgrade
         OntologyUpdater::syncModels();
         $currentVersion = '2.7.0';
     }
     if ($currentVersion == '2.7.0') {
         EntryPointService::getRegistry()->registerEntryPoint(new \taoDelivery_models_classes_entrypoint_FrontOfficeEntryPoint());
         $currentVersion = '2.7.1';
     }
     if ($currentVersion == '2.7.1' || $currentVersion == '2.8') {
         $currentVersion = '2.9';
     }
     if ($currentVersion == '2.9') {
         OntologyUpdater::syncModels();
         //grant access to anonymous user
         $anonymousRole = new \core_kernel_classes_Resource(INSTANCE_ROLE_ANONYMOUS);
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantActionAccess($anonymousRole, 'taoDelivery', 'DeliveryServer', 'guest');
         $currentVersion = '2.9.1';
     }
     if ($currentVersion == '2.9.1') {
         OntologyUpdater::syncModels();
         $currentVersion = '2.9.2';
     }
     if ($currentVersion == '2.9.2') {
         //$assignmentService = new \taoDelivery_models_classes_AssignmentService();
         //$this->getServiceManager()->register('taoDelivery/assignment', $assignmentService);
         $currentVersion = '2.9.3';
     }
     if ($currentVersion == '2.9.3') {
         try {
             $currentConfig = $this->getServiceManager()->get(\taoDelivery_models_classes_DeliveryServerService::CONFIG_ID);
             if (is_array($currentConfig)) {
                 $deliveryServerService = new \taoDelivery_models_classes_DeliveryServerService($currentConfig);
             } else {
                 $deliveryServerService = new \taoDelivery_models_classes_DeliveryServerService();
             }
         } catch (ServiceNotFoundException $e) {
             $deliveryServerService = new \taoDelivery_models_classes_DeliveryServerService();
         }
         $this->getServiceManager()->register(\taoDelivery_models_classes_DeliveryServerService::CONFIG_ID, $deliveryServerService);
         $currentVersion = '2.9.4';
     }
     $this->setVersion($currentVersion);
     if ($this->isVersion('2.9.4')) {
         OntologyUpdater::syncModels();
         $this->setVersion('3.0.0');
     }
     if ($this->isBetween('3.0.0', '3.1.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery');
         $config = $extension->getConfig('deliveryServer');
         $config->setOption('deliveryContainer', 'oat\\taoDelivery\\helper\\container\\DeliveryServiceContainer');
         $extension->setConfig('deliveryServer', $config);
         $this->setVersion('3.1.0');
     }
     $this->skip('3.1.0', '3.2.0');
     if ($this->isVersion('3.2.0')) {
         // set the test runner controller
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery');
         $config = $extension->getConfig('testRunner');
         $config['serviceController'] = 'Runner';
         $config['serviceExtension'] = 'taoQtiTest';
         $extension->setConfig('testRunner', $config);
         $this->setVersion('3.3.0');
     }
     $this->skip('3.3.0', '3.5.0');
 }
 public static function getExtensionAccess($extId)
 {
     try {
         $returnValue = self::getCacheImplementation()->get(self::CACHE_PREFIX_EXTENSION . $extId);
     } catch (common_cache_Exception $e) {
         $returnValue = array();
         $aclExtUri = funcAcl_models_classes_AccessService::singleton()->makeEMAUri($extId);
         $roleClass = new core_kernel_classes_Class(CLASS_ROLE);
         $roles = $roleClass->searchInstances(array(funcAcl_models_classes_AccessService::PROPERTY_ACL_GRANTACCESS => $aclExtUri), array('recursive' => true, 'like' => false));
         foreach ($roles as $grantedRole) {
             $returnValue[] = $grantedRole->getUri();
         }
         self::getCacheImplementation()->put($returnValue, self::CACHE_PREFIX_EXTENSION . $extId);
     }
     return $returnValue;
 }
 /**
  *
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     if ($currentVersion == '1.0') {
         $currentVersion = '1.0.1';
     }
     if ($currentVersion == '1.0.1') {
         $currentVersion = '1.1.0';
     }
     if ($currentVersion == '1.1.0') {
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $anonymous = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/generis.rdf#AnonymousRole');
         $accessService->grantModuleAccess($anonymous, 'taoClientDiagnostic', 'CompatibilityChecker');
         $currentVersion = '1.1.1';
     }
     if ($currentVersion == '1.1.1') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoClientDiagnostic');
         $extension->setConfig('clientDiag', array('footer' => ''));
         $currentVersion = '1.2.0';
     }
     if ($currentVersion == '1.2.0') {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoClientDiagnostic');
         $config = $extension->getConfig('clientDiag');
         $extension->setConfig('clientDiag', array_merge($config, array('performances' => array('samples' => array('taoClientDiagnostic/tools/performances/data/sample1/', 'taoClientDiagnostic/tools/performances/data/sample2/', 'taoClientDiagnostic/tools/performances/data/sample3/'), 'occurrences' => 10, 'timeout' => 30, 'optimal' => 0.025, 'threshold' => 0.25), 'bandwidth' => array('unit' => 0.16, 'ideal' => 45, 'max' => 100))));
         $currentVersion = '1.3.0';
     }
     $this->setVersion($currentVersion);
     if ($this->isVersion('1.3.0')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoClientDiagnostic');
         $config = $extension->getConfig('clientDiag');
         $extension->setConfig('clientDiag', array_merge($config, array('diagHeader' => 'This tool will run a number of tests in order to establish how well your current environment is suitable to run the TAO platform.')));
         $this->setVersion('1.3.1');
     }
     if ($this->isVersion('1.3.1')) {
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $anonymous = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/generis.rdf#AnonymousRole');
         $accessService->grantModuleAccess($anonymous, 'taoClientDiagnostic', 'Authenticator');
         if (!$this->getServiceManager()->has(Authorization::SERVICE_ID)) {
             $service = new RequireUsername();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(Authorization::SERVICE_ID, $service);
         }
         $this->setVersion('1.4.0');
     }
     if ($this->isVersion('1.4.0')) {
         $service = $this->getServiceManager()->get(Authorization::SERVICE_ID);
         if ($service instanceof RequireUsername) {
             $service = new RequireUsername(array('regexValidator' => '/^[0-9]{7}[A-Z]$/'));
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(Authorization::SERVICE_ID, $service);
         }
         $this->setVersion('1.4.1');
     }
     if ($this->isVersion('1.4.1')) {
         if (!$this->getServiceManager()->has(Storage::SERVICE_ID)) {
             $service = new Csv(array('filename' => FILES_PATH . 'taoClientDiagnostic' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'store.csv'));
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(Storage::SERVICE_ID, $service);
         }
         $this->setVersion('1.5.0');
     }
     $this->skip('1.5.0', '1.6.0');
     if ($this->isVersion('1.6.0')) {
         $storageService = $this->getServiceManager()->get(Storage::SERVICE_ID);
         if ($storageService instanceof Sql) {
             $persistence = $storageService->getPersistence();
             $schemaManager = $persistence->getDriver()->getSchemaManager();
             $schema = $schemaManager->createSchema();
             $fromSchema = clone $schema;
             /** @var \Doctrine\DBAL\Schema\Table $tableResults */
             $tableResults = $schema->getTable(Sql::DIAGNOSTIC_TABLE);
             $tableResults->dropColumn('browserVersion');
             $tableResults->dropColumn('osVersion');
             $tableResults->addColumn(Sql::DIAGNOSTIC_BROWSERVERSION, 'string', ['length' => 32]);
             $tableResults->addColumn(Sql::DIAGNOSTIC_OSVERSION, 'string', ['length' => 32]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_VERSION, ['type' => Type::getType('string'), 'length' => 16]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BROWSER, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_OS, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_COMPATIBLE, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_MIN, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_MAX, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_SUM, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_COUNT, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_AVERAGE, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_MEDIAN, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_VARIANCE, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_DURATION, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BANDWIDTH_SIZE, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_PERFORMANCE_MIN, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_PERFORMANCE_MAX, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_PERFORMANCE_SUM, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_PERFORMANCE_COUNT, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_PERFORMANCE_AVERAGE, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_PERFORMANCE_MEDIAN, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_PERFORMANCE_VARIANCE, ['notnull' => false]);
             $queries = $persistence->getPlatform()->getMigrateSchemaSql($fromSchema, $schema);
             foreach ($queries as $query) {
                 $persistence->exec($query);
             }
         }
         $this->setVersion('1.6.1');
     }
     $this->skip('1.6.1', '1.7.0');
     if ($this->isVersion('1.7.0')) {
         $storageService = $this->getServiceManager()->get(Storage::SERVICE_ID);
         if ($storageService instanceof Sql) {
             $persistence = $storageService->getPersistence();
             $schemaManager = $persistence->getDriver()->getSchemaManager();
             $schema = $schemaManager->createSchema();
             /* create temp column && Nullable os,browser version */
             $addTempSchema = clone $schema;
             $tableResults = $addTempSchema->getTable(Sql::DIAGNOSTIC_TABLE);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_BROWSERVERSION, ['notnull' => false]);
             $tableResults->changeColumn(Sql::DIAGNOSTIC_OSVERSION, ['notnull' => false]);
             $tableResults->addColumn('compatible_tmp', 'integer', ['length' => 1, 'notnull' => false]);
             $queries = $persistence->getPlatform()->getMigrateSchemaSql($schema, $addTempSchema);
             foreach ($queries as $query) {
                 $persistence->exec($query);
             }
             /* Migrate data to temp column */
             $sql = 'SELECT ' . Sql::DIAGNOSTIC_ID . ', ' . Sql::DIAGNOSTIC_COMPATIBLE . ' FROM ' . Sql::DIAGNOSTIC_TABLE;
             $stmt = $persistence->query($sql);
             $results = $stmt->fetchAll();
             foreach ($results as $result) {
                 if ($result['compatible'] === true || $result['compatible'] == 1) {
                     $compatible = 1;
                 } elseif ($result['compatible'] === false || $result['compatible'] == 0) {
                     $compatible = 0;
                 } else {
                     $compatible = (int) $result['compatible'];
                 }
                 $sql = 'UPDATE ' . Sql::DIAGNOSTIC_TABLE . ' SET compatible_tmp = :compatible' . ' WHERE ' . Sql::DIAGNOSTIC_ID . ' = :id';
                 $persistence->exec($sql, array('compatible' => $compatible, 'id' => $result['id']));
             }
             /* delete compatible boolean column */
             $deleteCompatibleSchema = clone $addTempSchema;
             $tableResults = $deleteCompatibleSchema->getTable(Sql::DIAGNOSTIC_TABLE);
             $tableResults->dropColumn(Sql::DIAGNOSTIC_COMPATIBLE);
             $queries = $persistence->getPlatform()->getMigrateSchemaSql($addTempSchema, $deleteCompatibleSchema);
             foreach ($queries as $query) {
                 $persistence->exec($query);
             }
             /* create compatible integer column */
             $addCompatibleSchema = clone $deleteCompatibleSchema;
             $tableResults = $addCompatibleSchema->getTable(Sql::DIAGNOSTIC_TABLE);
             $tableResults->addColumn(Sql::DIAGNOSTIC_COMPATIBLE, 'integer', ['length' => 1, 'notnull' => false]);
             $queries = $persistence->getPlatform()->getMigrateSchemaSql($deleteCompatibleSchema, $addCompatibleSchema);
             foreach ($queries as $query) {
                 $persistence->exec($query);
             }
             /* migrate date to compatible column */
             $sql = 'UPDATE ' . Sql::DIAGNOSTIC_TABLE . ' SET ' . Sql::DIAGNOSTIC_COMPATIBLE . ' = compatible_tmp';
             $persistence->exec($sql);
             /* delete temp column */
             $deleteTempSchema = clone $addCompatibleSchema;
             $tableResults = $deleteTempSchema->getTable(Sql::DIAGNOSTIC_TABLE);
             $tableResults->dropColumn('compatible_tmp');
             $queries = $persistence->getPlatform()->getMigrateSchemaSql($addCompatibleSchema, $deleteTempSchema);
             foreach ($queries as $query) {
                 $persistence->exec($query);
             }
         }
         $this->setVersion('1.7.1');
     }
     $this->skip('1.7.1', '1.9.1');
     if ($this->isVersion('1.9.1')) {
         $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoClientDiagnostic');
         $config = $extension->getConfig('clientDiag');
         $config['upload'] = ['size' => 1 * 1024 * 1024, 'optimal' => 1 * 1024 * 1024];
         $extension->setConfig('clientDiag', $config);
         $this->setVersion('1.10.0');
     }
 }
 /**
  *
  * @param string $initialVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     //migrate from 0.1 to 0.1.1
     if ($currentVersion == '0.1') {
         // mediaSources set in 0.2
         $currentVersion = '0.1.1';
     }
     if ($currentVersion == '0.1.1') {
         FileManager::setFileManagementModel(new SimpleFileManagement());
         // mediaSources unset in 0.2
         $currentVersion = '0.1.2';
     }
     if ($currentVersion == '0.1.2') {
         //add alt text to media manager
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'alt_text.rdf';
         $adapter = new \tao_helpers_data_GenerisAdapterRdf();
         if ($adapter->import($file)) {
             $currentVersion = '0.1.3';
         } else {
             \common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($currentVersion == '0.1.3') {
         OntologyUpdater::correctModelId(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'alt_text.rdf');
         $currentVersion = '0.1.4';
     }
     if ($currentVersion == '0.1.4') {
         //modify config files due to the new interfaces relation
         $tao = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao');
         $tao->unsetConfig('mediaManagementSources');
         $tao->unsetConfig('mediaBrowserSources');
         TaoMediaService::singleton()->addMediaSource(new MediaSource());
         //modify links in item content
         $service = \taoItems_models_classes_ItemsService::singleton();
         $items = $service->getAllByModel('http://www.tao.lu/Ontologies/TAOItem.rdf#QTI');
         foreach ($items as $item) {
             $itemContent = $service->getItemContent($item);
             $itemContent = preg_replace_callback('/src="mediamanager\\/([^"]+)"/', function ($matches) {
                 $mediaClass = MediaService::singleton()->getRootClass();
                 $medias = $mediaClass->searchInstances(array(MEDIA_LINK => $matches[1]), array('recursive' => true));
                 $media = array_pop($medias);
                 $uri = '';
                 if (!is_null($media) && $media->exists()) {
                     $uri = \tao_helpers_Uri::encode($media->getUri());
                 }
                 return 'src="taomedia://mediamanager/' . $uri . '"';
             }, $itemContent);
             $itemContent = preg_replace_callback('/src="local\\/([^"]+)"/', function ($matches) {
                 return 'src="' . $matches[1] . '"';
             }, $itemContent);
             $service->setItemContent($item, $itemContent);
         }
         $currentVersion = '0.2.0';
     }
     if ($currentVersion === '0.2.0') {
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         //revoke access right to back office
         $backOffice = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#BackOfficeRole');
         $accessService->revokeExtensionAccess($backOffice, 'taoMediaManager');
         //grant access right to media manager
         $mediaManager = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOMedia.rdf#MediaManagerRole');
         $accessService->grantExtensionAccess($mediaManager, 'taoMediaManager');
         $currentVersion = '0.2.1';
     }
     if ($currentVersion === '0.2.1') {
         //include mediamanager into globalmanager
         $mediaManager = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOMedia.rdf#MediaManagerRole');
         $globalManager = new \core_kernel_Classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#GlobalManagerRole');
         \tao_models_classes_RoleService::singleton()->includeRole($globalManager, $mediaManager);
         $currentVersion = '0.2.2';
     }
     if ($currentVersion === '0.2.2') {
         //copy file from /media to data/taoMediaManager/media and delete /media
         $dataPath = FILES_PATH . 'taoMediaManager' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR;
         $dir = dirname(dirname(__DIR__)) . '/media';
         if (file_exists($dir)) {
             if (\tao_helpers_File::copy($dir, $dataPath)) {
                 $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
                 $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
                 foreach ($files as $file) {
                     if ($file->isDir()) {
                         rmdir($file->getRealPath());
                     } else {
                         unlink($file->getRealPath());
                     }
                 }
                 rmdir($dir);
                 $currentVersion = '0.2.3';
             }
         } else {
             $currentVersion = '0.2.3';
         }
     }
     if ($currentVersion === '0.2.3') {
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         //grant access to item author
         $itemAuthor = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOItem.rdf#ItemAuthor');
         $accessService->grantExtensionAccess($itemAuthor, 'taoMediaManager');
         $currentVersion = '0.2.4';
     }
     if ($currentVersion === '0.2.4') {
         $mediaClass = MediaService::singleton()->getRootClass();
         $fileManager = FileManager::getFileManagementModel();
         foreach ($mediaClass->getInstances(true) as $media) {
             $fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
             $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink;
             $filePath = $fileManager->retrieveFile($fileLink);
             $mimeType = \tao_helpers_File::getMimeType($filePath);
             $mimeType = $mimeType === 'application/xhtml+xml' ? 'application/qti+xml' : $mimeType;
             $media->setPropertyValue(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType);
         }
         $currentVersion = '0.2.5';
     }
     if ($currentVersion === '0.2.5') {
         $fileManager = FileManager::getFileManagementModel();
         $iterator = new \core_kernel_classes_ResourceIterator(array(MediaService::singleton()->getRootClass()));
         foreach ($iterator as $media) {
             $fileLink = $media->getUniquePropertyValue(new \core_kernel_classes_Property(MEDIA_LINK));
             $fileLink = $fileLink instanceof \core_kernel_classes_Resource ? $fileLink->getUri() : (string) $fileLink;
             $filePath = $fileManager->retrieveFile($fileLink);
             try {
                 SharedStimulusImporter::isValidSharedStimulus($filePath);
                 $media->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), 'application/qti+xml');
             } catch (\Exception $e) {
                 $mimeType = \tao_helpers_File::getMimeType($filePath);
                 $media->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType);
             }
         }
         $currentVersion = '0.3.0';
     }
     $this->skip('0.3.0', '0.5.1');
 }
 public function revokeRule(AccessRule $rule)
 {
     if ($rule->isGrant()) {
         $accessService = funcAcl_models_classes_AccessService::singleton();
         $elements = $this->evalFilterMask($rule->getMask());
         switch (count($elements)) {
             case 1:
                 $extension = reset($elements);
                 $accessService->revokeExtensionAccess($rule->getRole(), $extension);
                 break;
             case 2:
                 list($extension, $shortName) = $elements;
                 $accessService->revokeModuleAccess($rule->getRole(), $extension, $shortName);
                 break;
             case 3:
                 list($extension, $shortName, $action) = $elements;
                 $accessService->revokeActionAccess($rule->getRole(), $extension, $shortName, $action);
                 break;
             default:
                 // fail silently warning should already be send
         }
     } else {
         common_Logger::w('Only grant rules accepted in ' . __CLASS__);
     }
 }
 protected function buildExtensionData(common_ext_Extension $extension, $roleUri, $includedRoleUris)
 {
     $extAccess = funcAcl_helpers_Cache::getExtensionAccess($extension->getId());
     $extAclUri = funcAcl_models_classes_AccessService::singleton()->makeEMAUri($extension->getId());
     $atLeastOneAccess = false;
     $allAccess = in_array($roleUri, $extAccess);
     $inherited = count(array_intersect($includedRoleUris, $extAccess)) > 0;
     $controllers = array();
     foreach (ControllerHelper::getControllers($extension->getId()) as $controllerClassName) {
         $controllerData = $this->buildControllerData($controllerClassName, $roleUri, $includedRoleUris);
         $atLeastOneAccess = $atLeastOneAccess || $controllerData['access'] != self::ACCESS_NONE;
         $controllers[] = $controllerData;
     }
     usort($controllers, function ($a, $b) {
         return strcmp($a['label'], $b['label']);
     });
     $access = $inherited ? 'inherited' : ($allAccess ? 'full' : ($atLeastOneAccess ? 'partial' : 'none'));
     return array('uri' => $extAclUri, 'label' => $extension->getName(), 'access' => $access, 'modules' => $controllers);
 }
 public static function getUriForAction($controllerClassName, $actionName)
 {
     $extension = self::getExtensionFromController($controllerClassName);
     $shortName = strpos($controllerClassName, '\\') !== false ? substr($controllerClassName, strrpos($controllerClassName, '\\') + 1) : substr($controllerClassName, strrpos($controllerClassName, '_') + 1);
     return funcAcl_models_classes_AccessService::singleton()->makeEMAUri($extension, $shortName, $actionName);
 }
 public function revokeRule(AccessRule $rule)
 {
     if ($rule->isGrant()) {
         $accessService = funcAcl_models_classes_AccessService::singleton();
         $filter = $rule->getMask();
         if (isset($filter['act']) && isset($filter['mod']) && isset($filter['ext'])) {
             $accessService->revokeActionAccess($rule->getRole(), $filter['ext'], $filter['mod'], $filter['act']);
         } elseif (isset($filter['mod']) && isset($filter['ext'])) {
             $accessService->revokeModuleAccess($rule->getRole(), $filter['ext'], $filter['mod']);
         } elseif (isset($filter['ext'])) {
             $accessService->revokeExtensionAccess($rule->getRole(), $filter['ext']);
         } elseif (isset($filter['controller'])) {
             $extension = funcAcl_helpers_Map::getExtensionFromController($filter['controller']);
             $shortName = strpos($filter['controller'], '\\') !== false ? substr($filter['controller'], strrpos($filter['controller'], '\\') + 1) : substr($filter['controller'], strrpos($filter['controller'], '_') + 1);
             $accessService->revokeModuleAccess($rule->getRole(), $extension, $shortName);
         } elseif (isset($filter['act']) && strpos($filter['act'], '@') !== false) {
             list($controller, $action) = explode('@', $mask['act'], 2);
             $extension = funcAcl_helpers_Map::getExtensionFromController($controller);
             $shortName = strpos($controller, '\\') !== false ? substr($controller, strrpos($controller, '\\') + 1) : substr($controller, strrpos($controller, '_') + 1);
             $accessService->revokeActionAccess($rule->getRole(), $extension, $shortName, $action);
         } else {
             common_Logger::w('Uninterpretable filter in ' . __CLASS__);
         }
     } else {
         common_Logger::w('Only grant rules accepted in ' . __CLASS__);
     }
 }
 /**
  * @param string $initialVersion
  * @return string string
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoProctoring');
     if ($currentVersion == '0.1') {
         $service = new DeliveryService();
         $ext->setConfig('delivery', $service);
         $currentVersion = '0.2';
     }
     if ($currentVersion == '0.2') {
         //            $service = new TestCenterService();
         //            $ext->setConfig('testCenter', $service);
         $currentVersion = '0.3';
     }
     if ($currentVersion == '0.3') {
         //grant access to test taker
         $testTakerRole = new \core_kernel_classes_Resource(INSTANCE_ROLE_DELIVERY);
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantModuleAccess($testTakerRole, 'taoProctoring', 'DeliveryServer');
         $mpManagerRole = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOProctor.rdf#ProctorRole');
         $accessService->revokeModuleAccess($mpManagerRole, 'taoProctoring', 'DeliveryServer');
         //replace delivery server
         $entryPointService = EntryPointService::getRegistry();
         $entryPointService->overrideEntryPoint('deliveryServer', new ProctoringDeliveryServer());
         $this->getServiceManager()->register(EntryPointService::SERVICE_ID, $entryPointService);
         $currentVersion = '0.4';
     }
     if ($currentVersion == '0.4') {
         OntologyUpdater::syncModels();
         $ext->unsetConfig('testCenter');
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $roleService = \tao_models_classes_RoleService::singleton();
         //grant access right to proctoring manager
         $testCenterManager = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOProctor.rdf#TestCenterManager');
         $globalManager = new \core_kernel_Classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#BackOfficeRole');
         $roleService->includeRole($globalManager, $testCenterManager);
         $accessService->grantModuleAccess($testCenterManager, 'taoProctoring', 'TestCenterManager');
         //revoke access to legacy delivery server
         $testTakerRole = new \core_kernel_classes_Resource(INSTANCE_ROLE_DELIVERY);
         $accessService->revokeModuleAccess($testTakerRole, 'taoDelivery', 'DeliveryServer');
         //grant access to proctor role
         $proctorRole = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOProctor.rdf#ProctorRole');
         $accessService->grantModuleAccess($proctorRole, 'taoProctoring', 'Delivery');
         $accessService->grantModuleAccess($proctorRole, 'taoProctoring', 'Diagnostic');
         $accessService->grantModuleAccess($proctorRole, 'taoProctoring', 'Reporting');
         $accessService->grantModuleAccess($proctorRole, 'taoProctoring', 'TestCenter');
         $currentVersion = '0.5';
     }
     if ($currentVersion == '0.5') {
         try {
             $this->getServiceManager()->get(AssessmentResultsService::CONFIG_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new AssessmentResultsService([AssessmentResultsService::OPTION_PRINTABLE_RUBRIC_TAG => 'x-tao-scorereport', AssessmentResultsService::OPTION_PRINT_REPORT_BUTTON => false]);
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(AssessmentResultsService::CONFIG_ID, $service);
         }
         $currentVersion = '0.6';
     }
     $this->setVersion($currentVersion);
     if ($this->isVersion('0.6')) {
         OntologyUpdater::syncModels();
         //grant access to test site admin role
         $proctorRole = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOProctor.rdf#TestCenterAdministratorRole');
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantModuleAccess($proctorRole, 'taoProctoring', 'ProctorManager');
         $this->setVersion('0.7');
     }
     if ($this->isVersion('0.7')) {
         try {
             $this->getServiceManager()->get(DeliveryMonitoringService::CONFIG_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new DeliveryMonitoringService(array(DeliveryMonitoringService::OPTION_PERSISTENCE => 'default'));
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(DeliveryMonitoringService::CONFIG_ID, $service);
         }
         include __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'createDeliveryMonitoringTables.php';
         $this->setVersion('0.8.0');
     }
     if ($this->isVersion('0.8.0')) {
         $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID);
         $eventManager->attach(TestChangedEvent::EVENT_NAME, array('oat\\taoProctoring\\model\\monitorCache\\update\\TestUpdate', 'testStateChange'));
         $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
         $this->setVersion('0.9.0');
     }
     // nothign to do
     if ($this->isVersion('0.9.0')) {
         $this->setVersion('1.0.0');
     }
     if ($this->isVersion('1.0.0')) {
         try {
             $this->getServiceManager()->get(DeliveryAuthorizationService::SERVICE_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new DeliveryAuthorizationService();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(DeliveryAuthorizationService::SERVICE_ID, $service);
         }
         $this->setVersion('1.1.0');
     }
     if ($this->isVersion('1.1.0')) {
         OntologyUpdater::syncModels();
         $this->setVersion('1.2.0');
     }
     if ($this->isVersion('1.2.0')) {
         try {
             $this->getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new DeliveryExecutionStateService();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(DeliveryExecutionStateService::SERVICE_ID, $service);
         }
         $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID);
         $eventManager->attach('oat\\taoTests\\models\\event\\TestChangedEvent', array('\\oat\\taoProctoring\\helpers\\DeliveryHelper', 'testStateChanged'));
         $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
         $this->setVersion('1.3.0');
     }
     if ($this->isVersion('1.3.0')) {
         $proctoringExtension = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoProctoring');
         $proctoringExtension->setConfig('monitoringUserExtraFields', array());
         $this->setVersion('1.4.0');
     }
     $this->skip('1.4.0', '1.4.1');
     $this->skip('1.4.1', '1.5.0');
     if ($this->isVersion('1.5.0')) {
         try {
             $this->getServiceManager()->get(RdsDeliveryLogService::SERVICE_ID);
         } catch (ServiceNotFoundException $e) {
             $action = new RegisterProctoringLog();
             $action->setServiceLocator($this->getServiceManager());
             $action->__invoke(array('default'));
         }
         $this->setVersion('1.6.0');
     }
     if ($this->isVersion('1.6.0')) {
         $settingsScript = new addDiagnosticSettings();
         $settingsScript([]);
         $sqlScript = new createDiagnosticTable();
         $sqlScript([]);
         //Grant access to the overridden controller
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $taoClientDiagnosticManager = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/generis.rdf#taoClientDiagnosticManager');
         $accessService->grantModuleAccess($taoClientDiagnosticManager, 'taoProctoring', 'DiagnosticChecker');
         $anonymousRole = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/generis.rdf#AnonymousRole');
         $accessService->grantModuleAccess($anonymousRole, 'taoProctoring', 'DiagnosticChecker');
         $this->setVersion('1.7.0');
     }
     $this->skip('1.7.0', '1.7.1');
     if ($this->isVersion('1.7.1')) {
         $deliveryExecutionStateService = $this->getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID);
         $deliveryExecutionStateService->setOption(DeliveryExecutionStateService::OPTION_TERMINATION_DELAY_AFTER_PAUSE, 'PT1H');
         $this->getServiceManager()->register(DeliveryExecutionStateService::SERVICE_ID, $deliveryExecutionStateService);
         $this->setVersion('1.8.0');
     }
     $this->skip('1.8.0', '1.9.0');
     if ($this->isVersion('1.9.0')) {
         $persistence = $this->getServiceManager()->get(PaginatedStorage::SERVICE_ID)->getPersistence();
         $schemaManager = $persistence->getDriver()->getSchemaManager();
         $schema = $schemaManager->createSchema();
         $fromSchema = clone $schema;
         /** @var \Doctrine\DBAL\Schema\Table $tableResults */
         $tableResults = $schema->getTable(DiagnosticStorage::DIAGNOSTIC_TABLE);
         $tableResults->changeColumn(DiagnosticStorage::DIAGNOSTIC_TEST_CENTER, ['notnull' => false]);
         $tableResults->changeColumn(DiagnosticStorage::DIAGNOSTIC_WORKSTATION, ['notnull' => false]);
         $queries = $persistence->getPlatform()->getMigrateSchemaSql($fromSchema, $schema);
         foreach ($queries as $query) {
             $persistence->exec($query);
         }
         $this->setVersion('1.9.1');
     }
     if ($this->isVersion('1.9.1')) {
         $assignmentService = new ProctoringAssignmentService();
         $assignmentService->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(ProctoringAssignmentService::CONFIG_ID, $assignmentService);
         $deliveryExt = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery');
         $deliveryServerConfig = $deliveryExt->getConfig('deliveryServer');
         $deliveryServerOptions = $deliveryServerConfig->getOptions();
         $deliveryServerService = new DeliveryServerService($deliveryServerOptions);
         $deliveryServerService->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(DeliveryServerService::CONFIG_ID, $deliveryServerService);
         $this->setVersion('1.9.2');
     }
     $this->skip('1.9.2', '1.12.2');
     if ($this->isVersion('1.12.2')) {
         $persistenceId = $this->getServiceManager()->get(DeliveryMonitoringService::CONFIG_ID)->getOption(DeliveryMonitoringService::OPTION_PERSISTENCE);
         $persistence = \common_persistence_Manager::getPersistence($persistenceId);
         $schemaManager = $persistence->getDriver()->getSchemaManager();
         $schema = $schemaManager->createSchema();
         $fromSchema = clone $schema;
         try {
             $tableData = $schema->getTable(DeliveryMonitoringService::TABLE_NAME);
             $tableData->changeColumn(DeliveryMonitoringService::COLUMN_START_TIME, array('type' => \Doctrine\DBAL\Types\Type::getType('string'), 'notnull' => false, 'length' => 255));
             $tableData->changeColumn(DeliveryMonitoringService::COLUMN_END_TIME, array('type' => \Doctrine\DBAL\Types\Type::getType('string'), 'notnull' => false, 'length' => 255));
         } catch (SchemaException $e) {
             \common_Logger::i('Database Schema already up to date.');
         }
         $queries = $persistence->getPlatform()->getMigrateSchemaSql($fromSchema, $schema);
         foreach ($queries as $query) {
             $persistence->exec($query);
         }
         $this->setVersion('1.12.3');
     }
     if ($this->isVersion('1.12.3')) {
         try {
             $this->getServiceManager()->get(TestSessionConnectivityStatusService::SERVICE_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new TestSessionConnectivityStatusService();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(TestSessionConnectivityStatusService::SERVICE_ID, $service);
         }
         $this->setVersion('1.13.0');
     }
     if ($this->isVersion('1.13.0')) {
         $this->refreshMonitoringData();
         $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID);
         $eventManager->attach('oat\\taoDelivery\\models\\classes\\execution\\event\\DeliveryExecutionState', ['oat\\taoProctoring\\model\\monitorCache\\update\\DeliveryExecutionStateUpdate', 'stateChange']);
         $eventManager->attach(EligiblityChanged::EVENT_NAME, ['oat\\taoProctoring\\model\\monitorCache\\update\\EligiblityUpdate', 'eligiblityChange']);
         $eventManager->attach(MetadataModified::class, ['oat\\taoProctoring\\model\\monitorCache\\update\\DeliveryUpdate', 'labelChange']);
         $eventManager->attach(MetadataModified::class, ['oat\\taoProctoring\\model\\monitorCache\\update\\TestTakerUpdate', 'propertyChange']);
         $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
         $this->setVersion('1.14.0');
     }
     $this->skip('1.14.0', '1.14.1');
     if ($this->isVersion('1.14.1')) {
         $this->refreshMonitoringData();
         $this->setVersion('1.14.2');
     }
     if ($this->isVersion('1.14.2') || $this->isVersion('1.14.3')) {
         $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery');
         $config = $ext->getConfig('execution_service');
         $config = new \oat\taoProctoring\model\execution\DeliveryExecutionService(['implementation' => $config]);
         $ext->setConfig('execution_service', $config);
         $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID);
         $eventManager->attach('oat\\taoDelivery\\models\\classes\\execution\\event\\DeliveryExecutionState', ['oat\\taoProctoring\\model\\monitorCache\\update\\DeliveryExecutionStateUpdate', 'stateChange']);
         $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
         OntologyUpdater::syncModels();
         $this->refreshMonitoringData();
         $this->setVersion('1.15.0');
     }
     if ($this->isVersion('1.15.0')) {
         $this->refreshMonitoringData();
         $this->setVersion('1.15.1');
     }
     $this->skip('1.15.1', '1.16.2');
     if ($this->isVersion('1.16.2')) {
         OntologyUpdater::syncModels();
         $this->setVersion('1.17.0');
     }
     $this->skip('1.17.0', '2.1.0');
     if ($this->isVersion('2.1.0')) {
         $authService = $this->getServiceManager()->get(AuthorizationService::SERVICE_ID);
         if ($authService instanceof AuthorizationAggregator) {
             $authService->unregister(StateValidation::class);
             $authService->addProvider(new ProctorAuthorizationProvider());
             $this->getServiceManager()->register(AuthorizationService::SERVICE_ID, $authService);
         } else {
             throw new \common_exception_Error('Incompatible AuthorizationService "' . get_class($authService) . '" found.');
         }
         $this->setVersion('3.0.0');
     }
     $this->skip('3.0.0', '3.0.6');
     if ($this->isVersion('3.0.6')) {
         //grant access to test taker
         $globalManagerRole = new \core_kernel_classes_Resource(INSTANCE_ROLE_GLOBALMANAGER);
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantModuleAccess($globalManagerRole, 'taoProctoring', 'Irregularity');
         $this->setVersion('3.1.0');
     }
     if ($this->isVersion('3.1.0')) {
         $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID);
         $eventManager->attach('oat\\taoTests\\models\\event\\TestExecutionPausedEvent', ['oat\\taoProctoring\\model\\implementation\\DeliveryExecutionStateService', 'catchSessionPause']);
         $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
         $this->setVersion('3.1.1');
     }
     $this->skip('3.1.1', '3.3.1');
     if ($this->isVersion('3.3.1')) {
         $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDelivery');
         $config = $ext->getConfig('execution_service');
         $implementation = $config->getImplementation();
         $ext->setConfig('execution_service', $implementation);
         $this->setVersion('3.4.0');
     }
     if ($this->isVersion('3.4.0')) {
         try {
             $this->getServiceManager()->get(TestSessionService::SERVICE_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new TestSessionService();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(TestSessionService::SERVICE_ID, $service);
         }
         $this->setVersion('3.4.1');
     }
     $this->skip('3.4.1', '3.6.3');
     if ($this->isVersion('3.6.3')) {
         $deliveryMonitoringService = $this->getServiceManager()->get(DeliveryMonitoringService::CONFIG_ID);
         $deliveryMonitoringService->setOption(DeliveryMonitoringService::OPTION_PRIMARY_COLUMNS, [DeliveryMonitoringService::COLUMN_DELIVERY_EXECUTION_ID, DeliveryMonitoringService::COLUMN_STATUS, DeliveryMonitoringService::COLUMN_CURRENT_ASSESSMENT_ITEM, DeliveryMonitoringService::COLUMN_TEST_TAKER, DeliveryMonitoringService::COLUMN_AUTHORIZED_BY, DeliveryMonitoringService::COLUMN_START_TIME, DeliveryMonitoringService::COLUMN_END_TIME]);
         $this->getServiceManager()->register(DeliveryMonitoringService::CONFIG_ID, $deliveryMonitoringService);
         $this->setVersion('3.6.5');
     }
     $this->skip('3.6.4', '3.6.5');
     if ($this->isVersion('3.6.5')) {
         $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID);
         $eventManager->detach('oat\\taoTests\\models\\event\\TestChangedEvent', array('\\oat\\taoProctoring\\helpers\\DeliveryHelper', 'testStateChanged'));
         $eventManager->attach('oat\\taoQtiTest\\models\\event\\QtiTestStateChangeEvent', array('\\oat\\taoProctoring\\helpers\\DeliveryHelper', 'testStateChanged'));
         $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
         $this->setVersion('3.6.6');
     }
     $this->skip('3.6.6', '3.6.18');
     if ($this->isVersion('3.6.18')) {
         $this->getServiceManager()->register(ProctoringTextConverter::SERVICE_ID, new ProctoringTextConverter());
         $proctorRole = new \core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOProctor.rdf#ProctorRole');
         $accessService = \funcAcl_models_classes_AccessService::singleton();
         $accessService->grantModuleAccess($proctorRole, 'taoProctoring', 'TextConverter');
         $this->setVersion('3.7.0');
     }
     $this->skip('3.7.0', '3.10.1');
     if ($this->isVersion('3.10.1')) {
         try {
             $this->getServiceManager()->get(TestSessionHistoryService::SERVICE_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new TestSessionHistoryService();
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(TestSessionHistoryService::SERVICE_ID, $service);
         }
         $this->setVersion('3.11.0');
     }
     if ($this->isVersion('3.11.0')) {
         // register timeHandling option
         try {
             $service = $this->getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new DeliveryExecutionStateService([DeliveryExecutionStateService::OPTION_TERMINATION_DELAY_AFTER_PAUSE => 'PT1H', DeliveryExecutionStateService::OPTION_TIME_HANDLING => false]);
         }
         $service->setOption(DeliveryExecutionStateService::OPTION_TIME_HANDLING, false);
         $service->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(DeliveryExecutionStateService::SERVICE_ID, $service);
         // extend the data table
         $persistenceId = $this->getServiceManager()->get(DeliveryMonitoringService::CONFIG_ID)->getOption(DeliveryMonitoringService::OPTION_PERSISTENCE);
         $persistence = \common_persistence_Manager::getPersistence($persistenceId);
         $schemaManager = $persistence->getDriver()->getSchemaManager();
         $schema = $schemaManager->createSchema();
         $fromSchema = clone $schema;
         try {
             $tableData = $schema->getTable(DeliveryMonitoringService::TABLE_NAME);
             $tableData->addColumn(DeliveryMonitoringService::COLUMN_REMAINING_TIME, "string", array("notnull" => false, "length" => 255));
             $tableData->addColumn(DeliveryMonitoringService::COLUMN_EXTRA_TIME, "string", array("notnull" => false, "length" => 255));
             $tableData->addColumn(DeliveryMonitoringService::COLUMN_CONSUMED_EXTRA_TIME, "string", array("notnull" => false, "length" => 255));
         } catch (SchemaException $e) {
             \common_Logger::i('Database Schema already up to date.');
         }
         $queries = $persistence->getPlatform()->getMigrateSchemaSql($fromSchema, $schema);
         foreach ($queries as $query) {
             $persistence->exec($query);
         }
         $this->setVersion('3.12.0');
     }
     $this->skip('3.12.0', '3.12.1');
     if ($this->isVersion('3.12.1')) {
         OntologyUpdater::syncModels();
         $this->setVersion('3.13.0');
     }
     $this->skip('3.13.0', '3.13.5');
 }