Esempio n. 1
0
 protected function loadAppConfig()
 {
     if (\Jelix\Core\App::config()) {
         return;
     }
     $ep = $this->getEntryPointInfo($this->entryPointName);
     if ($ep) {
         $configFile = $ep['config'];
     }
     if ($configFile == '') {
         throw new \Exception($this->name . ': Entry point is unknown');
     }
     $compiler = new \Jelix\Core\Config\Compiler($configFile, $this->entryPointName, true);
     \Jelix\Core\App::setConfig($compiler->read(true));
 }
Esempio n. 2
0
 protected function _execute(InputInterface $input, OutputInterface $output)
 {
     $module = $input->getArgument('module');
     $initialVersion = $input->getOption('ver');
     if (!$initialVersion) {
         $initialVersion = '0.1pre';
     }
     // note: since module name are used for name of generated name,
     // only this characters are allowed
     if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) {
         throw new \Exception("'" . $module . "' is not a valid name for a module");
     }
     // check if the module already exist or not
     $path = '';
     try {
         $path = $this->getModulePath($module);
     } catch (\Exception $e) {
     }
     if ($path != '') {
         throw new \Exception("module '" . $module . "' already exists");
     }
     // verify the given repository
     $repository = $input->getArgument('repository');
     if (substr($repository, -1) != '/') {
         $repository .= '/';
     }
     $repositoryPath = \jFile::parseJelixPath($repository);
     if (!$input->getOption('noregistration')) {
         $this->registerModulesDir($repository, $repositoryPath);
     }
     $path = $repositoryPath . $module . '/';
     $this->createDir($path);
     App::setConfig(null);
     $noSubDir = $input->getOption('nosubdir');
     $addInstallZone = $input->getOption('addinstallzone');
     $isdefault = $input->getOption('defaultmodule');
     if ($input->getOption('admin')) {
         $noSubDir = false;
         $addInstallZone = false;
     }
     $param = array();
     $param['module'] = $module;
     $param['version'] = $initialVersion;
     $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param);
     // create all sub directories of a module
     if (!$noSubDir) {
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'zones/');
         $this->createDir($path . 'controllers/');
         $this->createDir($path . 'templates/');
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'daos/');
         $this->createDir($path . 'forms/');
         $this->createDir($path . 'locales/');
         $this->createDir($path . 'locales/en_US/');
         $this->createDir($path . 'locales/fr_FR/');
         $this->createDir($path . 'install/');
         if ($this->verbose()) {
             $output->writeln("Sub directories have been created in the new module {$module}.");
         }
         $this->createFile($path . 'install/install.php', 'module/install.tpl', $param);
         $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array());
     }
     $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile());
     $urlsFile = App::appConfigPath($iniDefault->getValue('significantFile', 'urlengine'));
     $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true);
     // activate the module in the application
     if ($isdefault) {
         if ($this->allEntryPoint) {
             $xmlEp = $xmlMap->getDefaultEntryPoint($type);
         } else {
             $xmlEp = $xmlMap->getEntryPoint($this->entryPointId);
         }
         if ($xmlEp) {
             $xmlEp->addUrlAction('/', $module, 'default:index', null, null, array('default' => true));
             $xmlEp->addUrlModule('', $module);
             if ($this->verbose()) {
                 $output->writeln("The new module {$module} becomes the default module");
             }
         } else {
             if ($this->verbose()) {
                 $output->writeln("No default entry point found: the new module cannot be the default module");
             }
         }
     }
     $xmlMap->save();
     $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules');
     $iniDefault->save();
     $list = $this->getEntryPointsList();
     $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php'));
     // install the module for all needed entry points
     foreach ($list as $entryPoint) {
         $configFile = App::appConfigPath($entryPoint['config']);
         $epconfig = new \Jelix\IniFile\IniModifier($configFile);
         if ($this->allEntryPoint) {
             $access = 2;
         } else {
             $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0;
         }
         $epconfig->setValue($module . '.access', $access, 'modules');
         $epconfig->save();
         if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) {
             $install->setValue($module . '.installed', 1, $entryPoint['id']);
             $install->setValue($module . '.version', $initialVersion, $entryPoint['id']);
         }
         if ($this->verbose()) {
             $output->writeln("The module is initialized for the entry point " . $entryPoint['file']);
         }
     }
     $install->save();
     App::declareModule($path);
     // create a default controller
     if (!$input->getOption('nocontroller')) {
         $arguments = array('module' => $module, 'controller' => 'default', 'method' => 'index');
         if ($input->getOption('entry-point')) {
             $arguments['--entry-point'] = $input->getOption('entry-point');
         }
         if ($input->getOption('cmdline')) {
             $arguments['--cmdline'] = true;
         }
         if ($addInstallZone) {
             $arguments['--addinstallzone'] = true;
         }
         if ($output->isVerbose()) {
             $arguments['-v'] = true;
         }
         $this->executeSubCommand('module:create-ctrl', $arguments, $output);
     }
     if ($input->getOption('admin')) {
         $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener");
         $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param);
         file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module);
         file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module);
     }
 }
