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 From 54d60e3f7864cf0da4c6da9c824e29ba51d57a37 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 21:26:33 +0200 Subject: [ticket/12597] Fix coding style and typing mistakes PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (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 index 701f0f02fb..7387c260a9 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -55,7 +55,7 @@ class run extends \phpbb\console\command\command $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')); + ->addArgument('name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCR_CRON_ARG_RUN_1')) ; } @@ -69,11 +69,11 @@ class run extends \phpbb\console\command\command * 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 + * printed and the exit status is set to 2. 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. + * @param InputInterface $input The input stream used to get the argument + * @param OutputInterface $output The output stream, used for printing 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 */ @@ -81,9 +81,11 @@ class run extends \phpbb\console\command\command { if ($this->lock_db->acquire()) { - if ($task_name = $input->getArgument('name')) + $task_name = $input->getArgument('name'); + if ($task_name) { - if ($task = $this->cron_manager->find_task($task_name)) + $task = $this->cron_manager->find_task($task_name); + if ($task) { $task->run(); return 0; @@ -91,7 +93,7 @@ class run extends \phpbb\console\command\command else { $output->writeln('' . $this->user->lang('CRON_NO_TASK') . ''); - return -1; + return 2; } } else -- cgit v1.2.1 From 532e4470ea08e6245878e49e77f1ca51354681e7 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 22:09:38 +0200 Subject: [ticket/12597] Fix language key name PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (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 index 7387c260a9..df69b05321 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -54,8 +54,8 @@ class run extends \phpbb\console\command\command { $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')) + ->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_RUN')) + ->addArgument('name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1')) ; } -- cgit v1.2.1 From e7fd259766ff78edf98ee08fff83cb70ac46b6f7 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 16:37:45 +0200 Subject: [ticket/12597] Refactoring and test improving Adding tests of return status Refactoring code Adding consistency in verbose mode PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 104 ++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 29 deletions(-) (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 index df69b05321..14cda84e7f 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -33,7 +33,7 @@ class run extends \phpbb\console\command\command * Construct method * * @param \phpbb\cron\manager $cron_manager The cron manager containing - * the cron tasks to be executed. + * the cron tasks to be executed. * @param \phpbb\lock\db $lock_db The lock for accessing database. * @param \phobb\user $user The user object (used to get language information) */ @@ -68,14 +68,15 @@ class run extends \phpbb\console\command\command * 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 the exit status is set to 2. Verbose option does nothing in - * this case. + * argument will be started. If verbose option is specified, + * an info message containing the name of the task is printed. + * If no task matches the argument given, an error message is printed + * and the exit status is set to 2. * - * @param InputInterface $input The input stream used to get the argument + * @param InputInterface $input The input stream used to get the argument and verboe option. * @param OutputInterface $output The output stream, used for printing 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 + * @return int 0 if all is ok, 1 if a lock error occured and 2 if no task matching the argument was found. */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -84,40 +85,85 @@ class run extends \phpbb\console\command\command $task_name = $input->getArgument('name'); if ($task_name) { - $task = $this->cron_manager->find_task($task_name); - if ($task) - { - $task->run(); - return 0; - } - else - { - $output->writeln('' . $this->user->lang('CRON_NO_TASK') . ''); - return 2; - } + return $this->run_one($input, $output, $task_name); } else { - $run_tasks = $this->cron_manager->find_all_ready_tasks(); + $this->run_all($input, $output); + return 0; + } + } + else + { + $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); + return 1; + } + } - foreach ($run_tasks as $task) - { - if ($input->getOption('verbose')) - { - $output->writeln($this->user->lang('RUNNING_TASK', $task->get_name())); - } + /* + * Executes the command in the case when no argument was given. + * + * If verbose mode is set, an info message will be printed if their is no task to + * be run, or else for each starting task. + * + * @see execute + * @param InputInterface $input The input stream used to get the argument and verboe option. + * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. + * @return null + */ + private function run_all(InputInterface $input, OutputInterface $output) + { + $run_tasks = $this->cron_manager->find_all_ready_tasks(); - $task->run(); + if ($run_tasks) { + foreach ($run_tasks as $task) + { + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->user->lang('RUNNING_TASK', $task->get_name()) . ''); } - $this->lock_db->release(); - return 0; + $task->run(); } } else { - $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); - return 1; + $output->writeln('' . $this->user->lang('CRON_NO_TASK') . ''); + } + $this->lock_db->release(); + } + + /* + * Executes the command in the case where an argument is given. + * + * If their is a task whose name matches the argument, 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 verboe 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. + */ + private 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('' . $this->user->lang('RUNNING_TASK', $task_nameœ) . ''); + } + + $task->run(); + return 0; + } + else + { + $output->writeln('' . $this->user->lang('CRON_NO_SUCH_TASK') . ''); + return 2; } } } -- cgit v1.2.1 From c17a1e92c5d63beb0f7f602a061c33a9eb093639 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 16:59:41 +0200 Subject: [ticket/12597] Fix visibilty of two functions in run.php PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (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 index 14cda84e7f..0da4d7c86d 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -111,7 +111,7 @@ class run extends \phpbb\console\command\command * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. * @return null */ - private function run_all(InputInterface $input, OutputInterface $output) + protected function run_all(InputInterface $input, OutputInterface $output) { $run_tasks = $this->cron_manager->find_all_ready_tasks(); @@ -147,7 +147,7 @@ class run extends \phpbb\console\command\command * @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. */ - private function run_one(InputInterface $input, OutputInterface $output, $task_name) + protected function run_one(InputInterface $input, OutputInterface $output, $task_name) { $task = $this->cron_manager->find_task($task_name); if ($task) -- cgit v1.2.1 From 7508d2b546392c4a1e3ae4ea48cb45ebc502e5e7 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 17:03:34 +0200 Subject: [ticket/12597] Fix various mistakes Typing mistakes Coding style issue Verbose mode messag PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (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 index 0da4d7c86d..cb304d9161 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -115,7 +115,8 @@ class run extends \phpbb\console\command\command { $run_tasks = $this->cron_manager->find_all_ready_tasks(); - if ($run_tasks) { + if ($run_tasks) + { foreach ($run_tasks as $task) { if ($input->getOption('verbose')) @@ -128,7 +129,10 @@ class run extends \phpbb\console\command\command } else { - $output->writeln('' . $this->user->lang('CRON_NO_TASK') . ''); + if ($input->getOption('verbose')) + { + $output->writeln('' . $this->user->lang('CRON_NO_TASK') . ''); + } } $this->lock_db->release(); } @@ -154,7 +158,7 @@ class run extends \phpbb\console\command\command { if ($input->getOption('verbose')) { - $output->writeln('' . $this->user->lang('RUNNING_TASK', $task_nameœ) . ''); + $output->writeln('' . $this->user->lang('RUNNING_TASK', $task_name) . ''); } $task->run(); -- cgit v1.2.1 From 03e0e736ab054d8ad355012f5d34cfccb56c7955 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 17:26:58 +0200 Subject: [ticket/12597] Typing corrections and improvement of code consistency PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (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 index cb304d9161..07949cc962 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -60,7 +60,7 @@ class run extends \phpbb\console\command\command } /** - * Executes the function. + * Executes the command cron:run. * * 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 @@ -89,8 +89,7 @@ class run extends \phpbb\console\command\command } else { - $this->run_all($input, $output); - return 0; + return $this->run_all($input, $output); } } else @@ -101,15 +100,15 @@ class run extends \phpbb\console\command\command } /* - * Executes the command in the case when no argument was given. + * Executes all ready cron tasks. * - * If verbose mode is set, an info message will be printed if their is no task to + * If verbose mode is set, an info message will be printed if there is no task to * be run, or else for each starting task. * * @see execute * @param InputInterface $input The input stream used to get the argument and verboe option. * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. - * @return null + * @return int 0 */ protected function run_all(InputInterface $input, OutputInterface $output) { @@ -134,13 +133,15 @@ class run extends \phpbb\console\command\command $output->writeln('' . $this->user->lang('CRON_NO_TASK') . ''); } } + $this->lock_db->release(); + return 0; } /* - * Executes the command in the case where an argument is given. + * Executes a given cron task, if it is ready. * - * If their is a task whose name matches the argument, it is run and 0 is returned. + * If there is a task whose name matches the argument, 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. @@ -162,11 +163,13 @@ class run extends \phpbb\console\command\command } $task->run(); + $this->lock_db->release(); return 0; } else { $output->writeln('' . $this->user->lang('CRON_NO_SUCH_TASK') . ''); + $this->lock_db->release(); return 2; } } -- cgit v1.2.1 From fda2cc636cd3df852c7dc7ca0f12b4696ff0553c Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 18:03:23 +0200 Subject: [ticket/12597] Changing place of lock release in execute() method PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (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 index 07949cc962..c0fb521c52 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -85,12 +85,15 @@ class run extends \phpbb\console\command\command $task_name = $input->getArgument('name'); if ($task_name) { - return $this->run_one($input, $output, $task_name); + $exit_status = $this->run_one($input, $output, $task_name); } else { - return $this->run_all($input, $output); + $exit_status = $this->run_all($input, $output); } + + $this->lock_db->release(); + return $exit_status; } else { @@ -134,7 +137,6 @@ class run extends \phpbb\console\command\command } } - $this->lock_db->release(); return 0; } @@ -163,13 +165,11 @@ class run extends \phpbb\console\command\command } $task->run(); - $this->lock_db->release(); return 0; } else { $output->writeln('' . $this->user->lang('CRON_NO_SUCH_TASK') . ''); - $this->lock_db->release(); return 2; } } -- cgit v1.2.1 From 3b845b189316b341594fe3eeb0b63e42df033d57 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 18:08:02 +0200 Subject: [ticket/12597] Typo corrections PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (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 index c0fb521c52..835c93e4c4 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -109,7 +109,7 @@ class run extends \phpbb\console\command\command * be run, or else for each starting task. * * @see execute - * @param InputInterface $input The input stream used to get the argument and verboe option. + * @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 */ @@ -143,7 +143,7 @@ class run extends \phpbb\console\command\command /* * Executes a given cron task, if it is ready. * - * If there is a task whose name matches the argument, it is run and 0 is returned. + * 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. -- cgit v1.2.1 From 43fbb84cc39385a237e101bf3c915bdd711113de Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 29 May 2014 18:09:42 +0200 Subject: [ticket/12597] Typo correction PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 index 835c93e4c4..f76fb30e3b 100644 --- a/phpBB/phpbb/console/command/cron/run.php +++ b/phpBB/phpbb/console/command/cron/run.php @@ -150,7 +150,7 @@ class run extends \phpbb\console\command\command * * @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 verboe option. + * @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. */ -- cgit v1.2.1