Ejemplo n.º 1
0
 /**
  * Parse an existing crontab
  *
  * @param Crontab $crontab
  *
  * @return CrontabFileHandler
  */
 public function parseExistingCrontab(Crontab $crontab)
 {
     $result = exec($this->crontabCommand($crontab) . ' -l', $output, $retval);
     if (!empty($output)) {
         //\Dsc\System::addMessage(\Dsc\Debug::dump($output));
         foreach ($output as $line) {
             if (trim($line) == '') {
                 continue;
             }
             try {
                 $job = \Dsc\Cron\Job::parse($line);
                 $crontab->addJob($job);
             } catch (\Exception $e) {
                 \Dsc\System::addMessage('Encountered error (' . $e->getMessage() . ') when parsing cron job: ' . $line, 'error');
             }
         }
     }
     /*
     // parsing cron file
     $process = new Process($this->crontabCommand($crontab).' -l');
     $process->run();
     
     foreach ($this->parseString($process->getOutput()) as $job) {
         $crontab->addJob($job);
     }
     
     $this->error = $process->getErrorOutput();
     */
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Returns an array of Cron Jobs based on the contents of a file.
  *
  * @param string $input
  *
  * @return Job[]
  */
 protected function parseString($input)
 {
     $jobs = array();
     $lines = array_filter(explode(PHP_EOL, $input), function ($line) {
         return '' != trim($line);
     });
     foreach ($lines as $line) {
         // if line is not a comment, convert it to a cron
         if (0 !== \strpos($line, '#')) {
             $jobs[] = Job::parse($line);
         }
     }
     return $jobs;
 }
Ejemplo n.º 3
0
 /**
  * Remove a specified job in the current crontab
  *
  * @param Job $job
  *
  * @return Crontab
  */
 public function removeJob(Job $job)
 {
     unset($this->jobs[$job->getHash()]);
     return $this;
 }