Example #1
0
 public function run()
 {
     if (isset($this->_parameters['command'])) {
         if ($this->_parameters['command'] == 'help') {
             $command = $this;
         } else {
             $command = JelixScript::getCommand($this->_parameters['command'], $this->config, $this->getOption('-standalone'));
         }
         if ($this->config->helpLang == 'fr') {
             $this->disp("\nUtilisation de la commande " . $this->_parameters['command'] . " :\n");
         } else {
             $this->disp("\nUsage of " . $this->_parameters['command'] . ":\n");
         }
         $this->disp("# " . $_SERVER['argv'][0] . "  " . $this->_parameters['command'] . " " . $this->commonSyntaxOptions . $command->syntaxhelp . "\n\n");
         if (is_array($command->help)) {
             if (isset($command->help[$this->config->helpLang])) {
                 $this->disp($command->help[$this->config->helpLang]);
             } elseif (isset($command->help['en'])) {
                 $this->disp($command->help['en']);
             } else {
                 $this->disp(array_shift($command->help));
             }
         } else {
             $this->disp($command->help);
         }
         if (isset($this->commonOptionsHelp[$this->config->helpLang])) {
             $this->disp("\n" . $this->commonOptionsHelp[$this->config->helpLang]);
         } else {
             $this->disp("\n" . $this->commonOptionsHelp['en']);
         }
         $this->disp("\n\n");
     } else {
         if (isset($this->mainhelp[$this->config->helpLang])) {
             $help = $this->mainhelp[$this->config->helpLang];
         } else {
             $help = $this->mainhelp['en'];
         }
         $help = str_replace('%SCRIPT%', $_SERVER['argv'][0], $help);
         $this->disp($help);
         $list = JelixScript::commandList();
         sort($list);
         $l = '';
         foreach ($list as $k => $cmd) {
             if (($k + 1) % 6 == 0) {
                 $l .= $cmd . "\n\t";
             } else {
                 $l .= $cmd . ' ';
             }
         }
         $this->disp("{$l}\n\n");
     }
 }
Example #2
0
 /**
  * load the configuration of jelix-scripts
  * @param string $appname the application name
  * @return JelixScriptCommandConfig
  */
 static function loadConfig($appname = '')
 {
     $config = new JelixScriptCommandConfig();
     if ($appname == '') {
         $appname = $config->loadFromProject();
     }
     $home = '';
     if (isset($_SERVER['HOME'])) {
         $home = $_SERVER['HOME'];
     } else {
         if (isset($_ENV['HOME'])) {
             $home = $_ENV['HOME'];
         } else {
             if (isset($_SERVER['USERPROFILE'])) {
                 // windows
                 $home = $_SERVER['USERPROFILE'];
             } else {
                 if (isset($_SERVER['HOMEDRIVE']) && isset($_SERVER['HOMEPATH'])) {
                     // windows
                     $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
                 }
             }
         }
     }
     if ($home) {
         if (file_exists($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini')) {
             $config->loadFromIni($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini', $appname);
         } else {
             $config->loadFromIni($home . DIRECTORY_SEPARATOR . 'jelix-scripts.ini', $appname);
         }
         // windows users doesn't often use dot files.
     }
     self::$debugMode = $config->debugMode;
     if (function_exists('date_default_timezone_set')) {
         date_default_timezone_set($config->infoTimezone);
     }
     $config->appName = $appname;
     return $config;
 }
Example #3
0
 public function run()
 {
     $this->loadAppConfig();
     global $gJConfig;
     $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 = str_replace(array('lib:', 'app:'), array(LIB_PATH, jApp::appPath()), $repository);
     $iniDefault = new jIniFileModifier(jApp::configPath('defaultconfig.ini.php'));
     $this->updateModulePath($iniDefault, $iniDefault->getValue('modulesPath'), $repository, $repositoryPath);
     if (!$this->allEntryPoint) {
         $list = $this->getEntryPointsList();
         foreach ($list as $k => $entryPoint) {
             if ($entryPoint['file'] == $this->entryPointName) {
                 $ini = new jIniFileModifier(jApp::configPath($entryPoint['config']));
                 break;
             }
         }
         if (!$ini) {
             throw new Exception("entry point is unknown");
         }
         $this->updateModulePath($ini, $gJConfig->modulesPath, $repository, $repositoryPath);
     }
     $path = $repositoryPath . $module . '/';
     $this->createDir($path);
     $gJConfig = null;
     if ($this->getOption('-admin')) {
         $this->removeOption('-nosubdir');
         $this->removeOption('-addinstallzone');
     }
     $param = array();
     $param['module'] = $module;
     $param['default_id'] = $module . $this->config->infoIDSuffix;
     $param['version'] = $initialVersion;
     $this->createFile($path . 'module.xml', 'module/module.xml.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_EN/');
         $this->createDir($path . 'locales/fr_FR/');
         $this->createDir($path . 'install/');
         $this->createFile($path . 'install/install.php', 'module/install.tpl', $param);
     }
     $isdefault = $this->getOption('-defaultmodule');
     // activate the module in the application
     if ($isdefault) {
         $iniDefault->setValue('startModule', $module);
         $iniDefault->setValue('startAction', 'default:index');
     }
     $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules');
     $iniDefault->save();
     $list = $this->getEntryPointsList();
     $install = new jIniFileModifier(jApp::configPath('installer.ini.php'));
     // install the module for all needed entry points
     foreach ($list as $k => $entryPoint) {
         $configFile = jApp::configPath($entryPoint['config']);
         $epconfig = new jIniFileModifier($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();
                 }
             }
         }
     }
     $install->save();
     // create a default controller
     if (!$this->getOption('-nocontroller')) {
         $agcommand = JelixScript::getCommand('createctrl', $this->config);
         $options = array();
         if ($this->getOption('-cmdline')) {
             $options = array('-cmdline' => true);
         }
         if ($this->getOption('-addinstallzone')) {
             $options = array('-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);
         $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param);
         file_put_contents($path . 'locales/en_EN/interface.UTF-8.properties', 'menu.item=' . $module);
         file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module);
     }
 }
