/**
  * (non-PHPdoc)
  * @see \oat\oatbox\action\Action::__invoke()
  */
 public function __invoke($params)
 {
     $merged = array_merge(common_ext_ExtensionsManager::singleton()->getInstalledExtensions(), $this->getMissingExtensions());
     $sorted = \helpers_ExtensionHelper::sortByDependencies($merged);
     $report = new common_report_Report(common_report_Report::TYPE_INFO, 'Running extension update');
     foreach ($sorted as $ext) {
         try {
             if (!common_ext_ExtensionsManager::singleton()->isInstalled($ext->getId())) {
                 $installer = new \tao_install_ExtensionInstaller($ext);
                 $installer->install();
                 $report->add(new common_report_Report(common_report_Report::TYPE_SUCCESS, 'Installed ' . $ext->getName()));
             } else {
                 $report->add($this->updateExtension($ext));
             }
         } catch (common_ext_MissingExtensionException $ex) {
             $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, $ex->getMessage()));
             break;
         } catch (common_ext_OutdatedVersionException $ex) {
             $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, $ex->getMessage()));
             break;
         } catch (Exception $e) {
             $this->logError('Exception during update of ' . $ext->getId() . ': ' . get_class($e) . ' "' . $e->getMessage() . '"');
             $report->setType(common_report_Report::TYPE_ERROR);
             $report->setTitle('Update failed');
             $report->add(new common_report_Report(common_report_Report::TYPE_ERROR, 'Exception during update of ' . $ext->getId() . '.'));
             break;
         }
     }
     $this->logInfo(helpers_Report::renderToCommandline($report, false));
     return $report;
 }
 public function run()
 {
     $extmanger = common_ext_ExtensionsManager::singleton();
     $ext = $extmanger->getExtensionById('taoCe');
     $extinstaller = new tao_install_ExtensionInstaller($ext);
     $extinstaller->install();
 }
 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');
 }
 /**
  *
  * install action
  *
  */
 public function install()
 {
     $success = false;
     try {
         $extInstaller = new tao_install_ExtensionInstaller($this->getCurrentExtension());
         $extInstaller->install();
         $message = __('Extension ') . $this->getCurrentExtension()->getId() . __(' has been installed');
         $success = true;
         // reinit user session
         $session = \common_session_SessionManager::getSession()->refresh();
     } catch (common_ext_ExtensionException $e) {
         $message = $e->getMessage();
     }
     echo json_encode(array('success' => $success, 'message' => $message));
 }
Example #5
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);
     }
 }
Example #6
0
    date_default_timezone_set('UTC');
}
require_once dirname(__FILE__) . '/../includes/raw_start.php';
echo 'Look for missing required extensions' . PHP_EOL;
$missingId = \helpers_ExtensionHelper::getMissingExtensionIds(common_ext_ExtensionsManager::singleton()->getInstalledExtensions());
$missingExt = array();
foreach ($missingId as $extId) {
    $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById($extId);
    $missingExt[$extId] = $ext;
}
$merged = array_merge(common_ext_ExtensionsManager::singleton()->getInstalledExtensions(), $missingExt);
$sorted = \helpers_ExtensionHelper::sortByDependencies($merged);
foreach ($sorted as $ext) {
    if (!common_ext_ExtensionsManager::singleton()->isInstalled($ext->getId())) {
        echo 'Installing ' . $ext->getId() . PHP_EOL;
        $installer = new \tao_install_ExtensionInstaller($ext);
        $installer->install();
    } else {
        $installed = common_ext_ExtensionsManager::singleton()->getInstalledVersion($ext->getId());
        $current = $ext->getVersion();
        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());
 public function installExtension($extension)
 {
     // if all dependencies are installed
     $installed = array_keys(common_ext_ExtensionsManager::singleton()->getInstalledExtensions());
     $missing = array_diff($extension->getDependencies(), $installed);
     foreach ($missing as $dependency) {
         $this->installExtension($dependency);
     }
     $extinstaller = new tao_install_ExtensionInstaller($extension, false);
     set_time_limit(60);
     $extinstaller->install();
 }
Example #8
0
 /**
  * Short description of method actionInstall
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public function actionInstall()
 {
     $extensionId = $this->options['extension'];
     // ID of the extension to install.
     $importLocalData = $this->options['data'];
     // Import local data (local.rdf) or not ?
     try {
         // Retrieve the extension's information.
         $this->outVerbose("Locating extension '{$extensionId}'...");
         $extensionManager = common_ext_ExtensionsManager::singleton();
         $ext = $extensionManager->getExtensionById($extensionId);
         $this->outVerbose("Extension located.");
         try {
             // Install the extension.
             $this->outVerbose("Installing extension '{$extensionId}'...");
             $installer = new tao_install_ExtensionInstaller($ext, $importLocalData);
             $installer->install();
             $this->outVerbose("Extension successfully installed.");
         } catch (common_ext_ForbiddenActionException $e) {
             $this->error("A forbidden action was undertaken: " . $e->getMessage() . " .", true);
         } catch (common_ext_AlreadyInstalledException $e) {
             $this->error("Extension '" . $e->getExtensionId() . "' is already installed.", true);
         } catch (common_ext_MissingExtensionException $e) {
             $this->error("Extension '" . $extensionId . " is dependant on extension '" . $e->getExtensionId() . "' but is missing. Install '" . $e->getExtensionId() . "' first.", true);
         }
     } catch (common_ext_ExtensionException $e) {
         $this->error("An unexpected error occured: " . $e->getMessage(), true);
     }
 }