diff --git a/phpBB/config/default/container/services_search.yml b/phpBB/config/default/container/services_search.yml index dc29617bf8..fceb254eaa 100644 --- a/phpBB/config/default/container/services_search.yml +++ b/phpBB/config/default/container/services_search.yml @@ -4,7 +4,7 @@ services: class: phpbb\search\state_helper arguments: - '@config' - - '@search.backend_collection' + - '@search.backend_factory' # Search backends search.fulltext.mysql: @@ -15,6 +15,7 @@ services: - '@dispatcher' - '@language' - '@user' + - '%tables.search_results%' - '%core.root_path%' - '%core.php_ext%' tags: @@ -28,6 +29,9 @@ services: - '@dispatcher' - '@language' - '@user' + - '%tables.search_results%' + - '%tables.search_wordlist%' + - '%tables.search_wordmatch%' - '%core.root_path%' - '%core.php_ext%' tags: @@ -41,6 +45,7 @@ services: - '@dispatcher' - '@language' - '@user' + - '%tables.search_results%' - '%core.root_path%' - '%core.php_ext%' tags: diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 667e74baaa..cece03476b 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -323,21 +323,24 @@ class acp_search foreach ($this->search_backend_collection as $search) { - $this->template->assign_block_vars('backends', [ - 'NAME' => $search->get_name(), - 'TYPE' => $search->get_type(), + if ($search->is_available()) + { + $this->template->assign_block_vars('backends', [ + 'NAME' => $search->get_name(), + 'TYPE' => $search->get_type(), - 'S_ACTIVE' => $search->get_type() === $this->config['search_type'], - 'S_HIDDEN_FIELDS' => build_hidden_fields(['search_type' => $search->get_type()]), - 'S_INDEXED' => $search->index_created(), - 'S_STATS' => $search->index_stats(), - ]); + 'S_ACTIVE' => $search->get_type() === $this->config['search_type'], + 'S_HIDDEN_FIELDS' => build_hidden_fields(['search_type' => $search->get_type()]), + 'S_INDEXED' => $search->index_created(), + 'S_STATS' => $search->index_stats(), + ]); + + $this->template->assign_vars([ + 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), + 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), + ]); + } } - - $this->template->assign_vars([ - 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), - 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), - ]); } /** diff --git a/phpBB/phpbb/console/command/searchindex/create.php b/phpBB/phpbb/console/command/searchindex/create.php index 2ee2c0f35a..0bd291b99e 100644 --- a/phpBB/phpbb/console/command/searchindex/create.php +++ b/phpBB/phpbb/console/command/searchindex/create.php @@ -146,7 +146,7 @@ class create extends command $io->newLine(2); } - catch(index_created_exception $e) + catch (index_created_exception $e) { $this->state_helper->clear_state(); $io->error($this->language->lang('CLI_SEARCHINDEX_ALREADY_CREATED', $name)); diff --git a/phpBB/phpbb/console/command/searchindex/delete.php b/phpBB/phpbb/console/command/searchindex/delete.php index c2ba8f0476..8ffaa808f3 100644 --- a/phpBB/phpbb/console/command/searchindex/delete.php +++ b/phpBB/phpbb/console/command/searchindex/delete.php @@ -146,7 +146,7 @@ class delete extends command $io->newLine(2); } - catch(index_empty_exception $e) + catch (index_empty_exception $e) { $this->state_helper->clear_state(); $io->error($this->language->lang('CLI_SEARCHINDEX_NO_CREATED', $name)); diff --git a/phpBB/phpbb/post/post_helper.php b/phpBB/phpbb/post/post_helper.php index f039771e10..a70d38fb1c 100644 --- a/phpBB/phpbb/post/post_helper.php +++ b/phpBB/phpbb/post/post_helper.php @@ -13,7 +13,6 @@ namespace phpbb\post; - use phpbb\db\driver\driver_interface; class post_helper diff --git a/phpBB/phpbb/search/backend/base.php b/phpBB/phpbb/search/backend/base.php index e1b0f142a2..e554e0cc71 100644 --- a/phpBB/phpbb/search/backend/base.php +++ b/phpBB/phpbb/search/backend/base.php @@ -53,20 +53,27 @@ abstract class base implements search_backend_interface */ protected $user; + /** + * @var string + */ + protected $search_results_table; + /** * Constructor. * - * @param service $cache - * @param config $config + * @param service $cache + * @param config $config * @param driver_interface $db - * @param user $user + * @param user $user + * @param string $search_results_table */ - public function __construct(service $cache, config $config, driver_interface $db, user $user) + public function __construct(service $cache, config $config, driver_interface $db, user $user, string $search_results_table) { $this->cache = $cache; $this->config = $config; $this->db = $db; $this->user = $user; + $this->search_results_table = $search_results_table; } /** @@ -182,7 +189,7 @@ abstract class base implements search_backend_interface if (!empty($keywords) || count($author_ary)) { $sql = 'SELECT search_time - FROM ' . SEARCH_RESULTS_TABLE . ' + FROM ' . $this->search_results_table . ' WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\''; $result = $this->db->sql_query($sql); @@ -195,7 +202,7 @@ abstract class base implements search_backend_interface 'search_authors' => ' ' . implode(' ', $author_ary) . ' ' ); - $sql = 'INSERT INTO ' . SEARCH_RESULTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $sql = 'INSERT INTO ' . $this->search_results_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); } $this->db->sql_freeresult($result); @@ -255,7 +262,7 @@ abstract class base implements search_backend_interface } $this->cache->put('_search_results_' . $search_key, $store, $this->config['search_store_results']); - $sql = 'UPDATE ' . SEARCH_RESULTS_TABLE . ' + $sql = 'UPDATE ' . $this->search_results_table . ' SET search_time = ' . time() . ' WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\''; $this->db->sql_query($sql); @@ -282,7 +289,7 @@ abstract class base implements search_backend_interface } $sql = 'SELECT search_key - FROM ' . SEARCH_RESULTS_TABLE . " + FROM ' . $this->search_results_table . " WHERE search_keywords LIKE '%*%' $sql_where"; $result = $this->db->sql_query($sql); @@ -303,7 +310,7 @@ abstract class base implements search_backend_interface } $sql = 'SELECT search_key - FROM ' . SEARCH_RESULTS_TABLE . " + FROM ' . $this->search_results_table . " WHERE $sql_where"; $result = $this->db->sql_query($sql); @@ -315,7 +322,7 @@ abstract class base implements search_backend_interface } $sql = 'DELETE - FROM ' . SEARCH_RESULTS_TABLE . ' + FROM ' . $this->search_results_table . ' WHERE search_time < ' . (time() - (int) $this->config['search_store_results']); $this->db->sql_query($sql); } diff --git a/phpBB/phpbb/search/backend/fulltext_mysql.php b/phpBB/phpbb/search/backend/fulltext_mysql.php index febaee3495..e9fce05fc1 100644 --- a/phpBB/phpbb/search/backend/fulltext_mysql.php +++ b/phpBB/phpbb/search/backend/fulltext_mysql.php @@ -19,8 +19,8 @@ use phpbb\event\dispatcher_interface; use phpbb\language\language; use phpbb\search\exception\index_created_exception; use phpbb\search\exception\index_empty_exception; +use phpbb\search\exception\search_exception; use phpbb\user; -use RuntimeException; /** * Fulltext search for MySQL @@ -74,19 +74,20 @@ class fulltext_mysql extends base implements search_backend_interface * Constructor * Creates a new \phpbb\search\backend\fulltext_mysql, which is used as a search backend * - * @param config $config Config object - * @param driver_interface $db Database object + * @param config $config Config object + * @param driver_interface $db Database object * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object - * @param language $language - * @param user $user User object - * @param string $phpbb_root_path Relative path to phpBB root - * @param string $phpEx PHP file extension + * @param language $language + * @param user $user User object + * @param string $search_results_table + * @param string $phpbb_root_path Relative path to phpBB root + * @param string $phpEx PHP file extension */ - public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) + public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $search_results_table, string $phpbb_root_path, string $phpEx) { global $cache; - parent::__construct($cache, $config, $db, $user); + parent::__construct($cache, $config, $db, $user, $search_results_table); $this->phpbb_dispatcher = $phpbb_dispatcher; $this->language = $language; @@ -923,7 +924,7 @@ class fulltext_mysql extends base implements search_backend_interface // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) { - throw new RuntimeException($error); + throw new search_exception($error); } if (empty($this->stats)) @@ -982,7 +983,7 @@ class fulltext_mysql extends base implements search_backend_interface $this->db->sql_query($sql_query); } - $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table); return null; } @@ -1000,7 +1001,7 @@ class fulltext_mysql extends base implements search_backend_interface // Make sure we can actually use MySQL with fulltext indexes if ($error = $this->init()) { - throw new RuntimeException($error); + throw new search_exception($error); } if (empty($this->stats)) @@ -1053,7 +1054,7 @@ class fulltext_mysql extends base implements search_backend_interface $this->db->sql_query($sql_query); } - $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table); return null; } diff --git a/phpBB/phpbb/search/backend/fulltext_native.php b/phpBB/phpbb/search/backend/fulltext_native.php index f4d141dd59..dac6ebf803 100644 --- a/phpBB/phpbb/search/backend/fulltext_native.php +++ b/phpBB/phpbb/search/backend/fulltext_native.php @@ -99,25 +99,41 @@ class fulltext_native extends base implements search_backend_interface */ protected $language; + /** + * @var string + */ + protected $search_wordlist_table; + + /** + * @var string + */ + protected $search_wordmatch_table; + /** * Initialises the fulltext_native search backend with min/max word length * - * @param config $config Config object - * @param driver_interface $db Database object + * @param config $config Config object + * @param driver_interface $db Database object * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object - * @param language $language - * @param user $user User object - * @param string $phpbb_root_path phpBB root path - * @param string $phpEx PHP file extension + * @param language $language + * @param user $user User object + * @param string $search_results_table + * @param string $search_wordlist_table + * @param string $search_wordmatch_table + * @param string $phpbb_root_path phpBB root path + * @param string $phpEx PHP file extension */ - public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) + public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $search_results_table, string $search_wordlist_table, string $search_wordmatch_table, string $phpbb_root_path, string $phpEx) { global $cache; - parent::__construct($cache, $config, $db, $user); + parent::__construct($cache, $config, $db, $user, $search_results_table); $this->phpbb_dispatcher = $phpbb_dispatcher; $this->language = $language; + $this->search_wordlist_table = $search_wordlist_table; + $this->search_wordmatch_table = $search_wordmatch_table; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; @@ -336,7 +352,7 @@ class fulltext_native extends base implements search_backend_interface if (count($exact_words)) { $sql = 'SELECT word_id, word_text, word_common - FROM ' . SEARCH_WORDLIST_TABLE . ' + FROM ' . $this->search_wordlist_table . ' WHERE ' . $this->db->sql_in_set('word_text', $exact_words) . ' ORDER BY word_count ASC'; $result = $this->db->sql_query($sql); @@ -608,8 +624,8 @@ class fulltext_native extends base implements search_backend_interface $sql_array = array( 'SELECT' => ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id', 'FROM' => array( - SEARCH_WORDMATCH_TABLE => array(), - SEARCH_WORDLIST_TABLE => array(), + $this->search_wordmatch_table => array(), + $this->search_wordlist_table => array(), ), 'LEFT_JOIN' => array(array( 'FROM' => array(POSTS_TABLE => 'p'), @@ -661,7 +677,7 @@ class fulltext_native extends base implements search_backend_interface if (is_string($id)) { $sql_array['LEFT_JOIN'][] = array( - 'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), + 'FROM' => array($this->search_wordlist_table => 'w' . $w_num), 'ON' => "w$w_num.word_text LIKE $id" ); $word_ids[] = "w$w_num.word_id"; @@ -681,7 +697,7 @@ class fulltext_native extends base implements search_backend_interface } else if (is_string($subquery)) { - $sql_array['FROM'][SEARCH_WORDLIST_TABLE][] = 'w' . $w_num; + $sql_array['FROM'][$this->search_wordlist_table][] = 'w' . $w_num; $sql_where[] = "w$w_num.word_text LIKE $subquery"; $sql_where[] = "m$m_num.word_id = w$w_num.word_id"; @@ -694,7 +710,7 @@ class fulltext_native extends base implements search_backend_interface $sql_where[] = "m$m_num.word_id = $subquery"; } - $sql_array['FROM'][SEARCH_WORDMATCH_TABLE][] = 'm' . $m_num; + $sql_array['FROM'][$this->search_wordmatch_table][] = 'm' . $m_num; if ($title_match) { @@ -713,7 +729,7 @@ class fulltext_native extends base implements search_backend_interface if (is_string($subquery)) { $sql_array['LEFT_JOIN'][] = array( - 'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), + 'FROM' => array($this->search_wordlist_table => 'w' . $w_num), 'ON' => "w$w_num.word_text LIKE $subquery" ); @@ -727,7 +743,7 @@ class fulltext_native extends base implements search_backend_interface if (count($this->must_not_contain_ids)) { $sql_array['LEFT_JOIN'][] = array( - 'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), + 'FROM' => array($this->search_wordmatch_table => 'm' . $m_num), 'ON' => $this->db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id" ); @@ -743,7 +759,7 @@ class fulltext_native extends base implements search_backend_interface if (is_string($id)) { $sql_array['LEFT_JOIN'][] = array( - 'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), + 'FROM' => array($this->search_wordlist_table => 'w' . $w_num), 'ON' => "w$w_num.word_text LIKE $id" ); $id = "w$w_num.word_id"; @@ -753,7 +769,7 @@ class fulltext_native extends base implements search_backend_interface } $sql_array['LEFT_JOIN'][] = array( - 'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), + 'FROM' => array($this->search_wordmatch_table => 'm' . $m_num), 'ON' => "m$m_num.word_id = $id AND m$m_num.post_id = m0.post_id" . (($title_match) ? " AND m$m_num.$title_match" : '') ); $is_null_joins[] = "m$m_num.word_id IS NULL"; @@ -1311,7 +1327,7 @@ class fulltext_native extends base implements search_backend_interface $words['del']['title'] = array(); $sql = 'SELECT w.word_id, w.word_text, m.title_match - FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m + FROM ' . $this->search_wordlist_table . ' w, ' . $this->search_wordmatch_table . " m WHERE m.post_id = $post_id AND w.word_id = m.word_id"; $result = $this->db->sql_query($sql); @@ -1380,7 +1396,7 @@ class fulltext_native extends base implements search_backend_interface if (count($unique_add_words)) { $sql = 'SELECT word_id, word_text - FROM ' . SEARCH_WORDLIST_TABLE . ' + FROM ' . $this->search_wordlist_table . ' WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words); $result = $this->db->sql_query($sql); @@ -1402,7 +1418,7 @@ class fulltext_native extends base implements search_backend_interface $sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0); } $this->db->sql_return_on_error(true); - $this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); + $this->db->sql_multi_insert($this->search_wordlist_table, $sql_ary); $this->db->sql_return_on_error(false); } unset($new_words, $sql_ary); @@ -1425,13 +1441,13 @@ class fulltext_native extends base implements search_backend_interface $sql_in[] = $cur_words[$word_in][$word]; } - $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' + $sql = 'DELETE FROM ' . $this->search_wordmatch_table . ' WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND post_id = ' . intval($post_id) . " AND title_match = $title_match"; $this->db->sql_query($sql); - $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' + $sql = 'UPDATE ' . $this->search_wordlist_table . ' SET word_count = word_count - 1 WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND word_count > 0'; @@ -1448,13 +1464,13 @@ class fulltext_native extends base implements search_backend_interface if (count($word_ary)) { - $sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match) + $sql = 'INSERT INTO ' . $this->search_wordmatch_table . ' (post_id, word_id, title_match) SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . ' - FROM ' . SEARCH_WORDLIST_TABLE . ' + FROM ' . $this->search_wordlist_table . ' WHERE ' . $this->db->sql_in_set('word_text', $word_ary); $this->db->sql_query($sql); - $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' + $sql = 'UPDATE ' . $this->search_wordlist_table . ' SET word_count = word_count + 1 WHERE ' . $this->db->sql_in_set('word_text', $word_ary); $this->db->sql_query($sql); @@ -1480,7 +1496,7 @@ class fulltext_native extends base implements search_backend_interface if (count($post_ids)) { $sql = 'SELECT w.word_id, w.word_text, m.title_match - FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w + FROM ' . $this->search_wordmatch_table . ' m, ' . $this->search_wordlist_table . ' w WHERE ' . $this->db->sql_in_set('m.post_id', $post_ids) . ' AND w.word_id = m.word_id'; $result = $this->db->sql_query($sql); @@ -1502,7 +1518,7 @@ class fulltext_native extends base implements search_backend_interface if (count($title_word_ids)) { - $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' + $sql = 'UPDATE ' . $this->search_wordlist_table . ' SET word_count = word_count - 1 WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . ' AND word_count > 0'; @@ -1511,7 +1527,7 @@ class fulltext_native extends base implements search_backend_interface if (count($message_word_ids)) { - $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' + $sql = 'UPDATE ' . $this->search_wordlist_table . ' SET word_count = word_count - 1 WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . ' AND word_count > 0'; @@ -1521,7 +1537,7 @@ class fulltext_native extends base implements search_backend_interface unset($title_word_ids); unset($message_word_ids); - $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' + $sql = 'DELETE FROM ' . $this->search_wordmatch_table . ' WHERE ' . $this->db->sql_in_set('post_id', $post_ids); $this->db->sql_query($sql); } @@ -1550,7 +1566,7 @@ class fulltext_native extends base implements search_backend_interface $common_threshold = ((double) $this->config['fulltext_native_common_thres']) / 100.0; // First, get the IDs of common words $sql = 'SELECT word_id, word_text - FROM ' . SEARCH_WORDLIST_TABLE . ' + FROM ' . $this->search_wordlist_table . ' WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . ' OR word_common = 1'; $result = $this->db->sql_query($sql); @@ -1566,7 +1582,7 @@ class fulltext_native extends base implements search_backend_interface if (count($sql_in)) { // Flag the words - $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' + $sql = 'UPDATE ' . $this->search_wordlist_table . ' SET word_common = 1 WHERE ' . $this->db->sql_in_set('word_id', $sql_in); $this->db->sql_query($sql); @@ -1576,7 +1592,7 @@ class fulltext_native extends base implements search_backend_interface $this->config->set('search_last_gc', time(), false); // Delete the matches - $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' + $sql = 'DELETE FROM ' . $this->search_wordmatch_table . ' WHERE ' . $this->db->sql_in_set('word_id', $sql_in); $this->db->sql_query($sql); } @@ -1609,15 +1625,15 @@ class fulltext_native extends base implements search_backend_interface switch ($this->db->get_sql_layer()) { case 'sqlite3': - $sql_queries[] = 'DELETE FROM ' . SEARCH_WORDLIST_TABLE; - $sql_queries[] = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE; - $sql_queries[] = 'DELETE FROM ' . SEARCH_RESULTS_TABLE; + $sql_queries[] = 'DELETE FROM ' . $this->search_wordlist_table; + $sql_queries[] = 'DELETE FROM ' . $this->search_wordmatch_table; + $sql_queries[] = 'DELETE FROM ' . $this->search_results_table; break; default: - $sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE; - $sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE; - $sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE; + $sql_queries[] = 'TRUNCATE TABLE ' . $this->search_wordlist_table; + $sql_queries[] = 'TRUNCATE TABLE ' . $this->search_wordmatch_table; + $sql_queries[] = 'TRUNCATE TABLE ' . $this->search_results_table; break; } @@ -1678,8 +1694,8 @@ class fulltext_native extends base implements search_backend_interface */ protected function get_stats() { - $this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); - $this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); + $this->stats['total_words'] = $this->db->get_estimated_row_count($this->search_wordlist_table); + $this->stats['total_matches'] = $this->db->get_estimated_row_count($this->search_wordmatch_table); } /** diff --git a/phpBB/phpbb/search/backend/fulltext_postgres.php b/phpBB/phpbb/search/backend/fulltext_postgres.php index 077eee4f30..9b9822d2da 100644 --- a/phpBB/phpbb/search/backend/fulltext_postgres.php +++ b/phpBB/phpbb/search/backend/fulltext_postgres.php @@ -19,8 +19,8 @@ use phpbb\event\dispatcher_interface; use phpbb\language\language; use phpbb\search\exception\index_created_exception; use phpbb\search\exception\index_empty_exception; +use phpbb\search\exception\search_exception; use phpbb\user; -use RuntimeException; /** * Fulltext search for PostgreSQL @@ -86,19 +86,20 @@ class fulltext_postgres extends base implements search_backend_interface * Constructor * Creates a new \phpbb\search\backend\fulltext_postgres, which is used as a search backend * - * @param config $config Config object - * @param driver_interface $db Database object + * @param config $config Config object + * @param driver_interface $db Database object * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object - * @param language $language - * @param user $user User object - * @param string $phpbb_root_path Relative path to phpBB root - * @param string $phpEx PHP file extension + * @param language $language + * @param user $user User object + * @param string $search_results_table + * @param string $phpbb_root_path Relative path to phpBB root + * @param string $phpEx PHP file extension */ - public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) + public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $search_results_table, string $phpbb_root_path, string $phpEx) { global $cache; - parent::__construct($cache, $config, $db, $user); + parent::__construct($cache, $config, $db, $user, $search_results_table); $this->phpbb_dispatcher = $phpbb_dispatcher; $this->language = $language; @@ -878,7 +879,7 @@ class fulltext_postgres extends base implements search_backend_interface // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) { - throw new RuntimeException($error); + throw new search_exception($error); } if (empty($this->stats)) @@ -924,7 +925,7 @@ class fulltext_postgres extends base implements search_backend_interface $this->db->sql_query($sql_query); } - $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table); return null; } @@ -942,7 +943,7 @@ class fulltext_postgres extends base implements search_backend_interface // Make sure we can actually use PostgreSQL with fulltext indexes if ($error = $this->init()) { - throw new RuntimeException($error); + throw new search_exception($error); } if (empty($this->stats)) @@ -988,7 +989,7 @@ class fulltext_postgres extends base implements search_backend_interface $this->db->sql_query($sql_query); } - $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); + $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table); return null; } diff --git a/phpBB/phpbb/search/backend/fulltext_sphinx.php b/phpBB/phpbb/search/backend/fulltext_sphinx.php index 74ff23bbf8..53342e6214 100644 --- a/phpBB/phpbb/search/backend/fulltext_sphinx.php +++ b/phpBB/phpbb/search/backend/fulltext_sphinx.php @@ -632,7 +632,7 @@ class fulltext_sphinx implements search_backend_interface */ public function create_index(int &$post_counter = 0): ?array { - if (!$this->index_created()) + if ($this->index_created()) { throw new index_empty_exception(); } diff --git a/phpBB/phpbb/search/exception/action_in_progress_exception.php b/phpBB/phpbb/search/exception/action_in_progress_exception.php index 183c00f512..fdf9326414 100644 --- a/phpBB/phpbb/search/exception/action_in_progress_exception.php +++ b/phpBB/phpbb/search/exception/action_in_progress_exception.php @@ -13,7 +13,6 @@ namespace phpbb\search\exception; - class action_in_progress_exception extends search_exception { diff --git a/phpBB/phpbb/search/exception/index_created_exception.php b/phpBB/phpbb/search/exception/index_created_exception.php index 9be91bfbb8..e46f995baf 100644 --- a/phpBB/phpbb/search/exception/index_created_exception.php +++ b/phpBB/phpbb/search/exception/index_created_exception.php @@ -13,7 +13,6 @@ namespace phpbb\search\exception; - class index_created_exception extends search_exception { diff --git a/phpBB/phpbb/search/exception/index_empty_exception.php b/phpBB/phpbb/search/exception/index_empty_exception.php index a6a55698de..6045866235 100644 --- a/phpBB/phpbb/search/exception/index_empty_exception.php +++ b/phpBB/phpbb/search/exception/index_empty_exception.php @@ -13,7 +13,6 @@ namespace phpbb\search\exception; - class index_empty_exception extends search_exception { diff --git a/phpBB/phpbb/search/exception/no_action_in_progress_exception.php b/phpBB/phpbb/search/exception/no_action_in_progress_exception.php index 4c04b8c720..15ce250366 100644 --- a/phpBB/phpbb/search/exception/no_action_in_progress_exception.php +++ b/phpBB/phpbb/search/exception/no_action_in_progress_exception.php @@ -13,7 +13,6 @@ namespace phpbb\search\exception; - class no_action_in_progress_exception extends search_exception { diff --git a/phpBB/phpbb/search/exception/search_exception.php b/phpBB/phpbb/search/exception/search_exception.php index 962d30b879..18119b75a4 100644 --- a/phpBB/phpbb/search/exception/search_exception.php +++ b/phpBB/phpbb/search/exception/search_exception.php @@ -17,5 +17,5 @@ use phpbb\exception\runtime_exception; class search_exception extends runtime_exception { - // TODO: Launch this exception from search instead of RuntimeException + } diff --git a/phpBB/phpbb/search/state_helper.php b/phpBB/phpbb/search/state_helper.php index b3e5dd0aea..078096f2d4 100644 --- a/phpBB/phpbb/search/state_helper.php +++ b/phpBB/phpbb/search/state_helper.php @@ -16,6 +16,7 @@ namespace phpbb\search; use phpbb\config\config; use phpbb\search\exception\action_in_progress_exception; use phpbb\search\exception\no_action_in_progress_exception; +use phpbb\search\exception\search_exception; class state_helper { @@ -32,8 +33,8 @@ class state_helper /** * Constructor. * - * @param \phpbb\config\config $config - * @param \phpbb\search\search_backend_factory $search_backend_factory + * @param config $config + * @param search_backend_factory $search_backend_factory */ public function __construct(config $config, search_backend_factory $search_backend_factory) { @@ -108,7 +109,7 @@ class state_helper // Make sure the action is correct (just in case) if (!in_array($action, ['create', 'delete'])) { - throw new \RuntimeException('Invalid action'); + throw new search_exception('Invalid action'); } $state = [