/**
  * 
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     //migrate from 2.6 to 2.6.1
     if ($currentVersion == '2.6') {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_1.rdf';
         $adapter = new tao_helpers_data_GenerisAdapterRdf();
         if ($adapter->import($file)) {
             $currentVersion = '2.6.1';
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($currentVersion == '2.6.1') {
         // double check
         $index = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOItem.rdf#ItemContentIndex');
         $default = $index->getPropertyValues(new core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAO.rdf#IndexDefaultSearch'));
         if (count($default) == 0) {
             //no default search set, import
             $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_2.rdf';
             $adapter = new tao_helpers_data_GenerisAdapterRdf();
             if ($adapter->import($file)) {
                 $currentVersion = '2.6.2';
             } else {
                 common_Logger::w('Import failed for ' . $file);
             }
         } else {
             common_Logger::w('Defautl Search already set');
             $currentVersion = '2.6.2';
         }
     }
     if ($currentVersion == '2.6.2') {
         OntologyUpdater::correctModelId(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_1.rdf');
         OntologyUpdater::correctModelId(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_2.rdf');
         $currentVersion = '2.6.3';
     }
     if ($currentVersion == '2.6.3') {
         // update user roles
         $class = new core_kernel_classes_Class(CLASS_TAO_USER);
         $itemManagers = $class->searchInstances(array(PROPERTY_USER_ROLES => 'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemsManagerRole'), array('recursive' => true, 'like' => false));
         foreach ($itemManagers as $user) {
             $user->setPropertyValue(new core_kernel_classes_Property(PROPERTY_USER_ROLES), ItemAuthorRole::INSTANCE_URI);
         }
         $currentVersion = '2.6.4';
     }
     return $currentVersion;
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see tao_models_classes_export_ExportHandler::export()
  */
 public function export($formValues, $destination)
 {
     $file = null;
     if (isset($formValues['filename']) && isset($formValues['resource'])) {
         $class = new core_kernel_classes_Class($formValues['resource']);
         common_Logger::i('Exporting ' . $class->getUri());
         $adapter = new tao_helpers_data_GenerisAdapterRdf();
         $rdf = $adapter->export($class);
         if (!empty($rdf)) {
             $name = $formValues['filename'] . '_' . time() . '.rdf';
             $path = tao_helpers_File::concat(array($destination, $name));
             if (file_put_contents($path, $rdf)) {
                 $file = $path;
             }
         }
     }
     return $file;
 }
 /**
  *
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     //migrate from 2.6 to 2.6.1
     if ($this->isVersion('2.6')) {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_1.rdf';
         $adapter = new tao_helpers_data_GenerisAdapterRdf();
         if ($adapter->import($file)) {
             ${$this}->setVerion('2.6.1');
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($this->isVersion('2.6.1')) {
         // double check
         $index = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAOItem.rdf#ItemContentIndex');
         $default = $index->getPropertyValues(new core_kernel_classes_Property('http://www.tao.lu/Ontologies/TAO.rdf#IndexDefaultSearch'));
         if (count($default) == 0) {
             //no default search set, import
             $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_2.rdf';
             $adapter = new tao_helpers_data_GenerisAdapterRdf();
             if ($adapter->import($file)) {
                 $this->setVerion('2.6.2');
             } else {
                 common_Logger::w('Import failed for ' . $file);
             }
         } else {
             common_Logger::w('Defautl Search already set');
             ${$this}->setVerion('2.6.2');
         }
     }
     if ($this->isVersion('2.6.2')) {
         OntologyUpdater::correctModelId(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_1.rdf');
         OntologyUpdater::correctModelId(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'indexation_2_6_2.rdf');
         $this->setVerion('2.6.3');
     }
     if ($this->isVersion('2.6.3')) {
         // update user roles
         $class = new core_kernel_classes_Class(CLASS_TAO_USER);
         $itemManagers = $class->searchInstances(array(PROPERTY_USER_ROLES => 'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemsManagerRole'), array('recursive' => true, 'like' => false));
         foreach ($itemManagers as $user) {
             $user->setPropertyValue(new core_kernel_classes_Property(PROPERTY_USER_ROLES), ItemAuthorRole::INSTANCE_URI);
         }
         $this->setVerion('2.6.4');
     }
     if ($this->isBetween('2.6.4', '2.8')) {
         $this->setVersion('2.8');
     }
     // fix itemModelLabelProp
     if ($this->isVersion('2.8')) {
         $fakeProperty = new core_kernel_classes_Property('itemModelLabel');
         $iterator = new core_kernel_classes_ResourceIterator(array(taoItems_models_classes_ItemsService::singleton()->getRootClass()));
         foreach ($iterator as $resource) {
             $resource->removePropertyValues($fakeProperty);
         }
         $this->setVersion('2.8.1');
     }
     $this->skip('2.8.1', '2.14.0');
     if ($this->isVersion('2.14.0')) {
         OntologyUpdater::syncModels();
         AclProxy::applyRule(new AccessRule('grant', 'http://www.tao.lu/Ontologies/TAOItem.rdf#AbstractItemAuthor', 'taoItems_actions_ItemContent'));
         $this->setVersion('2.15.0');
     }
     $this->skip('2.15.0', '2.22.3');
     if ($this->isVersion('2.22.3')) {
         OntologyUpdater::syncModels();
         $categoryService = new CategoryService();
         $categoryService->setServiceManager($this->getServiceManager());
         $this->getServiceManager()->register(CategoryService::SERVICE_ID, $categoryService);
         $this->setVersion('2.23.0');
     }
     if ($this->isVersion('2.23.0')) {
         OntologyUpdater::syncModels();
         $this->setVersion('2.24.0');
     }
     $this->skip('2.24.0', '2.24.1');
 }
 /**
  *
  * @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');
 }
Example #5
0
 /**
  * Add the requested language in the ontology. It will used the parameters
  * the command line for logic.
  *
  * @access protected
  * @author Joel Bout, <*****@*****.**>
  * @return void
  */
 protected function addLanguageToOntology()
 {
     $this->outVerbose("Importing RDF language description '" . $this->options['language'] . "' to ontology...");
     // RDF Language Descriptions are stored in the tao meta-extension locales.
     $expectedDescriptionPath = $this->buildLanguagePath('tao', $this->options['language']) . '/lang.rdf';
     if (file_exists($expectedDescriptionPath)) {
         if (is_readable($expectedDescriptionPath)) {
             // Let's remove any instance of the language description before inserting the new one.
             $taoNS = 'http://www.tao.lu/Ontologies/TAO.rdf#';
             $expectedLangUri = $taoNS . 'Lang' . $this->options['language'];
             $lgDescription = new core_kernel_classes_Resource($expectedLangUri);
             if ($lgDescription->exists()) {
                 $lgDescription->delete();
                 $this->outVerbose("Existing RDF Description language '" . $this->options['language'] . "' deleted.");
             }
             $generisAdapterRdf = new tao_helpers_data_GenerisAdapterRdf();
             if (true === $generisAdapterRdf->import($expectedDescriptionPath, null, LOCAL_NAMESPACE)) {
                 $this->outVerbose("RDF language description '" . $this->options['language'] . "' successfully imported.");
             } else {
                 $this->err("An error occured while importing the RDF language description '" . $this->options['language'] . "'.", true);
             }
         } else {
             $this->err("RDF language description (lang.rdf) cannot be read in meta-extension 'tao' for language '" . $this->options['language'] . "'.", true);
         }
     } else {
         $this->err("RDF language description (lang.rdf) not found in meta-extension 'tao' for language '" . $this->options['language'] . "'.", true);
     }
     $this->outVerbose("RDF language description '" . $this->options['language'] . "' added to ontology.");
 }
