Ejemplo n.º 1
0
 /**
  * install an extension
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public function install()
 {
     common_Logger::i('Installing extension ' . $this->extension->getId(), 'INSTALL');
     if ($this->extension->getId() == 'generis') {
         throw new common_ext_ForbiddenActionException('Tried to install generis using the ExtensionInstaller', $this->extension->getId());
     }
     if (common_ext_ExtensionsManager::singleton()->isInstalled($this->extension->getId())) {
         throw new common_ext_AlreadyInstalledException('Problem installing extension ' . $this->extension->getId() . ' : Already installed', $this->extension->getId());
     }
     // we purge the whole cache.
     $cache = common_cache_FileCache::singleton();
     $cache->purge();
     // check reuired extensions, throws exception if failed
     helpers_ExtensionHelper::checkRequiredExtensions($this->getExtension());
     $this->installLoadDefaultConfig();
     $this->installOntology();
     $this->installRegisterExt();
     common_Logger::d('Installing custom script for extension ' . $this->extension->getId());
     $this->installCustomScript();
     common_Logger::d('Done installing custom script for extension ' . $this->extension->getId());
     if ($this->getLocalData() == true) {
         common_Logger::d('Installing local data for extension ' . $this->extension->getId());
         $this->installLocalData();
         common_Logger::d('Done installing local data for extension ' . $this->extension->getId());
     }
     common_Logger::d('Extended install for extension ' . $this->extension->getId());
     // Method to be overriden by subclasses
     // to extend the installation mechanism.
     $this->extendedInstall();
     common_Logger::d('Done extended install for extension ' . $this->extension->getId());
     $eventManager = ServiceManager::getServiceManager()->get(EventManager::CONFIG_ID);
     $eventManager->trigger(new common_ext_event_ExtensionInstalled($this->extension));
 }
 public function __invoke($params)
 {
     // recreate languages
     $modelCreator = new \tao_install_utils_ModelCreator(LOCAL_NAMESPACE);
     $models = $modelCreator->getLanguageModels();
     foreach ($models as $ns => $modelFiles) {
         foreach ($modelFiles as $file) {
             $modelCreator->insertLocalModel($file);
         }
     }
     OntologyUpdater::syncModels();
     // reapply access rights
     $exts = \common_ext_ExtensionsManager::singleton()->getInstalledExtensions();
     foreach ($exts as $ext) {
         $installer = new \tao_install_ExtensionInstaller($ext);
         $installer->installManagementRole();
         $installer->applyAccessRules();
     }
     // recreate admin
     if (count($params) >= 2) {
         $login = array_shift($params);
         $password = array_shift($params);
         $sysAdmin = $this->getResource(INSTANCE_ROLE_SYSADMIN);
         $userClass = $this->getClass(CLASS_TAO_USER);
         \core_kernel_users_Service::singleton()->addUser($login, $password, $sysAdmin, $userClass);
     }
     // empty cache
     \common_cache_FileCache::singleton()->purge();
     return \common_report_Report::createSuccess('All done');
 }
Ejemplo n.º 3
0
 /**
  * uninstall an extension
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return boolean
  */
 public function uninstall()
 {
     common_Logger::i('Uninstalling ' . $this->extension->getId(), 'UNINSTALL');
     // uninstall possible
     if (is_null($this->extension->getManifest()->getUninstallData())) {
         throw new common_Exception('Problem uninstalling extension ' . $this->extension->getId() . ' : Uninstall not supported');
     }
     // installed?
     if (!common_ext_ExtensionsManager::singleton()->isInstalled($this->extension->getId())) {
         throw new common_Exception('Problem uninstalling extension ' . $this->extension->getId() . ' : Not installed');
     }
     // check dependcies
     if (helpers_ExtensionHelper::isRequired($this->extension)) {
         throw new common_Exception('Problem uninstalling extension ' . $this->extension->getId() . ' : Still required');
     }
     common_Logger::d('uninstall script for ' . $this->extension->getId());
     $this->uninstallScripts();
     // hook
     $this->extendedUninstall();
     common_Logger::d('unregister extension ' . $this->extension->getId());
     $this->unregister();
     // we purge the whole cache.
     $cache = common_cache_FileCache::singleton();
     $cache->purge();
     common_Logger::i('Uninstalled ' . $this->extension->getId());
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Short description of method install
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function install()
 {
     if ($this->extension->getId() != 'generis') {
         throw new common_ext_ExtensionException('Tried to install "' . $this->extension->getId() . '" extension using the GenerisInstaller');
     }
     //$this->installCustomScript();
     $this->installLoadDefaultConfig();
     ModelManager::setModel(new \core_kernel_persistence_smoothsql_SmoothModel(array(\core_kernel_persistence_smoothsql_SmoothModel::OPTION_PERSISTENCE => 'default', \core_kernel_persistence_smoothsql_SmoothModel::OPTION_READABLE_MODELS => array('1'), \core_kernel_persistence_smoothsql_SmoothModel::OPTION_WRITEABLE_MODELS => array('1'), \core_kernel_persistence_smoothsql_SmoothModel::OPTION_NEW_TRIPLE_MODEL => '1')));
     $this->installOntology();
     //$this->installLocalData();
     //$this->installModuleModel();
     $this->installRegisterExt();
     common_cache_FileCache::singleton()->purge();
     common_Logger::d('Installing custom script for extension ' . $this->extension->getId());
     $this->installCustomScript();
 }
 /**
  * Short description of method prepare
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  array resources  results
  * @param  array columns    variables
  * @return mixed
  */
 public function prepare($resources, $columns)
 {
     $resultsService = taoResults_models_classes_ResultsService::singleton();
     foreach ($resources as $result) {
         $itemresults = $resultsService->getVariables($result, new core_kernel_classes_Class(TAO_RESULT_VARIABLE), false);
         $cellData = array();
         foreach ($itemresults as $itemResultUri => $vars) {
             //cache the item information pertaining to a given itemResult (stable over time)
             if (common_cache_FileCache::singleton()->has('itemResultItemCache' . $itemResultUri)) {
                 $itemUri = common_cache_FileCache::singleton()->get('itemResultItemCache' . $itemResultUri);
                 $item = new core_kernel_classes_Resource($itemUri);
             } else {
                 $item = $resultsService->getItemFromItemResult(new core_kernel_classes_Resource($itemResultUri));
                 common_cache_FileCache::singleton()->put($item->getUri(), 'itemResultItemCache' . $itemResultUri);
             }
             if (get_class($item) == "core_kernel_classes_Resource") {
                 $contextIdentifier = (string) $item->getUri();
             } else {
                 $contextIdentifier = (string) $item->__toString();
             }
             foreach ($vars as $var) {
                 //cache the variable data
                 if (common_cache_FileCache::singleton()->has('variableDataCache' . $var->getUri())) {
                     $varData = common_cache_FileCache::singleton()->get('variableDataCache' . $var->getUri());
                 } else {
                     $varData = $resultsService->getVariableData($var);
                     common_cache_FileCache::singleton()->put($varData, 'variableDataCache' . $var->getUri());
                 }
                 if (is_array($varData["value"])) {
                     $varData["value"] = json_encode($varData["value"]);
                 }
                 $variableIdentifier = (string) $varData["identifier"];
                 foreach ($columns as $column) {
                     if ($variableIdentifier == $column->getIdentifier() and $contextIdentifier == $column->getContextIdentifier()) {
                         $value = (string) $varData["value"];
                         $epoch = $varData["epoch"];
                         $readableTime = "";
                         if ($epoch != "") {
                             $readableTime = "@" . tao_helpers_Date::displayeDate(tao_helpers_Date::getTimeStamp($epoch), tao_helpers_Date::FORMAT_VERBOSE);
                         }
                         $this->cache[$varData["type"]->getUri()][$result->getUri()][$contextIdentifier . $variableIdentifier][(string) $epoch] = array($value, $readableTime);
                     }
                 }
             }
         }
     }
 }
 /**
  * install an extension
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public function install()
 {
     common_Logger::i('Installing extension ' . $this->extension->getId(), 'INSTALL');
     if ($this->extension->getId() == 'generis') {
         throw new common_ext_ForbiddenActionException('Tried to install generis using the ExtensionInstaller', $this->extension->getId());
     }
     try {
         // not yet installed?
         if (common_ext_ExtensionsManager::singleton()->isInstalled($this->extension->getId())) {
             throw new common_ext_AlreadyInstalledException('Problem installing extension ' . $this->extension->getId() . ' : Already installed', $this->extension->getId());
         } else {
             // we purge the whole cache.
             $cache = common_cache_FileCache::singleton();
             $cache->purge();
             //check dependances
             if (!$this->checkRequiredExtensions()) {
                 // unreachable code
             }
             // deprecated, but might still be used
             $this->installLoadDefaultConfig();
             $this->installOntology();
             $this->installRegisterExt();
             $this->installLoadConstants();
             $this->installExtensionModel();
             common_Logger::d('Installing custom script for extension ' . $this->extension->getId());
             $this->installCustomScript();
             common_Logger::d('Done installing custom script for extension ' . $this->extension->getId());
             if ($this->getLocalData() == true) {
                 common_Logger::d('Installing local data for extension ' . $this->extension->getId());
                 $this->installLocalData();
                 common_Logger::d('Done installing local data for extension ' . $this->extension->getId());
             }
             common_Logger::d('Extended install for extension ' . $this->extension->getId());
             // Method to be overriden by subclasses
             // to extend the installation mechanism.
             $this->extendedInstall();
             common_Logger::d('Done extended install for extension ' . $this->extension->getId());
         }
     } catch (common_ext_ExtensionException $e) {
         // Rethrow
         common_Logger::e('Exception raised ' . $e->getMessage());
         throw $e;
     }
 }
 /**
  * return all variable for taht deliveryResults (uri identifiers) 
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource deliveryResult
  * @param core_kernel_classes_Class to restrict to a specific class of variables
  * @param boolean flat a falt array is returned or a structured delvieryResult-ItemResult-Variable
  * @return array
  */
 public function getVariables(core_kernel_classes_Resource $deliveryResult, $variableClass = null, $flat = true)
 {
     $variables = array();
     //this service is slow due to the way the data model design
     //if the delvieryResult related execution is finished, the data is stored in cache.
     $serial = 'deliveryResultVariables';
     if ($variableClass != null) {
         $serial .= $variableClass->getUri();
     }
     if (common_cache_FileCache::singleton()->has($serial)) {
         $variables = common_cache_FileCache::singleton()->get($serial);
     } else {
         foreach ($this->getItemResultsFromDeliveryResult($deliveryResult) as $itemResult) {
             $itemResultVariables = $this->getVariablesFromItemResult($itemResult, $variableClass);
             $itemResultUri = $itemResult->getUri();
             $variables[$itemResultUri] = $itemResultVariables;
         }
         //overhead for cache handling, the data is stored only when the underlying deliveryExecution is finished
         try {
             $executionIdentifier = $deliveryResult->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_IDENTIFIER));
             $status = $executionIdentifier->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_DELVIERYEXECUTION_STATUS));
             if ($status->getUri() == INSTANCE_DELIVERYEXEC_FINISHED) {
                 common_cache_FileCache::singleton()->put($variables, $serial);
             }
         } catch (common_Exception $e) {
             common_Logger::i("List of variables of results of " . $deliveryResult->getUri() . " could not be reliable cached due to an unfinished execution");
         }
     }
     if ($flat) {
         $returnValue = array();
         foreach ($variables as $itemResultVariables) {
             $returnValue = array_merge($itemResultVariables, $returnValue);
         }
     } else {
         $returnValue = $variables;
     }
     return (array) $returnValue;
 }
