Esempio n. 1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $user = $input->getOption('user');
     $crontab = new Crontab($user, $name);
     $systemReader = new SystemReader($user, $crontab);
     $systemReader->read();
     $crontab->clearManagedTasks();
     $this->output($output, $crontab, $user);
 }
Esempio n. 2
0
 /**
  * @param array $array
  *
  * @return Crontab
  */
 protected function readArray(array $array)
 {
     foreach ($array as $name => $task) {
         if (true === $this->checkIfForThisMachine(isset($task['machine']) ? $task['machine'] : null)) {
             $task = $this->createTaskFromConfig($name, $task);
             $this->crontab->addTask($task);
         }
     }
     return $this->crontab;
 }
Esempio n. 3
0
 function let(Crontab $crontab, Task $nmTask1, Task $nmTask2, Task $task1, Task $task2, Variables $variables1)
 {
     $this->prepareTask($task1, $variables1);
     $this->prepareTask($task2, $variables1);
     $this->prepareTask($nmTask1, $variables1, true);
     $this->prepareTask($nmTask2, $variables1, true);
     $crontab->getName()->willReturn("TestAopTest");
     $crontab->getManagedTasks()->willReturn(array($task1, $task2));
     $crontab->getNotManagedTasks()->willReturn(array($nmTask1, $nmTask2));
 }
Esempio n. 4
0
 /**
  * @param OutputInterface $output
  * @param Crontab         $crontab
  * @param string|null     $user
  *
  * @return mixed
  */
 public function output(OutputInterface $output, Crontab $crontab, $user = null)
 {
     $writer = new SystemWriter(array('user' => $user));
     //Checking if we do want to save something if not it's better to left file as is
     if ($crontab->getManagedTasks()) {
         $writer->write($crontab);
         $output->writeln('Your crontab has been updated!');
     } else {
         $output->writeln('Your crontab does not need to be updated!');
     }
 }
Esempio n. 5
0
    function it_works_with_crons_without_comments(Task $taskWC, Variables $variablesWC, Crontab $crontabWC)
    {
        $this->prepareTask($taskWC, $variablesWC, true, false);
        $variablesWC->current()->willReturn('value');
        $variablesWC->key()->willReturn('key');
        $variablesWC->rewind()->shouldBeCalled();
        $variablesWC->valid()->willReturn(true, false);
        $variablesWC->next()->shouldBeCalled();
        $crontabWC->getName()->willReturn("TestAopTest");
        $crontabWC->getManagedTasks()->willReturn(array($taskWC));
        $crontabWC->getNotManagedTasks()->willReturn(array());
        //        echo($this->getContent($crontabWC)->getWrappedObject());
        //        die();
        $this->getContent($crontabWC)->shouldReturn(<<<CONTENT
#WARNING!!!
#This crontab file it at least partially managed by Crontab by Hexmedia, please check all restrictions that comes with that library at: https://github.com/Hexmedia/Crontab/blob/master/README.md
#EOT



# ------------ CURRENTLY MANAGED by TestAopTest --------------

key=value
*/10 * * * *       test > some_log_file.log

CONTENT
);
    }
Esempio n. 6
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, " "));
 }