Exakat\Tasks\CleanDb::run PHP Метод

run() публичный Метод

public run ( )
    public function run()
    {
        if ($this->config->quick) {
            $this->restartNeo4j();
            $this->cleanScripts();
            return false;
        }
        $queryTemplate = <<<GREMLIN
g.V().count();
GREMLIN;
        $result = null;
        $counts = 0;
        while ($counts < 100 && (!is_object($result) || $result->results === null)) {
            $result = $this->gremlin->query($queryTemplate);
            ++$counts;
            usleep(100000);
        }
        if ($counts === 100) {
            display('No connexion to neo4j : forcing restart (' . $counts . ')');
            // Can't connect to neo4j. Forcing restart.
            $this->restartNeo4j();
            $this->cleanScripts();
            return false;
        } else {
            display('Connexion to neo4j found (' . $counts . ')');
        }
        $nodes = $result->results[0];
        display($nodes . ' nodes in the database');
        $begin = microtime(true);
        if ($nodes == 0) {
            display('No nodes in neo4j. No need to clean');
        } elseif ($nodes > 10000) {
            display($nodes . 'nodes : forcing restart');
            $this->restartNeo4j();
        } else {
            display('Cleaning with gremlin');
            $queryTemplate = <<<GREMLIN

g.E().drop();
g.V().drop();

GREMLIN;
            $this->gremlin->query($queryTemplate);
            display('Database cleaned');
        }
        $end = microtime(true);
        display(number_format(($end - $begin) * 1000, 0) . ' ms');
        $this->cleanScripts();
        $this->cleanTmpDir();
    }

Usage Example

Пример #1
0
 public function run()
 {
     $project = 'test';
     // Check for requested file
     if (!empty($this->config->filename) && !file_exists($this->config->filename)) {
         throw new NoSuchFile($this->config->filename);
     } elseif (!empty($this->config->dirname) && !file_exists($this->config->dirname)) {
         throw new NoSuchDir($this->config->filename);
     }
     // Check for requested analyze
     $analyzer = $this->config->program;
     if (Analyzer::getClass($analyzer)) {
         $analyzers_class = array($analyzer);
     } else {
         $r = Analyzer::getSuggestionClass($analyzer);
         if (count($r) > 0) {
             echo 'did you mean : ', implode(', ', str_replace('_', '/', $r)), "\n";
         }
         throw new NoSuchAnalyzer($analyzer);
     }
     display("Cleaning DB\n");
     $clean = new CleanDb($this->gremlin, $this->config, Tasks::IS_SUBTASK);
     $clean->run();
     $load = new Load($this->gremlin, $this->config, Tasks::IS_SUBTASK);
     $load->run();
     unset($load);
     display("Project loaded\n");
     $analyze = new Analyze($this->gremlin, $this->config, Tasks::IS_SUBTASK);
     $analyze->run();
     unset($analyze);
     $results = new Results($this->gremlin, $this->config, Tasks::IS_SUBTASK);
     $results->run();
     unset($results);
     display("Analyzed project\n");
 }
All Usage Examples Of Exakat\Tasks\CleanDb::run