PageRenderTime 35ms CodeModel.GetById 3ms RepoModel.GetById 0ms app.codeStats 0ms

/script/chamilo.php

https://bitbucket.org/ywarnier/chamilo-dev
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
  1. <?php
  2. namespace script;
  3. use common\libraries\Path;
  4. use Console_Getopt;
  5. use install\CommandLineInstaller;
  6. require_once __DIR__ . '/bootstrap.php';
  7. require_once __DIR__ . '/../common/libraries/php/filesystem/path.class.php';
  8. require_once __DIR__ . '/../common/libraries/php/utilities.class.php';
  9. ini_set('include_path', realpath(Path :: get_plugin_path() . 'pear') . PATH_SEPARATOR . realpath(Path :: get_plugin_path() . 'google/library') . PATH_SEPARATOR . get_include_path());
  10. require_once 'Console/Getopt.php';
  11. spl_autoload_register('common\libraries\Utilities::autoload');
  12. $cg = new Console_Getopt();
  13. $args = $cg->readPHPArgv();
  14. ChamiloScript :: fire($args);
  15. class ChamiloScript
  16. {
  17. static function fire($args)
  18. {
  19. $script = new ChamiloScript($args);
  20. $script->run();
  21. }
  22. private $args;
  23. function __construct($args = array())
  24. {
  25. $this->args = $args;
  26. }
  27. public function run()
  28. {
  29. $command = '';
  30. if (isset($this->args[1]))
  31. {
  32. $command = $this->args[1];
  33. }
  34. switch ($command)
  35. {
  36. default :
  37. $this->usage();
  38. break;
  39. case 'install' :
  40. $this->install();
  41. break;
  42. case 'update-autoloader' :
  43. $this->update_autoloader();
  44. break;
  45. }
  46. }
  47. private function update_autoloader()
  48. {
  49. array_shift($this->args); // remove script name
  50. array_shift($this->args); // remove command flag
  51. $dir = reset($this->args);
  52. $dir = realpath(__DIR__ . '/../' . $dir);
  53. echo "process $dir \n";
  54. require_once __DIR__ . '/../common/libraries/php/util/various/autoloader_utilities.class.php';
  55. require_once __DIR__ . '/../common/libraries/php/util/various/code_utilities.class.php';
  56. set_time_limit(0);
  57. \common\libraries\AutoloaderUtilities :: synch($dir, $dir, true);
  58. echo "done $dir \n";
  59. }
  60. private function usage()
  61. {
  62. 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";
  63. }
  64. private function install()
  65. {
  66. array_shift($this->args); // remove script name
  67. array_shift($this->args); // remove 'install' flag
  68. $shortOpts = "c:";
  69. $longOpts = array("configuration=");
  70. $options = $this->condense_arguments($shortOpts, $longOpts);
  71. if (! isset($options['c']) && ! isset($options['--configuration']))
  72. {
  73. echo 'Please provide a configuration file for the installer';
  74. return;
  75. }
  76. $config_file = isset($options['c']) ? $options['c'] : $options['--configuration'];
  77. $installer = new CommandLineInstaller($config_file);
  78. try
  79. {
  80. $installer->run();
  81. }
  82. catch (\Exception $e)
  83. {
  84. echo "Installation Failed !\n";
  85. echo $e->getMessage();
  86. }
  87. }
  88. private function condense_arguments($shortOpts, $longOpts)
  89. {
  90. $cg = new Console_Getopt();
  91. $params = $cg->getopt2($this->args, $shortOpts, $longOpts);
  92. $parsed = array();
  93. foreach ($params[0] as $param)
  94. {
  95. $parsed[$param[0]] = $param[1];
  96. }
  97. return $parsed;
  98. }
  99. }