Exemplo n.º 1
0
 /**
  * 
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     if ($currentVersion == '2.7') {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'widgetdefinitions_2.7.1.rdf';
         $api = core_kernel_impl_ApiModelOO::singleton();
         $success = $api->importXmlRdf('http://www.tao.lu/datatypes/WidgetDefinitions.rdf', $file);
         if ($success) {
             $currentVersion = '2.7.1';
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($currentVersion == '2.7.1') {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'widgetdefinitions_2.7.2.rdf';
         $api = core_kernel_impl_ApiModelOO::singleton();
         $success = $api->importXmlRdf('http://www.tao.lu/datatypes/WidgetDefinitions.rdf', $file);
         if ($success) {
             $currentVersion = '2.7.2';
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($currentVersion == '2.7.2') {
         $implClass = common_ext_ExtensionsManager::singleton()->getExtensionById('generis')->getConfig(PermissionManager::CONFIG_KEY);
         if (is_string($implClass)) {
             if (class_exists($implClass)) {
                 $impl = new $implClass();
                 PermissionManager::setPermissionModel($impl);
                 $currentVersion = '2.7.3';
             } else {
                 common_Logger::w('Unexpected permission manager config type: ' . gettype($implClass));
             }
         } else {
             common_Logger::w('Unexpected permission manager config type: ' . gettype($implClass));
         }
     }
     if ($currentVersion == '2.7.3') {
         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 => $this->getReadableModelIds(), \core_kernel_persistence_smoothsql_SmoothModel::OPTION_WRITEABLE_MODELS => array('1'), \core_kernel_persistence_smoothsql_SmoothModel::OPTION_NEW_TRIPLE_MODEL => '1')));
         $currentVersion = '2.7.4';
     }
     if ($currentVersion == '2.7.4' && defined('GENERIS_URI_PROVIDER')) {
         if (in_array(GENERIS_URI_PROVIDER, array('DatabaseSerialUriProvider', 'AdvKeyValueUriProvider'))) {
             $uriProviderClassName = '\\core_kernel_uri_' . GENERIS_URI_PROVIDER;
             $options = array(\core_kernel_uri_DatabaseSerialUriProvider::OPTION_PERSISTENCE => 'default', \core_kernel_uri_DatabaseSerialUriProvider::OPTION_NAMESPACE => LOCAL_NAMESPACE . '#');
             $provider = new $uriProviderClassName($options);
         } else {
             $uriProviderClassName = '\\common_uri_' . GENERIS_URI_PROVIDER;
             $provider = new $uriProviderClassName();
         }
         \core_kernel_uri_UriService::singleton()->setUriProvider($provider);
         $currentVersion = '2.7.5';
     }
     // service manager support
     if ($currentVersion == '2.7.5' || $currentVersion == '2.7.6' || $currentVersion == '2.7.7' || $currentVersion == '2.8.0') {
         $currentVersion = '2.9.0';
     }
     return $currentVersion;
 }
Exemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * @see \oat\generis\model\data\RdfInterface::add()
  */
 public function add(\core_kernel_classes_Triple $triple)
 {
     if (!in_array($triple->modelid, $this->model->getReadableModels())) {
         $this->model->addReadableModel($triple->modelid);
     }
     $query = "INSERT INTO statements ( modelId, subject, predicate, object, l_language) VALUES ( ? , ? , ? , ? , ? );";
     $success = $this->getPersistence()->exec($query, array($triple->modelid, $triple->subject, $triple->predicate, $triple->object, is_null($triple->lg) ? '' : $triple->lg));
     if ($triple->predicate == RDFS_SUBCLASSOF || $triple->predicate == RDF_TYPE) {
         PermissionManager::getPermissionModel()->onResourceCreated(new core_kernel_classes_Resource($triple->subject));
     }
     return $success;
 }
