From 9f942776ad5a3b396045e6f97db6ef655c5d9fcc Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 19:51:59 +0200 Subject: [ticket/12597] Changes name of command cron:run-all to cron:run. Also adds an optional argument to specify one precise cron task to lauch, and modifies test file accordingly. PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 phpBB/phpbb/console/command/cron/run.php (limited to 'phpBB/phpbb/console/command/cron/run.php') diff --git a/phpBB/phpbb/console/command/cron/run.php b/phpBB/phpbb/console/command/cron/run.php new file mode 100644 index 0000000000..701f0f02fb --- /dev/null +++ b/phpBB/phpbb/console/command/cron/run.php @@ -0,0 +1,121 @@ +cron_manager = $cron_manager; + $this->lock_db = $lock_db; + $this->user = $user; + parent::__construct(); + } + + /** + * Sets the command name and description + * + * @return null + */ + protected function configure() + { + $this + ->setName('cron:run') + ->setDescription($this->user->lang('CLI_DESCR_CRON_RUN')) + ->addArgument('name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCR_CRON_ARG_RUN_1')); + ; + } + + /** + * Executes the function. + * + * Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks. + * If the cron lock can not be obtained, an error message is printed + * and the exit status is set to 1. + * If the verbose option is specified, each start of a task is printed. + * Otherwise there is no output. + * If an argument is given to the command, only the task whose name matches the + * argument will be started. If none exists, an error message is + * printed and theexit status is set to -1. Verbose option does nothing in + * this case. + * + * @param InputInterface $input The input stream, unused here + * @param OutputInterface $output The output stream, used for printig verbose-mode and error information. + * + * @return int 0 if all is ok, 1 if a lock error occured and -1 if no task matching the argument was found + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if ($this->lock_db->acquire()) + { + if ($task_name = $input->getArgument('name')) + { + if ($task = $this->cron_manager->find_task($task_name)) + { + $task->run(); + return 0; + } + else + { + $output->writeln('' . $this->user->lang('CRON_NO_TASK') . ''); + return -1; + } + } + else + { + $run_tasks = $this->cron_manager->find_all_ready_tasks(); + + foreach ($run_tasks as $task) + { + if ($input->getOption('verbose')) + { + $output->writeln($this->user->lang('RUNNING_TASK', $task->get_name())); + } + + $task->run(); + } + $this->lock_db->release(); + + return 0; + } + } + else + { + $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); + return 1; + } + } +} -- cgit v1.2.1