PageRenderTime 73ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/script/chamilo.php

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