Esempio n. 1
0
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     $this->disableCache();
     // creates a user using remote script from joel
     $testUserData = array(PROPERTY_USER_LOGIN => 'tjdoe', PROPERTY_USER_PASSWORD => 'test123', PROPERTY_USER_LASTNAME => 'Doe', PROPERTY_USER_FIRSTNAME => 'John', PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_DEFLG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_UILG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_ROLES => array(INSTANCE_ROLE_GLOBALMANAGER));
     $testUserData[PROPERTY_USER_PASSWORD] = 'test' . rand();
     $data = $testUserData;
     $data[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($data[PROPERTY_USER_PASSWORD]);
     $tmclass = new \core_kernel_classes_Class(CLASS_TAO_USER);
     $user = $tmclass->createInstanceWithProperties($data);
     \common_Logger::i('Created user ' . $user->getUri());
     // prepare a lookup table of languages and values
     $usage = new \core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI);
     $propValue = new \core_kernel_classes_Property(RDF_VALUE);
     $langService = \tao_models_classes_LanguageService::singleton();
     $lookup = array();
     foreach ($langService->getAvailableLanguagesByUsage($usage) as $lang) {
         $lookup[$lang->getUri()] = (string) $lang->getUniquePropertyValue($propValue);
     }
     $data = array('rootUrl' => ROOT_URL, 'userUri' => $user->getUri(), 'userData' => $testUserData, 'lang' => $lookup);
     $this->login = $data['userData'][PROPERTY_USER_LOGIN];
     $this->password = $data['userData'][PROPERTY_USER_PASSWORD];
     $this->userUri = $data['userUri'];
 }
Esempio n. 2
0
 /**
  * Short description of method initElements
  *
  * @access protected
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $langService = tao_models_classes_LanguageService::singleton();
     // Retrieve languages available for a GUI usage.
     $guiUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI);
     $guiOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($guiUsage) as $lang) {
         $guiOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     // Retrieve languages available for a Data usage.
     $dataUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA);
     $dataOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) {
         $dataOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $uiLangElement = tao_helpers_form_FormFactory::getElement('ui_lang', 'Combobox');
     $uiLangElement->setDescription(__('Interface language'));
     $uiLangElement->setOptions($guiOptions);
     $this->form->addElement($uiLangElement);
     $dataLangElement = tao_helpers_form_FormFactory::getElement('data_lang', 'Combobox');
     $dataLangElement->setDescription(__('Data language'));
     $dataLangElement->setOptions($dataOptions);
     $this->form->addElement($dataLangElement);
     $tzElement = tao_helpers_form_FormFactory::getElement('timezone', 'Combobox');
     $tzElement->setDescription(__('Time zone'));
     $options = array();
     foreach (DateTimeZone::listIdentifiers() as $id) {
         $options[$id] = $id;
     }
     $tzElement->setOptions($options);
     $this->form->addElement($tzElement);
 }
Esempio n. 3
0
 /**
  * Action dedicated to change the settings of the user (language, ...)
  */
 public function properties()
 {
     $myFormContainer = new tao_actions_form_UserSettings($this->getUserSettings());
     $myForm = $myFormContainer->getForm();
     if ($myForm->isSubmited()) {
         if ($myForm->isValid()) {
             $currentUser = $this->userService->getCurrentUser();
             $userSettings = array(PROPERTY_USER_UILG => $myForm->getValue('ui_lang'), PROPERTY_USER_DEFLG => $myForm->getValue('data_lang'), PROPERTY_USER_TIMEZONE => $myForm->getValue('timezone'));
             $uiLang = new core_kernel_classes_Resource($myForm->getValue('ui_lang'));
             $dataLang = new core_kernel_classes_Resource($myForm->getValue('data_lang'));
             $userSettings[PROPERTY_USER_UILG] = $uiLang->getUri();
             $userSettings[PROPERTY_USER_DEFLG] = $dataLang->getUri();
             $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($currentUser);
             if ($binder->bind($userSettings)) {
                 \common_session_SessionManager::getSession()->refresh();
                 $uiLangCode = tao_models_classes_LanguageService::singleton()->getCode($uiLang);
                 $extension = common_ext_ExtensionsManager::singleton()->getExtensionById('tao');
                 tao_helpers_I18n::init($extension, $uiLangCode);
                 $this->setData('message', __('Settings updated'));
                 $this->setData('reload', true);
             }
         }
     }
     $userLabel = $this->userService->getCurrentUser()->getLabel();
     $this->setData('formTitle', sprintf(__("My settings (%s)"), __($userLabel)));
     $this->setData('myForm', $myForm->render());
     //$this->setView('form.tpl');
     $this->setView('form/settings_user.tpl');
 }
