From 23ce5121a490cc9408ffc4c700308b1157d16ccb Mon Sep 17 00:00:00 2001 From: Ruben Calvo Date: Tue, 30 Nov 2021 00:04:46 +0100 Subject: [PATCH] [ticket/12683] Code review PHPBB3-12683 --- phpBB/language/en/cli.php | 2 +- .../phpbb/console/command/searchindex/create.php | 10 +++++----- .../phpbb/console/command/searchindex/delete.php | 10 +++++----- .../console/command/searchindex/list_all.php | 3 ++- phpBB/phpbb/search/backend/fulltext_native.php | 12 +++--------- phpBB/phpbb/search/state_helper.php | 6 +++--- tests/console/searchindex/create_test.php | 6 +++--- tests/console/searchindex/delete_test.php | 6 +++--- tests/console/searchindex/list_all_test.php | 6 +++--- ...ase.php => phpbb_console_searchindex_base.php} | 15 +++++++++++++-- .../searchindex => }/mock/search_backend_mock.php | 0 11 files changed, 41 insertions(+), 35 deletions(-) rename tests/console/searchindex/{base.php => phpbb_console_searchindex_base.php} (82%) rename tests/{console/searchindex => }/mock/search_backend_mock.php (100%) diff --git a/phpBB/language/en/cli.php b/phpBB/language/en/cli.php index 35f6f0b1df..8ad12848ae 100644 --- a/phpBB/language/en/cli.php +++ b/phpBB/language/en/cli.php @@ -152,7 +152,7 @@ $lang = array_merge($lang, array( 'CLI_SEARCHINDEX_CREATE_FAILURE' => 'Error creating search index', 'CLI_SEARCHINDEX_DELETE_SUCCESS' => 'Search index deleted successfully', 'CLI_SEARCHINDEX_DELETE_FAILURE' => 'Error deleting search index', - 'CLI_SEARCHINDEX_ACTION_IN_PROGRESS' => 'There is an action currently in progress. CLI doesn’t support incomplete index/delete actions, please solve it from the ACP', + 'CLI_SEARCHINDEX_ACTION_IN_PROGRESS' => 'There is an action currently in progress. CLI doesn’t support incomplete index/delete actions, please solve it from the ACP.', 'CLI_SEARCHINDEX_ACTIVE_NOT_INDEXED' => 'Active search backend isn’t indexed', // In all the case %1$s is the logical name of the file and %2$s the real name on the filesystem diff --git a/phpBB/phpbb/console/command/searchindex/create.php b/phpBB/phpbb/console/command/searchindex/create.php index ce282e94f8..9d6c71a67b 100644 --- a/phpBB/phpbb/console/command/searchindex/create.php +++ b/phpBB/phpbb/console/command/searchindex/create.php @@ -21,6 +21,7 @@ use phpbb\search\exception\no_search_backend_found_exception; use phpbb\search\search_backend_factory; use phpbb\search\state_helper; use phpbb\user; +use Symfony\Component\Console\Command\Command as symfony_command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -108,13 +109,13 @@ class create extends command catch (no_search_backend_found_exception $e) { $io->error($this->language->lang('CLI_SEARCHINDEX_BACKEND_NOT_FOUND', $search_backend)); - return command::FAILURE; + return symfony_command::FAILURE; } if ($this->state_helper->is_action_in_progress()) { $io->error($this->language->lang('CLI_SEARCHINDEX_ACTION_IN_PROGRESS', $search_backend)); - return command::FAILURE; + return symfony_command::FAILURE; } try @@ -130,7 +131,6 @@ class create extends command { $this->state_helper->update_counter($status['post_counter']); - $progress->setMaxSteps($status['max_post_id']); $progress->setProgress($status['post_counter']); $progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s'); } @@ -142,7 +142,7 @@ class create extends command catch (\Exception $e) { $io->error($this->language->lang('CLI_SEARCHINDEX_CREATE_FAILURE', $name)); - return command::FAILURE; + return symfony_command::FAILURE; } $search->tidy(); @@ -152,6 +152,6 @@ class create extends command $this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_CREATED', false, array($name)); $io->success($this->language->lang('CLI_SEARCHINDEX_CREATE_SUCCESS', $name)); - return command::SUCCESS; + return symfony_command::SUCCESS; } } diff --git a/phpBB/phpbb/console/command/searchindex/delete.php b/phpBB/phpbb/console/command/searchindex/delete.php index 5fe2514eea..78e045b5c8 100644 --- a/phpBB/phpbb/console/command/searchindex/delete.php +++ b/phpBB/phpbb/console/command/searchindex/delete.php @@ -21,6 +21,7 @@ use phpbb\search\exception\no_search_backend_found_exception; use phpbb\search\search_backend_factory; use phpbb\search\state_helper; use phpbb\user; +use Symfony\Component\Console\Command\Command as symfony_command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -108,13 +109,13 @@ class delete extends command catch (no_search_backend_found_exception $e) { $io->error($this->language->lang('CLI_SEARCHINDEX_BACKEND_NOT_FOUND', $search_backend)); - return command::FAILURE; + return symfony_command::FAILURE; } if ($this->state_helper->is_action_in_progress()) { $io->error($this->language->lang('CLI_SEARCHINDEX_ACTION_IN_PROGRESS', $search_backend)); - return command::FAILURE; + return symfony_command::FAILURE; } try @@ -130,7 +131,6 @@ class delete extends command { $this->state_helper->update_counter($status['post_counter']); - $progress->setMaxSteps($status['max_post_id']); $progress->setProgress($status['post_counter']); $progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s'); } @@ -142,7 +142,7 @@ class delete extends command catch (\Exception $e) { $io->error($this->language->lang('CLI_SEARCHINDEX_DELETE_FAILURE', $name)); - return command::FAILURE; + return symfony_command::FAILURE; } $search->tidy(); @@ -152,6 +152,6 @@ class delete extends command $this->log->add('admin', ANONYMOUS, '', 'LOG_SEARCH_INDEX_REMOVED', false, array($name)); $io->success($this->language->lang('CLI_SEARCHINDEX_DELETE_SUCCESS', $name)); - return command::SUCCESS; + return symfony_command::SUCCESS; } } diff --git a/phpBB/phpbb/console/command/searchindex/list_all.php b/phpBB/phpbb/console/command/searchindex/list_all.php index cf22b8e538..566efc1921 100644 --- a/phpBB/phpbb/console/command/searchindex/list_all.php +++ b/phpBB/phpbb/console/command/searchindex/list_all.php @@ -18,6 +18,7 @@ use phpbb\console\command\command; use phpbb\di\service_collection; use phpbb\language\language; use phpbb\user; +use Symfony\Component\Console\Command\Command as symfony_command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -92,6 +93,6 @@ class list_all extends command $io->listing($search_backends); - return command::SUCCESS; + return symfony_command::SUCCESS; } } diff --git a/phpBB/phpbb/search/backend/fulltext_native.php b/phpBB/phpbb/search/backend/fulltext_native.php index 6c97ba7a52..3d76638d67 100644 --- a/phpBB/phpbb/search/backend/fulltext_native.php +++ b/phpBB/phpbb/search/backend/fulltext_native.php @@ -93,19 +93,13 @@ class fulltext_native extends base implements search_backend_interface */ protected $phpbb_dispatcher; - /** - * @var language - */ + /** @var language */ protected $language; - /** - * @var string - */ + /** @var string */ protected $search_wordlist_table; - /** - * @var string - */ + /** @var string */ protected $search_wordmatch_table; /** diff --git a/phpBB/phpbb/search/state_helper.php b/phpBB/phpbb/search/state_helper.php index ba546f6173..4380d43980 100644 --- a/phpBB/phpbb/search/state_helper.php +++ b/phpBB/phpbb/search/state_helper.php @@ -44,7 +44,7 @@ class state_helper } /** - * Returns if there is an action in progress + * Returns whether there is an action in progress * * @return bool */ @@ -101,7 +101,7 @@ class state_helper */ public function init(string $search_type, string $action): void { - // Is not possible to start a new process when there is one already running + // It's not possible to start a new process when there is one already running if ($this->is_action_in_progress()) { throw new action_in_progress_exception(); @@ -158,7 +158,7 @@ class state_helper */ private function load_state(): array { - // Is not possible to execute an action over state if is empty + // Is not possible to execute an action over state if it's empty if (!$this->is_action_in_progress()) { throw new no_action_in_progress_exception(); diff --git a/tests/console/searchindex/create_test.php b/tests/console/searchindex/create_test.php index fef0117e7b..88c42ab897 100644 --- a/tests/console/searchindex/create_test.php +++ b/tests/console/searchindex/create_test.php @@ -5,10 +5,10 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -require_once __DIR__ . '/base.php'; -require_once __DIR__ . '/mock/search_backend_mock.php'; +require_once __DIR__ . '/phpbb_console_searchindex_base.php'; +require_once __DIR__ . '/../../mock/search_backend_mock.php'; -class create_test extends base +class phpbb_console_searchindex_create_test extends phpbb_console_searchindex_base { public function get_command_tester() { diff --git a/tests/console/searchindex/delete_test.php b/tests/console/searchindex/delete_test.php index 953fe556fc..5551231afa 100644 --- a/tests/console/searchindex/delete_test.php +++ b/tests/console/searchindex/delete_test.php @@ -5,10 +5,10 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -require_once __DIR__ . '/base.php'; -require_once __DIR__ . '/mock/search_backend_mock.php'; +require_once __DIR__ . '/phpbb_console_searchindex_base.php'; +require_once __DIR__ . '/../../mock/search_backend_mock.php'; -class delete_test extends base +class phpbb_console_searchindex_delete_test extends phpbb_console_searchindex_base { public function get_command_tester() { diff --git a/tests/console/searchindex/list_all_test.php b/tests/console/searchindex/list_all_test.php index b2308b3806..deeb262b43 100644 --- a/tests/console/searchindex/list_all_test.php +++ b/tests/console/searchindex/list_all_test.php @@ -5,10 +5,10 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -require_once __DIR__ . '/base.php'; -require_once __DIR__ . '/mock/search_backend_mock.php'; +require_once __DIR__ . '/phpbb_console_searchindex_base.php'; +require_once __DIR__ . '/../../mock/search_backend_mock.php'; -class list_all_test extends base +class phpbb_console_searchindex_list_all_test extends phpbb_console_searchindex_base { public function get_command_tester() { diff --git a/tests/console/searchindex/base.php b/tests/console/searchindex/phpbb_console_searchindex_base.php similarity index 82% rename from tests/console/searchindex/base.php rename to tests/console/searchindex/phpbb_console_searchindex_base.php index 15372a5582..58d850cc6e 100644 --- a/tests/console/searchindex/base.php +++ b/tests/console/searchindex/phpbb_console_searchindex_base.php @@ -1,4 +1,15 @@ + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ use phpbb\config\config; use phpbb\di\service_collection; @@ -9,9 +20,9 @@ use phpbb\search\search_backend_factory; use phpbb\search\state_helper; use phpbb\user; -require_once __DIR__ . '/mock/search_backend_mock.php'; +require_once __DIR__ . '/../../mock/search_backend_mock.php'; -class base extends phpbb_test_case +class phpbb_console_searchindex_base extends phpbb_test_case { /** @var config */ protected $config; diff --git a/tests/console/searchindex/mock/search_backend_mock.php b/tests/mock/search_backend_mock.php similarity index 100% rename from tests/console/searchindex/mock/search_backend_mock.php rename to tests/mock/search_backend_mock.php