From abb8a2892d862c097285ee7f300d12c32428e12c Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Tue, 27 May 2014 12:36:44 +0200 Subject: [ticket/12597] Command for executing all available cron tasks Command cron:execute-all executes all available cron tasks. Test files in tests/console/cron folder PHPBB3-12597 --- phpBB/phpbb/console/command/cron/execute_all.php | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 phpBB/phpbb/console/command/cron/execute_all.php (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/execute_all.php b/phpBB/phpbb/console/command/cron/execute_all.php new file mode 100644 index 0000000000..4f0f225e91 --- /dev/null +++ b/phpBB/phpbb/console/command/cron/execute_all.php @@ -0,0 +1,65 @@ +cron_manager = $cron_manager; + $this->lock_db = $lock_db; + $this->user = $user; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('cron:execute-all') + ->setDescription($this->user->lang('CLI_DESCR_CRON_EXECUTE_ALL')) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + if ($this->lock_db->acquire()) + { + $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()) . "\n"); + } + + $task->run(); + } + $this->lock_db->release(); + } + else + { + $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); + } + } +} + -- cgit v1.2.1 From 50cb9d583845bb99c94355266705e25994770622 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 11:57:20 +0200 Subject: [ticket/12597] Correcing coding style mistakes PHPBB3-12597 --- phpBB/phpbb/console/command/cron/execute_all.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/execute_all.php b/phpBB/phpbb/console/command/cron/execute_all.php index 4f0f225e91..6f061212ae 100644 --- a/phpBB/phpbb/console/command/cron/execute_all.php +++ b/phpBB/phpbb/console/command/cron/execute_all.php @@ -62,4 +62,3 @@ class execute_all extends \phpbb\console\command\command } } } - -- cgit v1.2.1 From 8a1e189970c57364a3192296546717d70fbdd2d4 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 12:20:02 +0200 Subject: [ticket/12597] Add doc blocs in execute_all.php PHPBB3-12597 --- phpBB/phpbb/console/command/cron/execute_all.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/execute_all.php b/phpBB/phpbb/console/command/cron/execute_all.php index 6f061212ae..bc46fbe81b 100644 --- a/phpBB/phpbb/console/command/cron/execute_all.php +++ b/phpBB/phpbb/console/command/cron/execute_all.php @@ -23,6 +23,14 @@ class execute_all extends \phpbb\console\command\command /** @var \phpbb\user */ protected $user; + /** + * Construct method + * + * @param \phpbb\cron\manager $cron_manager The cron manager containing + * 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) + */ public function __construct(\phpbb\cron\manager $cron_manager, \phpbb\lock\db $lock_db, \phpbb\user $user) { $this->cron_manager = $cron_manager; @@ -31,6 +39,11 @@ class execute_all extends \phpbb\console\command\command parent::__construct(); } + /** + * Sets the command name and description + * + * @return null + */ protected function configure() { $this @@ -39,6 +52,16 @@ class execute_all extends \phpbb\console\command\command ; } + /** + * Executes the function. Each cron tasks is executed. + * If option "--verbose" is not seted, there will be no output in case of + * successful execution. + * + * @param InputInterface input The input stream, unused here + * @param OutputInterface output The output stream, used for printig verbose-mode + * and error information. + * @return null + */ protected function execute(InputInterface $input, OutputInterface $output) { if ($this->lock_db->acquire()) -- cgit v1.2.1 From 9761c1bf617763671308fabc569ec13d40cb6843 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 12:57:49 +0200 Subject: [ticket/12597] Fix various refactoring mistakes PHPBB3-12597 --- phpBB/phpbb/console/command/cron/execute_all.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/execute_all.php b/phpBB/phpbb/console/command/cron/execute_all.php index bc46fbe81b..f7157f4d3a 100644 --- a/phpBB/phpbb/console/command/cron/execute_all.php +++ b/phpBB/phpbb/console/command/cron/execute_all.php @@ -72,7 +72,7 @@ class execute_all extends \phpbb\console\command\command { if ($input->getOption('verbose')) { - $output->writeln($this->user->lang('RUNNING_TASK', $task->get_name()) . "\n"); + $output->writeln($this->user->lang('RUNNING_TASK', $task->get_name())); } $task->run(); -- cgit v1.2.1 From 6f279c1bf47c4c86a507acc9ea7d705dad6e9b97 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 14:39:02 +0200 Subject: [ticket/12597] Update pull-request Removes a useless comment. Switchs command name from cron:execute-all to cron:run-all. Replaces assertEquals by assertSame PHPBB3-12597 --- phpBB/phpbb/console/command/cron/execute_all.php | 87 ------------------------ phpBB/phpbb/console/command/cron/run_all.php | 87 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 phpBB/phpbb/console/command/cron/execute_all.php create mode 100644 phpBB/phpbb/console/command/cron/run_all.php (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/execute_all.php b/phpBB/phpbb/console/command/cron/execute_all.php deleted file mode 100644 index f7157f4d3a..0000000000 --- a/phpBB/phpbb/console/command/cron/execute_all.php +++ /dev/null @@ -1,87 +0,0 @@ -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:execute-all') - ->setDescription($this->user->lang('CLI_DESCR_CRON_EXECUTE_ALL')) - ; - } - - /** - * Executes the function. Each cron tasks is executed. - * If option "--verbose" is not seted, there will be no output in case of - * successful execution. - * - * @param InputInterface input The input stream, unused here - * @param OutputInterface output The output stream, used for printig verbose-mode - * and error information. - * @return null - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if ($this->lock_db->acquire()) - { - $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(); - } - else - { - $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); - } - } -} diff --git a/phpBB/phpbb/console/command/cron/run_all.php b/phpBB/phpbb/console/command/cron/run_all.php new file mode 100644 index 0000000000..39b3e0c616 --- /dev/null +++ b/phpBB/phpbb/console/command/cron/run_all.php @@ -0,0 +1,87 @@ +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-all') + ->setDescription($this->user->lang('CLI_DESCR_CRON_EXECUTE_ALL')) + ; + } + + /** + * Executes the function. Each cron tasks is executed. + * If option "--verbose" is not seted, there will be no output in case of + * successful execution. + * + * @param InputInterface input The input stream, unused here + * @param OutputInterface output The output stream, used for printig verbose-mode + * and error information. + * @return null + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if ($this->lock_db->acquire()) + { + $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(); + } + else + { + $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); + } + } +} -- cgit v1.2.1 From 9a7877274596b8330c075299adf3683c189ba6ab Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 14:57:16 +0200 Subject: [ticket/12597] Change EXECUTE to RUN in language Fix previous commit : change execute to run in language keys PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run_all.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/run_all.php b/phpBB/phpbb/console/command/cron/run_all.php index 39b3e0c616..38a7735c03 100644 --- a/phpBB/phpbb/console/command/cron/run_all.php +++ b/phpBB/phpbb/console/command/cron/run_all.php @@ -48,7 +48,7 @@ class run_all extends \phpbb\console\command\command { $this ->setName('cron:run-all') - ->setDescription($this->user->lang('CLI_DESCR_CRON_EXECUTE_ALL')) + ->setDescription($this->user->lang('CLI_DESCR_CRON_RUN_ALL')) ; } -- cgit v1.2.1 From 0d839cbefc19247fd2b4c1132b91083bf0983305 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 18:02:30 +0200 Subject: [ticket/12597] Modification of return statuses and of test files PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run_all.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/run_all.php b/phpBB/phpbb/console/command/cron/run_all.php index 38a7735c03..e2d235395b 100644 --- a/phpBB/phpbb/console/command/cron/run_all.php +++ b/phpBB/phpbb/console/command/cron/run_all.php @@ -60,7 +60,7 @@ class run_all extends \phpbb\console\command\command * @param InputInterface input The input stream, unused here * @param OutputInterface output The output stream, used for printig verbose-mode * and error information. - * @return null + * @return boolean 0 if all is ok, 1 if a lock error occured */ protected function execute(InputInterface $input, OutputInterface $output) { -- cgit v1.2.1 From 18875894ec046e48e8627a9c1b2158670eea70e9 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 18:19:46 +0200 Subject: [ticket/12597] Fix constructor bug and servral doc blocs PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run_all.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/run_all.php b/phpBB/phpbb/console/command/cron/run_all.php index e2d235395b..b398e46ab9 100644 --- a/phpBB/phpbb/console/command/cron/run_all.php +++ b/phpBB/phpbb/console/command/cron/run_all.php @@ -53,12 +53,15 @@ class run_all extends \phpbb\console\command\command } /** - * Executes the function. Each cron tasks is executed. - * If option "--verbose" is not seted, there will be no output in case of - * successful execution. + * Executes the function. + * Tries to acquire the cron lock, then 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. * - * @param InputInterface input The input stream, unused here - * @param OutputInterface output The output stream, used for printig verbose-mode + * @param InputInterface $input The input stream, unused here + * @param OutputInterface $output The output stream, used for printig verbose-mode * and error information. * @return boolean 0 if all is ok, 1 if a lock error occured */ -- cgit v1.2.1 From 61ad42790f653c0fe7bf1c1b5d27181794bec997 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 28 May 2014 18:28:46 +0200 Subject: [ticket/12597] Fix various problems Actually fix the return status of command cron:run-all Fix some doc block coding style issue Fix missing and obsolete file headers Delete a useless constructor method PHPBB3-12597 --- phpBB/phpbb/console/command/cron/run_all.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/console/command/cron') diff --git a/phpBB/phpbb/console/command/cron/run_all.php b/phpBB/phpbb/console/command/cron/run_all.php index b398e46ab9..2f8166b857 100644 --- a/phpBB/phpbb/console/command/cron/run_all.php +++ b/phpBB/phpbb/console/command/cron/run_all.php @@ -1,11 +1,16 @@ run(); } $this->lock_db->release(); + + return 0; } else { $output->writeln('' . $this->user->lang('CRON_LOCK_ERROR') . ''); + return 1; } } } -- cgit v1.2.1 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 +++++++++++++++++++++++++++ phpBB/phpbb/console/command/cron/run_all.php | 99 ---------------------- 2 files changed, 121 insertions(+), 99 deletions(-) create mode 100644 phpBB/phpbb/console/command/cron/run.php delete mode 100644 phpBB/phpbb/console/command/cron/run_all.php (limited to 'phpBB/phpbb/console/command/cron') 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; + } + } +} diff --git a/phpBB/phpbb/console/command/cron/run_all.php b/phpBB/phpbb/console/command/cron/run_all.php deleted file mode 100644 index 2f8166b857..0000000000 --- a/phpBB/phpbb/console/command/cron/run_all.php +++ /dev/null @@ -1,99 +0,0 @@ -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-all') - ->setDescription($this->user->lang('CLI_DESCR_CRON_RUN_ALL')) - ; - } - - /** - * Executes the function. - * - * Tries to acquire the cron lock, then 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. - * - * @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 - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if ($this->lock_db->acquire()) - { - $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') 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') 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') 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') 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') 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') 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') 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') 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') 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