Example #6
0
 /**
  * Short description of method run
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public function run()
 {
     $userService = tao_models_classes_UserService::singleton();
     $this->outVerbose("Connecting to TAO as '" . $this->options['user'] . "' ...");
     if ($userService->loginUser($this->options['user'], $this->options['password'])) {
         $this->outVerbose("Connected to TAO as '" . $this->options['user'] . "'.");
         //determine the target namespace.
         $targetNamespace = rtrim(common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri(), '#');
         if (!empty($this->options['model'])) {
             $targetNamespace = $this->options['model'];
         } else {
             // Look for XML Base.
             $this->outVerbose("Looking up for the value of xml:base as the model URI.");
             try {
                 $dom = new DOMDocument('1.0', TAO_DEFAULT_ENCODING);
                 if (false !== $dom->load($this->options['input'])) {
                     $this->outVerbose("RDF-XML document loaded.");
                     // try to find the 'xml:base' attribute on the root node.
                     $roots = $dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'RDF');
                     if ($roots->length > 0) {
                         $this->outVerbose("Root RDF element found.");
                         $root = $roots->item(0);
                         $node = $root->getAttributeNodeNS('http://www.w3.org/XML/1998/namespace', 'base');
                         if (!empty($node)) {
                             $targetNamespace = $node->value;
                         } else {
                             $this->outVerbose("No xml:base attribute found. The local model will be used.");
                         }
                     }
                 } else {
                     $this->err("RDF-XML could not be loaded.", true);
                 }
             } catch (DOMException $e) {
                 $this->err("RDF-XML parsing error: " . $e->getMessage(), true);
             }
         }
         //validate the file to import
         $parser = new tao_models_classes_Parser($this->options['input'], array('extension' => 'rdf'));
         $parser->validate();
         $this->outVerbose("Model URI is '{$targetNamespace}'.");
         if (!$parser->isValid()) {
             foreach ($parser->getErrors() as $error) {
                 $this->outVerbose("RDF-XML parsing error in '" . $error['file'] . "' at line '" . $error['line'] . "': '" . $error['message'] . "'.");
             }
             $userService->logout();
             $this->err("RDF-XML parsing error.", true);
         } else {
             //initialize the adapter (no target class but a target namespace)
             $adapter = new tao_helpers_data_GenerisAdapterRdf();
             if ($adapter->import($this->options['input'], null, $targetNamespace)) {
                 $this->outVerbose("RDF 'input' file successfully imported.");
                 $userService->logout();
             } else {
                 $userService->logout();
                 $this->err("An error occured during RDF-XML import.", true);
             }
         }
     } else {
         $this->err("Unable to connect to TAO as '" . $this->options['user'] . "'.", true);
     }
 }