Exakat\Tasks\Update::run PHP Method

run() public method

public run ( )
    public function run()
    {
        if ($this->config->project === 'default') {
            throw new ProjectNeeded();
        }
        $path = $this->config->projects_root . '/projects/' . $this->config->project;
        if (!file_exists($path)) {
            throw new NoSuchProject($this->config->project);
        }
        if (!file_exists($path . '/code')) {
            throw new NoCodeInProject($this->config->project);
        }
        switch (true) {
            // symlink case
            case $this->config->project_vcs === 'symlink':
                // Nothing to do, the symlink is here for that
                break;
                // copy case
            // copy case
            case $this->config->project_vcs === 'copy':
                // Remove and copy again
                $total = rmdirRecursive($this->config->projects_root . '/projects/' . $this->config->project . '/code/');
                display("{$total} files were removed");
                $total = copyDir(realpath($this->config->project_url), $this->config->projects_root . '/projects/' . $this->config->project . '/code');
                display("{$total} files were copied");
                break;
                // Git case
            // Git case
            case file_exists($path . '/code/.git'):
                display('Git pull for ' . $this->config->project);
                $res = shell_exec('cd ' . $path . '/code/; git branch | grep \\*');
                $branch = substr(trim($res), 2);
                $resInitial = shell_exec('cd ' . $path . '/code/; git show-ref --heads ' . $branch);
                $date = trim(shell_exec('cd ' . $path . '/code/; git pull --quiet; git log -1 --format=%cd '));
                $resFinal = shell_exec('cd ' . $path . '/code/; git show-ref --heads ' . $branch);
                if ($resFinal != $resInitial) {
                    display("Git updated to commit {$res} (Last commit : {$date})");
                } else {
                    display("No update available (Last commit : {$date})");
                }
                break;
                // svn case
            // svn case
            case file_exists($path . '/code/.svn'):
                display('SVN update ' . $this->config->project);
                $res = shell_exec('cd ' . $path . '/code/; svn update');
                preg_match('/At revision (\\d+)/', $res, $r);
                display("SVN updated to revision {$r['1']}");
                break;
                // bazaar case
            // bazaar case
            case file_exists($path . '/code/.bzr'):
                display('Bazaar update ' . $this->config->project);
                $res = shell_exec('cd ' . $path . '/code/; bzr update 2>&1');
                preg_match('/revision (\\d+)/', $res, $r);
                display("Bazaar updated to revision {$r['1']}");
                break;
                // composer case
            // composer case
            case $this->config->project_vcs === 'composer':
                display('Composer update ' . $this->config->project);
                $res = shell_exec('cd ' . $path . '/code/; composer install ');
                $json = file_get_contents($path . '/code/composer.lock');
                $json = json_decode($json);
                foreach ($json->packages as $package) {
                    if ($package->name == $this->config->project_url) {
                        display("Composer updated to revision " . $package->source->reference . ' ( version : ' . $package->version . ' )');
                    }
                }
                break;
            default:
                display('No VCS found to update (Only git, svn and bazaar are supported. Ask exakat to add more.');
        }
    }

Usage Example

Beispiel #1
0
 public function execute(Config $config)
 {
     switch ($config->command) {
         case 'doctor':
             $doctor = new Tasks\Doctor($this->gremlin, $this->config);
             $doctor->run($config);
             break;
         case 'init':
             $task = new Tasks\Initproject($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'anonymize':
             $task = new Tasks\Anonymize($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'files':
             $task = new Tasks\Files($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'load':
             $task = new Tasks\Load($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'stat':
             $task = new Tasks\Stat($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'analyze':
             $task = new Tasks\Analyze($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'results':
             $task = new Tasks\Results($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'export':
             $task = new Tasks\Export($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'report':
             $task = new Tasks\Report2($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'project':
             $task = new Tasks\Project($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'magicnumber':
             $task = new Tasks\Magicnumber($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'clean':
             $task = new Tasks\Clean($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'status':
             $task = new Tasks\Status($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'help':
             $task = new Tasks\Help($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'cleandb':
             $task = new Tasks\CleanDb($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'onepage':
             $task = new Tasks\OnePage($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'update':
             $task = new Tasks\Update($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'onepagereport':
             $task = new Tasks\OnepageReport($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'phploc':
             $task = new Tasks\Phploc($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'findextlib':
             $task = new Tasks\FindExternalLibraries($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'dump':
             $task = new Tasks\Dump($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'jobqueue':
             $task = new Tasks\Jobqueue($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'queue':
             $task = new Tasks\Queue($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'test':
             $task = new Tasks\Test($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'remove':
             $task = new Tasks\Remove($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'server':
             $task = new Tasks\Server($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'upgrade':
             $task = new Tasks\Upgrade($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'version':
         default:
             $version = self::VERSION;
             $build = self::BUILD;
             $date = date('r', filemtime(__FILE__));
             echo "\n ________                 __              _    \n|_   __  |               [  |  _         / |_  \n  | |_ \\_| _   __  ,--.   | | / ]  ,--. `| |-' \n  |  _| _ [ \\ [  ]`'_\\ :  | '' <  `'_\\ : | |   \n _| |__/ | > '  < // | |, | |`\\ \\ // | |,| |,  \n|________|[__]`\\_]\\'-;__/[__|  \\_]\\'-;__/\\__/  \n                                               \n\nExakat : @ 2014-2016 Damien Seguy. \nVersion : ", $version, ' - Build ', $build, ' - ', $date, "\n";
             break;
     }
 }