Exakat\Tasks\Clean::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);
        }
        display("Cleaning project {$this->config->project}\n");
        $dirsToErase = array('log', 'report', 'Premier-ace', 'faceted', 'faceted2', 'ambassador');
        foreach ($dirsToErase as $dir) {
            $dirPath = $path . '/' . $dir;
            if (file_exists($dirPath)) {
                display('removing ' . $dir);
                rmdirRecursive($dirPath);
            }
        }
        // rebuild log
        mkdir($path . '/log', 0755);
        $filesToErase = array('Flat-html.html', 'Flat-markdown.md', 'Flat-sqlite.sqlite', 'Flat-text.txt', 'Premier-ace.zip', 'Premier-html.html', 'Premier-markdown.md', 'Premier-sqlite.sqlite', 'Premier-text.txt', 'datastore.sqlite', 'magicnumber.sqlite', 'report.html', 'report.md', 'report.odt', 'report.pdf', 'report.sqlite', 'report.txt', 'report.zip', 'EchoWithConcat.json', 'PhpFunctions.json', 'bigArrays.txt', 'counts.sqlite', 'stats.txt', 'dump.sqlite', 'faceted.zip', 'faceted2.zip');
        $total = 0;
        foreach ($filesToErase as $file) {
            $filePath = $path . '/' . $file;
            if (file_exists($filePath)) {
                display('removing ' . $file);
                unlink($filePath);
                ++$total;
            }
        }
        display("Removed {$total} files\n");
        $this->datastore = new Datastore($this->config, Datastore::CREATE);
        display("Recreating database\n");
    }

Usage Example

Esempio n. 1
0
 public function run()
 {
     if (!file_exists($this->pipefile)) {
         throw new NoJobqueueStarted();
     }
     if ($this->config->stop === true) {
         display('Stopping queue');
         $queuePipe = fopen($this->pipefile, 'w');
         fwrite($queuePipe, "quit\n");
         fclose($queuePipe);
         return;
     }
     if ($this->config->ping === true) {
         display('Ping queue');
         $queuePipe = fopen($this->pipefile, 'w');
         fwrite($queuePipe, "ping\n");
         fclose($queuePipe);
         return;
     }
     if ($this->config->project != 'default') {
         if (file_exists($this->config->projects_root . '/projects/' . $this->config->project . '/report/')) {
             display('Cleaning the project first');
             $clean = new Clean($this->gremlin, $this->config);
             $clean->run();
         }
         display('Adding project ' . $this->config->project . ' to the queue');
         $queuePipe = fopen($this->pipefile, 'w');
         fwrite($queuePipe, $this->config->project . "\n");
         fclose($queuePipe);
     } elseif (!empty($this->config->filename)) {
         if (!file_exists($this->config->projects_root . '/in/' . $this->config->filename . '.php')) {
             throw new \Exakat\Exceptions\NoSuchFile('No such file "' . $this->config->filename . '" in /in/ folder');
         }
         if (file_exists($this->config->projects_root . '/out/' . $this->config->filename . '.json')) {
             throw new \Exakat\Exceptions\ReportAlreadyDone($this->config->filename);
         }
         display('Adding file ' . $this->config->project . ' to the queue');
         $queuePipe = fopen($this->pipefile, 'w');
         fwrite($queuePipe, $this->config->filename . "\n");
         fclose($queuePipe);
     }
     display('Done');
 }
All Usage Examples Of Exakat\Tasks\Clean::run