Exemplo n.º 3
0
 /**
  * 
  * @param string $currentVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     if ($currentVersion == '1.0') {
         $impl = new PermissionProvider();
         // add read access to Items
         $class = new \core_kernel_classes_Class(TAO_ITEM_CLASS);
         AdminService::addPermissionToClass($class, INSTANCE_ROLE_BACKOFFICE, array('READ'));
         // add backoffice user rights to Tests
         $class = new \core_kernel_classes_Class(TAO_TEST_CLASS);
         AdminService::addPermissionToClass($class, INSTANCE_ROLE_BACKOFFICE, $impl->getSupportedRights());
         $currentVersion = '1.0.1';
     }
     if ($currentVersion == '1.0.1') {
         $currentVersion = '1.0.2';
     }
     if ($currentVersion == '1.0.2') {
         $taoClass = new \core_kernel_classes_Class(TAO_OBJECT_CLASS);
         $classAdmin = new AdminAction();
         ClassActionRegistry::getRegistry()->registerAction($taoClass, $classAdmin);
         $currentVersion = '1.1';
     }
     if ($currentVersion == '1.1') {
         $classesToAdd = array(new \core_kernel_classes_Class(CLASS_GENERIS_USER), new \core_kernel_classes_Class(CLASS_ROLE));
         // add admin to new instances
         $classAdmin = new AdminAction();
         foreach ($classesToAdd as $class) {
             ClassActionRegistry::getRegistry()->registerAction($class, $classAdmin);
         }
         // add base permissions to new classes
         $taoClass = new \core_kernel_classes_Class(TAO_OBJECT_CLASS);
         foreach ($taoClass->getSubClasses(false) as $class) {
             if (!in_array($class->getUri(), array(TAO_ITEM_CLASS, TAO_TEST_CLASS))) {
                 $classesToAdd[] = $class;
             }
         }
         $rights = PermissionManager::getPermissionModel()->getSupportedRights();
         foreach ($classesToAdd as $class) {
             if (count(AdminService::getUsersPermissions($class->getUri())) == 0) {
                 AdminService::addPermissionToClass($class, INSTANCE_ROLE_BACKOFFICE, $rights);
             } else {
                 \common_Logger::w('Unexpected rights present for ' . $class->getUri());
             }
         }
         $currentVersion = '1.2.0';
     }
     return $currentVersion;
 }
Exemplo n.º 4
0
 /**
  * Whenever or not the user has the required rights
  * 
  * required takes the form of:
  *   resourceId => $right
  * 
  * @param User $user
  * @param array $required
  * @return boolean
  */
 public static function hasPrivileges(User $user, array $required)
 {
     foreach ($required as $resourceId => $right) {
         if ($right === 'WRITE' && !self::hasWritePrivilege($user, $resourceId)) {
             common_Logger::d('User \'' . $user->getIdentifier() . '\' does not have lock for resource \'' . $resourceId . '\'');
             return false;
         }
         if (!in_array($right, PermissionManager::getPermissionModel()->getSupportedRights())) {
             $required[$resourceId] = PermissionInterface::RIGHT_UNSUPPORTED;
         }
     }
     $permissions = PermissionManager::getPermissionModel()->getPermissions($user, array_keys($required));
     foreach ($required as $id => $right) {
         if (!isset($permissions[$id]) || !in_array($right, $permissions[$id])) {
             common_Logger::d('User \'' . $user->getIdentifier() . '\' does not have \'' . $right . '\' permission for resource \'' . $id . '\'');
             return false;
         }
     }
     return true;
 }
 * as published by the Free Software Foundation; under version 2
 * of the License (non-upgradable).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
 *
 *
 */
use oat\taoDacSimple\model\DataBaseAccess;
use oat\generis\model\data\permission\PermissionManager;
use oat\taoDacSimple\model\AdminService;
use oat\generis\model\data\permission\implementation\FreeAccess;
$persistence = common_persistence_Manager::getPersistence('default');
$schema = $persistence->getDriver()->getSchemaManager()->createSchema();
$fromSchema = clone $schema;
$table = $schema->dropTable(DataBaseAccess::TABLE_PRIVILEGES_NAME);
$queries = $persistence->getPlatform()->getMigrateSchemaSql($fromSchema, $schema);
foreach ($queries as $query) {
    $persistence->exec($query);
}
$impl = new FreeAccess();
PermissionManager::setPermissionModel($impl);
 /**
  * please use core_kernel_classes_ResourceFactory::create()
  * instead of this function whenever possible
  *
  * Creates a new instance using the properties provided.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  array properties May contain additional types
  * @return core_kernel_classes_Resource
  * @see core_kernel_classes_ResourceFactory
  */
 public function createInstanceWithProperties($properties)
 {
     $returnValue = null;
     // remove the additional types, because they might be implemented differently
     $additonalTypes = array();
     if (isset($properties[RDF_TYPE])) {
         $types = is_array($properties[RDF_TYPE]) ? $properties[RDF_TYPE] : array($properties[RDF_TYPE]);
         foreach ($types as $type) {
             $uri = is_object($type) ? $type->getUri() : $type;
             if ($uri != $this->getUri()) {
                 $additonalTypes[] = new core_kernel_classes_Class($uri);
             }
         }
         unset($properties[RDF_TYPE]);
     }
     // create the instance
     $returnValue = $this->getImplementation()->createInstanceWithProperties($this, $properties);
     foreach ($additonalTypes as $type) {
         $returnValue->setType($type);
     }
     PermissionManager::getPermissionModel()->onResourceCreated($returnValue);
     return $returnValue;
 }
