From 656e57fbf642ce366cf48b54a04954a985e2a222 Mon Sep 17 00:00:00 2001 From: rubencm Date: Tue, 23 Mar 2021 04:16:34 +0100 Subject: [PATCH] [ticket/15540] Properties PHPBB3-15540 --- .../default/container/services_search.yml | 9 ++ phpBB/phpbb/search/backend/base.php | 103 ++++++++++++------ phpBB/phpbb/search/backend/fulltext_mysql.php | 40 +++---- .../phpbb/search/backend/fulltext_native.php | 46 +++----- .../search/backend/fulltext_postgres.php | 43 +++----- .../phpbb/search/backend/fulltext_sphinx.php | 59 ++++++---- tests/search/mysql_test.php | 6 +- tests/search/native_test.php | 6 +- tests/search/postgres_test.php | 6 +- 9 files changed, 173 insertions(+), 145 deletions(-) diff --git a/phpBB/config/default/container/services_search.yml b/phpBB/config/default/container/services_search.yml index 0ec01e187e..ba0f8f2761 100644 --- a/phpBB/config/default/container/services_search.yml +++ b/phpBB/config/default/container/services_search.yml @@ -4,9 +4,11 @@ services: search.fulltext.native: class: phpbb\search\backend\fulltext_native arguments: + - '@cache' - '@config' - '@dbal.conn' - '@dispatcher' + - '@language' - '@user' - '%core.root_path%' - '%core.php_ext%' @@ -16,9 +18,11 @@ services: search.fulltext.mysql: class: phpbb\search\backend\fulltext_mysql arguments: + - '@cache' - '@config' - '@dbal.conn' - '@dispatcher' + - '@language' - '@user' - '%core.root_path%' - '%core.php_ext%' @@ -28,9 +32,11 @@ services: search.fulltext.postgres: class: phpbb\search\backend\fulltext_postgres arguments: + - '@cache' - '@config' - '@dbal.conn' - '@dispatcher' + - '@language' - '@user' - '%core.root_path%' - '%core.php_ext%' @@ -43,7 +49,10 @@ services: - '@auth' - '@config' - '@dbal.conn' + - '@dbal.tools' - '@dispatcher' + - '@language' + - '@log' - '@user' - '%core.root_path%' - '%core.php_ext%' diff --git a/phpBB/phpbb/search/backend/base.php b/phpBB/phpbb/search/backend/base.php index f62d798d53..52a4448a45 100644 --- a/phpBB/phpbb/search/backend/base.php +++ b/phpBB/phpbb/search/backend/base.php @@ -13,6 +13,11 @@ namespace phpbb\search\backend; +use phpbb\cache\service; +use phpbb\config\config; +use phpbb\db\driver\driver_interface; +use phpbb\user; + /** * optional base class for search plugins providing simple caching based on ACM * and functions to retrieve ignore_words and synonyms @@ -26,6 +31,42 @@ abstract class base implements search_backend_interface // Batch size for create_index and delete_index private const BATCH_SIZE = 100; + /** + * @var service + */ + protected $cache; + + /** + * @var config + */ + protected $config; + + /** + * @var driver_interface + */ + protected $db; + + /** + * @var user + */ + protected $user; + + /** + * Constructor. + * + * @param service $cache + * @param config $config + * @param driver_interface $db + * @param user $user + */ + public function __construct(service $cache, config $config, driver_interface $db, user $user) + { + $this->cache = $cache; + $this->config = $config; + $this->db = $db; + $this->user = $user; + } + /** * Retrieves cached search results * @@ -40,9 +81,7 @@ abstract class base implements search_backend_interface */ protected function obtain_ids(string $search_key, &$result_count, &$id_ary, &$start, $per_page, string $sort_dir): int { - global $cache; - - if (!($stored_ids = $cache->get('_search_results_' . $search_key))) + if (!($stored_ids = $this->cache->get('_search_results_' . $search_key))) { // no search results cached for this search_key return self::SEARCH_RESULT_NOT_IN_CACHE; @@ -121,9 +160,9 @@ abstract class base implements search_backend_interface */ protected function save_ids(string $search_key, string $keywords, $author_ary, int $result_count, &$id_ary, int $start, string $sort_dir) { - global $cache, $config, $db, $user; + global $user; - $length = min(count($id_ary), $config['search_block_size']); + $length = min(count($id_ary), $this->config['search_block_size']); // nothing to cache so exit if (!$length) @@ -135,17 +174,17 @@ abstract class base implements search_backend_interface // create a new resultset if there is none for this search_key yet // or add the ids to the existing resultset - if (!($store = $cache->get('_search_results_' . $search_key))) + if (!($store = $this->cache->get('_search_results_' . $search_key))) { // add the current keywords to the recent searches in the cache which are listed on the search page if (!empty($keywords) || count($author_ary)) { $sql = 'SELECT search_time FROM ' . SEARCH_RESULTS_TABLE . ' - WHERE search_key = \'' . $db->sql_escape($search_key) . '\''; - $result = $db->sql_query($sql); + WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\''; + $result = $this->db->sql_query($sql); - if (!$db->sql_fetchrow($result)) + if (!$this->db->sql_fetchrow($result)) { $sql_ary = array( 'search_key' => $search_key, @@ -154,16 +193,16 @@ abstract class base implements search_backend_interface 'search_authors' => ' ' . implode(' ', $author_ary) . ' ' ); - $sql = 'INSERT INTO ' . SEARCH_RESULTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); + $sql = 'INSERT INTO ' . SEARCH_RESULTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } $sql = 'UPDATE ' . USERS_TABLE . ' SET user_last_search = ' . time() . ' WHERE user_id = ' . $user->data['user_id']; - $db->sql_query($sql); + $this->db->sql_query($sql); $store = array(-1 => $result_count, -2 => $sort_dir); $id_range = range($start, $start + $length - 1); @@ -191,10 +230,10 @@ abstract class base implements search_backend_interface $store += $store_ids; // if the cache is too big - if (count($store) - 2 > 20 * $config['search_block_size']) + if (count($store) - 2 > 20 * $this->config['search_block_size']) { // remove everything in front of two blocks in front of the current start index - for ($i = 0, $n = $id_range[0] - 2 * $config['search_block_size']; $i < $n; $i++) + for ($i = 0, $n = $id_range[0] - 2 * $this->config['search_block_size']; $i < $n; $i++) { if (isset($store[$i])) { @@ -204,7 +243,7 @@ abstract class base implements search_backend_interface // remove everything after two blocks after the current stop index end($id_range); - for ($i = $store[-1] - 1, $n = current($id_range) + 2 * $config['search_block_size']; $i > $n; $i--) + for ($i = $store[-1] - 1, $n = current($id_range) + 2 * $this->config['search_block_size']; $i > $n; $i--) { if (isset($store[$i])) { @@ -212,12 +251,12 @@ abstract class base implements search_backend_interface } } } - $cache->put('_search_results_' . $search_key, $store, $config['search_store_results']); + $this->cache->put('_search_results_' . $search_key, $store, $this->config['search_store_results']); $sql = 'UPDATE ' . SEARCH_RESULTS_TABLE . ' SET search_time = ' . time() . ' - WHERE search_key = \'' . $db->sql_escape($search_key) . '\''; - $db->sql_query($sql); + WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\''; + $this->db->sql_query($sql); } unset($store, $store_ids, $id_range); @@ -231,27 +270,25 @@ abstract class base implements search_backend_interface */ protected function destroy_cache($words, $authors = false): void { - global $db, $cache, $config; - // clear all searches that searched for the specified words if (count($words)) { $sql_where = ''; foreach ($words as $word) { - $sql_where .= " OR search_keywords " . $db->sql_like_expression($db->get_any_char() . $word . $db->get_any_char()); + $sql_where .= " OR search_keywords " . $this->db->sql_like_expression($this->db->get_any_char() . $word . $this->db->get_any_char()); } $sql = 'SELECT search_key FROM ' . SEARCH_RESULTS_TABLE . " WHERE search_keywords LIKE '%*%' $sql_where"; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { - $cache->destroy('_search_results_' . $row['search_key']); + $this->cache->destroy('_search_results_' . $row['search_key']); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } // clear all searches that searched for the specified authors @@ -260,25 +297,25 @@ abstract class base implements search_backend_interface $sql_where = ''; foreach ($authors as $author) { - $sql_where .= (($sql_where) ? ' OR ' : '') . 'search_authors ' . $db->sql_like_expression($db->get_any_char() . ' ' . (int) $author . ' ' . $db->get_any_char()); + $sql_where .= (($sql_where) ? ' OR ' : '') . 'search_authors ' . $this->db->sql_like_expression($this->db->get_any_char() . ' ' . (int) $author . ' ' . $this->db->get_any_char()); } $sql = 'SELECT search_key FROM ' . SEARCH_RESULTS_TABLE . " WHERE $sql_where"; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { - $cache->destroy('_search_results_' . $row['search_key']); + $this->cache->destroy('_search_results_' . $row['search_key']); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } $sql = 'DELETE FROM ' . SEARCH_RESULTS_TABLE . ' - WHERE search_time < ' . (time() - (int) $config['search_store_results']); - $db->sql_query($sql); + 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 0860d3d7a8..8471d16ed6 100644 --- a/phpBB/phpbb/search/backend/fulltext_mysql.php +++ b/phpBB/phpbb/search/backend/fulltext_mysql.php @@ -13,9 +13,11 @@ namespace phpbb\search\backend; +use phpbb\cache\service; use phpbb\config\config; use phpbb\db\driver\driver_interface; use phpbb\event\dispatcher_interface; +use phpbb\language\language; use phpbb\user; use RuntimeException; @@ -36,18 +38,6 @@ class fulltext_mysql extends base implements search_backend_interface */ protected $split_words = array(); - /** - * Config object - * @var config - */ - protected $config; - - /** - * Database connection - * @var driver_interface - */ - protected $db; - /** * phpBB event dispatcher object * @var dispatcher_interface @@ -55,10 +45,9 @@ class fulltext_mysql extends base implements search_backend_interface protected $phpbb_dispatcher; /** - * User object - * @var user + * @var language */ - protected $user; + protected $language; /** * Associative array stores the min and max word length to be searched @@ -84,19 +73,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 service $cache * @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 */ - public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, user $user, string $phpbb_root_path, string $phpEx) + public function __construct(service $cache, config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) { - $this->config = $config; - $this->db = $db; + parent::__construct($cache, $config, $db, $user); $this->phpbb_dispatcher = $phpbb_dispatcher; - $this->user = $user; + $this->language = $language; $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']); @@ -138,7 +128,7 @@ class fulltext_mysql extends base implements search_backend_interface { if (!$this->is_available()) { - return $this->user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE']; + return $this->language->lang('FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE'); } $result = $this->db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\''); @@ -159,7 +149,7 @@ class fulltext_mysql extends base implements search_backend_interface if (!$fulltext_supported) { - return $this->user->lang['FULLTEXT_MYSQL_NOT_SUPPORTED']; + return $this->language->lang('FULLTEXT_MYSQL_NOT_SUPPORTED'); } $sql = 'SHOW VARIABLES @@ -236,7 +226,7 @@ class fulltext_mysql extends base implements search_backend_interface // We limit the number of allowed keywords to minimize load on the database if ($this->config['max_num_search_keywords'] && count($this->split_words) > $this->config['max_num_search_keywords']) { - trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], count($this->split_words))); + trigger_error($this->language->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], count($this->split_words))); } // to allow phrase search, we need to concatenate quoted words @@ -1080,7 +1070,7 @@ class fulltext_mysql extends base implements search_backend_interface } return array( - $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->language->lang('FULLTEXT_MYSQL_TOTAL_POSTS') => ($this->index_created()) ? $this->stats['total_posts'] : 0, ); } @@ -1160,11 +1150,11 @@ class fulltext_mysql extends base implements search_backend_interface { $tpl = '
-

' . $this->user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN') . '
' . $this->config['fulltext_mysql_min_word_len'] . '
-

' . $this->user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN') . '
' . $this->config['fulltext_mysql_max_word_len'] . '
'; diff --git a/phpBB/phpbb/search/backend/fulltext_native.php b/phpBB/phpbb/search/backend/fulltext_native.php index a49d4f59f8..56075186ae 100644 --- a/phpBB/phpbb/search/backend/fulltext_native.php +++ b/phpBB/phpbb/search/backend/fulltext_native.php @@ -13,9 +13,11 @@ namespace phpbb\search\backend; +use phpbb\cache\service; use phpbb\config\config; use phpbb\db\driver\driver_interface; use phpbb\event\dispatcher_interface; +use phpbb\language\language; use phpbb\user; /** @@ -86,18 +88,6 @@ class fulltext_native extends base implements search_backend_interface */ protected $php_ext; - /** - * Config object - * @var config - */ - protected $config; - - /** - * Database connection - * @var driver_interface - */ - protected $db; - /** * phpBB event dispatcher object * @var dispatcher_interface @@ -105,27 +95,27 @@ class fulltext_native extends base implements search_backend_interface protected $phpbb_dispatcher; /** - * User object - * @var user + * @var language */ - protected $user; + protected $language; /** * Initialises the fulltext_native search backend with min/max word length * + * @param service $cache * @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 */ - public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, user $user, string $phpbb_root_path, string $phpEx) + public function __construct(service $cache, config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) { - $this->config = $config; - $this->db = $db; + parent::__construct($cache, $config, $db, $user); $this->phpbb_dispatcher = $phpbb_dispatcher; - $this->user = $user; + $this->language = $language; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; @@ -304,7 +294,7 @@ class fulltext_native extends base implements search_backend_interface // We limit the number of allowed keywords to minimize load on the database if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords']) { - trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], $num_keywords)); + trigger_error($this->language->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], $num_keywords)); } // $keywords input format: each word separated by a space, words in a bracket are not separated @@ -478,7 +468,7 @@ class fulltext_native extends base implements search_backend_interface // throw an error if we shall not ignore unexistant words else if (!$ignore_no_id && count($non_common_words)) { - trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode($this->user->lang['COMMA_SEPARATOR'], $non_common_words))); + trigger_error(sprintf($this->language->lang('WORDS_IN_NO_POST'), implode($this->language->lang('COMMA_SEPARATOR'), $non_common_words))); } unset($non_common_words); } @@ -1691,8 +1681,8 @@ class fulltext_native extends base implements search_backend_interface } return array( - $this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'], - $this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']); + $this->language->lang('TOTAL_WORDS') => $this->stats['total_words'], + $this->language->lang('TOTAL_MATCHES') => $this->stats['total_matches']); } /** @@ -2026,19 +2016,19 @@ class fulltext_native extends base implements search_backend_interface $tpl = '
-

