Esempio n. 1
0
 public function testSave()
 {
     $inputData = file_get_contents(dirname(__DIR__) . '/Data/crontabRead.txt');
     $outputData = file_get_contents(dirname(__DIR__) . '/Data/crontabWrite.txt');
     $crontab = $this->getCrontabWithMockedProcesses($this->getMockedProcessRead($inputData), $this->getMockedProcessWrite($outputData));
     $jobs = $crontab->getJobs();
     $jobs[0]->setCommand('changed command');
     $newJob = new Job();
     $newJob->setCommand('new command');
     $newJob->setHour('5');
     $newJob->setMinute('4');
     $newJob->setDayOfMonth('3');
     $newJob->setDayOfWeek('2');
     $newJob->setMonth('1');
     $crontab->addJob($newJob);
     $crontab->save();
 }
Esempio n. 2
0
 /**
  * @param string $line
  * @return Job|null
  */
 private function parseLine($line)
 {
     if (strlen($line) === 0) {
         return null;
     }
     if ($line[0] === '#') {
         // It's a comment
         return null;
     }
     $elements = explode(' ', $line, 6);
     if (count($elements) < 6) {
         throw ParserException::insufficientArgumentsForJob($line);
     }
     $job = new Job();
     $job->setMinute($elements[0]);
     $job->setHour($elements[1]);
     $job->setDayOfMonth($elements[2]);
     $job->setMonth($elements[3]);
     $job->setDayOfWeek($elements[4]);
     $job->setCommand($elements[5]);
     return $job;
 }
Esempio n. 3
0
 public static function jobAlreadyExists(Job $job)
 {
     return new self('A job with the same characteristics already exists in this crontab. Command: ' . $job->getCommand());
 }
Esempio n. 4
0
 /**
  * Remove the given job from the crontab
  * CrontabException will be thrown if the job does not exist
  *
  * @param Job $job
  */
 public function removeJob(Job $job)
 {
     $this->removeById($job->getId());
 }
Esempio n. 5
0
 /**
  * @param Job $job
  * @return string
  */
 private function dumpJob(Job $job)
 {
     return sprintf(self::LINE_FORMAT, $job->getMinute(), $job->getHour(), $job->getDayOfMonth(), $job->getMonth(), $job->getDayOfWeek(), $job->getCommand());
 }