chamilo /script/chamilo.php

Language PHP Lines 124
MD5 Hash 62f04b727e76cd15914080b1b5f6c6bf Estimated Cost $2,357 (why?)
Repository https://bitbucket.org/cbenelug/chamilo View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php

namespace script;

use common\libraries\Path;
use Console_Getopt;
use install\CommandLineInstaller;

require_once __DIR__ . '/bootstrap.php';
require_once __DIR__ . '/../common/libraries/php/shared/filesystem/path.class.php';
require_once __DIR__ . '/../common/libraries/php/shared/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/shared/util/various/autoloader_utilities.class.php';
        require_once __DIR__ . '/../common/libraries/php/shared/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;
    }

}
Back to Top