Esempio n. 3
0
 public static function setConfig($config)
 {
     \Jelix\Core\App::setConfig($config);
 }
Esempio n. 4
0
 public function run()
 {
     $this->loadAppConfig();
     $module = $this->getParam('module');
     $initialVersion = $this->getOption('-ver');
     if ($initialVersion === false) {
         $initialVersion = '0.1pre';
     }
     // note: since module name are used for name of generated name,
     // only this characters are allowed
     if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) {
         throw new Exception("'" . $module . "' is not a valid name for a module");
     }
     // check if the module already exist or not
     $path = '';
     try {
         $path = $this->getModulePath($module);
     } catch (Exception $e) {
     }
     if ($path != '') {
         throw new Exception("module '" . $module . "' already exists");
     }
     // verify the given repository
     $repository = $this->getParam('repository', 'app:modules/');
     if (substr($repository, -1) != '/') {
         $repository .= '/';
     }
     $repositoryPath = jFile::parseJelixPath($repository);
     if (!$this->getOption('-noregistration')) {
         $this->registerModulesDir($repository, $repositoryPath);
     }
     $path = $repositoryPath . $module . '/';
     $this->createDir($path);
     App::setConfig(null);
     if ($this->getOption('-admin')) {
         $this->removeOption('-nosubdir');
         $this->removeOption('-addinstallzone');
     }
     $param = array();
     $param['module'] = $module;
     $param['version'] = $initialVersion;
     $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param);
     // create all sub directories of a module
     if (!$this->getOption('-nosubdir')) {
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'zones/');
         $this->createDir($path . 'controllers/');
         $this->createDir($path . 'templates/');
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'daos/');
         $this->createDir($path . 'forms/');
         $this->createDir($path . 'locales/');
         $this->createDir($path . 'locales/en_US/');
         $this->createDir($path . 'locales/fr_FR/');
         $this->createDir($path . 'install/');
         if ($this->verbose()) {
             echo "Sub directories have been created in the new module {$module}.\n";
         }
         $this->createFile($path . 'install/install.php', 'module/install.tpl', $param);
         $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array());
     }
     $isdefault = $this->getOption('-defaultmodule');
     $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile());
     // activate the module in the application
     if ($isdefault) {
         $iniDefault->setValue('startModule', $module);
         $iniDefault->setValue('startAction', 'default:index');
         if ($this->verbose()) {
             echo "The new module {$module} becomes the default module\n";
         }
     }
     $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules');
     $iniDefault->save();
     $list = $this->getEntryPointsList();
     $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php'));
     // install the module for all needed entry points
     foreach ($list as $entryPoint) {
         $configFile = App::configPath($entryPoint['config']);
         $epconfig = new \Jelix\IniFile\IniModifier($configFile);
         if ($this->allEntryPoint) {
             $access = 2;
         } else {
             $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0;
         }
         $epconfig->setValue($module . '.access', $access, 'modules');
         $epconfig->save();
         if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) {
             $install->setValue($module . '.installed', 1, $entryPoint['id']);
             $install->setValue($module . '.version', $initialVersion, $entryPoint['id']);
         }
         if ($isdefault) {
             // we set the module as default module for one or all entry points.
             // we set the startModule option for all entry points except
             // if an entry point is indicated on the command line
             if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) {
                 if ($epconfig->getValue('startModule') != '') {
                     $epconfig->setValue('startModule', $module);
                     $epconfig->setValue('startAction', 'default:index');
                     $epconfig->save();
                 }
             }
         }
         if ($this->verbose()) {
             echo "The module is initialized for the entry point " . $entryPoint['file'] . ".\n";
         }
     }
     $install->save();
     // create a default controller
     if (!$this->getOption('-nocontroller')) {
         $agcommand = JelixScript::getCommand('createctrl', $this->config);
         $options = $this->getCommonActiveOption();
         if ($this->getOption('-cmdline')) {
             $options['-cmdline'] = true;
         }
         if ($this->getOption('-addinstallzone')) {
             $options['-addinstallzone'] = true;
         }
         $agcommand->initOptParam($options, array('module' => $module, 'name' => 'default', 'method' => 'index'));
         $agcommand->run();
     }
     if ($this->getOption('-admin')) {
         $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener");
         $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param);
         file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module);
         file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module);
     }
 }