Ejemplo n.º 8
0
 /**
  * Update a specific extension
  * 
  * @param common_ext_Extension $ext
  * @return common_report_Report
  */
 protected function updateExtension(common_ext_Extension $ext)
 {
     helpers_ExtensionHelper::checkRequiredExtensions($ext);
     $installed = common_ext_ExtensionsManager::singleton()->getInstalledVersion($ext->getId());
     $codeVersion = $ext->getVersion();
     if ($installed !== $codeVersion) {
         $report = new common_report_Report(common_report_Report::TYPE_INFO, $ext->getName() . ' requires update from ' . $installed . ' to ' . $codeVersion);
         $updaterClass = $ext->getManifest()->getUpdateHandler();
         if (is_null($updaterClass)) {
             $report = new common_report_Report(common_report_Report::TYPE_WARNING, 'No Updater found for  ' . $ext->getName());
         } elseif (!class_exists($updaterClass)) {
             $report = new common_report_Report(common_report_Report::TYPE_ERROR, 'Updater ' . $updaterClass . ' not found');
         } else {
             $updater = new $updaterClass($ext);
             $returnedVersion = $updater->update($installed);
             $currentVersion = common_ext_ExtensionsManager::singleton()->getInstalledVersion($ext->getId());
             if (!is_null($returnedVersion) && $returnedVersion != $currentVersion) {
                 common_ext_ExtensionsManager::singleton()->updateVersion($ext, $returnedVersion);
                 $report->add(new common_report_Report(common_report_Report::TYPE_WARNING, 'Manually saved extension version'));
                 $currentVersion = $returnedVersion;
             }
             if ($currentVersion == $codeVersion) {
                 $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, 'Successfully updated ' . $ext->getName() . ' to ' . $currentVersion));
             } else {
                 $report->add(new common_report_Report(common_report_Report::TYPE_WARNING, 'Update of ' . $ext->getName() . ' exited with version ' . $currentVersion));
             }
             common_cache_FileCache::singleton()->purge();
         }
     } else {
         $report = new common_report_Report(common_report_Report::TYPE_INFO, $ext->getName() . ' already up to data');
     }
     return $report;
 }
