Beispiel #1
0
 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.");
     }
 }
Beispiel #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);
     }
 }
Beispiel #3
0
 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');
 }