public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '')
 {
     $tempPath = jApp::tempBasePath();
     $configPath = jApp::configPath();
     if ($tempPath == '/') {
         throw new Exception('Application temp directory doesn\'t exist !', 3);
     }
     if (!is_writable($tempPath)) {
         throw new Exception('Application temp base directory is not writable -- (' . $tempPath . ')', 4);
     }
     if (!is_writable(jApp::logPath())) {
         throw new Exception('Application log directory is not writable -- (' . jApp::logPath() . ')', 4);
     }
     self::$commonConfig = jIniFile::read($configPath . 'defaultconfig.ini.php', true);
     $config = jIniFile::read(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php');
     if (self::$commonConfig) {
         self::_mergeConfig($config, self::$commonConfig);
     }
     if ($configFile != 'defaultconfig.ini.php') {
         if (!file_exists($configPath . $configFile)) {
             throw new Exception("Configuration file is missing -- {$configFile} ", 5);
         }
         if (false === ($userConfig = parse_ini_file($configPath . $configFile, true))) {
             throw new Exception("Syntax error in the configuration file -- {$configFile}", 6);
         }
         self::_mergeConfig($config, $userConfig);
     }
     $config = (object) $config;
     self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName);
     self::$commonConfig = null;
     return $config;
 }
 /**
  * read the given ini file, for the current entry point, or for the entrypoint given
  * in $pseudoScriptName. Merge it with the content of defaultconfig.ini.php
  * It also calculates some options.
  * If you are in a CLI script but you want to load a configuration file for a web entry point
  * or vice-versa, you need to indicate the $pseudoScriptName parameter with the name of the entry point
  * @param string $configFile the config file name
  * @param boolean $allModuleInfo may be true for the installer, which needs all informations
  *                               else should be false, these extra informations are
  *                               not needed to run the application
  * @param boolean $isCli  indicate if the configuration to read is for a CLI script or no
  * @param string $pseudoScriptName the name of the entry point, relative to the base path,
  *              corresponding to the readed configuration
  * @return object an object which contains configuration values
  */
 public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '')
 {
     $tempPath = jApp::tempBasePath();
     $configPath = jApp::configPath();
     if ($tempPath == '/') {
         // if it equals to '/', this is because realpath has returned false in the application.init.php
         // so this is because the path doesn't exist.
         throw new Exception('Application temp directory doesn\'t exist !', 3);
     }
     if (!is_writable($tempPath)) {
         throw new Exception('Application temp base directory is not writable -- (' . $tempPath . ')', 4);
     }
     if (!is_writable(jApp::logPath())) {
         throw new Exception('Application log directory is not writable -- (' . jApp::logPath() . ')', 4);
     }
     $config = jelix_read_ini(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php');
     self::$commonConfig = clone $config;
     @jelix_read_ini($configPath . 'defaultconfig.ini.php', $config);
     if ($configFile != 'defaultconfig.ini.php') {
         if (!file_exists($configPath . $configFile)) {
             throw new Exception("Configuration file is missing -- {$configFile}", 5);
         }
         if (false === @jelix_read_ini($configPath . $configFile, $config)) {
             throw new Exception("Syntax error in the configuration file -- {$configFile}", 6);
         }
     }
     self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName);
     self::$commonConfig = null;
     return $config;
 }
 /**
  * @param jIniFileModifier    $mainConfig   the mainconfig.ini.php file
  * @param string $configFile the path of the configuration file, relative
  *                           to the var/config directory
  * @param string $file the filename of the entry point
  * @param string $type type of the entry point ('classic', 'cli', 'xmlrpc'....)
  */
 function __construct($mainConfig, $configFile, $file, $type)
 {
     $this->type = $type;
     $this->isCliScript = $type == 'cmdline';
     $this->configFile = $configFile;
     $this->scriptName = $this->isCliScript ? $file : '/' . $file;
     $this->file = $file;
     $this->configIni = new jIniMultiFilesModifier($mainConfig, jApp::configPath($configFile));
     $this->config = jConfigCompiler::read($configFile, true, $this->isCliScript, $this->scriptName);
 }
 /**
  * initialize a full jelix environment with a coordinator, a request object etc.
  *
  * it initializes a coordinator, a classic request object. It sets jApp::coord(),
  * @param string $url the full requested URL (with http://, the domaine name etc.)
  * @param string $config the configuration file to use, as if you were inside an entry point
  * @param string $entryPoint the entrypoint name as indicated into project.xml
  */
 protected static function initClassicRequest($url, $config = 'index/config.ini.php', $entryPoint = 'index.php')
 {
     self::$fakeServer = new jelix\FakeServerConf\ApacheMod(jApp::wwwPath(), '/' . $entryPoint);
     self::$fakeServer->setHttpRequest($url);
     $config = jConfigCompiler::read($config, true, false, '/' . $entryPoint);
     $coord = new jCoordinatorForTest($config, false);
     jApp::setCoord($coord);
     $request = new jClassicRequest();
     $coord->testSetRequest($request);
 }
 /**
  * load and read the configuration of the application
  * The combination of all configuration files (the given file
  * and the mainconfig.ini.php) is stored
  * in a single temporary file. So it calls the jConfigCompiler
  * class if needed
  * @param string $configFile the config file name
  * @return object it contains all configuration options
  * @see jConfigCompiler
  */
 public static function load($configFile)
 {
     $config = array();
     $file = jApp::tempPath() . str_replace('/', '~', $configFile);
     if (BYTECODE_CACHE_EXISTS) {
         $file .= '.conf.php';
     } else {
         $file .= '.resultini.php';
     }
     self::$fromCache = true;
     if (!file_exists($file)) {
         // no cache, let's compile
         self::$fromCache = false;
     } else {
         $t = filemtime($file);
         $dc = jApp::mainConfigFile();
         $lc = jApp::configPath('localconfig.ini.php');
         if (file_exists($dc) && filemtime($dc) > $t || filemtime(jApp::configPath($configFile)) > $t || file_exists($lc) && filemtime($lc) > $t) {
             // one of the config files have been modified: let's compile
             self::$fromCache = false;
         } else {
             // let's read the cache file
             if (BYTECODE_CACHE_EXISTS) {
                 include $file;
                 $config = (object) $config;
             } else {
                 $config = jelix_read_ini($file);
             }
             // we check all directories to see if it has been modified
             if ($config->compilation['checkCacheFiletime']) {
                 foreach ($config->_allBasePath as $path) {
                     if (!file_exists($path) || filemtime($path) > $t) {
                         self::$fromCache = false;
                         break;
                     }
                 }
             }
         }
     }
     if (!self::$fromCache) {
         require_once JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php';
         return jConfigCompiler::readAndCache($configFile);
     } else {
         return $config;
     }
 }
