/** * Executes the command cron:list. * * Prints a list of ready and unready cron jobs. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null */ protected function execute(InputInterface $input, OutputInterface $output) { $tasks = $this->cron_manager->get_tasks(); if (empty($tasks)) { $output->writeln($this->user->lang('CRON_NO_TASKS')); return; } $ready_tasks = array(); $not_ready_tasks = array(); foreach ($tasks as $task) { if ($task->is_ready()) { $ready_tasks[] = $task; } else { $not_ready_tasks[] = $task; } } if (!empty($ready_tasks)) { $output->writeln('<info>' . $this->user->lang('TASKS_READY') . '</info>'); $this->print_tasks_names($ready_tasks, $output); } if (!empty($ready_tasks) && !empty($not_ready_tasks)) { $output->writeln(''); } if (!empty($not_ready_tasks)) { $output->writeln('<info>' . $this->user->lang('TASKS_NOT_READY') . '</info>'); $this->print_tasks_names($not_ready_tasks, $output); } }
/** * Executes a given cron task, if it is ready. * * If there is a task whose name matches $task_name, it is run and 0 is returned. * and if verbose mode is set, print an info message with the name of the task. * If there is no task matching $task_name, the function prints an error message * and returns with status 2. * * @see execute * @param string $task_name The name of the task that should be run. * @param InputInterface $input The input stream used to get the argument and verbose option. * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. * @return int 0 if all is well, 2 if no task matches $task_name. */ protected function run_one(InputInterface $input, OutputInterface $output, $task_name) { $task = $this->cron_manager->find_task($task_name); if ($task) { if ($input->getOption('verbose')) { $output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task_name) . '</info>'); } $task->run(); return 0; } else { $output->writeln('<error>' . $this->user->lang('CRON_NO_SUCH_TASK', $task_name) . '</error>'); return 2; } }