Esempio n. 4
0
 /**
  * (non-PHPdoc)
  * @see \oat\oatbox\action\Action::__invoke()
  */
 public function __invoke($params)
 {
     try {
         $loggers = array($this->getLogger(), $this->getServiceLocator()->get(UpdateLogger::SERVICE_ID));
         $this->setLogger(new LoggerAggregator($loggers));
     } catch (ServiceNotFoundException $e) {
         // update script to add update logger hasn't run yet, ignore
     }
     $report = parent::__invoke($params);
     // regenrate locals
     $files = \tao_models_classes_LanguageService::singleton()->generateClientBundles();
     if (count($files) > 0) {
         $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Successfully updated %s client translation bundles', count($files))));
     } else {
         $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, __('No client translation bundles updated')));
     }
     return $report;
 }
 /**
  * initialize a test method
  */
 public function setUp()
 {
     TaoPhpUnitTestRunner::initTest();
     error_reporting(E_ALL);
     if (is_null($this->userService)) {
         $this->userService = wfEngine_models_classes_UserService::singleton();
     }
     $login = '******';
     $pass = '******';
     $langResource = tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG);
     $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => $langResource, PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_FIRSTNAME => 'Sammy', PROPERTY_USER_LASTNAME => 'Norville Rogers', PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW);
     if (!$this->userService->loginAvailable($login)) {
         $this->fail('test login already taken');
     }
     $userClass = new core_kernel_classes_Class(CLASS_WORKFLOWUSER);
     $this->currentUser = $userClass->createInstanceWithProperties($userData);
     $this->assertTrue($this->userService->loginUser($login, $pass));
     $this->service = wfEngine_models_classes_NotificationService::singleton();
 }
 /**
  * Used to create the form elements and bind them to the form instance
  *
  * @access protected
  * @return mixed
  */
 protected function initElements()
 {
     //create file upload form box
     $fileElt = \tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add a media file"));
     if (isset($_POST['import_sent_file'])) {
         $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => \tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     $langService = \tao_models_classes_LanguageService::singleton();
     $dataUsage = new \core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA);
     $dataLang = \common_session_SessionManager::getSession()->getDataLanguage();
     $dataLang = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $dataLang;
     if (!is_null($this->instanceUri)) {
         $instance = new \core_kernel_classes_Resource($this->instanceUri);
         $lang = $instance->getOnePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE));
         if ($lang instanceof \core_kernel_classes_Resource) {
             $dataLang = $lang->getUri();
         }
     }
     $langOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) {
         $langOptions[\tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $langElt = \tao_helpers_form_FormFactory::getElement('lang', 'Combobox');
     $langElt->setValue(\tao_helpers_Uri::encode($dataLang));
     $langElt->setOptions($langOptions);
     $this->form->addElement($langElt);
     $this->form->createGroup('options', __('Media Options'), array($langElt));
     $fileSentElt = \tao_helpers_form_FormFactory::getElement('import_sent_file', 'Hidden');
     $fileSentElt->setValue(1);
     $this->form->addElement($fileSentElt);
     if (!is_null($this->instanceUri)) {
         $instanceElt = \tao_helpers_form_FormFactory::getElement('instanceUri', 'Hidden');
         $instanceElt->setValue($this->instanceUri);
         $this->form->addElement($instanceElt);
     }
 }
Esempio n. 7
0
 /**
  * Run the TAO install from the given data
  * @throws tao_install_utils_Exception
  * @param $installData data coming from the install form
  * @see tao_install_form_Settings
  */
 public function install(array $installData)
 {
     try {
         /*
          * 0 - Check input parameters. 
          */
         $this->log('i', "Checking install data");
         self::checkInstallData($installData);
         $this->log('i', "Starting TAO install", 'INSTALL');
         // Sanitize $installData if needed.
         if (!preg_match("/\\/\$/", $installData['module_url'])) {
             $installData['module_url'] .= '/';
         }
         if (isset($installData['extensions'])) {
             $extensionIDs = is_array($installData['extensions']) ? $installData['extensions'] : explode(',', $installData['extensions']);
         } else {
             $extensionIDs = array('taoCe');
         }
         $installData['file_path'] = rtrim($installData['file_path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         /*
          *  1 - Check configuration with checks described in the manifest.
          */
         $configChecker = tao_install_utils_ChecksHelper::getConfigChecker($extensionIDs);
         // Silence checks to have to be escaped.
         foreach ($configChecker->getComponents() as $c) {
             if (method_exists($c, 'getName') && in_array($c->getName(), $this->getEscapedChecks())) {
                 $configChecker->silent($c);
             }
         }
         $reports = $configChecker->check();
         foreach ($reports as $r) {
             $msg = $r->getMessage();
             $component = $r->getComponent();
             $this->log('i', $msg);
             if ($r->getStatus() !== common_configuration_Report::VALID && !$component->isOptional()) {
                 throw new tao_install_utils_Exception($msg);
             }
         }
         /*
          *  2 - Test DB connection (done by the constructor)
          */
         $this->log('i', "Spawning DbCreator", 'INSTALL');
         $dbName = $installData['db_name'];
         if ($installData['db_driver'] == 'pdo_oci') {
             $installData['db_name'] = $installData['db_host'];
             $installData['db_host'] = '';
         }
         $dbConfiguration = array('driver' => $installData['db_driver'], 'host' => $installData['db_host'], 'dbname' => $installData['db_name'], 'user' => $installData['db_user'], 'password' => $installData['db_pass']);
         $hostParts = explode(':', $installData['db_host']);
         if (count($hostParts) == 2) {
             $dbConfiguration['host'] = $hostParts[0];
             $dbConfiguration['port'] = $hostParts[1];
         }
         if ($installData['db_driver'] == 'pdo_mysql') {
             $dbConfiguration['dbname'] = '';
         }
         if ($installData['db_driver'] == 'pdo_oci') {
             $dbConfiguration['wrapperClass'] = 'Doctrine\\DBAL\\Portability\\Connection';
             $dbConfiguration['portability'] = \Doctrine\DBAL\Portability\Connection::PORTABILITY_ALL;
             $dbConfiguration['fetch_case'] = PDO::CASE_LOWER;
         }
         $dbCreator = new tao_install_utils_DbalDbCreator($dbConfiguration);
         $this->log('d', "DbCreator spawned", 'INSTALL');
         /*
          *   3 - Load the database schema
          */
         // If the database already exists, drop all tables
         if ($dbCreator->dbExists($dbName)) {
             try {
                 //If the target Sgbd is mysql select the database after creating it
                 if ($installData['db_driver'] == 'pdo_mysql') {
                     $dbCreator->setDatabase($installData['db_name']);
                 }
                 $dbCreator->cleanDb($dbName);
             } catch (Exception $e) {
                 $this->log('i', 'Problem cleaning db will try to erase the whole db: ' . $e->getMessage());
                 try {
                     $dbCreator->destroyTaoDatabase($dbName);
                 } catch (Exception $e) {
                     $this->log('i', 'isssue during db cleaning : ' . $e->getMessage());
                 }
             }
             $this->log('i', "Dropped all tables", 'INSTALL');
         } else {
             try {
                 $dbCreator->createDatabase($installData['db_name']);
                 $this->log('i', "Created database " . $installData['db_name'], 'INSTALL');
             } catch (Exception $e) {
                 throw new tao_install_utils_Exception('Unable to create the database, make sure that ' . $installData['db_user'] . ' is granted to create databases. Otherwise create the database with your super user and give to  ' . $installData['db_user'] . ' the right to use it.');
             }
             //If the target Sgbd is mysql select the database after creating it
             if ($installData['db_driver'] == 'pdo_mysql') {
                 $dbCreator->setDatabase($installData['db_name']);
             }
         }
         // reset db name for mysql
         if ($installData['db_driver'] == 'pdo_mysql') {
             $dbConfiguration['dbname'] = $installData['db_name'];
         }
         // Create tao tables
         $dbCreator->initTaoDataBase();
         $this->log('i', 'Created tables', 'INSTALL');
         $storedProcedureFile = $this->options['install_path'] . 'db/tao_stored_procedures_' . str_replace('pdo_', '', $installData['db_driver']) . '.sql';
         if (file_exists($storedProcedureFile) && is_readable($storedProcedureFile)) {
             $this->log('i', 'Installing stored procedures for ' . $installData['db_driver'], 'INSTALL');
             $dbCreator->loadProc($storedProcedureFile);
         } else {
             $this->log('e', 'Could not find storefile : ' . $storedProcedureFile);
         }
         /*
          *  4 - Create the local namespace
          */
         // 			$this->log('i', 'Creating local namespace', 'INSTALL');
         // 			$dbCreator->addLocalModel('8',$installData['module_namespace']);
         // 			$dbCreator->addModels();
         /*
          *  5 - Create the generis config files
          */
         $this->log('d', 'Removing old config', 'INSTALL');
         if (!helpers_File::emptyDirectory($this->options['root_path'] . 'config/', true)) {
             throw new common_exception_Error('Unable to empty ' . $this->options['root_path'] . 'config/ folder.');
         }
         $this->log('d', 'Writing generis config', 'INSTALL');
         $generisConfigWriter = new tao_install_utils_ConfigWriter($this->options['root_path'] . 'generis/config/sample/generis.conf.php', $this->options['root_path'] . 'config/generis.conf.php');
         $generisConfigWriter->createConfig();
         $generisConfigWriter->writeConstants(array('LOCAL_NAMESPACE' => $installData['module_namespace'], 'GENERIS_INSTANCE_NAME' => $installData['instance_name'], 'GENERIS_SESSION_NAME' => self::generateSessionName(), 'ROOT_PATH' => $this->options['root_path'], 'FILES_PATH' => $installData['file_path'], 'ROOT_URL' => $installData['module_url'], 'DEFAULT_LANG' => $installData['module_lang'], 'DEBUG_MODE' => $installData['module_mode'] == 'debug' ? true : false, 'TIME_ZONE' => $installData['timezone']));
         /*
          * 5b - Prepare the file/cache folder (FILES_PATH) not yet defined)
          * @todo solve this more elegantly
          */
         $file_path = $installData['file_path'];
         if (is_dir($file_path)) {
             $this->log('i', 'Data from previous install found and will be removed');
             if (!helpers_File::emptyDirectory($installData['file_path'], true)) {
                 throw new common_exception_Error('Unable to empty ' . $installData['file_path'] . ' folder.');
             }
         } else {
             mkdir($installData['file_path'], 0700, true);
         }
         $cachePath = $installData['file_path'] . 'generis' . DIRECTORY_SEPARATOR . 'cache';
         mkdir($cachePath, 0700, true);
         /*
          * 6 - Run the extensions bootstrap
          */
         $this->log('d', 'Running the extensions bootstrap', 'INSTALL');
         require_once $this->options['root_path'] . 'generis/common/inc.extension.php';
         /*
          * 6b - Create cache persistence
          */
         common_persistence_Manager::addPersistence('cache', array('driver' => 'phpfile'));
         common_persistence_KeyValuePersistence::getPersistence('cache')->purge();
         /*
          * 6c - Create generis persistence 
          */
         common_persistence_Manager::addPersistence('default', $dbConfiguration);
         /*
          * 6d - Create generis user
          */
         // Init model creator and create the Generis User.
         $modelCreator = new tao_install_utils_ModelCreator(LOCAL_NAMESPACE);
         $modelCreator->insertGenerisUser(helpers_Random::generateString(8));
         /*
          * 7 - Add languages
          */
         $models = $modelCreator->getLanguageModels();
         foreach ($models as $ns => $modelFiles) {
             foreach ($modelFiles as $file) {
                 $this->log('d', "Inserting language description model '" . $file . "'", 'INSTALL');
                 $modelCreator->insertLocalModel($file);
             }
         }
         /*
          * 8 - Finish Generis Install
          */
         $generis = common_ext_ExtensionsManager::singleton()->getExtensionById('generis');
         $generisInstaller = new common_ext_GenerisInstaller($generis);
         $generisInstaller->install();
         /*
          * 9 - Install the extensions
          */
         $toInstall = array();
         foreach ($extensionIDs as $id) {
             try {
                 $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($id);
                 if (!common_ext_ExtensionsManager::singleton()->isInstalled($ext->getId())) {
                     $this->log('d', 'Extension ' . $id . ' needs to be installed');
                     $toInstall[$id] = $ext;
                 }
             } catch (common_ext_ExtensionException $e) {
                 $this->log('w', 'Extension ' . $id . ' not found');
             }
         }
         while (!empty($toInstall)) {
             $modified = false;
             foreach ($toInstall as $key => $extension) {
                 // if all dependencies are installed
                 $this->log('d', 'Considering extension ' . $key);
                 $installed = array_keys(common_ext_extensionsmanager::singleton()->getinstalledextensions());
                 $missing = array_diff(array_keys($extension->getDependencies()), $installed);
                 if (count($missing) == 0) {
                     try {
                         $importLocalData = $installData['import_local'] == true;
                         $extinstaller = new tao_install_ExtensionInstaller($extension, $importLocalData);
                         set_time_limit(300);
                         $extinstaller->install();
                         $this->log('ext', $key);
                         $this->log('i', 'Extension ' . $key . ' installed');
                     } catch (common_ext_ExtensionException $e) {
                         $this->log('w', 'Exception(' . $e->getMessage() . ') during install for extension "' . $extension->getId() . '"');
                         throw new tao_install_utils_Exception("An error occured during the installation of extension '" . $extension->getId() . "'.");
                     }
                     unset($toInstall[$key]);
                     $modified = true;
                 } else {
                     $missing = array_diff($missing, array_keys($toInstall));
                     foreach ($missing as $extID) {
                         $this->log('d', 'Extension ' . $extID . ' is required but missing, added to install list');
                         $toInstall[$extID] = common_ext_ExtensionsManager::singleton()->getExtensionById($extID);
                         $modified = true;
                     }
                 }
             }
             // no extension could be installed, and no new requirements was added
             if (!$modified) {
                 throw new common_exception_Error('Unfulfilable/Cyclic reference found in extensions');
             }
         }
         /*
          *  9bis - Generates client side translation bundles (depends on extension install)
          */
         $this->log('i', 'Generates client side translation bundles', 'INSTALL');
         //
         $files = tao_models_classes_LanguageService::singleton()->generateClientBundles();
         /*
          *  10 - Insert Super User
          */
         $this->log('i', 'Spawning SuperUser ' . $installData['user_login'], 'INSTALL');
         $modelCreator->insertSuperUser(array('login' => $installData['user_login'], 'password' => core_kernel_users_Service::getPasswordHash()->encrypt($installData['user_pass1']), 'userLastName' => $installData['user_lastname'], 'userFirstName' => $installData['user_firstname'], 'userMail' => $installData['user_email'], 'userDefLg' => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $installData['module_lang'], 'userUILg' => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $installData['module_lang'], 'userTimezone' => TIME_ZONE));
         /*
          *  11 - Secure the install for production mode
          */
         if ($installData['module_mode'] == 'production') {
             $extensions = common_ext_ExtensionsManager::singleton()->getInstalledExtensions();
             $this->log('i', 'Securing tao for production', 'INSTALL');
             // 11.1 Remove Generis User
             $dbCreator->removeGenerisUser();
             // 11.2 Protect TAO dist
             $shield = new tao_install_utils_Shield(array_keys($extensions));
             $shield->disableRewritePattern(array("!/test/", "!/doc/"));
             $shield->denyAccessTo(array('views/sass', 'views/js/test', 'views/build'));
             $shield->protectInstall();
         }
         /*
          *  12 - Create the version file
          */
         $this->log('d', 'Creating TAO version file', 'INSTALL');
         file_put_contents($installData['file_path'] . 'version', TAO_VERSION);
     } catch (Exception $e) {
         if ($this->retryInstallation($e)) {
             return;
         }
         // In any case, we transmit a single exception type (at the moment)
         // for a clearer API for client code.
         $this->log('e', 'Error Occurs : ' . $e->getMessage() . $e->getTraceAsString(), 'INSTALL');
         throw new tao_install_utils_Exception($e->getMessage(), 0, $e);
     }
 }
Esempio n. 8
0
 protected function getUserData()
 {
     return array(PROPERTY_USER_LOGIN => 'tjdoe', PROPERTY_USER_PASSWORD => 'test123', PROPERTY_USER_LASTNAME => 'Doe', PROPERTY_USER_FIRSTNAME => 'John', PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_DEFLG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_UILG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_PASSWORD => 'test' . rand(), PROPERTY_USER_ROLES => array(INSTANCE_ROLE_GLOBALMANAGER));
 }
Esempio n. 9
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;
Esempio n. 10
0
 * 
 * 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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung (under the project TAO-TRANSFER);
 *               2009-2012 (update and modification) Public Research Centre Henri Tudor (under the project TAO-SUSTAIN & TAO-DEV);
 * 
 */
include_once dirname(__FILE__) . '/../../includes/raw_start.php';
$testUserData = array(PROPERTY_USER_LOGIN => 'tjdoe', PROPERTY_USER_PASSWORD => 'test123', PROPERTY_USER_LASTNAME => 'Doe', PROPERTY_USER_FIRSTNAME => 'John', PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_DEFLG => tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_UILG => tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_ROLES => array(INSTANCE_ROLE_GLOBALMANAGER));
$testUserData[PROPERTY_USER_PASSWORD] = 'test' . rand();
$data = $testUserData;
$data[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($data[PROPERTY_USER_PASSWORD]);
$tmclass = new core_kernel_classes_Class(CLASS_TAO_USER);
$user = $tmclass->createInstanceWithProperties($data);
common_Logger::i('Created user ' . $user->getUri());
// prepare a lookup table of languages and values
$usage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI);
$propValue = new core_kernel_classes_Property(RDF_VALUE);
$langService = tao_models_classes_LanguageService::singleton();
$lookup = array();
foreach ($langService->getAvailableLanguagesByUsage($usage) as $lang) {
    $lookup[$lang->getUri()] = (string) $lang->getUniquePropertyValue($propValue);
}
echo json_encode(array('rootUrl' => ROOT_URL, 'userUri' => $user->getUri(), 'userData' => $testUserData, 'lang' => $lookup));
 /**
  * Short description of method initElements
  *
  * @access protected
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     if (!isset($this->options['mode'])) {
         throw new Exception("Please set a mode into container options ");
     }
     parent::initElements();
     //login field
     $loginElement = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_LOGIN));
     $loginElement->setDescription($loginElement->getDescription() . ' *');
     if ($this->options['mode'] == 'add') {
         $loginElement->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Callback', array('object' => tao_models_classes_UserService::singleton(), 'method' => 'loginAvailable', 'message' => __('This Login is already in use')))));
     } else {
         $loginElement->setAttributes(array('readonly' => 'readonly', 'disabled' => 'disabled'));
     }
     //set default lang to the languages fields
     $langService = tao_models_classes_LanguageService::singleton();
     $dataLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_DEFLG));
     $dataLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $dataLangElt->setDescription($dataLangElt->getDescription() . ' *');
     $dataUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA);
     $dataOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) {
         $dataOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $dataLangElt->setOptions($dataOptions);
     $uiLangElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_USER_UILG));
     $uiLangElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $uiLangElt->setDescription($uiLangElt->getDescription() . ' *');
     $guiUsage = new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI);
     $guiOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($guiUsage) as $lang) {
         $guiOptions[tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $uiLangElt->setOptions($guiOptions);
     // roles field
     $property = new core_kernel_classes_Property(PROPERTY_USER_ROLES);
     $roles = $property->getRange()->getInstances(true);
     $rolesOptions = array();
     foreach ($roles as $r) {
         $rolesOptions[tao_helpers_Uri::encode($r->getUri())] = $r->getLabel();
     }
     asort($rolesOptions);
     $rolesElt = $this->form->getElement(tao_helpers_Uri::encode($property->getUri()));
     $rolesElt->setDescription($rolesElt->getDescription() . ' *');
     $rolesElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $rolesElt->setOptions($rolesOptions);
     // password field
     $this->form->removeElement(tao_helpers_Uri::encode(PROPERTY_USER_PASSWORD));
     if ($this->options['mode'] == 'add') {
         $pass1Element = tao_helpers_form_FormFactory::getElement('password1', 'Hiddenbox');
         $pass1Element->setDescription(__('Password *'));
         $pass1Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
         $this->form->addElement($pass1Element);
         $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox');
         $pass2Element->setDescription(__('Repeat password *'));
         $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass1Element))));
         $this->form->addElement($pass2Element);
     } else {
         if (helpers_PlatformInstance::isDemo()) {
             $warning = tao_helpers_form_FormFactory::getElement('warningpass', 'Label');
             $warning->setValue(__('Unable to change passwords in demo mode'));
             $this->form->addElement($warning);
             $this->form->createGroup("pass_group", __("Change the password"), array('warningpass'));
         } else {
             $pass2Element = tao_helpers_form_FormFactory::getElement('password2', 'Hiddenbox');
             $pass2Element->setDescription(__('New password'));
             $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
             $this->form->addElement($pass2Element);
             $pass3Element = tao_helpers_form_FormFactory::getElement('password3', 'Hiddenbox');
             $pass3Element->setDescription(__('Repeat new password'));
             $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element))));
             $this->form->addElement($pass3Element);
             $this->form->createGroup("pass_group", __("Change the password"), array('password1', 'password2', 'password3'));
             if (empty($_POST[$pass2Element->getName()]) && empty($_POST[$pass3Element->getName()])) {
                 $pass2Element->setForcedValid();
                 $pass3Element->setForcedValid();
             }
         }
     }
     /**/
 }
 /**
  * Once some extensions have been installed, we trigger this action.
  */
 public function postInstall()
 {
     $success = true;
     $message = '';
     // try to regenerate languages bundles
     try {
         tao_models_classes_LanguageService::singleton()->generateClientBundles(true);
     } catch (common_excpetion_Error $e) {
         $message = $e->getMessage();
         $success = false;
     }
     $this->returnJson(array('success' => $success, 'message' => $message));
 }