Example #6
0
 /**
  * load and read the configuration of the application
  * The combination of all configuration files (the given file
  * and the defaultconfig.ini.php) is stored
  * in a single temporary file. So it calls the jConfigCompiler
  * class if needed
  * @param string $configFile the config file name
  * @return object it contains all configuration options
  * @see jConfigCompiler
  */
 public static function load($configFile)
 {
     $config = array();
     if (BYTECODE_CACHE_EXISTS) {
         $file = JELIX_APP_TEMP_PATH . str_replace('/', '~', $configFile) . '.conf.php';
     } else {
         $file = JELIX_APP_TEMP_PATH . str_replace('/', '~', $configFile) . '.resultini.php';
     }
     $compil = false;
     if (!file_exists($file)) {
         // pas de cache, on compile
         $compil = true;
     } else {
         $t = filemtime($file);
         $dc = JELIX_APP_CONFIG_PATH . 'defaultconfig.ini.php';
         if (file_exists($dc) && filemtime($dc) > $t || filemtime(JELIX_APP_CONFIG_PATH . $configFile) > $t) {
             // le fichier de conf ou le fichier defaultconfig.ini.php ont ete modifié : on compile
             $compil = true;
         } else {
             // on lit le fichier de conf du cache
             if (BYTECODE_CACHE_EXISTS) {
                 include $file;
                 $config = (object) $config;
             } else {
                 $config = parse_ini_file($file, true);
                 $config = (object) $config;
             }
             // on va verifier tous les chemins
             if ($config->compilation['checkCacheFiletime']) {
                 foreach ($config->_allBasePath as $path) {
                     if (!file_exists($path) || filemtime($path) > $t) {
                         $compil = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($compil) {
         require JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php';
         return jConfigCompiler::read($configFile);
     } else {
         return $config;
     }
 }
Example #7
0
 /**
  * read the given ini file, for the current entry point, or for the entrypoint given
  * in $pseudoScriptName. Merge it with the content of defaultconfig.ini.php
  * It also calculates some options.
  * If you are in a CLI script but you want to load a configuration file for a web entry point
  * or vice-versa, you need to indicate the $pseudoScriptName parameter with the name of the entry point
  * @param string $configFile the config file name
  * @param boolean $allModuleInfo may be true for the installer, which needs all informations
  *                               else should be false, these extra informations are
  *                               not needed to run the application
  * @param boolean $isCli  indicate if the configuration to read is for a CLI script or no
  * @param string $pseudoScriptName the name of the entry point, relative to the base path,
  *              corresponding to the readed configuration
  * @return object an object which contains configuration values
  */
 public static function read($configFile, $allModuleInfo = false, $isCli = false, $pseudoScriptName = '')
 {
     $tempPath = jApp::tempBasePath();
     $configPath = jApp::configPath();
     if ($tempPath == '/') {
         // if it equals to '/', this is because realpath has returned false in the application.init.php
         // so this is because the path doesn't exist.
         throw new Exception('Application temp directory doesn\'t exist !', 3);
     }
     if (!is_writable($tempPath)) {
         throw new Exception('Application temp base directory (' . $tempPath . ') is not writable', 4);
     }
     self::$commonConfig = jIniFile::read($configPath . 'defaultconfig.ini.php', true);
     #if ENABLE_PHP_JELIX
     $config = jelix_read_ini(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php');
     @jelix_read_ini($configPath . 'defaultconfig.ini.php', $config);
     if ($configFile != 'defaultconfig.ini.php') {
         if (!file_exists($configPath . $configFile)) {
             throw new Exception("Config file {$configFile} is missing !", 5);
         }
         if (false === @jelix_read_ini($configPath . $configFile, $config)) {
             throw new Exception("Syntax error in the config file {$configFile} !", 6);
         }
     }
     #else
     $config = jIniFile::read(JELIX_LIB_CORE_PATH . 'defaultconfig.ini.php');
     if (self::$commonConfig) {
         self::_mergeConfig($config, self::$commonConfig);
     }
     if ($configFile != 'defaultconfig.ini.php') {
         if (!file_exists($configPath . $configFile)) {
             throw new Exception("Config file {$configFile} is missing !", 5);
         }
         if (false === ($userConfig = parse_ini_file($configPath . $configFile, true))) {
             throw new Exception("Syntax error in the config file {$configFile} !", 6);
         }
         self::_mergeConfig($config, $userConfig);
     }
     $config = (object) $config;
     #endif
     self::prepareConfig($config, $allModuleInfo, $isCli, $pseudoScriptName);
     self::$commonConfig = null;
     return $config;
 }
Example #8
0
function getDocumentRoot()
{
    if (isset($_SERVER['DOCUMENT_ROOT'])) {
        return $_SERVER['DOCUMENT_ROOT'];
    }
    require_once JELIX_LIB_PATH . "core/jConfigCompiler.class.php";
    $config = parse_ini_file(jApp::configPath('defaultconfig.ini.php'));
    $urlengine = $config['urlengine'];
    if ($urlengine['scriptNameServerVariable'] == '') {
        $urlengine['scriptNameServerVariable'] = jConfigCompiler::findServerName('.php');
    }
    $urlScript = $_SERVER[$urlengine['scriptNameServerVariable']];
    $lastslash = strrpos($urlScript, '/');
    $urlScriptPath = substr($urlScript, 0, $lastslash) . '/';
    $basepath = $urlengine['basePath'];
    if ($basepath == '') {
        // for beginners or simple site, we "guess" the base path
        $basepath = $urlScriptPath;
    } elseif ($basepath != '/') {
        if ($basepath[0] != '/') {
            $basepath = '/' . $basepath;
        }
        if (substr($basepath, -1) != '/') {
            $basepath .= '/';
        }
        if (strpos($urlScriptPath, $basepath) !== 0) {
            throw new Exception('Jelix Error: basePath (' . $basepath . ') in config file doesn\'t correspond to current base path. You should setup it to ' . $urlengine['urlScriptPath']);
        }
    }
    if ($basepath == '/') {
        return jApp::wwwPath();
    }
    if (strpos(jApp::wwwPath(), $basepath) === false) {
        return jApp::wwwPath();
    }
    return substr(jApp::wwwPath(), 0, -strlen($basepath));
}
 /**
  * since urls.xml declare all entrypoints, current entry point does not have
  * access to all modules, so doesn't know all their paths.
  * this method retrieve all module paths declared in the configuration
  * of an entry point or the global configuration
  * @param string $configFile the config file name
  */
 protected function retrieveModulePaths($configFile)
 {
     $conf = jConfigCompiler::read($configFile);
     $this->modulesPath = array_merge($this->modulesPath, jConfigCompiler::getModulesPaths($conf));
 }
 /**
  * since urls.xml declare all entrypoints, current entry point does not have
  * access to all modules, so doesn't know all their paths.
  * this method retrieve all module paths declared in the configuration
  * of an entry point or the global configuration
  * @param string $configFile the config file name
  */
 protected function retrieveModulePaths($configFile, $entrypoint = '')
 {
     $conf = jConfigCompiler::read($configFile, true, false, $entrypoint);
     $this->modulesPath = array_merge($this->modulesPath, jConfigCompiler::getModulesPaths($conf));
 }
Example #11
0
 /**
  * load and read the configuration of the application
  * The combination of all configuration files (the given file
  * and the defaultconfig.ini.php) is stored
  * in a single temporary file. So it calls the jConfigCompiler
  * class if needed
  * @param string $configFile the config file name
  * @return object it contains all configuration options
  * @see jConfigCompiler
  */
 public static function load($configFile)
 {
     $config = array();
     $file = jApp::tempPath();
     #if WITH_BYTECODE_CACHE == 'auto'
     if (BYTECODE_CACHE_EXISTS) {
         $file .= str_replace('/', '~', $configFile) . '.conf.php';
     } else {
         $file .= str_replace('/', '~', $configFile) . '.resultini.php';
     }
     #elseif WITH_BYTECODE_CACHE
     $file .= str_replace('/', '~', $configFile) . '.conf.php';
     #else
     $file .= str_replace('/', '~', $configFile) . '.resultini.php';
     #endif
     $compil = false;
     if (!file_exists($file)) {
         // no cache, let's compile
         $compil = true;
     } else {
         $t = filemtime($file);
         $dc = jApp::configPath('defaultconfig.ini.php');
         if (file_exists($dc) && filemtime($dc) > $t || filemtime(jApp::configPath($configFile)) > $t) {
             // one of the two config file have been modified: let's compile
             $compil = true;
         } else {
             // let's read the cache file
             #if WITH_BYTECODE_CACHE == 'auto'
             if (BYTECODE_CACHE_EXISTS) {
                 include $file;
                 $config = (object) $config;
             } else {
                 #if ENABLE_PHP_JELIX
                 $config = jelix_read_ini($file);
                 #else
                 $config = parse_ini_file($file, true);
                 $config = (object) $config;
                 #endif
             }
             #elseif WITH_BYTECODE_CACHE
             include $file;
             $config = (object) $config;
             #else
             #if ENABLE_PHP_JELIX
             $config = jelix_read_ini($file);
             #else
             $config = parse_ini_file($file, true);
             $config = (object) $config;
             #endif
             #endif
             // we check all directories to see if it has been modified
             if ($config->compilation['checkCacheFiletime']) {
                 foreach ($config->_allBasePath as $path) {
                     if (!file_exists($path) || filemtime($path) > $t) {
                         $compil = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($compil) {
         require_once JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php';
         return jConfigCompiler::readAndCache($configFile);
     } else {
         return $config;
     }
 }
Example #12
0
 public static function load($configFile)
 {
     $config = array();
     $file = jApp::tempPath();
     if (BYTECODE_CACHE_EXISTS) {
         $file .= str_replace('/', '~', $configFile) . '.conf.php';
     } else {
         $file .= str_replace('/', '~', $configFile) . '.resultini.php';
     }
     $compil = false;
     if (!file_exists($file)) {
         $compil = true;
     } else {
         $t = filemtime($file);
         $dc = jApp::configPath('defaultconfig.ini.php');
         if (file_exists($dc) && filemtime($dc) > $t || filemtime(jApp::configPath($configFile)) > $t) {
             $compil = true;
         } else {
             if (BYTECODE_CACHE_EXISTS) {
                 include $file;
                 $config = (object) $config;
             } else {
                 $config = parse_ini_file($file, true);
                 $config = (object) $config;
             }
             if ($config->compilation['checkCacheFiletime']) {
                 foreach ($config->_allBasePath as $path) {
                     if (!file_exists($path) || filemtime($path) > $t) {
                         $compil = true;
                         break;
                     }
                 }
             }
         }
     }
     if ($compil) {
         require_once JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php';
         return jConfigCompiler::readAndCache($configFile);
     } else {
         return $config;
     }
 }
 function loadAppConfig()
 {
     if (jApp::config()) {
         return;
     }
     $xml = simplexml_load_file(jApp::appPath('project.xml'));
     $configFile = '';
     foreach ($xml->entrypoints->entry as $entrypoint) {
         $file = (string) $entrypoint['file'];
         if ($file == $this->entryPointName) {
             $configFile = (string) $entrypoint['config'];
             break;
         }
     }
     if ($configFile == '') {
         throw new Exception("Entry point is unknown");
     }
     require_once JELIX_LIB_PATH . "core/jConfigCompiler.class.php";
     jApp::setConfig(jConfigCompiler::read($configFile, true, true, $this->entryPointName));
 }
Example #14
0
function jelix_init_test_env()
{
    require_once JELIX_LIB_CORE_PATH . 'jConfigCompiler.class.php';
    global $gJConfig;
    $gJConfig = jConfigCompiler::read('index/config.ini.php', false, true);
}
Example #15
0
 protected function handleCustomTestSuite()
 {
     $modulesTests = -1;
     /*
     $this->options[0] is an array of all options '--xxx'.
       each values is an array(0=>'optionname', 1=>'value if given')
     $this->options[1] is a list of parameters given after options
       it can be array(0=>'test name', 1=>'filename')
     */
     foreach ($this->options[0] as $option) {
         switch ($option[0]) {
             case '--entrypoint':
                 $this->entryPoint = $option[1];
                 break;
             case '--all-modules':
                 $modulesTests = 0;
                 break;
             case '--module':
                 $modulesTests = 1;
                 // test is the module name
                 // testFile is the test file inside the module
                 break;
             case '--testtype':
                 $this->testType = $option[1];
                 break;
         }
     }
     if (isset($this->options[1][1]) && $modulesTests != 0) {
         // a specifique test file
         $this->arguments['testFile'] = $this->options[1][1];
     } else {
         $this->arguments['testFile'] = '';
     }
     $appInstaller = new jInstallerApplication();
     $this->epInfo = $appInstaller->getEntryPointInfo($this->entryPoint);
     // let's load configuration now, and coordinator. it could be needed by tests
     // (during load of their php files or during execution)
     jApp::setConfig(jConfigCompiler::readAndCache($this->epInfo->configFile, null, $this->entryPoint));
     jApp::setCoord(new jCoordinator('', false));
     if ($modulesTests == 0) {
         // we add all modules in the test list
         $suite = $this->getAllModulesTestSuites();
         if (count($suite)) {
             $this->arguments['test'] = $suite;
             unset($this->arguments['testFile']);
         } else {
             $this->showMessage("Error: no tests in modules\n");
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     } else {
         if ($modulesTests == 1 && !$this->version36) {
             $suite = $this->getModuleTestSuite($this->options[1][0]);
             if (count($suite)) {
                 $this->arguments['test'] = $suite;
                 if (isset($this->options[1][1])) {
                     // a specifique test file
                     $this->arguments['testFile'] = $this->options[1][1];
                 } else {
                     $this->arguments['testFile'] = '';
                 }
             } else {
                 $this->showMessage("Error: no tests in the module\n");
                 exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
             }
         } else {
             if ($modulesTests == 1) {
                 if (isset($this->options[1][1])) {
                     // a specifique test file
                     $suite = $this->getModuleTestSuite($this->options[1][0], $this->options[1][1]);
                 } else {
                     $suite = $this->getModuleTestSuite($this->options[1][0]);
                 }
                 if (count($suite)) {
                     $this->arguments['test'] = $suite;
                 } else {
                     $this->showMessage("Error: no tests in the module\n");
                     exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
                 }
             }
         }
     }
 }
 function loadAppConfig()
 {
     if (jApp::config()) {
         return;
     }
     $xml = simplexml_load_file(jApp::appPath('project.xml'));
     $configFile = '';
     foreach ($xml->entrypoints->entry as $entrypoint) {
         $file = (string) $entrypoint['file'];
         if ($file == $this->entryPointName) {
             $configFile = (string) $entrypoint['config'];
             break;
         }
     }
     if ($configFile == '') {
         throw new Exception($this->name . ": Entry point is unknown");
     }
     jApp::setConfig(jConfigCompiler::read($configFile, true, true, $this->entryPointName));
 }
Example #17
0
 /**
  * core of the installation
  * @param array $modules list of jInstallerComponentModule
  * @param string $epId  the entrypoint id
  * @param boolean $installWholeApp true if the installation is done during app installation
  * @param integer $flags to know what to do
  * @return boolean true if the installation is ok
  */
 protected function _installModules(&$modules, $epId, $installWholeApp, $flags = 3)
 {
     $this->notice('install.entrypoint.start', $epId);
     $ep = $this->entryPoints[$epId];
     jApp::setConfig($ep->config);
     if ($ep->config->disableInstallers) {
         $this->notice('install.entrypoint.installers.disabled');
     }
     // first, check dependencies of the component, to have the list of component
     // we should really install. It fills $this->_componentsToInstall, in the right
     // order
     $result = $this->checkDependencies($modules, $epId);
     if (!$result) {
         $this->error('install.bad.dependencies');
         $this->ok('install.entrypoint.bad.end', $epId);
         return false;
     }
     $this->ok('install.dependencies.ok');
     // ----------- pre install
     // put also available installers into $componentsToInstall for
     // the next step
     $componentsToInstall = array();
     foreach ($this->_componentsToInstall as $item) {
         list($component, $toInstall) = $item;
         try {
             if ($flags == self::FLAG_MIGRATION_11X) {
                 $this->installerIni->setValue($component->getName() . '.installed', 1, $epId);
                 $this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
                 if ($ep->config->disableInstallers) {
                     $upgraders = array();
                 } else {
                     $upgraders = $component->getUpgraders($ep);
                     foreach ($upgraders as $upgrader) {
                         $upgrader->preInstall();
                     }
                 }
                 $componentsToInstall[] = array($upgraders, $component, false);
             } else {
                 if ($toInstall) {
                     if ($ep->config->disableInstallers) {
                         $installer = null;
                     } else {
                         $installer = $component->getInstaller($ep, $installWholeApp);
                     }
                     $componentsToInstall[] = array($installer, $component, $toInstall);
                     if ($flags & self::FLAG_INSTALL_MODULE && $installer) {
                         $installer->preInstall();
                     }
                 } else {
                     if ($ep->config->disableInstallers) {
                         $upgraders = array();
                     } else {
                         $upgraders = $component->getUpgraders($ep);
                     }
                     if ($flags & self::FLAG_UPGRADE_MODULE && count($upgraders)) {
                         foreach ($upgraders as $upgrader) {
                             $upgrader->preInstall();
                         }
                     }
                     $componentsToInstall[] = array($upgraders, $component, $toInstall);
                 }
             }
         } catch (jInstallerException $e) {
             $result = false;
             $this->error($e->getLocaleKey(), $e->getLocaleParameters());
         } catch (Exception $e) {
             $result = false;
             $this->error('install.module.error', array($component->getName(), $e->getMessage()));
         }
     }
     if (!$result) {
         $this->warning('install.entrypoint.bad.end', $epId);
         return false;
     }
     $installedModules = array();
     // -----  installation process
     try {
         foreach ($componentsToInstall as $item) {
             list($installer, $component, $toInstall) = $item;
             if ($toInstall) {
                 if ($installer && $flags & self::FLAG_INSTALL_MODULE) {
                     $installer->install();
                 }
                 $this->installerIni->setValue($component->getName() . '.installed', 1, $epId);
                 $this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
                 $this->installerIni->setValue($component->getName() . '.version.date', $component->getSourceDate(), $epId);
                 $this->installerIni->setValue($component->getName() . '.firstversion', $component->getSourceVersion(), $epId);
                 $this->installerIni->setValue($component->getName() . '.firstversion.date', $component->getSourceDate(), $epId);
                 $this->ok('install.module.installed', $component->getName());
                 $installedModules[] = array($installer, $component, true);
             } else {
                 $lastversion = '';
                 foreach ($installer as $upgrader) {
                     if ($flags & self::FLAG_UPGRADE_MODULE) {
                         $upgrader->install();
                     }
                     // we set the version of the upgrade, so if an error occurs in
                     // the next upgrader, we won't have to re-run this current upgrader
                     // during a future update
                     $this->installerIni->setValue($component->getName() . '.version', $upgrader->version, $epId);
                     $this->installerIni->setValue($component->getName() . '.version.date', $upgrader->date, $epId);
                     $this->ok('install.module.upgraded', array($component->getName(), $upgrader->version));
                     $lastversion = $upgrader->version;
                 }
                 // we set the version to the component version, because the version
                 // of the last upgrader could not correspond to the component version.
                 if ($lastversion != $component->getSourceVersion()) {
                     $this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
                     $this->installerIni->setValue($component->getName() . '.version.date', $component->getSourceDate(), $epId);
                     $this->ok('install.module.upgraded', array($component->getName(), $component->getSourceVersion()));
                 }
                 $installedModules[] = array($installer, $component, false);
             }
             // we always save the configuration, so it invalidates the cache
             $ep->configIni->save();
             // we re-load configuration file for each module because
             // previous module installer could have modify it.
             $ep->config = jConfigCompiler::read($ep->configFile, true, $ep->isCliScript, $ep->scriptName);
             jApp::setConfig($ep->config);
         }
     } catch (jInstallerException $e) {
         $result = false;
         $this->error($e->getLocaleKey(), $e->getLocaleParameters());
     } catch (Exception $e) {
         $result = false;
         $this->error('install.module.error', array($component->getName(), $e->getMessage()));
     }
     if (!$result) {
         $this->warning('install.entrypoint.bad.end', $epId);
         return false;
     }
     // post install
     foreach ($installedModules as $item) {
         try {
             list($installer, $component, $toInstall) = $item;
             if ($toInstall) {
                 if ($installer && $flags & self::FLAG_INSTALL_MODULE) {
                     $installer->postInstall();
                     $component->installFinished($ep);
                 }
             } else {
                 if ($flags & self::FLAG_UPGRADE_MODULE) {
                     foreach ($installer as $upgrader) {
                         $upgrader->postInstall();
                         $component->upgradeFinished($ep, $upgrader);
                     }
                 }
             }
             // we always save the configuration, so it invalidates the cache
             $ep->configIni->save();
             // we re-load configuration file for each module because
             // previous module installer could have modify it.
             $ep->config = jConfigCompiler::read($ep->configFile, true, $ep->isCliScript, $ep->scriptName);
             jApp::setConfig($ep->config);
         } catch (jInstallerException $e) {
             $result = false;
             $this->error($e->getLocaleKey(), $e->getLocaleParameters());
         } catch (Exception $e) {
             $result = false;
             $this->error('install.module.error', array($component->getName(), $e->getMessage()));
         }
     }
     $this->ok('install.entrypoint.end', $epId);
     return $result;
 }
Example #18
0
 protected function _installModules(&$modules, $epId, $installWholeApp, $flags = 3)
 {
     $this->notice('install.entrypoint.start', $epId);
     $ep = $this->entryPoints[$epId];
     jApp::setConfig($ep->config);
     if ($ep->config->disableInstallers) {
         $this->notice('install.entrypoint.installers.disabled');
     }
     $result = $this->checkDependencies($modules, $epId);
     if (!$result) {
         $this->error('install.bad.dependencies');
         $this->ok('install.entrypoint.bad.end', $epId);
         return false;
     }
     $this->ok('install.dependencies.ok');
     $componentsToInstall = array();
     foreach ($this->_componentsToInstall as $item) {
         list($component, $toInstall) = $item;
         try {
             if ($flags == self::FLAG_MIGRATION_11X) {
                 $this->installerIni->setValue($component->getName() . '.installed', 1, $epId);
                 $this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
                 if ($ep->config->disableInstallers) {
                     $upgraders = array();
                 } else {
                     $upgraders = $component->getUpgraders($ep);
                     foreach ($upgraders as $upgrader) {
                         $upgrader->preInstall();
                     }
                 }
                 $componentsToInstall[] = array($upgraders, $component, false);
             } else {
                 if ($toInstall) {
                     if ($ep->config->disableInstallers) {
                         $installer = null;
                     } else {
                         $installer = $component->getInstaller($ep, $installWholeApp);
                     }
                     $componentsToInstall[] = array($installer, $component, $toInstall);
                     if ($flags & self::FLAG_INSTALL_MODULE && $installer) {
                         $installer->preInstall();
                     }
                 } else {
                     if ($ep->config->disableInstallers) {
                         $upgraders = array();
                     } else {
                         $upgraders = $component->getUpgraders($ep);
                     }
                     if ($flags & self::FLAG_UPGRADE_MODULE && count($upgraders)) {
                         foreach ($upgraders as $upgrader) {
                             $upgrader->preInstall();
                         }
                     }
                     $componentsToInstall[] = array($upgraders, $component, $toInstall);
                 }
             }
         } catch (jInstallerException $e) {
             $result = false;
             $this->error($e->getLocaleKey(), $e->getLocaleParameters());
         } catch (Exception $e) {
             $result = false;
             $this->error('install.module.error', array($component->getName(), $e->getMessage()));
         }
     }
     if (!$result) {
         $this->warning('install.entrypoint.bad.end', $epId);
         return false;
     }
     $installedModules = array();
     try {
         foreach ($componentsToInstall as $item) {
             list($installer, $component, $toInstall) = $item;
             if ($toInstall) {
                 if ($installer && $flags & self::FLAG_INSTALL_MODULE) {
                     $installer->install();
                 }
                 $this->installerIni->setValue($component->getName() . '.installed', 1, $epId);
                 $this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
                 $this->installerIni->setValue($component->getName() . '.version.date', $component->getSourceDate(), $epId);
                 $this->installerIni->setValue($component->getName() . '.firstversion', $component->getSourceVersion(), $epId);
                 $this->installerIni->setValue($component->getName() . '.firstversion.date', $component->getSourceDate(), $epId);
                 $this->ok('install.module.installed', $component->getName());
                 $installedModules[] = array($installer, $component, true);
             } else {
                 $lastversion = '';
                 foreach ($installer as $upgrader) {
                     if ($flags & self::FLAG_UPGRADE_MODULE) {
                         $upgrader->install();
                     }
                     $this->installerIni->setValue($component->getName() . '.version', $upgrader->version, $epId);
                     $this->installerIni->setValue($component->getName() . '.version.date', $upgrader->date, $epId);
                     $this->ok('install.module.upgraded', array($component->getName(), $upgrader->version));
                     $lastversion = $upgrader->version;
                 }
                 if ($lastversion != $component->getSourceVersion()) {
                     $this->installerIni->setValue($component->getName() . '.version', $component->getSourceVersion(), $epId);
                     $this->installerIni->setValue($component->getName() . '.version.date', $component->getSourceDate(), $epId);
                     $this->ok('install.module.upgraded', array($component->getName(), $component->getSourceVersion()));
                 }
                 $installedModules[] = array($installer, $component, false);
             }
             $ep->configIni->save();
             $ep->config = jConfigCompiler::read($ep->configFile, true, $ep->isCliScript, $ep->scriptName);
             jApp::setConfig($ep->config);
         }
     } catch (jInstallerException $e) {
         $result = false;
         $this->error($e->getLocaleKey(), $e->getLocaleParameters());
     } catch (Exception $e) {
         $result = false;
         $this->error('install.module.error', array($component->getName(), $e->getMessage()));
     }
     if (!$result) {
         $this->warning('install.entrypoint.bad.end', $epId);
         return false;
     }
     foreach ($installedModules as $item) {
         try {
             list($installer, $component, $toInstall) = $item;
             if ($toInstall) {
                 if ($installer && $flags & self::FLAG_INSTALL_MODULE) {
                     $installer->postInstall();
                     $component->installFinished($ep);
                 }
             } else {
                 if ($flags & self::FLAG_UPGRADE_MODULE) {
                     foreach ($installer as $upgrader) {
                         $upgrader->postInstall();
                         $component->upgradeFinished($ep, $upgrader);
                     }
                 }
             }
             $ep->configIni->save();
             $ep->config = jConfigCompiler::read($ep->configFile, true, $ep->isCliScript, $ep->scriptName);
             jApp::setConfig($ep->config);
         } catch (jInstallerException $e) {
             $result = false;
             $this->error($e->getLocaleKey(), $e->getLocaleParameters());
         } catch (Exception $e) {
             $result = false;
             $this->error('install.module.error', array($component->getName(), $e->getMessage()));
         }
     }
     $this->ok('install.entrypoint.end', $epId);
     return $result;
 }