[ticket/15540] Display only available search backends

PHPBB3-15540
This commit is contained in:
rubencm 2021-03-22 17:51:51 +01:00
parent 911a31d898
commit 457c750773
6 changed files with 74 additions and 36 deletions

View file

@ -79,32 +79,32 @@ class acp_search
foreach ($search_types as $search) foreach ($search_types as $search)
{ {
$type = get_class($search); // Only show available search backends
if($search->is_available()) {
$name = $search->get_name(); $name = $search->get_name();
$type = get_class($search);
$selected = ($config['search_type'] == $type) ? ' selected="selected"' : ''; $selected = ($config['search_type'] == $type) ? ' selected="selected"' : '';
$identifier = substr($type, strrpos($type, '\\') + 1); $identifier = substr($type, strrpos($type, '\\') + 1);
$search_options .= "<option value=\"$type\"$selected data-toggle-setting=\"#search_{$identifier}_settings\">$name</option>"; $search_options .= "<option value=\"$type\"$selected data-toggle-setting=\"#search_{$identifier}_settings\">$name</option>";
if (method_exists($search, 'acp')) if (method_exists($search, 'acp')) {
{
$vars = $search->acp(); $vars = $search->acp();
if (!$submit) if (!$submit) {
{
$template->assign_block_vars('backend', array( $template->assign_block_vars('backend', array(
'NAME' => $name, 'NAME' => $name,
'SETTINGS' => $vars['tpl'], 'SETTINGS' => $vars['tpl'],
'IDENTIFIER' => $identifier, 'IDENTIFIER' => $identifier,
)); ));
} } else if (is_array($vars['config'])) {
else if (is_array($vars['config']))
{
$settings = array_merge($settings, $vars['config']); $settings = array_merge($settings, $vars['config']);
} }
} }
} }
}
unset($search); unset($search);
$cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => ''), true) : array(); $cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => ''), true) : array();

View file

@ -116,6 +116,14 @@ class fulltext_mysql extends base implements search_backend_interface
return 'MySQL Fulltext'; return 'MySQL Fulltext';
} }
/**
* {@inheritdoc}
*/
public function is_available(): bool
{
return $this->db->get_sql_layer() == 'mysqli';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -147,7 +155,7 @@ class fulltext_mysql extends base implements search_backend_interface
*/ */
public function init() public function init()
{ {
if ($this->db->get_sql_layer() != 'mysqli') if (!$this->is_available())
{ {
return $this->user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE']; return $this->user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE'];
} }

View file

@ -23,12 +23,12 @@ use phpbb\user;
*/ */
class fulltext_native extends base implements search_backend_interface class fulltext_native extends base implements search_backend_interface
{ {
const UTF8_HANGUL_FIRST = "\xEA\xB0\x80"; protected const UTF8_HANGUL_FIRST = "\xEA\xB0\x80";
const UTF8_HANGUL_LAST = "\xED\x9E\xA3"; protected const UTF8_HANGUL_LAST = "\xED\x9E\xA3";
const UTF8_CJK_FIRST = "\xE4\xB8\x80"; protected const UTF8_CJK_FIRST = "\xE4\xB8\x80";
const UTF8_CJK_LAST = "\xE9\xBE\xBB"; protected const UTF8_CJK_LAST = "\xE9\xBE\xBB";
const UTF8_CJK_B_FIRST = "\xF0\xA0\x80\x80"; protected const UTF8_CJK_B_FIRST = "\xF0\xA0\x80\x80";
const UTF8_CJK_B_LAST = "\xF0\xAA\x9B\x96"; protected const UTF8_CJK_B_LAST = "\xF0\xAA\x9B\x96";
/** /**
* Associative array holding index stats * Associative array holding index stats
@ -149,6 +149,14 @@ class fulltext_native extends base implements search_backend_interface
return 'phpBB Native Fulltext'; return 'phpBB Native Fulltext';
} }
/**
* {@inheritdoc}
*/
public function is_available(): bool
{
return true;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -56,7 +56,7 @@ class fulltext_postgres extends base implements search_backend_interface
/** /**
* Database connection * Database connection
* @var \phpbb\db\driver\driver_interface * @var driver_interface
*/ */
protected $db; protected $db;
@ -129,6 +129,14 @@ class fulltext_postgres extends base implements search_backend_interface
return 'PostgreSQL Fulltext'; return 'PostgreSQL Fulltext';
} }
/**
* {@inheritdoc}
*/
public function is_available(): bool
{
return $this->db->get_sql_layer() == 'postgres';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -170,7 +178,7 @@ class fulltext_postgres extends base implements search_backend_interface
*/ */
public function init() public function init()
{ {
if ($this->db->get_sql_layer() != 'postgres') if (!$this->is_available())
{ {
return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE']; return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE'];
} }
@ -1047,7 +1055,7 @@ class fulltext_postgres extends base implements search_backend_interface
} }
/** /**
* Computes the stats and store them in the $this->stats associative array * {@inheritdoc}
*/ */
protected function get_stats() protected function get_stats()
{ {

View file

@ -16,6 +16,7 @@ namespace phpbb\search\backend;
use phpbb\auth\auth; use phpbb\auth\auth;
use phpbb\config\config; use phpbb\config\config;
use phpbb\db\driver\driver_interface; use phpbb\db\driver\driver_interface;
use phpbb\db\tools\tools_interface;
use phpbb\event\dispatcher_interface; use phpbb\event\dispatcher_interface;
use phpbb\user; use phpbb\user;
@ -85,13 +86,13 @@ class fulltext_sphinx implements search_backend_interface
/** /**
* Database connection * Database connection
* @var \phpbb\db\driver\driver_interface * @var driver_interface
*/ */
protected $db; protected $db;
/** /**
* Database Tools object * Database Tools object
* @var \phpbb\db\tools\tools_interface * @var tools_interface
*/ */
protected $db_tools; protected $db_tools;
@ -180,6 +181,14 @@ class fulltext_sphinx implements search_backend_interface
return 'Sphinx Fulltext'; return 'Sphinx Fulltext';
} }
/**
* {@inheritdoc}
*/
public function is_available(): bool
{
return ($this->db->get_sql_layer() == 'mysqli' || $this->db->get_sql_layer() == 'postgres') && class_exists('SphinxClient');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -211,7 +220,7 @@ class fulltext_sphinx implements search_backend_interface
*/ */
public function init() public function init()
{ {
if ($this->db->get_sql_layer() != 'mysqli' && $this->db->get_sql_layer() != 'postgres') if (!$this->is_available())
{ {
return $this->user->lang['FULLTEXT_SPHINX_WRONG_DATABASE']; return $this->user->lang['FULLTEXT_SPHINX_WRONG_DATABASE'];
} }
@ -922,9 +931,7 @@ class fulltext_sphinx implements search_backend_interface
} }
/** /**
* Returns an associative array containing information about the indexes * {@inheritdoc}
*
* @return string|bool Language string of error false otherwise
*/ */
public function index_stats() public function index_stats()
{ {

View file

@ -22,6 +22,13 @@ interface search_backend_interface
*/ */
public function get_name(); public function get_name();
/**
* Returns if the search engine is available
*
* @return bool
*/
public function is_available();
/** /**
* Returns the search_query * Returns the search_query
* *
@ -142,7 +149,7 @@ interface search_backend_interface
/** /**
* Returns an associative array containing information about the indexes * Returns an associative array containing information about the indexes
* *
* @return array|bool Language string of error false otherwise * @return array|false Language string of error false otherwise
*/ */
public function index_stats(); public function index_stats();