Ejemplo n.º 9
0
 public static function flushCache()
 {
     common_cache_FileCache::singleton()->remove(self::SERIAL);
     self::$cache = array();
 }
Ejemplo n.º 10
0
 public static function flushCache()
 {
     self::$structure = array();
     \common_cache_FileCache::singleton()->remove(self::CACHE_KEY);
 }
Ejemplo n.º 11
0
 /**
  * Returns the funcACL Cache implementation
  * @return common_cache_Cache
  */
 private static function getCacheImplementation()
 {
     return common_cache_FileCache::singleton();
 }
 public function emptyCache()
 {
     \common_cache_FileCache::singleton()->purge();
     return $this->returnJson(array('success' => true, 'message' => __('Cache has been emptied')));
 }
Ejemplo n.º 13
0
 /**
  * Test the referencer on properties, using the file caching mode
  * (it's the default caching mode for the properties)
  * @see oat\generisHard\models\hardapi\ResourceReferencer
  */
 public function testPropertyReferencer()
 {
     $referencer = ResourceReferencer::singleton();
     $this->assertIsA($referencer, 'oat\\generisHard\\models\\hardapi\\ResourceReferencer');
     $referencer->setPropertyCache(ResourceReferencer::CACHE_FILE);
     $referencer->clearCaches();
     $class = new core_kernel_classes_Class(CLASS_GENERIS_USER);
     $table = '_' . Utils::getShortName($class);
     // this part simulates a hardifying of the Userclass
     $myUserTblMgr = new TableManager($table);
     $this->assertFalse($myUserTblMgr->exists());
     $this->assertTrue($myUserTblMgr->create(array(array('name' => '05label'), array('name' => '05comment'), array('name' => '07login'), array('name' => '07password'), array('name' => '07userMail'), array('name' => '07userFirstName'), array('name' => '07userLastName'))));
     $this->assertTrue($myUserTblMgr->exists());
     $referencer->referenceClass($class);
     $this->assertTrue($referencer->isClassReferenced($class));
     // test start on the cache containing the simulated data
     // in case of a  fallback to the real sata (class_to_table) the tests fail
     $labelProperty = new core_kernel_classes_Property(RDFS_LABEL);
     $this->assertTrue($referencer->isPropertyReferenced($labelProperty));
     $commentProperty = new core_kernel_classes_Property(RDFS_COMMENT);
     $this->assertTrue($referencer->isPropertyReferenced($commentProperty));
     $loginProperty = new core_kernel_classes_Property(PROPERTY_USER_LOGIN);
     $this->assertTrue($referencer->isPropertyReferenced($loginProperty));
     $passwordProperty = new core_kernel_classes_Property(PROPERTY_USER_PASSWORD);
     $this->assertTrue($referencer->isPropertyReferenced($passwordProperty));
     $firstNameProperty = new core_kernel_classes_Property(PROPERTY_USER_FIRSTNAME);
     foreach ($referencer->propertyLocation($firstNameProperty) as $foundTable) {
         $this->assertEquals($foundTable, $table);
     }
     $this->assertTrue($myUserTblMgr->exists());
     $referencer->unReferenceClass($class);
     $this->assertFalse($referencer->isClassReferenced($class));
     $this->assertFalse($myUserTblMgr->exists());
     // Testing the cache...
     $cache = common_cache_FileCache::singleton();
     $serial = 'hard-api-property';
     $this->assertTrue($cache->has($serial));
     try {
         $cacheContent = $cache->get($serial);
         $this->assertTrue(is_array($cacheContent));
         $this->assertTrue(count($cacheContent) > 0);
         $this->assertTrue(array_key_exists(RDFS_LABEL, $cacheContent));
         $this->assertTrue(array_key_exists(PROPERTY_USER_LOGIN, $cacheContent));
     } catch (common_cache_Exception $e) {
         $this->fail('Cannot access hard-api-property cache.');
     }
     //clear the cache
     $cache->remove($serial);
     $this->assertFalse($cache->has($serial));
 }