Exemplo n.º 7
0
 /**
  * @param string $initialVersion
  * @return string $versionUpdatedTo
  */
 public function update($initialVersion)
 {
     $currentVersion = $initialVersion;
     if ($currentVersion == '2.7') {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'widgetdefinitions_2.7.1.rdf';
         $api = core_kernel_impl_ApiModelOO::singleton();
         $success = $api->importXmlRdf('http://www.tao.lu/datatypes/WidgetDefinitions.rdf', $file);
         if ($success) {
             $currentVersion = '2.7.1';
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($currentVersion == '2.7.1') {
         $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'widgetdefinitions_2.7.2.rdf';
         $api = core_kernel_impl_ApiModelOO::singleton();
         $success = $api->importXmlRdf('http://www.tao.lu/datatypes/WidgetDefinitions.rdf', $file);
         if ($success) {
             $currentVersion = '2.7.2';
         } else {
             common_Logger::w('Import failed for ' . $file);
         }
     }
     if ($currentVersion == '2.7.2') {
         $implClass = common_ext_ExtensionsManager::singleton()->getExtensionById('generis')->getConfig(PermissionManager::CONFIG_KEY);
         if (is_string($implClass)) {
             if (class_exists($implClass)) {
                 $impl = new $implClass();
                 PermissionManager::setPermissionModel($impl);
                 $currentVersion = '2.7.3';
             } else {
                 common_Logger::w('Unexpected permission manager config type: ' . gettype($implClass));
             }
         } else {
             common_Logger::w('Unexpected permission manager config type: ' . gettype($implClass));
         }
     }
     if ($currentVersion == '2.7.3') {
         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 => $this->getReadableModelIds(), core_kernel_persistence_smoothsql_SmoothModel::OPTION_WRITEABLE_MODELS => array('1'), core_kernel_persistence_smoothsql_SmoothModel::OPTION_NEW_TRIPLE_MODEL => '1')));
         $currentVersion = '2.7.4';
     }
     if ($currentVersion == '2.7.4' && defined('GENERIS_URI_PROVIDER')) {
         if (in_array(GENERIS_URI_PROVIDER, array('DatabaseSerialUriProvider', 'AdvKeyValueUriProvider'))) {
             $uriProviderClassName = '\\core_kernel_uri_' . GENERIS_URI_PROVIDER;
             $options = array(core_kernel_uri_DatabaseSerialUriProvider::OPTION_PERSISTENCE => 'default', core_kernel_uri_DatabaseSerialUriProvider::OPTION_NAMESPACE => LOCAL_NAMESPACE . '#');
             $provider = new $uriProviderClassName($options);
         } else {
             $uriProviderClassName = '\\common_uri_' . GENERIS_URI_PROVIDER;
             $provider = new $uriProviderClassName();
         }
         core_kernel_uri_UriService::singleton()->setUriProvider($provider);
         $currentVersion = '2.7.5';
     }
     // service manager support
     if ($currentVersion == '2.7.5' || $currentVersion == '2.7.6' || $currentVersion == '2.7.7' || $currentVersion == '2.8.0') {
         $currentVersion = '2.9.0';
     }
     if ($currentVersion == '2.9.0') {
         // skip, unused
         //try {
         //    $this->getServiceManager()->get('generis/FsManager');
         //} catch (ServiceNotFoundException $e) {
         //    $FsManager = new \common_persistence_fileSystem_Manager(array(
         //        \common_persistence_fileSystem_Manager::OPTION_FILE_PATH => FILES_PATH
         //    ));
         //
         //    $this->getServiceManager()->register('generis/FsManager', $FsManager);
         //}
         // update persistences
         $persistenceConfig = $this->getServiceManager()->get('generis/persistences');
         if (is_array($persistenceConfig)) {
             $service = new common_persistence_Manager(array(common_persistence_Manager::OPTION_PERSISTENCES => $persistenceConfig));
             $this->getServiceManager()->register('generis/persistences', $service);
         }
         // update cache
         try {
             $this->getServiceManager()->get('generis/cache');
         } catch (ServiceNotFoundException $e) {
             $cache = new common_cache_KeyValueCache(array(common_cache_KeyValueCache::OPTION_PERSISTENCE => 'cache'));
             $cache->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register('generis/cache', $cache);
         }
         $currentVersion = '2.10.0';
     }
     if ($currentVersion == '2.10.0') {
         $eventManager = new EventManager();
         $eventManager->attach('oat\\generis\\model\\data\\event\\ResourceCreated', array('oat\\generis\\model\\data\\permission\\PermissionManager', 'catchEvent'));
         $this->getServiceManager()->register(EventManager::CONFIG_ID, $eventManager);
         $currentVersion = '2.11.0';
     }
     $this->setVersion($currentVersion);
     if ($this->isVersion('2.11.0')) {
         $FsManager = new FileSystemService(array(FileSystemService::OPTION_FILE_PATH => FILES_PATH, FileSystemService::OPTION_ADAPTERS => array()));
         $class = new core_kernel_classes_Class(GENERIS_NS . '#VersionedRepository');
         foreach ($class->getInstances(true) as $resource) {
             $oldFs = new core_kernel_versioning_Repository($resource);
             $path = core_kernel_fileSystem_Cache::getFileSystemPath($oldFs);
             $FsManager->registerLocalFileSystem($resource->getUri(), $path);
         }
         $this->getServiceManager()->register(FileSystemService::SERVICE_ID, $FsManager);
         $this->setVersion('2.12.0');
     }
     $this->skip('2.12.0', '2.18.0');
     if ($this->isVersion('2.18.0')) {
         $this->getServiceManager()->register(ActionService::SERVICE_ID, new ActionService());
         $this->setVersion('2.19.0');
     }
     if ($this->isVersion('2.19.0')) {
         try {
             $this->getServiceManager()->get(Queue::CONFIG_ID);
         } catch (ServiceNotFoundException $e) {
             $service = new SyncQueue([]);
             $service->setServiceManager($this->getServiceManager());
             $this->getServiceManager()->register(Queue::CONFIG_ID, $service);
         }
         $this->setVersion('2.20.0');
     }
     $this->skip('2.20.0', '2.29.1');
     if ($this->isVersion('2.29.1')) {
         $this->getServiceManager()->register(FileReferenceSerializer::SERVICE_ID, new ResourceFileSerializer());
         $this->setVersion('2.30.0');
     }
     $this->skip('2.30.0', '2.31.6');
     if ($this->isVersion('2.31.6')) {
         $complexSearch = new ComplexSearchService(array('shared' => array('search.query.query' => false, 'search.query.builder' => false, 'search.query.criterion' => false, 'search.tao.serialyser' => false, 'search.tao.result' => false), 'invokables' => array('search.query.query' => '\\oat\\search\\Query', 'search.query.builder' => '\\oat\\search\\QueryBuilder', 'search.query.criterion' => '\\oat\\search\\QueryCriterion', 'search.driver.postgres' => '\\oat\\search\\DbSql\\Driver\\PostgreSQL', 'search.driver.mysql' => '\\oat\\search\\DbSql\\Driver\\MySQL', 'search.driver.tao' => '\\oat\\generis\\model\\kernel\\persistence\\smoothsql\\search\\driver\\TaoSearchDriver', 'search.tao.serialyser' => '\\oat\\search\\DbSql\\TaoRdf\\UnionQuerySerialyser', 'search.factory.query' => '\\oat\\search\\factory\\QueryFactory', 'search.factory.builder' => '\\oat\\search\\factory\\QueryBuilderFactory', 'search.factory.criterion' => '\\oat\\search\\factory\\QueryCriterionFactory', 'search.tao.gateway' => '\\oat\\generis\\model\\kernel\\persistence\\smoothsql\\search\\GateWay', 'search.tao.result' => '\\oat\\generis\\model\\kernel\\persistence\\smoothsql\\search\\TaoResultSet'), 'abstract_factories' => array('\\oat\\search\\Command\\OperatorAbstractfactory'), 'services' => array('search.options' => array('table' => 'statements', 'driver' => 'taoRdf'))));
         $this->getServiceManager()->register(ComplexSearchService::SERVICE_ID, $complexSearch);
         $this->setVersion('3.0.0');
     }
     $this->skip('3.0.0', '3.6.1');
     if ($this->isVersion('3.6.1')) {
         $model = ModelManager::getModel();
         if ($model instanceof \core_kernel_persistence_smoothsql_SmoothModel) {
             $model->setOption(\core_kernel_persistence_smoothsql_SmoothModel::OPTION_SEARCH_SERVICE, ComplexSearchService::SERVICE_ID);
             ModelManager::setModel($model);
         }
         $this->setVersion('3.7.0');
     }
     if ($this->isBetween('3.7.0', '3.8.3')) {
         /* @var $modelWrapper WrapperModel */
         $modelWrapper = ModelManager::getModel();
         if ($modelWrapper instanceof WrapperModel) {
             $inner = $modelWrapper->getInnerModel();
             $inner->setOption(\core_kernel_persistence_smoothsql_SmoothModel::OPTION_SEARCH_SERVICE, ComplexSearchService::SERVICE_ID);
             $workspace = $modelWrapper->getWorkspaceModel();
             $workspace->setOption(core_kernel_persistence_smoothsql_SmoothModel::OPTION_SEARCH_SERVICE, ComplexSearchService::SERVICE_ID);
             $wrapedModel = WrapperModel::wrap($inner, $workspace);
             $wrapedModel->setServiceLocator($this->getServiceManager());
             ModelManager::setModel($wrapedModel);
         }
         $this->setVersion('3.8.4');
     }
     $this->skip('3.8.4', '3.8.5');
 }