/script/chamilo.php
PHP | 123 lines | 99 code | 24 blank | 0 comment | 4 complexity | 9bde354876f8df660179264167475bae MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
- <?php
-
- namespace script;
-
- use common\libraries\Path;
- use Console_Getopt;
- use install\CommandLineInstaller;
-
- require_once __DIR__ . '/bootstrap.php';
- require_once __DIR__ . '/../common/libraries/php/filesystem/path.class.php';
- require_once __DIR__ . '/../common/libraries/php/utilities.class.php';
-
- ini_set('include_path', realpath(Path :: get_plugin_path() . 'pear') . PATH_SEPARATOR . realpath(Path :: get_plugin_path() . 'google/library') . PATH_SEPARATOR . get_include_path());
-
-
- require_once 'Console/Getopt.php';
-
- spl_autoload_register('common\libraries\Utilities::autoload');
-
- $cg = new Console_Getopt();
- $args = $cg->readPHPArgv();
- ChamiloScript :: fire($args);
-
- class ChamiloScript
- {
-
- static function fire($args)
- {
- $script = new ChamiloScript($args);
- $script->run();
- }
-
- private $args;
-
- function __construct($args = array())
- {
- $this->args = $args;
- }
-
- public function run()
- {
- $command = '';
- if (isset($this->args[1]))
- {
- $command = $this->args[1];
- }
-
- switch ($command)
- {
- default :
- $this->usage();
- break;
- case 'install' :
- $this->install();
- break;
- case 'update-autoloader' :
- $this->update_autoloader();
- break;
- }
- }
-
- private function update_autoloader()
- {
- array_shift($this->args); // remove script name
- array_shift($this->args); // remove command flag
- $dir = reset($this->args);
- $dir = realpath(__DIR__ . '/../' . $dir);
- echo "process $dir \n";
-
- require_once __DIR__ . '/../common/libraries/php/util/various/autoloader_utilities.class.php';
- require_once __DIR__ . '/../common/libraries/php/util/various/code_utilities.class.php';
-
- set_time_limit(0);
- \common\libraries\AutoloaderUtilities :: synch($dir, $dir, true);
- echo "done $dir \n";
- }
-
- private function usage()
- {
- echo "USAGE : " . $this->args[0] . " [FLAG] \n" . "FLAG LIST : \n" . "\t usage \t\t\t\t\t\t: print this message\n" . "\t install [-c FILE | --configuration=FILE] \t: install chamilo according to config\n" . "\t update-autoloader PATH \t: update the autoloader of PATH \n";
- }
-
- private function install()
- {
- array_shift($this->args); // remove script name
- array_shift($this->args); // remove 'install' flag
- $shortOpts = "c:";
- $longOpts = array("configuration=");
- $options = $this->condense_arguments($shortOpts, $longOpts);
-
- if (! isset($options['c']) && ! isset($options['--configuration']))
- {
- echo 'Please provide a configuration file for the installer';
- return;
- }
-
- $config_file = isset($options['c']) ? $options['c'] : $options['--configuration'];
-
- $installer = new CommandLineInstaller($config_file);
- try
- {
- $installer->run();
- }
- catch (\Exception $e)
- {
- echo "Installation Failed !\n";
- echo $e->getMessage();
- }
- }
-
- private function condense_arguments($shortOpts, $longOpts)
- {
- $cg = new Console_Getopt();
- $params = $cg->getopt2($this->args, $shortOpts, $longOpts);
- $parsed = array();
- foreach ($params[0] as $param)
- {
- $parsed[$param[0]] = $param[1];
- }
- return $parsed;
- }
-
- }