Example #4
0
}
// ------------- retrieve the name of the jelix command
if ($_SERVER['argc'] < 2) {
    echo "Error: command is missing. See '" . $_SERVER['argv'][0] . " help'.\n";
    exit(1);
}
$argv = $_SERVER['argv'];
$scriptName = array_shift($argv);
// shift the script name
$commandName = array_shift($argv);
// get the command name
// ------------ load the config and retrieve the command object
require JELIX_SCRIPTS_PATH . 'includes/JelixScript.class.php';
set_error_handler('JelixScript::errorHandler');
set_exception_handler('JelixScript::exceptionHandler');
$config = JelixScript::loadConfig();
$command = JelixScript::getCommand($commandName, $config);
if (!\Jelix\Core\App::isInit()) {
    echo "Error: should run within an application\n";
    exit(1);
}
if ($command->applicationRequirement == JelixScriptCommand::APP_MUST_NOT_EXIST) {
    echo "Error: This command doesn't apply on an existing application\n";
    exit(1);
}
\Jelix\Core\App::setEnv('jelix-scripts');
JelixScript::checkTempPath();
// --------- launch the command now
$command->init($argv);
$command->run();
exit(0);
Example #5
0
 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->projectXml = 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 jIniFileModifier(jApp::configPath('installer.ini.php'));
     $inifile = new jIniMultiFilesModifier(jApp::configPath('defaultconfig.ini.php'), jApp::configPath($ep['config']));
     $params = array();
     $this->createFile(jApp::appPath('responses/adminHtmlResponse.class.php'), 'responses/adminHtmlResponse.class.php.tpl', $params);
     $this->createFile(jApp::appPath('responses/adminLoginHtmlResponse.class.php'), 'responses/adminLoginHtmlResponse.class.php.tpl', $params);
     $inifile->setValue('html', 'adminHtmlResponse', 'responses');
     $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses');
     $inifile->setValue('startModule', 'master_admin');
     $inifile->setValue('startAction', 'default:index');
     $modulePath = $inifile->getValue("modulesPath", 0, null, true);
     if (strpos($modulePath, 'lib:jelix-admin-modules') === false) {
         // we set it on defaultconfig.ini.php, so if the url engine is "significant"
         // it could know the admin modules during the parsing of modules
         $inifile->setValue('modulesPath', 'lib:jelix-admin-modules/,' . $modulePath, 0, null, true);
     }
     $installConfig->setValue('jacldb.installed', '0', $entrypoint);
     $inifile->setValue('jacldb.access', '0', 'modules');
     $installConfig->setValue('junittests.installed', '0', $entrypoint);
     $inifile->setValue('junittests.access', '0', 'modules');
     $installConfig->setValue('jWSDL.installed', '0', $entrypoint);
     $inifile->setValue('jWSDL.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', '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', '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';
         }
         $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();
     require_once JELIX_LIB_PATH . 'installer/jInstaller.class.php';
     $verbose = $this->getOption("-v");
     $reporter = new textInstallReporter($verbose ? 'notice' : 'warning');
     $installer = new jInstaller($reporter);
     $installer->installModules(array('master_admin'), $entrypoint . '.php');
     $authini = new jIniFileModifier(jApp::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 jIniFileModifier(jApp::configPath('profiles.ini.php'));
             $dbini->setValue('jacl2_profile', $profile, 'jdb');
             $dbini->save();
         }
         $installer = new jInstaller($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();
     }
 }
