Exakat\Tasks\Status::run PHP Method

run() public method

public run ( )
    public function run()
    {
        $project = $this->config->project;
        if ($project === 'default') {
            $status = array();
            if (file_exists($this->config->projects_root . '/projects/.exakat/Project.json')) {
                if (file_exists($this->config->projects_root . '/projects/.exakat/Project.json')) {
                    $json = json_decode(file_get_contents($this->config->projects_root . '/projects/.exakat/Project.json'));
                    $projectStatus = $json->project;
                    $projectStep = $json->step;
                }
                $log = file_get_contents($this->config->neo4j_folder . '/data/log/console.log');
                if (strpos($log, 'java.lang.OutOfMemoryError: Java heap space2') !== false) {
                    $pid = trim(file_get_contents($this->config->neo4j_folder . '/data/neo4j-service.pid'));
                    $projectStatus = 'Neo4j died : Java heap space. Kill neo4j (' . $pid . ') and run exakat again.';
                    $inGraph = 'N/A';
                    $projectStep = 'N/A';
                } else {
                    $res = $this->gremlin->query('g.V().hasLabel("Project").values("fullcode")');
                    $inGraph = isset($res->results[0]) ? $res->results[0] : '<None>';
                }
                $status = array('Running' => 'Project', 'project' => $projectStatus, 'in graph' => $inGraph, 'step' => $projectStep);
            } else {
                $status['Running'] = 'idle';
                $res = $this->gremlin->query('g.V().hasLabel("Project").values("fullcode")');
                if (isset($res->results[0])) {
                    $status['Project'] = $res->results[0];
                }
            }
            $this->display($status, $this->config->json);
            return;
        }
        $path = $this->config->projects_root . '/projects/' . $project;
        if (!file_exists($path . '/')) {
            throw new NoSuchProject($project);
        }
        $status = array('project' => $project);
        $status['loc'] = $this->datastore->getHash('loc');
        $status['tokens'] = $this->datastore->getHash('tokens');
        if (file_exists($this->config->projects_root . '/projects/.exakat/Project.json')) {
            $json = json_decode(file_get_contents($this->config->projects_root . '/projects/.exakat/Project.json'));
            if ($json->project === $project) {
                $status['status'] = $json->step;
            } else {
                $status['status'] = 'Not running';
            }
        } else {
            $status['status'] = 'Not running';
        }
        switch ($this->config->project_vcs) {
            case 'git':
                if (file_exists($this->config->projects_root . '/projects/' . $this->config->project . '/code/')) {
                    $status['git status'] = trim(shell_exec('cd ' . $this->config->projects_root . '/projects/' . $this->config->project . '/code/; git rev-parse HEAD'));
                }
                if (file_exists($this->config->projects_root . '/projects/' . $this->config->project . '/code/')) {
                    $res = shell_exec('cd ' . $this->config->projects_root . '/projects/' . $this->config->project . '/code/; git remote update; git status -uno | grep \'up-to-date\'');
                    $status['updatable'] = empty($res);
                } else {
                    $status['updatable'] = false;
                }
                break 1;
            case 'composer':
                $json = @json_decode(@file_get_contents($this->config->projects_root . '/projects/' . $this->config->project . '/code/composer.lock'));
                if (isset($json->hash)) {
                    $status['hash'] = $json->hash;
                } else {
                    $status['hash'] = 'Can\'t read hash';
                }
                $res = shell_exec('cd ' . $this->config->projects_root . '/projects/' . $this->config->project . '; git remote update; git status -uno | grep \'Nothing to install or update\'');
                $status['updatable'] = empty($res);
                break 1;
            case 'copy':
            case 'symlink':
                $status['hash'] = 'None';
                $status['updatable'] = false;
                break 1;
            default:
                $status['hash'] = 'None';
                $status['updatable'] = 'N/A';
                break 1;
        }
        $this->configuration = array();
        //
        // Check the logs
        $errors = $this->getErrors($path);
        if (!empty($errors)) {
            $status['errors'] = $errors;
        }
        // Status of progress
        // errors?
        $formats = array();
        foreach (Reports::$FORMATS as $format) {
            $a = $this->datastore->getHash($format);
            if (!empty($a)) {
                $formats[$format] = $a;
            }
        }
        // Always have formats, even if empty
        $status['formats'] = $formats;
        $this->display($status, $this->config->json);
    }

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;
     }
 }