예제 #1
0
 function it_is_not_allowing_to_remove_not_managed_task(Task $task)
 {
     $task->isNotManaged()->willReturn(true);
     $task->getName()->willReturn("Some Name");
     $this->getNotManagedTasks()->shouldHaveCount(0);
     $this->addTask($task);
     $this->getNotManagedTasks()->shouldHaveCount(1);
     $this->shouldThrow(new NotManagedException("This task is not managed by this application so you cannot remove it!"))->duringRemoveTask($task);
 }
예제 #2
0
 /**
  * @param Task $task
  *
  * @return $this
  * @throws NotManagedException
  */
 public function removeTask(Task $task)
 {
     if ($task->isNotManaged()) {
         throw new NotManagedException('This task is not managed by this application so you cannot remove it!');
     }
     foreach ($this->managedTasks as $key => $taskIteration) {
         if ($taskIteration->getName() === $task->getName()) {
             unset($this->managedTasks[$key]);
         }
     }
     return $this;
 }
예제 #3
0
 /**
  * @param string $name
  * @param array  $taskArray
  *
  * @return Task
  */
 private function createTaskFromConfig($name, array $taskArray)
 {
     $task = new Task();
     $task->setMd5Name($name);
     $task->setNotManaged($this->notManaged);
     $task->setCommand($taskArray['command']);
     $task->setMinute($taskArray['minute']);
     $task->setDayOfMonth($taskArray['day_of_month']);
     $task->setDayOfWeek($taskArray['day_of_week']);
     $task->setMonth($taskArray['month']);
     if (isset($taskArray['variables'])) {
         $task->setVariables(new Variables($taskArray['variables']));
     }
     if (isset($taskArray['log_file'])) {
         $task->setLogFile($taskArray['log_file']);
     }
     return $task;
 }
예제 #4
0
 /**
  * @param Task $task
  *
  * @return string
  */
 private function prepareTask(Task $task, Crontab $crontab)
 {
     $log = $task->getLogFile() ? '> ' . $task->getLogFile() : '';
     if ($task->isNotManaged()) {
         $comment = $task->getBeforeComment();
     } else {
         $comment = $this->prepareTaskNameLine($task, $crontab->getName()) . $task->getBeforeComment();
     }
     $comment = $this->prepareComment($comment);
     $variables = '';
     if ($task->getVariables() instanceof \Iterator) {
         foreach ($task->getVariables() as $name => $value) {
             $variables .= sprintf("%s=%s\n", $name, $value);
         }
     }
     return trim(sprintf('%s%s%s %s %s %s %s       %s %s', $comment, $variables, $task->getMinute(), $task->getHour(), $task->getDayOfMonth(), $task->getMonth(), $task->getDayOfWeek(), $task->getCommand(), $log, " "));
 }