Example #6
0
 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');
 }
Example #7
0
 /**
  * load the configuration of jelix-scripts
  * @param string $appname the application name
  * @return JelixScriptCommandConfig
  */
 static function loadConfig($appname = '')
 {
     $config = new JelixScriptCommandConfig();
     if ($appname === '') {
         $appname = $config->loadFromProject();
     } else {
         if ($appname === false) {
             // don't load from project..
             $appname = '';
         }
     }
     // try to find a .jelix-scripts.ini in the current directory or parent directories
     $dir = getcwd();
     $found = false;
     do {
         if (file_exists($dir . DIRECTORY_SEPARATOR . '.jelix-scripts.ini')) {
             $config->loadFromIni($dir . DIRECTORY_SEPARATOR . '.jelix-scripts.ini', $appname);
             $found = true;
         } else {
             if (file_exists($dir . DIRECTORY_SEPARATOR . 'jelix-scripts.ini')) {
                 $config->loadFromIni($dir . DIRECTORY_SEPARATOR . 'jelix-scripts.ini', $appname);
                 // windows users don't often use dot files.
                 $found = true;
             }
         }
         $previousdir = $dir;
         $dir = dirname($dir);
     } while ($dir != '.' && $dir != $previousdir && !$found);
     // we didn't find a .jelix-scripts, try to read one from the home directory
     if (!$found) {
         $home = '';
         if (isset($_SERVER['HOME'])) {
             $home = $_SERVER['HOME'];
         } else {
             if (isset($_ENV['HOME'])) {
                 $home = $_ENV['HOME'];
             } else {
                 if (isset($_SERVER['USERPROFILE'])) {
                     // windows
                     $home = $_SERVER['USERPROFILE'];
                 } else {
                     if (isset($_SERVER['HOMEDRIVE']) && isset($_SERVER['HOMEPATH'])) {
                         // windows
                         $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
                     }
                 }
             }
         }
         if ($home) {
             if (file_exists($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini')) {
                 $config->loadFromIni($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini', $appname);
             } else {
                 $config->loadFromIni($home . DIRECTORY_SEPARATOR . 'jelix-scripts.ini', $appname);
             }
             // windows users don't often use dot files.
         }
     }
     self::$debugMode = $config->debugMode;
     if (function_exists('date_default_timezone_set')) {
         date_default_timezone_set($config->infoTimezone);
     }
     $config->appName = $appname;
     return $config;
 }
Example #8
0
*/
// caller script should setup :
// $commandName
error_reporting(E_ALL);
define('JELIX_SCRIPTS_PATH', dirname(__FILE__) . '/../');
if (PHP_SAPI != 'cli') {
    echo "You must use the CLI version of PHP, not the " . PHP_SAPI . " version\n";
    exit(1);
}
// ------------- retrieve the name of the jelix command
$argv = $_SERVER['argv'];
$scriptName = array_shift($argv);
// shift the script name
// ------------ load the config and retrieve the command object
require JELIX_SCRIPTS_PATH . '../jelix/init.php';
require JELIX_SCRIPTS_PATH . 'includes/JelixScript.class.php';
set_error_handler('JelixScriptsErrorHandler');
set_exception_handler('JelixScriptsExceptionHandler');
$command = JelixScript::getCommand($commandName, null, true);
if (jApp::isInit()) {
    echo "Error: shouldn't run within an application\n";
    exit(1);
}
if ($command->applicationRequirement == JelixScriptCommand::APP_MUST_EXIST) {
    echo "Error: This command needs an existing application\n";
    exit(1);
}
// --------- launch the command now
$command->init($argv);
$command->run();
exit(0);
 public function run()
 {
     $this->loadAppConfig();
     $module = $this->_parameters['module'];
     $path = $this->getModulePath($module);
     $table = $this->getParam('table');
     $ctrlname = $this->getParam('ctrlname', $table);
     $acl2 = $this->getOption('-acl2');
     if (file_exists($path . 'controllers/' . $ctrlname . '.classic.php')) {
         throw new Exception("controller '" . $ctrlname . "' already exists");
     }
     $agcommand = JelixScript::getCommand('createdao', $this->config);
     $options = $this->getCommonActiveOption();
     $profile = '';
     if ($this->getOption('-profile')) {
         $profile = $this->getOption('-profile');
         $options['-profile'] = $profile;
     }
     $agcommand->initOptParam($options, array('module' => $module, 'name' => $table, 'table' => $table));
     $agcommand->run();
     $agcommand = JelixScript::getCommand('createform', $this->config);
     $options = $this->getCommonActiveOption();
     if ($this->getOption('-createlocales')) {
         $options['-createlocales'] = true;
     }
     $agcommand->initOptParam($options, array('module' => $module, 'form' => $table, 'dao' => $table));
     $agcommand->run();
     $acl2rights = '';
     $pluginsParameters = "\n                '*'          =>array('auth.required'=>true),\n                'index'      =>array('jacl2.right'=>'{$module}.{$ctrlname}.view'),\n                'precreate'  =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n                'create'     =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n                'savecreate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n                'preupdate'  =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n                'editupdate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n                'saveupdate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n                'view'       =>array('jacl2.right'=>'{$module}.{$ctrlname}.view'),\n                'delete'     =>array('jacl2.right'=>'{$module}.{$ctrlname}.delete')";
     if ($acl2) {
         $subjects = array('view' => 'View', 'create' => 'Create', 'update' => 'Update', 'delete' => 'Delete');
         $sel = $this->getOption('-acl2locale');
         if (!$sel) {
             $sel = $module . '~acl' . $ctrlname;
         }
         foreach ($subjects as $subject => $label) {
             $subject = $module . "." . $ctrlname . "." . $subject;
             $labelkey = $sel . '.' . $subject;
             try {
                 $options = $this->getCommonActiveOption();
                 $agcommand = JelixScript::getCommand('acl2right', $this->config);
                 $agcommand->initOptParam($options, array('action' => 'subject_create', '...' => array($subject, $labelkey, 'null', $label . ' ' . $ctrlname)));
                 $agcommand->run();
             } catch (Exception $e) {
             }
         }
     } else {
         $pluginsParameters = "/*" . $pluginsParameters . "\n*/";
     }
     $this->createDir($path . 'controllers/');
     $params = array('name' => $ctrlname, 'module' => $module, 'table' => $table, 'profile' => $profile, 'acl2rights' => $pluginsParameters);
     $this->createFile($path . 'controllers/' . $ctrlname . '.classic.php', 'module/controller.daocrud.tpl', $params, "Controller");
     if ($this->getOption('-masteradmin')) {
         if ($acl2) {
             $params['checkacl2'] = "if(jAcl2::check('{$module}.{$ctrlname}.view'))";
         } else {
             $params['checkacl2'] = '';
         }
         $this->createFile($path . 'classes/' . $ctrlname . 'menu.listener.php', 'module/masteradminmenu.listener.php.tpl', $params, "Listener");
         if (file_exists($path . 'events.xml')) {
             $xml = simplexml_load_file($path . 'events.xml');
             $xml->registerXPathNamespace('j', 'http://jelix.org/ns/events/1.0');
             $listenerPath = "j:listener[@name='" . $ctrlname . "menu']";
             $eventPath = "j:event[@name='masteradminGetMenuContent']";
             if (!($event = $xml->xpath("//{$listenerPath}/{$eventPath}"))) {
                 if ($listeners = $xml->xpath("//{$listenerPath}")) {
                     $listener = $listeners[0];
                 } else {
                     $listener = $xml->addChild('listener');
                     $listener->addAttribute('name', $ctrlname . 'menu');
                 }
                 $event = $listener->addChild('event');
                 $event->addAttribute('name', 'masteradminGetMenuContent');
                 $result = $xml->asXML($path . 'events.xml');
                 if ($this->verbose() && $result) {
                     echo "Events.xml in module '" . $this->_parameters['module'] . "' has been updated.\n";
                 } else {
                     if (!$result) {
                         echo "Warning: events.xml in module '" . $this->_parameters['module'] . "' cannot be updated, check permissions or add the event manually.\n";
                     }
                 }
             } else {
                 if ($this->verbose()) {
                     echo "events.xml in module '" . $this->_parameters['module'] . "' is already updated.\n";
                 }
             }
         } else {
             $this->createFile($path . 'events.xml', 'module/events_crud.xml.tpl', array('classname' => $ctrlname . 'menu'));
         }
     }
     if (jApp::config()->urlengine['engine'] == 'significant') {
         if (!file_exists($path . 'urls.xml')) {
             $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array());
             if ($this->verbose()) {
                 echo "Notice: you should link the urls.xml of the module " . $this->_parameters['module'] . "', into the urls.xml in var/config.\n";
             }
         }
         $xml = simplexml_load_file($path . 'urls.xml');
         $xml->registerXPathNamespace('j', 'http://jelix.org/ns/suburls/1.0');
         // if the url already exists, let's try an other
         $count = 0;
         $urlXPath = "//j:url[@pathinfo='/" . $ctrlname . "/']";
         while ($url = $xml->xpath("//{$urlXPath}")) {
             $count++;
             $urlXPath = "//j:url[@pathinfo='/" . $ctrlname . "-" . $count . "/']";
         }
         if ($count == 0) {
             $urlPath = "/" . $ctrlname . "/";
         } else {
             $urlPath = "/" . $ctrlname . "-" . $count . "/";
         }
         /*
          
          <url pathinfo="/thedata/" action="mycrud:index" />
         <url pathinfo="/thedata/view/:id" action="mycrud:view" />
         <url pathinfo="/thedata/precreate" action="mycrud:precreate" />
         <url pathinfo="/thedata/create" action="mycrud:create" />
         <url pathinfo="/thedata/savecreate" action="mycrud:savecreate" />
         <url pathinfo="/thedata/preedit/:id" action="mycrud:preupdate" />
         <url pathinfo="/thedata/edit/:id" action="mycrud:editupdate" />
         <url pathinfo="/thedata/save/:id" action="mycrud:saveupdate" />
         <url pathinfo="/thedata/delete/:id" action="mycrud:delete" />
         */
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath);
         $url->addAttribute('action', $ctrlname . ':index');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "view/:id");
         $url->addAttribute('action', $ctrlname . ':view');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "precreate");
         $url->addAttribute('action', $ctrlname . ':precreate');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "create");
         $url->addAttribute('action', $ctrlname . ':create');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "savecreate");
         $url->addAttribute('action', $ctrlname . ':savecreate');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "preedit/:id");
         $url->addAttribute('action', $ctrlname . ':preupdate');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "edit/:id");
         $url->addAttribute('action', $ctrlname . ':editupdate');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "save/:id");
         $url->addAttribute('action', $ctrlname . ':saveupdate');
         $url = $xml->addChild('url');
         $url->addAttribute('pathinfo', $urlPath . "delete/:id");
         $url->addAttribute('action', $ctrlname . ':delete');
         $result = $xml->asXML($path . 'urls.xml');
         if ($this->verbose() && $result) {
             echo "urls.xml in module '" . $this->_parameters['module'] . "' has been updated.\n";
         } else {
             if (!$result) {
                 echo "Warning: urls.xml in module '" . $this->_parameters['module'] . "' cannot be updated, check permissions or add the urls manually.\n";
             }
         }
     }
 }