Esempio n. 5
0
 protected function runPostInstall($installedModules, $ep, $flags)
 {
     $result = true;
     // post install
     foreach ($installedModules as $item) {
         try {
             list($installer, $component, $action) = $item;
             if ($action == Resolver::ACTION_INSTALL) {
                 if ($installer && $flags & self::FLAG_INSTALL_MODULE) {
                     $installer->postInstall();
                     $component->installFinished($ep);
                 }
             } else {
                 if ($action == Resolver::ACTION_UPGRADE) {
                     if ($flags & self::FLAG_UPGRADE_MODULE) {
                         foreach ($installer as $upgrader) {
                             $upgrader->postInstall();
                             $component->upgradeFinished($ep, $upgrader);
                         }
                     }
                 } elseif ($action == Resolver::ACTION_REMOVE) {
                     if ($installer && $flags & self::FLAG_REMOVE_MODULE) {
                         $installer->postUninstall();
                         $component->uninstallFinished($ep);
                     }
                 }
             }
             // we always save the configuration, so it invalidates the cache
             $ep->getConfigIni()->save();
             $this->xmlMapFile->save();
             // we re-load configuration file for each module because
             // previous module installer could have modify it.
             $compiler = new \Jelix\Core\Config\Compiler($ep->getConfigFile(), $ep->scriptName, $ep->isCliScript);
             $ep->setConfigObj($compiler->read(true));
             App::setConfig($ep->getConfigObj());
         } catch (Exception $e) {
             $result = false;
             $this->error($e->getLocaleKey(), $e->getLocaleParameters());
         } catch (\Exception $e) {
             $result = false;
             $this->error('install.module.error', array($component->getName(), $e->getMessage()));
         }
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * core of the installation
  * @param ModuleInstallLauncher[] $modules
  * @param EntryPoint $ep  the entrypoint
  * @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, EntryPoint $ep, $installWholeApp, $flags = 3)
 {
     $epId = $ep->getEpId();
     $this->notice('install.entrypoint.start', $epId);
     $ep = $this->entryPoints[$epId];
     App::setConfig($ep->getConfigObj());
     if ($ep->getConfigObj()->disableInstallers) {
         $this->notice('install.entrypoint.installers.disabled');
     }
     // first, check dependencies of the component, to have the list of component
     // we should really install.
     $orderedModules = $ep->getOrderedDependencies($modules, $this);
     if ($orderedModules === false) {
         $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();
     $result = true;
     foreach ($orderedModules 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->getConfigObj()->disableInstallers) {
                     $upgraders = array();
                 } else {
                     $upgraders = $component->getUpgraders($ep);
                     foreach ($upgraders as $upgrader) {
                         $upgrader->preInstall();
                     }
                 }
                 $componentsToInstall[] = array($upgraders, $component, false);
             } else {
                 if ($toInstall) {
                     if ($ep->getConfigObj()->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->getConfigObj()->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 (Exception $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->getConfigIni()->save();
             $this->xmlMapFile->save();
             // we re-load configuration file for each module because
             // previous module installer could have modify it.
             $compiler = new \Jelix\Core\Config\Compiler($ep->getConfigFile(), $ep->scriptName, $ep->isCliScript);
             $ep->setConfigObj($compiler->read(true));
             App::setConfig($ep->getConfigObj());
         }
     } catch (Exception $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->getConfigIni()->save();
             $this->xmlMapFile->save();
             // we re-load configuration file for each module because
             // previous module installer could have modify it.
             $compiler = new \Jelix\Core\Config\Compiler($ep->getConfigFile(), $ep->scriptName, $ep->isCliScript);
             $ep->setConfigObj($compiler->read(true));
             App::setConfig($ep->getConfigObj());
         } catch (Exception $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;
 }