/** * @param string $path path to the app directory. If not given * call \Jelix\Core\App to retrieve it. */ function __construct($path = '') { $config = \Jelix\Core\App::config(); if ($config) { $locale = $config->locale; } else { $locale = ''; } if (!$path) { $path = \Jelix\Core\App::appPath(); if (!$path) { throw new \Exception("Jelix Application is not initialized with Jelix\\Core\\App"); } } $this->path = rtrim($path, '/') . '/'; if (file_exists($this->path . 'jelix-app.json')) { $parser = new AppJsonParser($this->path . 'jelix-app.json', $locale); } else { if (file_exists($this->path . 'project.xml')) { $this->isXml = true; $parser = new ProjectXmlParser($this->path . 'project.xml', $locale); } else { return; } } $this->_exists = true; $parser->parse($this); }
protected function _execute(InputInterface $input, OutputInterface $output) { $config = App::config(); $model_lang = $input->getArgument('model_lang'); if (!$model_lang) { $model_lang = $config->locale; } $lang = $input->getArgument('lang'); foreach ($config->_modulesPathList as $module => $dir) { $source_dir = $dir . 'locales/' . $model_lang . '/'; if (!file_exists($source_dir)) { continue; } if ($input->getOption('to-overload')) { $target_dir = App::appPath('app/overloads/' . $module . '/locales/' . $lang . '/'); } else { $target_dir = App::appPath('app/locales/' . $lang . '/' . $module . '/locales/'); } \jFile::createDir($target_dir); if ($dir_r = opendir($source_dir)) { while (FALSE !== ($fich = readdir($dir_r))) { if ($fich != "." && $fich != ".." && is_file($source_dir . $fich) && strpos($fich, '.' . $config->charset . '.properties') && !file_exists($target_dir . $fich)) { copy($source_dir . $fich, $target_dir . $fich); if ($this->verbose()) { $output->writeln("Copy Locales file {$fich} from {$source_dir} to {$target_dir}."); } } } closedir($dir_r); } } }
static function getInstalledPackages() { if (self::$packages === null) { self::$packages = array(); $path = App::appPath('composer.lock'); if (file_exists($path)) { $lock = json_decode(file_get_contents($path)); if ($lock) { foreach ($lock->packages as $package) { self::$packages[$package->name] = $package; } } } } return self::$packages; }
public function run() { $this->loadAppConfig(); $entrypoint = $this->getParam('entrypoint'); if (($p = strpos($entrypoint, '.php')) !== false) { $entrypoint = substr($entrypoint, 0, $p); } $ep = $this->getEntryPointInfo($entrypoint); if ($ep == null) { try { $cmd = JelixScript::getCommand('createentrypoint', $this->config); $cmd->initOptParam(array(), array('name' => $entrypoint)); $cmd->run(); $this->appInfos = null; $ep = $this->getEntryPointInfo($entrypoint); } catch (Exception $e) { throw new Exception("The entrypoint has not been created because of this error: " . $e->getMessage() . ". No other files have been created.\n"); } } $installConfig = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), App::configPath($ep['config'])); $params = array(); $this->createFile(App::appPath('responses/adminHtmlResponse.class.php'), 'responses/adminHtmlResponse.class.php.tpl', $params, "Response for admin interface"); $this->createFile(App::appPath('responses/adminLoginHtmlResponse.class.php'), 'responses/adminLoginHtmlResponse.class.php.tpl', $params, "Response for login page"); $inifile->setValue('html', 'adminHtmlResponse', 'responses'); $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses'); $inifile->setValue('startModule', 'master_admin'); $inifile->setValue('startAction', 'default:index'); $repositoryPath = jFile::parseJelixPath('lib:jelix-admin-modules'); $this->registerModulesDir('lib:jelix-admin-modules', $repositoryPath); $installConfig->setValue('jacl.installed', '0', $entrypoint); $inifile->setValue('jacl.access', '0', 'modules'); $installConfig->setValue('jacldb.installed', '0', $entrypoint); $inifile->setValue('jacldb.access', '0', 'modules'); $urlconf = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints', null, true); if ($urlconf === null || $urlconf == '') { // in defaultconfig $inifile->setValue($entrypoint, 'jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints', null, true); // in the config of the entry point $inifile->setValue($entrypoint, 'jacl2db~*@classic, jauth~*@classic, jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic, jpref_admin~*@classic', 'simple_urlengine_entrypoints'); } else { $urlconf2 = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints'); if (strpos($urlconf, 'jacl2db_admin~*@classic') === false) { $urlconf .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf, 'jauthdb_admin~*@classic') === false) { $urlconf .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf, 'master_admin~*@classic') === false) { $urlconf .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db_admin~*@classic') === false) { $urlconf2 .= ',jacl2db_admin~*@classic'; } if (strpos($urlconf2, 'jauthdb_admin~*@classic') === false) { $urlconf2 .= ',jauthdb_admin~*@classic'; } if (strpos($urlconf2, 'master_admin~*@classic') === false) { $urlconf2 .= ',master_admin~*@classic'; } if (strpos($urlconf2, 'jacl2db~*@classic') === false) { $urlconf2 .= ',jacl2db~*@classic'; } if (strpos($urlconf2, 'jauth~*@classic') === false) { $urlconf2 .= ',jauth~*@classic'; } if (strpos($urlconf2, 'jpref_admin~*@classic') === false) { $urlconf2 .= ',jpref_admin~*@classic'; } $inifile->setValue($entrypoint, $urlconf, 'simple_urlengine_entrypoints', null, true); $inifile->setValue($entrypoint, $urlconf2, 'simple_urlengine_entrypoints'); } if (null == $inifile->getValue($entrypoint, 'basic_significant_urlengine_entrypoints', null, true)) { $inifile->setValue($entrypoint, '1', 'basic_significant_urlengine_entrypoints', null, true); } $inifile->save(); $verbose = $this->verbose(); $reporter = new \Jelix\Installer\Reporter\Console($verbose ? 'notice' : 'warning'); $installer = new \Jelix\Installer\Installer($reporter); $installer->installModules(array('master_admin'), $entrypoint . '.php'); $authini = new \Jelix\IniFile\IniModifier(App::configPath($entrypoint . '/auth.coord.ini.php')); $authini->setValue('after_login', 'master_admin~default:index'); $authini->setValue('timeout', '30'); $authini->save(); $profile = $this->getOption('-profile'); if (!$this->getOption('-noauthdb')) { if ($profile != '') { $authini->setValue('profile', $profile, 'Db'); } $authini->save(); $installer->setModuleParameters('jauthdb', array('defaultuser' => true)); $installer->installModules(array('jauthdb', 'jauthdb_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jauthdb_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jauthdb_admin.access', '0', 'modules'); $inifile->save(); } if (!$this->getOption('-noacl2db')) { if ($profile != '') { $dbini = new \Jelix\IniFile\IniModifier(App::configPath('profiles.ini.php')); $dbini->setValue('jacl2_profile', $profile, 'jdb'); $dbini->save(); } $installer = new \Jelix\Installer\Installer($reporter); $installer->setModuleParameters('jacl2db', array('defaultuser' => true)); $installer->installModules(array('jacl2db', 'jacl2db_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jacl2db_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jacl2db_admin.access', '0', 'modules'); $inifile->save(); } $installer->installModules(array('jpref_admin'), $entrypoint . '.php'); }
/** * calculate miscelaneous path, depending of the server configuration and other informations * in the given array : script path, script name, documentRoot .. * @param array $urlconf urlengine configuration. scriptNameServerVariable, basePath, * jelixWWWPath and jqueryPath should be present */ protected function getPaths(&$urlconf, $pseudoScriptName = '', $isCli = false) { // retrieve the script path+name. // for cli, it will be the path from the directory were we execute the script (given to the php exec). // for web, it is the path from the root of the url if ($pseudoScriptName) { $urlconf['urlScript'] = $pseudoScriptName; } else { if ($urlconf['scriptNameServerVariable'] == '') { $urlconf['scriptNameServerVariable'] = self::findServerName('.php', $isCli); } $urlconf['urlScript'] = $_SERVER[$urlconf['scriptNameServerVariable']]; } // now we separate the path and the name of the script, and then the basePath if ($isCli) { $lastslash = strrpos($urlconf['urlScript'], DIRECTORY_SEPARATOR); if ($lastslash === false) { $urlconf['urlScriptPath'] = $pseudoScriptName ? App::appPath('/scripts/') : getcwd() . '/'; $urlconf['urlScriptName'] = $urlconf['urlScript']; } else { $urlconf['urlScriptPath'] = getcwd() . '/' . substr($urlconf['urlScript'], 0, $lastslash) . '/'; $urlconf['urlScriptName'] = substr($urlconf['urlScript'], $lastslash + 1); } $basepath = $urlconf['urlScriptPath']; $snp = $urlconf['urlScriptName']; $urlconf['urlScript'] = $basepath . $snp; } else { $lastslash = strrpos($urlconf['urlScript'], '/'); $urlconf['urlScriptPath'] = substr($urlconf['urlScript'], 0, $lastslash) . '/'; $urlconf['urlScriptName'] = substr($urlconf['urlScript'], $lastslash + 1); $basepath = $urlconf['basePath']; if ($basepath == '') { // for beginners or simple site, we "guess" the base path $basepath = $localBasePath = $urlconf['urlScriptPath']; } else { if ($basepath != '/') { if ($basepath[0] != '/') { $basepath = '/' . $basepath; } if (substr($basepath, -1) != '/') { $basepath .= '/'; } } if ($pseudoScriptName) { // with pseudoScriptName, we aren't in a true context, we could be in a cli context // (the installer), and we want the path like when we are in a web context. // $pseudoScriptName is supposed to be relative to the basePath $urlconf['urlScriptPath'] = substr($basepath, 0, -1) . $urlconf['urlScriptPath']; $urlconf['urlScript'] = $urlconf['urlScriptPath'] . $urlconf['urlScriptName']; } $localBasePath = $basepath; if ($urlconf['backendBasePath']) { $localBasePath = $urlconf['backendBasePath']; // we have to change urlScriptPath. it may contains the base path of the backend server // we should replace this base path by the basePath of the frontend server if (strpos($urlconf['urlScriptPath'], $urlconf['backendBasePath']) === 0) { $urlconf['urlScriptPath'] = $basepath . substr($urlconf['urlScriptPath'], strlen($urlconf['backendBasePath'])); } else { $urlconf['urlScriptPath'] = $basepath . substr($urlconf['urlScriptPath'], 1); } } elseif (strpos($urlconf['urlScriptPath'], $basepath) !== 0) { throw new Exception('Error in main configuration on basePath -- basePath (' . $basepath . ') in config file doesn\'t correspond to current base path. You should setup it to ' . $urlconf['urlScriptPath']); } } $urlconf['basePath'] = $basepath; if ($urlconf['jelixWWWPath'][0] != '/') { $urlconf['jelixWWWPath'] = $basepath . $urlconf['jelixWWWPath']; } if ($urlconf['jqueryPath'][0] != '/') { $urlconf['jqueryPath'] = $basepath . $urlconf['jqueryPath']; } $snp = substr($urlconf['urlScript'], strlen($localBasePath)); if ($localBasePath == '/') { $urlconf['documentRoot'] = App::wwwPath(); } else { if (strpos(App::wwwPath(), $localBasePath) === false) { if (isset($_SERVER['DOCUMENT_ROOT'])) { $urlconf['documentRoot'] = $_SERVER['DOCUMENT_ROOT']; } else { $urlconf['documentRoot'] = App::wwwPath(); } } else { $urlconf['documentRoot'] = substr(App::wwwPath(), 0, -strlen($localBasePath)); } } } $pos = strrpos($snp, '.php'); if ($pos !== false) { $snp = substr($snp, 0, $pos); } $urlconf['urlScriptId'] = $snp; $urlconf['urlScriptIdenc'] = rawurlencode($snp); }
protected function registerModulesDir($repository, $repositoryPath) { $allDirs = \Jelix\Core\App::getDeclaredModulesDir(); $path = realpath($repositoryPath); if ($path == '') { throw new \Exception('The modules dir ' . $repository . ' is not a valid path'); } $path = \Jelix\FileUtilities\Path::shortestPath(\Jelix\Core\App::appPath(), $path); $found = false; foreach ($allDirs as $dir) { $dir = \Jelix\FileUtilities\Path::shortestPath(\Jelix\Core\App::appPath(), $dir); if ($dir == $path) { $found = true; break; } } // the modules dir is not known, we should register it. if (!$found) { $this->createDir($repositoryPath); if (file_exists(\Jelix\Core\App::appPath('composer.json')) && file_exists(\Jelix\Core\App::appPath('vendor'))) { // we update composer.json $json = json_decode(file_get_contents(\Jelix\Core\App::appPath('composer.json')), true); if (!$json) { throw new \Exception('composer.json has bad json format'); } if (!isset($json['extra'])) { $json['extra'] = array('jelix' => array('modules-dir' => array())); } elseif (!isset($json['extra']['jelix'])) { $json['extra']['jelix'] = array('modules-dir' => array()); } elseif (!isset($json['extra']['jelix']['modules-dir'])) { $json['extra']['jelix']['modules-dir'] = array(); } $json['extra']['jelix']['modules-dir'][] = $path; file_put_contents(\Jelix\Core\App::appPath('composer.json'), json_encode($json, JSON_PRETTY_PRINT)); if ($this->verbose()) { $this->output->writeln('<notice>The given modules dir has been added into your composer.json.</notice>'); } $this->output->writeln('<notice>You should launch \'composer update\' to have your module repository recognized.</notice>'); } elseif (file_exists(\Jelix\Core\App::appPath('application.init.php'))) { // we modify the application.init.php directly $content = file_get_contents(\Jelix\Core\App::appPath('application.init.php')); $content .= "\njApp::declareModulesDir(__DIR__.'/" . $path . "');\n"; file_put_contents(\Jelix\Core\App::appPath('application.init.php'), $content); if ($this->verbose()) { $this->output->writeln('<notice>The given modules dir has been added into your application.init.php.</notice>'); } } } }
public static function appPath($file = '') { return \Jelix\Core\App::appPath($file); }
/** * fill some properties from informations stored into the project.xml or jelix-app.json file. * @return string the application name */ function loadFromProject() { $infos = new \Jelix\Core\Infos\AppInfos(\Jelix\Core\App::appPath()); if (!$infos->exists()) { throw new Exception("cannot load jelix-app.json or project.xml"); } $this->infoLicence = $infos->license; $this->infoLicenceUrl = $infos->licenseURL; $this->infoCopyright = $infos->copyright; $this->infoWebsite = $infos->homepageURL; return $infos->name; }
public function run() { // retrieve the type of entry point we want to create $type = $this->getOption('-type'); if (!$type) { $type = 'classic'; } else { if (!in_array($type, array('classic', 'jsonrpc', 'xmlrpc', 'soap', 'cmdline'))) { throw new Exception("invalid type"); } } // retrieve the name of the entry point $name = $this->getParam('name'); if (preg_match('/(.*)\\.php$/', $name, $m)) { $name = $m[1]; } // the full path of the entry point if ($type == 'cmdline') { $entryPointFullPath = App::scriptsPath($name . '.php'); $entryPointTemplate = 'scripts/cmdline.php.tpl'; } else { $entryPointFullPath = App::wwwPath($name . '.php'); $entryPointTemplate = 'www/' . ($type == 'classic' ? 'index' : $type) . '.php.tpl'; } if (file_exists($entryPointFullPath)) { throw new Exception("the entry point already exists"); } $entryPointDir = dirname($entryPointFullPath) . '/'; $this->loadAppInfos(); // retrieve the config file name $configFile = $this->getParam('config'); if ($configFile == null) { if ($type == 'cmdline') { $configFile = 'cmdline/' . $name . '.ini.php'; } else { $configFile = $name . '/config.ini.php'; } } // let's create the config file if needed $configFilePath = App::configPath($configFile); if (!file_exists($configFilePath)) { $this->createDir(dirname($configFilePath)); // the file doesn't exists // if there is a -copy-config parameter, we copy this file $originalConfig = $this->getOption('-copy-config'); if ($originalConfig) { if (!file_exists(App::configPath($originalConfig))) { throw new Exception("unknown original configuration file"); } file_put_contents($configFilePath, file_get_contents(App::configPath($originalConfig))); if ($this->verbose()) { echo "Configuration file {$configFile} has been created from the config file {$originalConfig}.\n"; } } else { // else we create a new config file, with the startmodule of the default // config as a module name. $mainConfig = parse_ini_file(App::mainConfigFile(), true); $param = array(); if (isset($mainConfig['startModule'])) { $param['modulename'] = $mainConfig['startModule']; } else { $param['modulename'] = 'jelix'; } $this->createFile($configFilePath, 'var/config/index/config.ini.php.tpl', $param, "Configuration file"); } } $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), $configFilePath); $param = array(); $param['modulename'] = $inifile->getValue('startModule'); // creation of the entry point $this->createDir($entryPointDir); $param['rp_app'] = $this->getRelativePath($entryPointDir, App::appPath()); $param['config_file'] = $configFile; $this->createFile($entryPointFullPath, $entryPointTemplate, $param, "Entry point"); if ($type != 'cmdline') { if (null === $inifile->getValue($name, 'simple_urlengine_entrypoints', null, true)) { $inifile->setValue($name, '', 'simple_urlengine_entrypoints', null, true); } if (null === $inifile->getValue($name, 'basic_significant_urlengine_entrypoints', null, true)) { $inifile->setValue($name, '1', 'basic_significant_urlengine_entrypoints', null, true); } $inifile->save(); } $this->appInfos->addEntryPointInfo($name . ".php", $configFile, $type); if ($this->verbose()) { echo $this->appInfos->getFile() . " has been updated.\n"; } $installer = new \Jelix\Installer\Installer(new \Jelix\Installer\Reporter\Console('warning')); $installer->installEntryPoint($name . ".php"); if ($this->verbose()) { echo "All modules have been initialized for the new entry point.\n"; } }
protected function _createPath() { if (!isset(App::config()->_modulesPathList[$this->module])) { if ($this->module == 'jelix') { throw new Exception('jelix module is not enabled !!'); } throw new \Jelix\Core\Selector\Exception('jelix~errors.selector.module.unknown', $this->toString()); } $this->_cacheSuffix = '.' . $this->locale . '.' . $this->charset . '.php'; // check if the locale has been overloaded in var/ $overloadedPath = App::varPath('overloads/' . $this->module . '/locales/' . $this->locale . '/' . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'var/overloaded/'; return; } // check if the locale is available in the locales directory in var/ $localesPath = App::varPath('locales/' . $this->locale . '/' . $this->module . '/locales/' . $this->resource . $this->_suffix); if (is_readable($localesPath)) { $this->_path = $localesPath; $this->_where = 'var/locales/'; return; } // check if the locale has been overloaded in app/ $overloadedPath = App::appPath('app/overloads/' . $this->module . '/locales/' . $this->locale . '/' . $this->resource . $this->_suffix); if (is_readable($overloadedPath)) { $this->_path = $overloadedPath; $this->_where = 'app/overloaded/'; return; } // check if the locale is available in the locales directory in app/ $localesPath = App::appPath('app/locales/' . $this->locale . '/' . $this->module . '/locales/' . $this->resource . $this->_suffix); if (is_readable($localesPath)) { $this->_path = $localesPath; $this->_where = 'app/locales/'; return; } // else check for the original locale file in the module $path = App::config()->_modulesPathList[$this->module] . 'locales/' . $this->locale . '/' . $this->resource . $this->_suffix; if (is_readable($path)) { $this->_where = 'modules/'; $this->_path = $path; return; } // to avoid infinite loop in a specific lang or charset, we should check if we don't // try to retrieve the same message as the one we use for the exception below, // and if it is this message, it means that the error message doesn't exist // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset if ($this->toString() == 'jelix~errors.selector.invalid.target') { $l = 'en_US'; $c = 'UTF-8'; } else { $l = null; $c = null; } throw new \Jelix\Core\Selector\Exception('jelix~errors.selector.invalid.target', array($this->toString(), "locale"), 1, $l, $c); }
protected function execute(InputInterface $input, OutputInterface $output) { // retrieve the type of entry point we want to create $type = $input->getOption('type'); if (!in_array($type, array('classic', 'jsonrpc', 'xmlrpc', 'soap', 'cmdline'))) { throw new \Exception("invalid type"); } // retrieve the name of the entry point $name = $input->getArgument('entrypoint'); if (preg_match('/(.*)\\.php$/', $name, $m)) { $name = $m[1]; } // the full path of the entry point if ($type == 'cmdline') { $entryPointFullPath = App::scriptsPath($name . '.php'); $entryPointTemplate = 'scripts/cmdline.php.tpl'; } else { $entryPointFullPath = App::wwwPath($name . '.php'); $entryPointTemplate = 'www/' . ($type == 'classic' ? 'index' : $type) . '.php.tpl'; } if (file_exists($entryPointFullPath)) { throw new \Exception("the entry point already exists"); } $entryPointDir = dirname($entryPointFullPath) . '/'; $this->loadAppInfos(); // retrieve the config file name $configFile = $input->getArgument('config'); if ($configFile == null) { if ($type == 'cmdline') { $configFile = 'cmdline/' . $name . '.ini.php'; } else { $configFile = $name . '/config.ini.php'; } } // let's create the config file if needed $configFilePath = App::appConfigPath($configFile); if (!file_exists($configFilePath)) { $this->createDir(dirname($configFilePath)); // the file doesn't exists // if there is a -copy-config parameter, we copy this file $originalConfig = $input->getOption('copy-config'); if ($originalConfig) { if (!file_exists(App::appConfigPath($originalConfig))) { throw new \Exception("unknown original configuration file"); } file_put_contents($configFilePath, file_get_contents(App::appConfigPath($originalConfig))); if ($this->verbose()) { $output->writeln("Configuration file {$configFile} has been created from the config file {$originalConfig}."); } } else { // else we create a new config file $param = array(); $this->createFile($configFilePath, 'app/config/index/config.ini.php.tpl', $param, "Configuration file"); } } $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), $configFilePath); $urlsFile = App::appConfigPath($inifile->getValue('significantFile', 'urlengine')); $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true); $param = array(); // creation of the entry point $this->createDir($entryPointDir); $param['rp_app'] = Path::shortestPath($entryPointDir, App::appPath()); $param['config_file'] = $configFile; $this->createFile($entryPointFullPath, $entryPointTemplate, $param, "Entry point"); if ($type != 'cmdline') { $xmlEp = $xmlMap->addEntryPoint($name, $type); /*if ($type == 'classic') { $xmlEp->addUrlAction('/', $module, $action); }*/ $xmlMap->save(); } $this->appInfos->addEntryPointInfo($name . ".php", $configFile, $type); if ($this->verbose()) { $output->writeln($this->appInfos->getFile() . " has been updated."); } $installer = new \Jelix\Installer\Installer(new \Jelix\Installer\Reporter\Console('warning')); $installer->installEntryPoint($name . ".php"); if ($this->verbose()) { $output->writeln("All modules have been initialized for the new entry point."); } }
protected function _createSkeleton($appPath, $appName, $wwwpath, InputInterface $input) { $this->createDir($appPath); $this->createDir(App::tempBasePath()); $this->createDir($wwwpath); $varPath = App::varPath(); $configPath = App::configPath(); $this->createDir($varPath); $this->createDir(App::logPath()); $this->createDir(App::appConfigPath()); $this->createDir($configPath); $this->createDir(App::appConfigPath('index/')); $this->createDir(App::appPath('app/overloads/')); $this->createDir(App::appPath('app/themes')); $this->createDir(App::appPath('app/themes/default/')); $this->createDir($varPath . 'uploads/'); $this->createDir($varPath . 'sessions/'); $this->createDir($varPath . 'mails/'); $this->createDir($appPath . 'install'); $this->createDir($appPath . 'modules'); $this->createDir($appPath . 'plugins'); $this->createDir(App::appPath('app/responses')); $this->createDir($appPath . 'tests'); $this->createDir(App::scriptsPath()); $param = array(); if ($input->getOption('nodefaultmodule')) { $param['tplname'] = 'jelix~defaultmain'; $param['modulename'] = 'jelix'; } else { $moduleName = $input->getOption('modulename'); if (!$moduleName) { // note: since module name are used for name of generated name, // only this characters are allowed $moduleName = preg_replace('/([^a-zA-Z_0-9])/', '_', $appName); } $param['modulename'] = $moduleName; $param['tplname'] = $moduleName . '~main'; } $param['config_file'] = 'index/config.ini.php'; $param['rp_temp'] = Path::shortestPath($appPath, App::tempBasePath()) . '/'; $param['rp_var'] = Path::shortestPath($appPath, App::varPath()) . '/'; $param['rp_log'] = Path::shortestPath($appPath, App::logPath()) . '/'; $param['rp_conf'] = Path::shortestPath($appPath, $configPath) . '/'; $param['rp_www'] = Path::shortestPath($appPath, $wwwpath) . '/'; $param['rp_cmd'] = Path::shortestPath($appPath, App::scriptsPath()) . '/'; $param['rp_jelix'] = Path::shortestPath($appPath, JELIX_LIB_PATH) . '/'; $param['rp_lib'] = Path::shortestPath($appPath, LIB_PATH) . '/'; $param['rp_vendor'] = ''; foreach (array(LIB_PATH . 'vendor/', LIB_PATH . '../vendor/', LIB_PATH . '../../../') as $path) { if (file_exists($path)) { $param['rp_vendor'] = Path::shortestPath($appPath, realpath($path) . '/') . '/'; break; } } $param['rp_app'] = Path::shortestPath($wwwpath, $appPath) . '/'; $this->createFile(App::logPath() . '.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'mails/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'sessions/.dummy', 'dummy.tpl', array()); $this->createFile(App::appPath() . 'app/overloads/.dummy', 'dummy.tpl', array()); $this->createFile(App::appPath() . 'app/themes/default/.dummy', 'dummy.tpl', array()); $this->createFile(App::varPath() . 'uploads/.dummy', 'dummy.tpl', array()); $this->createFile($appPath . 'plugins/.dummy', 'dummy.tpl', array()); $this->createFile(App::scriptsPath() . '.dummy', 'dummy.tpl', array()); $this->createFile(App::tempBasePath() . '.dummy', 'dummy.tpl', array()); $this->createFile($appPath . '.htaccess', 'htaccess_deny', $param, "Configuration file for Apache"); $this->createFile($appPath . '.gitignore', 'git_ignore.tpl', $param, ".gitignore"); $this->createFile($appPath . 'jelix-app.json', 'jelix-app.json.tpl', $param, "Project description file"); $this->createFile($appPath . 'composer.json', 'composer.json.tpl', $param, "Composer file"); $this->createFile($appPath . 'cmd.php', 'cmd.php.tpl', $param, "Script for developer commands"); $this->createFile(App::appConfigPath('mainconfig.ini.php'), 'app/config/mainconfig.ini.php.tpl', $param, "Main configuration file"); $this->createFile($configPath . 'localconfig.ini.php.dist', 'var/config/localconfig.ini.php.tpl', $param, "Configuration file for specific environment"); $this->createFile($configPath . 'profiles.ini.php', 'var/config/profiles.ini.php.tpl', $param, "Profiles file"); $this->createFile($configPath . 'profiles.ini.php.dist', 'var/config/profiles.ini.php.tpl', $param, "Profiles file for your repository"); $this->createFile($configPath . 'preferences.ini.php', 'var/config/preferences.ini.php.tpl', $param, "Preferences file"); $this->createFile(App::appConfigPath('urls.xml'), 'app/config/urls.xml.tpl', $param, "URLs mapping file"); $this->createFile(App::appConfigPath('index/config.ini.php'), 'app/config/index/config.ini.php.tpl', $param, "Entry point configuration file"); $this->createFile($appPath . 'app/responses/myHtmlResponse.class.php', 'app/responses/myHtmlResponse.class.php.tpl', $param, "Main response class"); $this->createFile($appPath . 'install/installer.php', 'installer/installer.php.tpl', $param, "Installer script"); $this->createFile($appPath . 'tests/runtests.php', 'tests/runtests.php', $param, "Tests script"); $temp = dirname(rtrim(App::tempBasePath(), '/')); if ($temp != rtrim($appPath, '/')) { if (file_exists($temp . '/.gitignore')) { $gitignore = file_get_contents($temp . '/.gitignore') . "\n" . $appName . "/*\n"; file_put_contents($temp . '/.gitignore', $gitignore); } else { file_put_contents($temp . '/.gitignore', $appName . "/*\n"); } } else { $gitignore = file_get_contents($appPath . '.gitignore') . "\n" . basename(rtrim(App::tempBasePath(), '/')) . "/*\n"; file_put_contents($appPath . '.gitignore', $gitignore); } $this->createFile($wwwpath . 'index.php', 'www/index.php.tpl', $param, "Main entry point"); $this->createFile($wwwpath . '.htaccess', 'htaccess_allow', $param, "Configuration file for Apache"); $param['php_rp_temp'] = $this->convertRp($param['rp_temp']); $param['php_rp_var'] = $this->convertRp($param['rp_var']); $param['php_rp_log'] = $this->convertRp($param['rp_log']); $param['php_rp_conf'] = $this->convertRp($param['rp_conf']); $param['php_rp_www'] = $this->convertRp($param['rp_www']); $param['php_rp_cmd'] = $this->convertRp($param['rp_cmd']); $param['php_rp_jelix'] = $this->convertRp($param['rp_jelix']); if ($param['rp_vendor']) { $param['php_rp_vendor'] = $this->convertRp($param['rp_vendor']); $this->createFile($appPath . 'application.init.php', 'application2.init.php.tpl', $param, "Bootstrap file"); } else { $this->createFile($appPath . 'application.init.php', 'application.init.php.tpl', $param, "Bootstrap file"); } return $param; }
protected function migrate_1_7_0() { $this->reporter->message('Start migration to 1.7.0', 'notice'); $newConfigPath = App::appConfigPath(); if (!file_exists($newConfigPath)) { $this->reporter->message('Create app/config/', 'notice'); \jFile::createDir($newConfigPath); } // move mainconfig.php to app/config/ if (!file_exists($newConfigPath . 'mainconfig.ini.php')) { if (!file_exists(App::configPath('mainconfig.ini.php'))) { if (!file_exists(App::configPath('defaultconfig.ini.php'))) { throw new \Exception("Migration to Jelix 1.7.0 canceled: where is your mainconfig.ini.php?"); } $this->reporter->message('Move var/config/defaultconfig.ini.php to app/config/mainconfig.ini.php', 'notice'); rename(App::configPath('defaultconfig.ini.php'), $newConfigPath . 'mainconfig.ini.php'); } else { $this->reporter->message('Move var/config/mainconfig.ini.php to app/config/', 'notice'); rename(App::configPath('mainconfig.ini.php'), $newConfigPath . 'mainconfig.ini.php'); } } // move entrypoint configs to app/config $projectxml = simplexml_load_file(App::appPath('project.xml')); // read all entry points data foreach ($projectxml->entrypoints->entry as $entrypoint) { $configFile = (string) $entrypoint['config']; $dest = App::appConfigPath($configFile); if (!file_exists($dest)) { if (!file_exists(App::configPath($configFile))) { $this->reporter->message("Config file var/config/{$configFile} indicated in project.xml, does not exist", 'warning'); continue; } $this->reporter->message("Move var/config/{$configFile} to app/config/", 'notice'); \jFile::createDir(dirname($dest)); rename(App::configPath($configFile), $dest); } $config = parse_ini_file(App::appConfigPath($configFile), true); if (isset($config['urlengine']['significantFile'])) { $urlFile = $config['urlengine']['significantFile']; if (!file_exists(App::appConfigPath($urlFile)) && file_exists(App::configPath($urlFile))) { $this->reporter->message("Move var/config/{$urlFile} to app/config/", 'notice'); rename(App::configPath($urlFile), App::appConfigPath($urlFile)); } } } // move urls.xml to app/config $mainconfig = parse_ini_file(App::appConfigPath('mainconfig.ini.php'), true); if (isset($mainconfig['urlengine']['significantFile'])) { $urlFile = $mainconfig['urlengine']['significantFile']; } else { $urlFile = 'urls.xml'; } if (!file_exists(App::appConfigPath($urlFile)) && file_exists(App::configPath($urlFile))) { $this->reporter->message("Move var/config/{$urlFile} to app/config/", 'notice'); rename(App::configPath($urlFile), App::appConfigPath($urlFile)); } $this->reporter->message('Migration to 1.7.0 is done', 'notice'); if (!file_exists(App::appPath('app/responses'))) { $this->reporter->message("Move responses/ to app/responses/", 'notice'); rename(App::appPath('responses'), App::appPath('app/responses')); } }
protected function _execute(InputInterface $input, OutputInterface $output) { $entrypoint = $input->getArgument('entrypoint'); if (($p = strpos($entrypoint, '.php')) !== false) { $entrypoint = substr($entrypoint, 0, $p); } $ep = $this->getEntryPointInfo($entrypoint); if ($ep == null) { try { $options = array('entrypoint' => $entrypoint); $this->executeSubCommand('app:createentrypoint', $options, $output); $this->appInfos = null; $ep = $this->getEntryPointInfo($entrypoint); } catch (\Exception $e) { throw new \Exception("The entrypoint has not been created because of this error: " . $e->getMessage() . ". No other files have been created.\n"); } } $installConfig = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php')); $inifile = new \Jelix\IniFile\MultiIniModifier(App::mainConfigFile(), App::appConfigPath($ep['config'])); $params = array(); $this->createFile(App::appPath('app/responses/adminHtmlResponse.class.php'), 'app/responses/adminHtmlResponse.class.php.tpl', $params, "Response for admin interface"); $this->createFile(App::appPath('app/responses/adminLoginHtmlResponse.class.php'), 'app/responses/adminLoginHtmlResponse.class.php.tpl', $params, "Response for login page"); $inifile->setValue('html', 'adminHtmlResponse', 'responses'); $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses'); $repositoryPath = \jFile::parseJelixPath('lib:jelix-admin-modules'); $this->registerModulesDir('lib:jelix-admin-modules', $repositoryPath); $installConfig->setValue('jacl.installed', '0', $entrypoint); $inifile->setValue('jacl.access', '0', 'modules'); $installConfig->setValue('jacldb.installed', '0', $entrypoint); $inifile->setValue('jacldb.access', '0', 'modules'); $inifile->save(); $urlsFile = jApp::appConfigPath($inifile->getValue('significantFile', 'urlengine')); $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true); $xmlEp = $xmlMap->getEntryPoint($entrypoint); $xmlEp->addUrlAction('/', 'master_admin', 'default:index', null, null, array('default' => true)); $xmlEp->addUrlModule('', 'master_admin'); $xmlEp->addUrlInclude('/admin/acl', 'jacl2db_admin', 'urls.xml'); $xmlEp->addUrlInclude('/admin/auth', 'jauthdb_admin', 'urls.xml'); $xmlEp->addUrlInclude('/admin/pref', 'jpref_admin', 'urls.xml'); $xmlEp->addUrlInclude('/auth', 'jauth', 'urls.xml'); $xmlMap->save(); $reporter = new \Jelix\Installer\Reporter\Console($output->isVerbose() ? 'notice' : 'warning'); $installer = new \Jelix\Installer\Installer($reporter); $installer->installModules(array('jauth', 'master_admin'), $entrypoint . '.php'); $authini = new \Jelix\IniFile\IniModifier(App::configPath($entrypoint . '/auth.coord.ini.php')); $authini->setValue('after_login', 'master_admin~default:index'); $authini->setValue('timeout', '30'); $authini->save(); $profile = $input->getOption('profile'); if (!$input->getOption('noauthdb')) { if ($profile != '') { $authini->setValue('profile', $profile, 'Db'); } $authini->save(); $installer->setModuleParameters('jauthdb', array('defaultuser' => true)); $installer->installModules(array('jauthdb', 'jauthdb_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jauthdb_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jauthdb_admin.access', '0', 'modules'); $inifile->save(); } if (!$input->getOption('noacl2db')) { if ($profile != '') { $dbini = new \Jelix\IniFile\IniModifier(App::configPath('profiles.ini.php')); $dbini->setValue('jacl2_profile', $profile, 'jdb'); $dbini->save(); } $installer = new \Jelix\Installer\Installer($reporter); $installer->setModuleParameters('jacl2db', array('defaultuser' => true)); $installer->installModules(array('jacl2db', 'jacl2db_admin'), $entrypoint . '.php'); } else { $installConfig->setValue('jacl2db_admin.installed', '0', $entrypoint); $installConfig->save(); $inifile->setValue('jacl2db_admin.access', '0', 'modules'); $inifile->save(); } $installer->installModules(array('jpref_admin'), $entrypoint . '.php'); }