Example #10
0
 public function run()
 {
     $this->loadAppConfig();
     global $gJConfig;
     $module = $this->_parameters['module'];
     $path = $this->getModulePath($module);
     $table = $this->getParam('table');
     $ctrlname = $this->getParam('ctrlname', $table);
     $acl2 = $this->getOption('-acl2');
     if (file_exists($path . 'controllers/' . $ctrlname . '.classic.php')) {
         throw new Exception("controller '" . $ctrlname . "' already exists");
     }
     $agcommand = JelixScript::getCommand('createdao', $this->config);
     $options = array();
     $profile = '';
     if ($this->getOption('-profile')) {
         $profile = $this->getOption('-profile');
         $options = array('-profile' => $profile);
     }
     $agcommand->initOptParam($options, array('module' => $module, 'name' => $table, 'table' => $table));
     $agcommand->run();
     $agcommand = JelixScript::getCommand('createform', $this->config);
     if ($this->getOption('-createlocales')) {
         $options = array('-createlocales' => true);
     } else {
         $options = array();
     }
     $agcommand->initOptParam($options, array('module' => $module, 'form' => $table, 'dao' => $table));
     $agcommand->run();
     $acl2rights = '';
     $pluginsParameters = "\n                '*'          =>array('auth.required'=>true),\n                'index'      =>array('jacl2.right'=>'{$module}.{$ctrlname}.view'),\n                'precreate'  =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n                'create'     =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n                'savecreate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.create'),\n                'preupdate'  =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n                'editupdate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n                'saveupdate' =>array('jacl2.right'=>'{$module}.{$ctrlname}.update'),\n                'view'       =>array('jacl2.right'=>'{$module}.{$ctrlname}.view'),\n                'delete'     =>array('jacl2.right'=>'{$module}.{$ctrlname}.delete')";
     if ($acl2) {
         $subjects = array('view' => 'View', 'create' => 'Create', 'update' => 'Update', 'delete' => 'Delete');
         $sel = $this->getOption('-acl2locale');
         if (!$sel) {
             $sel = $module . '~acl' . $ctrlname;
         }
         foreach ($subjects as $subject => $label) {
             $subject = $module . "." . $ctrlname . "." . $subject;
             $labelkey = $sel . '.' . $subject;
             try {
                 $agcommand = JelixScript::getCommand('acl2right', $this->config);
                 $agcommand->initOptParam(array(), array('action' => 'subject_create', '...' => array($subject, $labelkey, 'null', $label . ' ' . $ctrlname)));
                 $agcommand->run();
             } catch (Exception $e) {
             }
         }
     } else {
         $pluginsParameters = "/*" . $pluginsParameters . "\n*/";
     }
     $this->createDir($path . 'controllers/');
     $params = array('name' => $ctrlname, 'module' => $module, 'table' => $table, 'profile' => $profile, 'acl2rights' => $pluginsParameters);
     $this->createFile($path . 'controllers/' . $ctrlname . '.classic.php', 'module/controller.daocrud.tpl', $params);
     if ($this->getOption('-masteradmin')) {
         if ($acl2) {
             $params['checkacl2'] = "if(jAcl2::check('{$module}.{$ctrlname}.view'))";
         } else {
             $params['checkacl2'] = '';
         }
         $this->createFile($path . 'classes/' . $ctrlname . 'menu.listener.php', 'module/masteradminmenu.listener.php.tpl', $params);
         if (file_exists($path . 'events.xml')) {
             $xml = simplexml_load_file($path . 'events.xml');
             $xml->registerXPathNamespace('j', 'http://jelix.org/ns/events/1.0');
             $listenerPath = "j:listener[@name='" . $ctrlname . "menu']";
             $eventPath = "j:event[@name='masteradminGetMenuContent']";
             if (!($event = $xml->xpath("//{$listenerPath}/{$eventPath}"))) {
                 if ($listeners = $xml->xpath("//{$listenerPath}")) {
                     $listener = $listeners[0];
                 } else {
                     $listener = $xml->addChild('listener');
                     $listener->addAttribute('name', $ctrlname . 'menu');
                 }
                 $event = $listener->addChild('event');
                 $event->addAttribute('name', 'masteradminGetMenuContent');
                 $result = $xml->asXML($path . 'events.xml');
                 if ($result) {
                     echo "Notice: events.xml in module '" . $this->_parameters['module'] . "' has been updated.\n";
                 } else {
                     echo "Warning: events.xml in module '" . $this->_parameters['module'] . "' cannot be updated, check permissions or add the event manually.\n";
                 }
             } else {
                 echo "Notice: events.xml in module '" . $this->_parameters['module'] . "' is already up to date.\n";
             }
         } else {
             $this->createFile($path . 'events.xml', 'module/events_crud.xml.tpl', array('classname' => $ctrlname . 'menu'));
             echo "Notice: events.xml in module '" . $this->_parameters['module'] . "' has been created.\n";
         }
     }
 }