' . $this->user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '
-
+

' . $this->language->lang('YES_SEARCH_UPDATE_EXPLAIN') . '
+
-

' . $this->user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '
+

' . $this->language->lang('MIN_SEARCH_CHARS_EXPLAIN') . '
-

' . $this->user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '
+

' . $this->language->lang('MAX_SEARCH_CHARS_EXPLAIN') . '
-

' . $this->user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '
+

' . $this->language->lang('COMMON_WORD_THRESHOLD_EXPLAIN') . '
%
'; diff --git a/phpBB/phpbb/search/backend/fulltext_postgres.php b/phpBB/phpbb/search/backend/fulltext_postgres.php index 863c2d43e6..7ffb9da857 100644 --- a/phpBB/phpbb/search/backend/fulltext_postgres.php +++ b/phpBB/phpbb/search/backend/fulltext_postgres.php @@ -13,9 +13,11 @@ namespace phpbb\search\backend; +use phpbb\cache\service; use phpbb\config\config; use phpbb\db\driver\driver_interface; use phpbb\event\dispatcher_interface; +use phpbb\language\language; use phpbb\user; use RuntimeException; @@ -49,18 +51,6 @@ class fulltext_postgres extends base implements search_backend_interface */ protected $phrase_search = false; - /** - * Config object - * @var config - */ - protected $config; - - /** - * Database connection - * @var driver_interface - */ - protected $db; - /** * phpBB event dispatcher object * @var dispatcher_interface @@ -68,11 +58,9 @@ class fulltext_postgres extends base implements search_backend_interface protected $phpbb_dispatcher; /** - * User object - * @var user + * @var language */ - protected $user; - + protected $language; /** * Contains tidied search query. * Operators are prefixed in search query and common words excluded @@ -97,19 +85,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 service $cache * @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 */ - public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, user $user, string $phpbb_root_path, string $phpEx) + public function __construct(service $cache, config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) { - $this->config = $config; - $this->db = $db; + parent::__construct($cache, $config, $db, $user); $this->phpbb_dispatcher = $phpbb_dispatcher; - $this->user = $user; + $this->language = $language; $this->word_length = array('min' => $this->config['fulltext_postgres_min_word_len'], 'max' => $this->config['fulltext_postgres_max_word_len']); @@ -145,7 +134,7 @@ class fulltext_postgres extends base implements search_backend_interface { if (!$this->is_available()) { - return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; + return $this->language->lang('FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE'); } return false; @@ -1015,7 +1004,7 @@ class fulltext_postgres extends base implements search_backend_interface } return array( - $this->user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->language->lang('FULLTEXT_POSTGRES_TOTAL_POSTS') => ($this->index_created()) ? $this->stats['total_posts'] : 0, ); } @@ -1096,11 +1085,11 @@ class fulltext_postgres extends base implements search_backend_interface { $tpl = '
-

' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '
-
' . (($this->db->get_sql_layer() == 'postgres') ? $this->user->lang['YES'] : $this->user->lang['NO']) . '
+

' . $this->language->lang('FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN') . '
+
' . (($this->db->get_sql_layer() == 'postgres') ? $this->language->lang('YES') : $this->language->lang('NO')) . '
-

' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_POSTGRES_TS_NAME_EXPLAIN') . '
-

' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN') . '
-

' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN') . '
'; diff --git a/phpBB/phpbb/search/backend/fulltext_sphinx.php b/phpBB/phpbb/search/backend/fulltext_sphinx.php index a7df8fcb23..cb376c1502 100644 --- a/phpBB/phpbb/search/backend/fulltext_sphinx.php +++ b/phpBB/phpbb/search/backend/fulltext_sphinx.php @@ -14,10 +14,13 @@ namespace phpbb\search\backend; use phpbb\auth\auth; +use phpbb\cache\service; use phpbb\config\config; use phpbb\db\driver\driver_interface; use phpbb\db\tools\tools_interface; use phpbb\event\dispatcher_interface; +use phpbb\language\language; +use phpbb\log\log; use phpbb\user; /** @@ -108,6 +111,16 @@ class fulltext_sphinx implements search_backend_interface */ protected $phpbb_dispatcher; + /** + * @var language + */ + protected $language; + + /** + * @var log + */ + protected $log; + /** * User object * @var user @@ -134,26 +147,28 @@ class fulltext_sphinx implements search_backend_interface * @param auth $auth Auth object * @param config $config Config object * @param driver_interface $db Database object + * @param tools_interface $db_tools * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object + * @param language $language + * @param log $log * @param user $user User object * @param string $phpbb_root_path Relative path to phpBB root * @param string $phpEx PHP file extension - * @throws \Exception */ - public function __construct(auth $auth, config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, user $user, string $phpbb_root_path, string $phpEx) + public function __construct(auth $auth, config $config, driver_interface $db, tools_interface $db_tools, dispatcher_interface $phpbb_dispatcher, language $language, log $log, user $user, string $phpbb_root_path, string $phpEx) { $this->auth = $auth; $this->config = $config; $this->db = $db; $this->phpbb_dispatcher = $phpbb_dispatcher; + $this->language = $language; + $this->log = $log; $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; - // Initialize \phpbb\db\tools\tools object - global $phpbb_container; // TODO inject into object - $this->db_tools = $phpbb_container->get('dbal.tools'); + $this->db_tools = $db_tools; if (!$this->config['fulltext_sphinx_id']) { @@ -196,7 +211,7 @@ class fulltext_sphinx implements search_backend_interface { if (!$this->is_available()) { - return $this->user->lang['FULLTEXT_SPHINX_WRONG_DATABASE']; + return $this->language->lang('FULLTEXT_SPHINX_WRONG_DATABASE'); } // Move delta to main index each hour @@ -268,8 +283,6 @@ class fulltext_sphinx implements search_backend_interface */ public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { - global $user, $phpbb_log; - // No keywords? No posts. if (!strlen($this->search_query) && !count($author_ary)) { @@ -450,14 +463,14 @@ class fulltext_sphinx implements search_backend_interface if ($this->sphinx->GetLastError()) { - $phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_SPHINX_ERROR', false, array($this->sphinx->GetLastError())); + $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_SPHINX_ERROR', false, array($this->sphinx->GetLastError())); if ($this->auth->acl_get('a_')) { - trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError())); + trigger_error($this->language->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError())); } else { - trigger_error($this->user->lang('SPHINX_SEARCH_FAILED_LOG')); + trigger_error($this->language->lang('SPHINX_SEARCH_FAILED_LOG')); } } @@ -683,9 +696,9 @@ class fulltext_sphinx implements search_backend_interface } return array( - $this->user->lang['FULLTEXT_SPHINX_MAIN_POSTS'] => ($this->index_created()) ? $this->stats['main_posts'] : 0, - $this->user->lang['FULLTEXT_SPHINX_DELTA_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0, - $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0, + $this->language->lang('FULLTEXT_SPHINX_MAIN_POSTS') => ($this->index_created()) ? $this->stats['main_posts'] : 0, + $this->language->lang('FULLTEXT_SPHINX_DELTA_POSTS') => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0, + $this->language->lang('FULLTEXT_MYSQL_TOTAL_POSTS') => ($this->index_created()) ? $this->stats['total_posts'] : 0, ); } @@ -781,25 +794,25 @@ class fulltext_sphinx implements search_backend_interface ); $tpl = ' - ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE']. ' + ' . $this->language->lang('FULLTEXT_SPHINX_CONFIGURE'). '
-

