diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 438d798b76..b38e39300c 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -78,7 +78,8 @@ class acp_search foreach ($search_types as $search) { // Only show available search backends - if($search->is_available()) { + if ($search->is_available()) + { $name = $search->get_name(); @@ -88,16 +89,20 @@ class acp_search $identifier = substr($type, strrpos($type, '\\') + 1); $search_options .= ""; - if (method_exists($search, 'acp')) { + if (method_exists($search, 'acp')) + { $vars = $search->acp(); - if (!$submit) { + if (!$submit) + { $template->assign_block_vars('backend', array( 'NAME' => $name, 'SETTINGS' => $vars['tpl'], 'IDENTIFIER' => $identifier, )); - } else if (is_array($vars['config'])) { + } + else if (is_array($vars['config'])) + { $settings = array_merge($settings, $vars['config']); } } diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 5d61ac640d..5e257cfa11 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -1404,11 +1404,6 @@ function mcp_fork_topic($topic_ids) $search_backend_factory = $phpbb_container->get('search.backend_factory'); $search = $search_backend_factory->get_active(); $search_mode = 'post'; - - if ($error) - { - trigger_error($error); - } } else if (!isset($search_type) && !$topic_row['enable_indexing']) { diff --git a/phpBB/phpbb/search/backend/base.php b/phpBB/phpbb/search/backend/base.php index 172edeca4d..f62d798d53 100644 --- a/phpBB/phpbb/search/backend/base.php +++ b/phpBB/phpbb/search/backend/base.php @@ -296,6 +296,11 @@ abstract class base implements search_backend_interface { $rows = $this->get_posts_between($post_counter + 1, $post_counter + self::BATCH_SIZE); + if ($this->db->sql_buffer_nested_transactions()) + { + $rows = iterator_to_array($rows); + } + foreach ($rows as $row) { // Indexing enabled for this forum @@ -415,7 +420,7 @@ abstract class base implements search_backend_interface AND post_id <= ' . $final_id; $result = $this->db->sql_query($sql); - while($row = $this->db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { yield $row; } diff --git a/phpBB/phpbb/search/backend/fulltext_mysql.php b/phpBB/phpbb/search/backend/fulltext_mysql.php index b35f392578..0860d3d7a8 100644 --- a/phpBB/phpbb/search/backend/fulltext_mysql.php +++ b/phpBB/phpbb/search/backend/fulltext_mysql.php @@ -123,7 +123,7 @@ class fulltext_mysql extends base implements search_backend_interface public function is_available(): bool { // Check if we are using mysql - if($this->db->get_sql_layer() != 'mysqli') + if ($this->db->get_sql_layer() != 'mysqli') { return false; } diff --git a/phpBB/phpbb/search/backend/fulltext_sphinx.php b/phpBB/phpbb/search/backend/fulltext_sphinx.php index cd8d2194e1..a7df8fcb23 100644 --- a/phpBB/phpbb/search/backend/fulltext_sphinx.php +++ b/phpBB/phpbb/search/backend/fulltext_sphinx.php @@ -649,7 +649,8 @@ class fulltext_sphinx implements search_backend_interface */ public function delete_index(int &$post_counter = null): ?array { - if ($this->index_created()) { + if ($this->index_created()) + { $this->db_tools->sql_table_drop(SPHINX_TABLE); } diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index bba1281551..8f3c6295e6 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -13,7 +13,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions_admin.php'; require_once __DIR__ . '/../../phpBB/includes/functions_posting.php'; -require_once __DIR__ . '/../mock/search.php'; class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case { diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php index b849724bf9..885cd9c684 100644 --- a/tests/functional/search/base.php +++ b/tests/functional/search/base.php @@ -38,7 +38,7 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case $this->login(); $this->admin_login(); - $this->create_search_index('phpbb\search\backend\fulltext_native'); + $this->create_search_index('phpbb\\search\\backend\\fulltext_native'); $post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.'); @@ -49,18 +49,28 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case if ($values["config[search_type]"] != $this->search_backend) { $values["config[search_type]"] = $this->search_backend; - $form->setValues($values); + + try + { + $form->setValues($values); + } + catch(\InvalidArgumentException $e) + { + // Search backed is not supported because don't appear in the select + $this->delete_topic($post['topic_id']); + $this->markTestSkipped("Search backend is not supported/running"); + } + $crawler = self::submit($form); $form = $crawler->selectButton('Yes')->form(); $values = $form->getValues(); $crawler = self::submit($form); - // check if search backend is not supported + // Unknown error selecting search backend if ($crawler->filter('.errorbox')->count() > 0) { - $this->delete_topic($post['topic_id']); - $this->markTestSkipped("Search backend is not supported/running"); + $this->fail('Error when trying to select available search backend'); } $this->create_search_index(); diff --git a/tests/mock/user.php b/tests/mock/user.php index 5352a22b27..254c02f669 100644 --- a/tests/mock/user.php +++ b/tests/mock/user.php @@ -26,7 +26,7 @@ class phpbb_mock_user public $lang = []; private $options = array(); - public function optionget($item) + public function optionget($item, $data = false) { if (!isset($this->options[$item])) { @@ -36,7 +36,7 @@ class phpbb_mock_user return $this->options[$item]; } - public function optionset($item, $value) + public function optionset($item, $value, $data = false) { $this->options[$item] = $value; } diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 75f534c328..d8f1ac9e94 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -24,13 +24,15 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case protected function setUp(): void { - global $phpbb_root_path, $phpEx, $config, $user, $cache; + global $phpbb_root_path, $phpEx, $config, $cache; parent::setUp(); // dbal uses cache $cache = new phpbb_mock_cache(); + $user = $this->createMock('\phpbb\user'); + // set config values $config['fulltext_mysql_min_word_len'] = 4; $config['fulltext_mysql_max_word_len'] = 254; diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 652206e1b4..fe2caa6cdd 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -24,13 +24,15 @@ class phpbb_search_native_test extends phpbb_search_test_case protected function setUp(): void { - global $phpbb_root_path, $phpEx, $config, $user, $cache; + global $phpbb_root_path, $phpEx, $config, $cache; parent::setUp(); // dbal uses cache $cache = new phpbb_mock_cache(); + $user = $this->createMock('\phpbb\user'); + $this->db = $this->new_dbal(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $class = self::get_search_wrapper('\phpbb\search\backend\fulltext_native'); diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 5f2466a76b..bfb69cf14e 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -24,13 +24,15 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case protected function setUp(): void { - global $phpbb_root_path, $phpEx, $config, $user, $cache; + global $phpbb_root_path, $phpEx, $config, $cache; parent::setUp(); // dbal uses cache $cache = new phpbb_mock_cache(); + $user = $this->createMock('\phpbb\user'); + // set config values $config['fulltext_postgres_min_word_len'] = 4; $config['fulltext_postgres_max_word_len'] = 254;