diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 53fc6f5925..2c7e36d6e3 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -155,7 +155,8 @@ class acp_search $search = $search_backend_factory->get($cfg_array['search_type']); if (confirm_box(true)) { - if (!method_exists($search, 'init') || !($error = $search->init())) + // Initialize search backend, if $error is false means that everything is ok + if (!($error = $search->init())) { $config->set('search_type', $cfg_array['search_type']); diff --git a/phpBB/phpbb/search/backend/fulltext_mysql.php b/phpBB/phpbb/search/backend/fulltext_mysql.php index e95596022b..ef06911c65 100644 --- a/phpBB/phpbb/search/backend/fulltext_mysql.php +++ b/phpBB/phpbb/search/backend/fulltext_mysql.php @@ -121,38 +121,18 @@ class fulltext_mysql extends base implements search_backend_interface */ public function is_available(): bool { - return $this->db->get_sql_layer() == 'mysqli'; + // Check if we are using mysql + if($this->db->get_sql_layer() != 'mysqli') + { + return false; + } + + return true; } /** * {@inheritdoc} */ - public function get_search_query(): string - { - return $this->search_query; - } - - /** - * {@inheritdoc} - */ - public function get_common_words(): array - { - return $this->common_words; - } - - /** - * {@inheritdoc} - */ - public function get_word_length(): array - { - return $this->word_length; - } - - /** - * Checks for correct MySQL version and stores min/max word length in the config - * - * @return string|bool Language key of the error/incompatibility occurred - */ public function init() { if (!$this->is_available()) @@ -164,15 +144,7 @@ class fulltext_mysql extends base implements search_backend_interface $info = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $engine = ''; - if (isset($info['Engine'])) - { - $engine = $info['Engine']; - } - else if (isset($info['Type'])) - { - $engine = $info['Type']; - } + $engine = $info['Engine'] ?? $info['Type'] ?? ''; $fulltext_supported = $engine === 'Aria' || $engine === 'MyISAM' /** @@ -182,7 +154,7 @@ class fulltext_mysql extends base implements search_backend_interface * fixed for proper overall operation. Hence we require 5.6.8. */ || ($engine === 'InnoDB' - && phpbb_version_compare($this->db->sql_server_info(true), '5.6.8', '>=')); + && phpbb_version_compare($this->db->sql_server_info(true), '5.6.8', '>=')); if (!$fulltext_supported) { @@ -214,6 +186,30 @@ class fulltext_mysql extends base implements search_backend_interface return false; } + /** + * {@inheritdoc} + */ + public function get_search_query(): string + { + return $this->search_query; + } + + /** + * {@inheritdoc} + */ + public function get_common_words(): array + { + return $this->common_words; + } + + /** + * {@inheritdoc} + */ + public function get_word_length(): array + { + return $this->word_length; + } + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/search/backend/fulltext_native.php b/phpBB/phpbb/search/backend/fulltext_native.php index 81541930a7..ad042a545a 100644 --- a/phpBB/phpbb/search/backend/fulltext_native.php +++ b/phpBB/phpbb/search/backend/fulltext_native.php @@ -157,6 +157,14 @@ class fulltext_native extends base implements search_backend_interface return true; } + /** + * {@inheritdoc} + */ + public function init() + { + return false; + } + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/search/backend/fulltext_postgres.php b/phpBB/phpbb/search/backend/fulltext_postgres.php index 234b820f29..ad0ad220fc 100644 --- a/phpBB/phpbb/search/backend/fulltext_postgres.php +++ b/phpBB/phpbb/search/backend/fulltext_postgres.php @@ -137,6 +137,19 @@ class fulltext_postgres extends base implements search_backend_interface return $this->db->get_sql_layer() == 'postgres'; } + /** + * {@inheritdoc} + */ + public function init() + { + if (!$this->is_available()) + { + return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; + } + + return false; + } + /** * {@inheritdoc} */ @@ -171,21 +184,6 @@ class fulltext_postgres extends base implements search_backend_interface return $this->phrase_search; } - /** - * Checks for correct PostgreSQL version and stores min/max word length in the config - * - * @return string|bool Language key of the error/incompatibility occurred - */ - public function init() - { - if (!$this->is_available()) - { - return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; - } - - return false; - } - /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/search/backend/fulltext_sphinx.php b/phpBB/phpbb/search/backend/fulltext_sphinx.php index c53116af71..4a65aa944a 100644 --- a/phpBB/phpbb/search/backend/fulltext_sphinx.php +++ b/phpBB/phpbb/search/backend/fulltext_sphinx.php @@ -214,9 +214,7 @@ class fulltext_sphinx implements search_backend_interface } /** - * Checks permissions and paths, if everything is correct it generates the config file - * - * @return string|bool Language key of the error/incompatibility encountered, or false if successful + * {@inheritdoc} */ public function init() { diff --git a/phpBB/phpbb/search/backend/search_backend_interface.php b/phpBB/phpbb/search/backend/search_backend_interface.php index 26c87909b9..a22c4bda46 100644 --- a/phpBB/phpbb/search/backend/search_backend_interface.php +++ b/phpBB/phpbb/search/backend/search_backend_interface.php @@ -29,6 +29,15 @@ interface search_backend_interface */ public function is_available(); + /** + * Method executed when a search backend is set from acp. + * + * Checks permissions and paths, if everything is correct it generates the config file + * + * @return string|false False if everything was ok or string with error message + */ + public function init(); + /** * Returns the search_query *