1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-03-21 16:10:38 +01:00

[ticket/15540] Properties

PHPBB3-15540
This commit is contained in:
rubencm 2021-03-23 04:16:34 +01:00
parent 5c67eabeed
commit 656e57fbf6
9 changed files with 173 additions and 145 deletions

View File

@ -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%'

View File

@ -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);
}
/**

View File

@ -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 = '
<dl>
<dt><label>' . $this->user->lang['MIN_SEARCH_CHARS'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dt><label>' . $this->language->lang('MIN_SEARCH_CHARS') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN') . '</span></dt>
<dd>' . $this->config['fulltext_mysql_min_word_len'] . '</dd>
</dl>
<dl>
<dt><label>' . $this->user->lang['MAX_SEARCH_CHARS'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dt><label>' . $this->language->lang('MAX_SEARCH_CHARS') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN') . '</span></dt>
<dd>' . $this->config['fulltext_mysql_max_word_len'] . '</dd>
</dl>
';

View File

@ -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 = '
<dl>
<dt><label for="fulltext_native_load_upd">' . $this->user->lang['YES_SEARCH_UPDATE'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '</span></dt>
<dd><label><input type="radio" id="fulltext_native_load_upd" name="config[fulltext_native_load_upd]" value="1"' . (($this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->user->lang['YES'] . '</label><label><input type="radio" name="config[fulltext_native_load_upd]" value="0"' . ((!$this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->user->lang['NO'] . '</label></dd>
<dt><label for="fulltext_native_load_upd">' . $this->language->lang('YES_SEARCH_UPDATE') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('YES_SEARCH_UPDATE_EXPLAIN') . '</span></dt>
<dd><label><input type="radio" id="fulltext_native_load_upd" name="config[fulltext_native_load_upd]" value="1"' . (($this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->language->lang('YES') . '</label><label><input type="radio" name="config[fulltext_native_load_upd]" value="0"' . ((!$this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->language->lang('NO') . '</label></dd>
</dl>
<dl>
<dt><label for="fulltext_native_min_chars">' . $this->user->lang['MIN_SEARCH_CHARS'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_native_min_chars">' . $this->language->lang('MIN_SEARCH_CHARS') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('MIN_SEARCH_CHARS_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_native_min_chars" type="number" min="0" max="255" name="config[fulltext_native_min_chars]" value="' . (int) $this->config['fulltext_native_min_chars'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_native_max_chars">' . $this->user->lang['MAX_SEARCH_CHARS'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_native_max_chars">' . $this->language->lang('MAX_SEARCH_CHARS') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('MAX_SEARCH_CHARS_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_native_max_chars" type="number" min="0" max="255" name="config[fulltext_native_max_chars]" value="' . (int) $this->config['fulltext_native_max_chars'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_native_common_thres">' . $this->user->lang['COMMON_WORD_THRESHOLD'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_native_common_thres">' . $this->language->lang('COMMON_WORD_THRESHOLD') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('COMMON_WORD_THRESHOLD_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_native_common_thres" type="text" name="config[fulltext_native_common_thres]" value="' . (double) $this->config['fulltext_native_common_thres'] . '" /> %</dd>
</dl>
';

View File

@ -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 = '
<dl>
<dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '</span></dt>
<dd>' . (($this->db->get_sql_layer() == 'postgres') ? $this->user->lang['YES'] : $this->user->lang['NO']) . '</dd>
<dt><label>' . $this->language->lang('FULLTEXT_POSTGRES_VERSION_CHECK') . '</label><br /><span>' . $this->language->lang('FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN') . '</span></dt>
<dd>' . (($this->db->get_sql_layer() == 'postgres') ? $this->language->lang('YES') : $this->language->lang('NO')) . '</dd>
</dl>
<dl>
<dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '</span></dt>
<dt><label>' . $this->language->lang('FULLTEXT_POSTGRES_TS_NAME') . '</label><br /><span>' . $this->language->lang('FULLTEXT_POSTGRES_TS_NAME_EXPLAIN') . '</span></dt>
<dd><select name="config[fulltext_postgres_ts_name]">';
if ($this->db->get_sql_layer() == 'postgres')
@ -1123,11 +1112,11 @@ class fulltext_postgres extends base implements search_backend_interface
$tpl .= '</select></dd>
</dl>
<dl>
<dt><label for="fulltext_postgres_min_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_postgres_min_word_len">' . $this->language->lang('FULLTEXT_POSTGRES_MIN_WORD_LEN') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_postgres_min_word_len" type="number" min="0" max="255" name="config[fulltext_postgres_min_word_len]" value="' . (int) $this->config['fulltext_postgres_min_word_len'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_postgres_max_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_postgres_max_word_len">' . $this->language->lang('FULLTEXT_POSTGRES_MAX_WORD_LEN') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_postgres_max_word_len" type="number" min="0" max="255" name="config[fulltext_postgres_max_word_len]" value="' . (int) $this->config['fulltext_postgres_max_word_len'] . '" /></dd>
</dl>
';

View File

@ -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 = '
<span class="error">' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE']. '</span>
<span class="error">' . $this->language->lang('FULLTEXT_SPHINX_CONFIGURE'). '</span>
<dl>
<dt><label for="fulltext_sphinx_data_path">' . $this->user->lang['FULLTEXT_SPHINX_DATA_PATH'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_SPHINX_DATA_PATH_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_sphinx_data_path">' . $this->language->lang('FULLTEXT_SPHINX_DATA_PATH') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_SPHINX_DATA_PATH_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_sphinx_data_path" type="text" size="40" maxlength="255" name="config[fulltext_sphinx_data_path]" value="' . $this->config['fulltext_sphinx_data_path'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_sphinx_host">' . $this->user->lang['FULLTEXT_SPHINX_HOST'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_SPHINX_HOST_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_sphinx_host">' . $this->language->lang('FULLTEXT_SPHINX_HOST') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_SPHINX_HOST_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_sphinx_host" type="text" size="40" maxlength="255" name="config[fulltext_sphinx_host]" value="' . $this->config['fulltext_sphinx_host'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_sphinx_port">' . $this->user->lang['FULLTEXT_SPHINX_PORT'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_SPHINX_PORT_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_sphinx_port">' . $this->language->lang('FULLTEXT_SPHINX_PORT') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_SPHINX_PORT_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_sphinx_port" type="number" min="0" max="9999999999" name="config[fulltext_sphinx_port]" value="' . $this->config['fulltext_sphinx_port'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_sphinx_indexer_mem_limit">' . $this->user->lang['FULLTEXT_SPHINX_INDEXER_MEM_LIMIT'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_sphinx_indexer_mem_limit" type="number" min="0" max="9999999999" name="config[fulltext_sphinx_indexer_mem_limit]" value="' . $this->config['fulltext_sphinx_indexer_mem_limit'] . '" /> ' . $this->user->lang['MIB'] . '</dd>
<dt><label for="fulltext_sphinx_indexer_mem_limit">' . $this->language->lang('FULLTEXT_SPHINX_INDEXER_MEM_LIMIT') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_SPHINX_INDEXER_MEM_LIMIT_EXPLAIN') . '</span></dt>
<dd><input id="fulltext_sphinx_indexer_mem_limit" type="number" min="0" max="9999999999" name="config[fulltext_sphinx_indexer_mem_limit]" value="' . $this->config['fulltext_sphinx_indexer_mem_limit'] . '" /> ' . $this->language->lang('MIB') . '</dd>
</dl>
<dl>
<dt><label for="fulltext_sphinx_config_file">' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE'] . $this->user->lang['COLON'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '</span></dt>
<dt><label for="fulltext_sphinx_config_file">' . $this->language->lang('FULLTEXT_SPHINX_CONFIG_FILE') . $this->language->lang('COLON') . '</label><br /><span>' . $this->language->lang('FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN') . '</span></dt>
<dd>' . (($this->config_generate()) ? '<textarea readonly="readonly" rows="6" id="sphinx_config_data">' . htmlspecialchars($this->config_file_data, ENT_COMPAT) . '</textarea>' : $this->config_file_data) . '</dd>
<dl>
';
@ -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;
}

View File

@ -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);
}
}

View File

@ -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()

View File

@ -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);
}
}