Example #11
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);
     }
 }
Example #12
0
 public function run()
 {
     require_once LIB_PATH . 'clearbricks/jelix.inc.php';
     require_once JELIX_LIB_PATH . 'installer/jInstaller.class.php';
     $appPath = $this->getParam('path');
     $appPath = $this->getRealPath($appPath);
     $appName = basename($appPath);
     $appPath .= '/';
     if (file_exists($appPath)) {
         throw new Exception("this application is already created");
     }
     $this->config = JelixScript::loadConfig($appName);
     $this->config->infoIDSuffix = $this->config->newAppInfoIDSuffix;
     $this->config->infoWebsite = $this->config->newAppInfoWebsite;
     $this->config->infoLicence = $this->config->newAppInfoLicence;
     $this->config->infoLicenceUrl = $this->config->newAppInfoLicenceUrl;
     $this->config->newAppInfoLocale = $this->config->newAppInfoLocale;
     $this->config->newAppInfoCopyright = $this->config->newAppInfoCopyright;
     $this->config->initAppPaths($appPath);
     jApp::setEnv('jelix-scripts');
     jApp::initLegacy();
     JelixScript::checkTempPath();
     if ($p = $this->getOption('-wwwpath')) {
         $wwwpath = path::real($appPath . $p, false) . '/';
     } else {
         $wwwpath = jApp::wwwPath();
     }
     $this->createDir($appPath);
     $this->createDir(jApp::tempBasePath());
     $this->createDir($wwwpath);
     $varPath = jApp::varPath();
     $configPath = jApp::configPath();
     $this->createDir($varPath);
     $this->createDir(jApp::logPath());
     $this->createDir($configPath);
     $this->createDir($configPath . 'index/');
     $this->createDir($varPath . 'overloads/');
     $this->createDir($varPath . 'themes/');
     $this->createDir($varPath . '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($appPath . 'plugins/coord/');
     $this->createDir($appPath . 'plugins/tpl/');
     $this->createDir($appPath . 'plugins/tpl/common');
     $this->createDir($appPath . 'plugins/tpl/html');
     $this->createDir($appPath . 'plugins/tpl/text');
     $this->createDir($appPath . 'plugins/db/');
     $this->createDir($appPath . 'plugins/auth/');
     $this->createDir($appPath . 'responses');
     $this->createDir($appPath . 'tests');
     $this->createDir(jApp::scriptsPath());
     $param = array();
     $param['default_id'] = $appName . $this->config->infoIDSuffix;
     if ($this->getOption('-nodefaultmodule')) {
         $param['tplname'] = 'jelix~defaultmain';
         $param['modulename'] = 'jelix';
     } else {
         // note: since module name are used for name of generated name,
         // only this characters are allowed
         $param['modulename'] = preg_replace('/([^a-zA-Z_0-9])/', '_', $appName);
         $param['tplname'] = $param['modulename'] . '~main';
     }
     $param['config_file'] = 'index/config.ini.php';
     $param['rp_temp'] = $this->getRelativePath($appPath, jApp::tempBasePath());
     $param['rp_var'] = $this->getRelativePath($appPath, jApp::varPath());
     $param['rp_log'] = $this->getRelativePath($appPath, jApp::logPath());
     $param['rp_conf'] = $this->getRelativePath($appPath, $configPath);
     $param['rp_www'] = $this->getRelativePath($appPath, $wwwpath);
     $param['rp_cmd'] = $this->getRelativePath($appPath, jApp::scriptsPath());
     $param['rp_jelix'] = $this->getRelativePath($appPath, JELIX_LIB_PATH);
     $param['rp_app'] = $this->getRelativePath($wwwpath, $appPath);
     $this->createFile($appPath . '.htaccess', 'htaccess_deny', $param);
     $this->createFile($appPath . 'project.xml', 'project.xml.tpl', $param);
     $this->createFile($appPath . 'cmd.php', 'cmd.php.tpl', $param);
     $this->createFile($configPath . 'defaultconfig.ini.php', 'var/config/defaultconfig.ini.php.tpl', $param);
     $this->createFile($configPath . 'profiles.ini.php', 'var/config/profiles.ini.php.tpl', $param);
     $this->createFile($configPath . 'urls.xml', 'var/config/urls.xml.tpl', $param);
     //$this->createFile(JELIX_APP_CONFIG_PATH.'installer.ini.php', 'var/config/installer.ini.php.tpl', $param);
     $this->createFile($configPath . 'index/config.ini.php', 'var/config/index/config.ini.php.tpl', $param);
     $this->createFile($appPath . 'responses/myHtmlResponse.class.php', 'responses/myHtmlResponse.class.php.tpl', $param);
     $this->createFile($appPath . 'install/installer.php', 'installer/installer.php.tpl', $param);
     $this->createFile($appPath . 'tests/runtests.php', 'tests/runtests.php', $param);
     $this->createFile($wwwpath . 'index.php', 'www/index.php.tpl', $param);
     $this->createFile($wwwpath . '.htaccess', 'htaccess_allow', $param);
     $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']);
     $this->createFile($appPath . 'application.init.php', 'application.init.php.tpl', $param);
     $installer = new jInstaller(new textInstallReporter('warning'));
     $installer->installApplication();
     $moduleok = true;
     if (!$this->getOption('-nodefaultmodule')) {
         try {
             $cmd = JelixScript::getCommand('createmodule', $this->config);
             $cmd->initOptParam(array('-addinstallzone' => true), array('module' => $param['modulename']));
             $cmd->run();
             $this->createFile($appPath . 'modules/' . $param['modulename'] . '/templates/main.tpl', 'module/main.tpl.tpl', $param);
         } catch (Exception $e) {
             $moduleok = false;
             echo "The module has not been created because of this error: " . $e->getMessage() . "\nHowever the application has been created\n";
         }
     }
     if ($this->getOption('-withcmdline')) {
         if (!$this->getOption('-nodefaultmodule') && $moduleok) {
             $agcommand = JelixScript::getCommand('createctrl', $this->config);
             $options = array('-cmdline' => true);
             $agcommand->initOptParam($options, array('module' => $param['modulename'], 'name' => 'default', 'method' => 'index'));
             $agcommand->run();
         }
         $agcommand = JelixScript::getCommand('createentrypoint', $this->config);
         $options = array('-type' => 'cmdline');
         $parameters = array('name' => $param['modulename']);
         $agcommand->initOptParam($options, $parameters);
         $agcommand->run();
     }
 }
Example #13
-1
 public function run()
 {
     $appPath = $this->getParam('path');
     $appPath = $this->getRealPath($appPath);
     $appName = basename($appPath);
     $appPath .= '/';
     if (file_exists($appPath . '/jelix-app.json') || file_exists($appPath . '/project.xml')) {
         throw new Exception("this application is already created");
     }
     $this->config = JelixScript::loadConfig($appName);
     $this->config->infoWebsite = $this->config->newAppInfoWebsite;
     $this->config->infoLicence = $this->config->newAppInfoLicence;
     $this->config->infoLicenceUrl = $this->config->newAppInfoLicenceUrl;
     $this->config->infoLocale = $this->config->newAppInfoLocale;
     $this->config->infoCopyright = $this->config->newAppInfoCopyright;
     $this->config->initAppPaths($appPath);
     App::setEnv('jelix-scripts');
     JelixScript::checkTempPath();
     if ($p = $this->getOption('-wwwpath')) {
         $wwwpath = path::real($appPath . $p, false) . '/';
     } else {
         $wwwpath = App::wwwPath();
     }
     $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($configPath);
     $this->createDir($configPath . 'index/');
     $this->createDir($varPath . 'overloads/');
     $this->createDir($varPath . 'themes/');
     $this->createDir($varPath . '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($appPath . 'responses');
     $this->createDir($appPath . 'tests');
     $this->createDir(App::scriptsPath());
     $param = array();
     if ($this->getOption('-nodefaultmodule')) {
         $param['tplname'] = 'jelix~defaultmain';
         $param['modulename'] = 'jelix';
     } else {
         $moduleName = $this->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'] = $this->getRelativePath($appPath, App::tempBasePath());
     $param['rp_var'] = $this->getRelativePath($appPath, App::varPath());
     $param['rp_log'] = $this->getRelativePath($appPath, App::logPath());
     $param['rp_conf'] = $this->getRelativePath($appPath, $configPath);
     $param['rp_www'] = $this->getRelativePath($appPath, $wwwpath);
     $param['rp_cmd'] = $this->getRelativePath($appPath, App::scriptsPath());
     $param['rp_jelix'] = $this->getRelativePath($appPath, JELIX_LIB_PATH);
     $param['rp_vendor'] = '';
     foreach (array(LIB_PATH . 'vendor/', LIB_PATH . '../vendor/', LIB_PATH . '../../../') as $path) {
         if (file_exists($path)) {
             $param['rp_vendor'] = $this->getRelativePath($appPath, realpath($path) . '/');
             break;
         }
     }
     $param['rp_app'] = $this->getRelativePath($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::varPath() . 'overloads/.dummy', 'dummy.tpl', array());
     $this->createFile(App::varPath() . '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($configPath . 'mainconfig.ini.php', 'var/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($configPath . 'urls.xml', 'var/config/urls.xml.tpl', $param, "URLs mapping file");
     $this->createFile($configPath . 'index/config.ini.php', 'var/config/index/config.ini.php.tpl', $param, "Entry point configuration file");
     $this->createFile($appPath . 'responses/myHtmlResponse.class.php', '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");
     }
     $installer = new \Jelix\Installer\Installer(new \Jelix\Installer\Reporter\Console('warning'));
     $installer->installApplication();
     $moduleok = true;
     if (!$this->getOption('-nodefaultmodule')) {
         try {
             $cmd = JelixScript::getCommand('createmodule', $this->config);
             $options = $this->getCommonActiveOption();
             $options['-addinstallzone'] = true;
             $options['-noregistration'] = true;
             $cmd->initOptParam($options, array('module' => $param['modulename']));
             $cmd->run();
             $this->createFile($appPath . 'modules/' . $param['modulename'] . '/templates/main.tpl', 'module/main.tpl.tpl', $param, "Main template");
         } catch (Exception $e) {
             $moduleok = false;
             echo "The module has not been created because of this error: " . $e->getMessage() . "\nHowever the application has been created\n";
         }
     }
     if ($this->getOption('-withcmdline')) {
         if (!$this->getOption('-nodefaultmodule') && $moduleok) {
             $agcommand = JelixScript::getCommand('createctrl', $this->config);
             $options = $this->getCommonActiveOption();
             $options['-cmdline'] = true;
             $agcommand->initOptParam($options, array('module' => $param['modulename'], 'name' => 'default', 'method' => 'index'));
             $agcommand->run();
         }
         $agcommand = JelixScript::getCommand('createentrypoint', $this->config);
         $options = $this->getCommonActiveOption();
         $options['-type'] = 'cmdline';
         $parameters = array('name' => $param['modulename']);
         $agcommand->initOptParam($options, $parameters);
         $agcommand->run();
     }
 }