' . $this->user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_SPHINX_DATA_PATH_EXPLAIN') . '
-

' . $this->user->lang['FULLTEXT_SPHINX_HOST_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_SPHINX_HOST_EXPLAIN') . '
-

' . $this->user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_SPHINX_PORT_EXPLAIN') . '
-

' . $this->user->lang['FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN'] . '
-
' . $this->user->lang['MIB'] . '
+

' . $this->language->lang('FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN') . '
+
' . $this->language->lang('MIB') . '
-

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
+

' . $this->language->lang('FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN') . '
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; @@ -829,14 +842,14 @@ class fulltext_sphinx implements search_backend_interface } else { - $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_WRONG_DATABASE'); + $this->config_file_data = $this->language->lang('FULLTEXT_SPHINX_WRONG_DATABASE'); return false; } // Check if directory paths have been filled if (!$this->config['fulltext_sphinx_data_path']) { - $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA'); + $this->config_file_data = $this->language->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA'); return false; } diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index d8f1ac9e94..513135bac1 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -29,8 +29,8 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_mock_cache(); - + $cache = $this->createMock('\phpbb\cache\service'); + $language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $user = $this->createMock('\phpbb\user'); // set config values @@ -40,6 +40,6 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case $this->db = $this->new_dbal(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $class = self::get_search_wrapper('\phpbb\search\backend\fulltext_mysql'); - $this->search = new $class($config, $this->db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx); + $this->search = new $class($cache, $config, $this->db, $phpbb_dispatcher, $language, $user, $phpbb_root_path, $phpEx); } } diff --git a/tests/search/native_test.php b/tests/search/native_test.php index fe2caa6cdd..015d8f0b27 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -29,8 +29,8 @@ class phpbb_search_native_test extends phpbb_search_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_mock_cache(); - + $cache = $this->createMock('\phpbb\cache\service'); + $language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $user = $this->createMock('\phpbb\user'); $this->db = $this->new_dbal(); @@ -38,7 +38,7 @@ class phpbb_search_native_test extends phpbb_search_test_case $class = self::get_search_wrapper('\phpbb\search\backend\fulltext_native'); $config['fulltext_native_min_chars'] = 2; $config['fulltext_native_max_chars'] = 14; - $this->search = new $class($config, $this->db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx); + $this->search = new $class($cache, $config, $this->db, $phpbb_dispatcher, $language, $user, $phpbb_root_path, $phpEx); } public function keywords() diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index bfb69cf14e..b4dbb507b3 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -29,8 +29,8 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_mock_cache(); - + $cache = $this->createMock('\phpbb\cache\service'); + $language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $user = $this->createMock('\phpbb\user'); // set config values @@ -40,6 +40,6 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case $this->db = $this->new_dbal(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $class = self::get_search_wrapper('\phpbb\search\backend\fulltext_postgres'); - $this->search = new $class($config, $this->db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx); + $this->search = new $class($cache, $config, $this->db, $phpbb_dispatcher, $language, $user, $phpbb_root_path, $phpEx); } }