Ejemplo n.º 14
0
 public static function setLgDependencyCache($uri, $bool)
 {
     $lgDependencyCache = common_cache_FileCache::singleton()->put($bool, self::getSerial($uri));
 }
Ejemplo n.º 15
0
 /**
  * This method returns the languages available in TAO.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  boolean langName If set to true, an associative array where keys are language codes and values are language labels. If set to false (default), a simple array of language codes is returned.
  * @return array
  * @throws common_exception_InconsistentData
  */
 private static function getAvailableLangs()
 {
     //get it into the api only once
     if (count(self::$availableLangs) == 0) {
         try {
             self::$availableLangs = common_cache_FileCache::singleton()->get(self::AVAILABLE_LANGS_CACHEKEY);
         } catch (common_cache_NotFoundException $e) {
             $langClass = new core_kernel_classes_Class(CLASS_LANGUAGES);
             $valueProperty = new core_kernel_classes_Property(RDF_VALUE);
             foreach ($langClass->getInstances() as $lang) {
                 $values = $lang->getPropertiesValues(array(RDF_VALUE, PROPERTY_LANGUAGE_USAGES, PROPERTY_LANGUAGE_ORIENTATION));
                 if (count($values[RDF_VALUE]) != 1) {
                     throw new common_exception_InconsistentData('Error with value of language ' . $lang->getUri());
                 }
                 $value = current($values[RDF_VALUE])->__toString();
                 $usages = array();
                 foreach ($values[PROPERTY_LANGUAGE_USAGES] as $usage) {
                     $usages[] = $usage->getUri();
                 }
                 if (count($values[PROPERTY_LANGUAGE_ORIENTATION]) != 1) {
                     common_Logger::w('Error with orientation of language ' . $lang->getUri());
                     $orientation = INSTANCE_ORIENTATION_LTR;
                 } else {
                     $orientation = current($values[PROPERTY_LANGUAGE_ORIENTATION])->getUri();
                 }
                 self::$availableLangs[$value] = array('uri' => $lang->getUri(), PROPERTY_LANGUAGE_USAGES => $usages, PROPERTY_LANGUAGE_ORIENTATION => $orientation);
             }
             common_cache_FileCache::singleton()->put(self::$availableLangs, self::AVAILABLE_LANGS_CACHEKEY);
         }
     }
     return self::$availableLangs;
 }
 /**
  * Clears the caches without immediately recalculating them
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function clearCaches()
 {
     self::$_properties = null;
     self::$_classes = null;
     self::$_resources = array();
     self::$_resources_loaded = false;
     ClassProxy::$ressourcesDelegatedTo = array();
     ResourceProxy::$ressourcesDelegatedTo = array();
     PropertyProxy::$ressourcesDelegatedTo = array();
     // remove hard-api-property cache.
     $cache = \common_cache_FileCache::singleton();
     $cache->remove('hard-api-property');
 }
Ejemplo n.º 17
0
 protected static function getParamName(core_kernel_classes_Resource $paramDefinition)
 {
     try {
         $paramKey = common_cache_FileCache::singleton()->get(self::CACHE_PREFIX_PARAM_NAME . urlencode($paramDefinition->getUri()));
     } catch (common_cache_NotFoundException $e) {
         $paramKey = common_Utils::fullTrim($paramDefinition->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_FORMALPARAMETER_NAME)));
         common_cache_FileCache::singleton()->put($paramKey, self::CACHE_PREFIX_PARAM_NAME . urlencode($paramDefinition->getUri()));
     }
     return $paramKey;
 }
Ejemplo n.º 18
0
        if ($installed !== $current) {
            echo $ext->getName() . ' requires update from ' . $installed . ' to ' . $current . PHP_EOL;
            $updaterClass = $ext->getManifest()->getUpdateHandler();
            if (!is_null($updaterClass)) {
                if (class_exists($updaterClass)) {
                    $updater = new $updaterClass($ext);
                    echo '  Running ' . $updaterClass . PHP_EOL;
                    $newVersion = $updater->update($installed);
                    if ($newVersion == $current) {
                        common_ext_ExtensionsManager::singleton()->registerExtension($ext);
                        common_ext_ExtensionsManager::singleton()->setEnabled($ext->getId());
                        echo '  Successfully updated ' . $ext->getName() . ' to ' . $newVersion . PHP_EOL;
                    } else {
                        echo '  Update of ' . $ext->getName() . ' exited with version ' . $newVersion . '' . PHP_EOL;
                    }
                } else {
                    echo '  Updater ' . $updaterClass . ' not found' . PHP_EOL;
                }
                common_cache_FileCache::singleton()->purge();
            } else {
                echo '  No Updater found for ' . $ext->getName() . PHP_EOL;
            }
        } else {
            echo $ext->getName() . ' already up-to-date' . PHP_EOL;
        }
    }
}
//regenerage all client side translation
echo 'Regenerate all client side translations' . PHP_EOL;
tao_models_classes_LanguageService::singleton()->generateClientBundles();
echo 'Update completed' . PHP_EOL;
Ejemplo n.º 19
0
 /**
  * Short description of method singleton
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return common_cache_FileCache
  */
 public static function singleton()
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 20
0
 /**
  * Removes all entries related to included roles from the Cache memory.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public static function flush()
 {
     common_cache_FileCache::singleton()->purge();
 }
Ejemplo n.º 21
0
 /**
  * Get the required rights for the execution of an action
  *
  * Returns an associative array with the parameter as key
  * and the rights as values
  *
  * @param string $controllerClassName
  * @param string $actionName
  * @return array
  */
 public static function getRequiredRights($controllerClassName, $actionName)
 {
     try {
         $rights = \common_cache_FileCache::singleton()->get(self::ACTION_PREFIX . $controllerClassName . '@' . $actionName);
     } catch (\common_cache_NotFoundException $e) {
         $factory = new Factory();
         $controller = $factory->getActionDescription($controllerClassName, $actionName);
         $rights = $controller->getRequiredRights();
         \common_cache_FileCache::singleton()->put($rights, self::ACTION_PREFIX . $controllerClassName . '@' . $actionName);
     }
     return $rights;
 }