mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-08 01:36:57 +02:00
[ticket/15540] Refactor search backend classes to Symfony services
PHPBB3-15540
This commit is contained in:
@@ -646,11 +646,10 @@ class acp_main
|
||||
}
|
||||
|
||||
// Warn if no search index is created
|
||||
if ($config['num_posts'] && class_exists($config['search_type']))
|
||||
if ($config['num_posts'])
|
||||
{
|
||||
$error = false;
|
||||
$search_type = $config['search_type'];
|
||||
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
$search_backend_factory = $phpbb_container->get('search.backend_factory');
|
||||
$search = $search_backend_factory->get_active();
|
||||
|
||||
if (!$search->index_created())
|
||||
{
|
||||
|
@@ -52,6 +52,7 @@ class acp_search
|
||||
{
|
||||
global $user, $template, $phpbb_log, $request;
|
||||
global $config, $phpbb_admin_path, $phpEx;
|
||||
global $phpbb_container;
|
||||
|
||||
$submit = $request->is_set_post('submit');
|
||||
|
||||
@@ -60,7 +61,7 @@ class acp_search
|
||||
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$search_types = $this->get_search_types();
|
||||
$search_types = $phpbb_container->get('search.backend_collection');
|
||||
|
||||
$settings = [
|
||||
'search_interval' => 'float',
|
||||
@@ -74,14 +75,11 @@ class acp_search
|
||||
];
|
||||
|
||||
$search = null;
|
||||
$error = false;
|
||||
$search_options = '';
|
||||
foreach ($search_types as $type)
|
||||
|
||||
foreach ($search_types as $search)
|
||||
{
|
||||
if ($this->init_search($type, $search, $error))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$type = get_class($search);
|
||||
|
||||
$name = $search->get_name();
|
||||
|
||||
@@ -108,7 +106,6 @@ class acp_search
|
||||
}
|
||||
}
|
||||
unset($search);
|
||||
unset($error);
|
||||
|
||||
$cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => ''), true) : array();
|
||||
$updated = $request->variable('updated', false);
|
||||
@@ -240,7 +237,7 @@ class acp_search
|
||||
function index($id, $mode)
|
||||
{
|
||||
global $db, $user, $template, $phpbb_log, $request;
|
||||
global $config, $phpbb_admin_path, $phpEx;
|
||||
global $config, $phpbb_admin_path, $phpEx, $phpbb_container;
|
||||
|
||||
$action = $request->variable('action', '');
|
||||
$this->state = explode(',', $config['search_indexing_state']);
|
||||
@@ -285,12 +282,11 @@ class acp_search
|
||||
$this->state[0] = $request->variable('search_type', '');
|
||||
}
|
||||
|
||||
$this->search = null;
|
||||
$error = false;
|
||||
if ($this->init_search($this->state[0], $this->search, $error))
|
||||
{
|
||||
trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$search_backend_factory = $phpbb_container->get('search.backend_factory');
|
||||
$this->search = $search_backend_factory->get($this->state[0]);
|
||||
|
||||
$name = $this->search->get_name();
|
||||
|
||||
$action = &$this->state[1];
|
||||
@@ -454,16 +450,13 @@ class acp_search
|
||||
}
|
||||
}
|
||||
|
||||
$search_types = $this->get_search_types();
|
||||
$search_types = $phpbb_container->get('search.backend_collection');
|
||||
|
||||
$search = null;
|
||||
$error = false;
|
||||
foreach ($search_types as $type)
|
||||
|
||||
foreach ($search_types as $search)
|
||||
{
|
||||
if ($this->init_search($type, $search, $error) || !method_exists($search, 'index_created'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$type = get_class($search);
|
||||
|
||||
$name = $search->get_name();
|
||||
|
||||
@@ -508,7 +501,6 @@ class acp_search
|
||||
}
|
||||
}
|
||||
unset($search);
|
||||
unset($error);
|
||||
unset($statistics);
|
||||
unset($data);
|
||||
|
||||
@@ -562,19 +554,6 @@ class acp_search
|
||||
"</script>\n";
|
||||
}
|
||||
|
||||
function get_search_types()
|
||||
{
|
||||
global $phpbb_extension_manager;
|
||||
|
||||
$finder = $phpbb_extension_manager->get_finder();
|
||||
|
||||
return $finder
|
||||
->extension_suffix('_backend')
|
||||
->extension_directory('/search')
|
||||
->core_path('phpbb/search/')
|
||||
->get_classes();
|
||||
}
|
||||
|
||||
function get_max_post_id()
|
||||
{
|
||||
global $db;
|
||||
@@ -601,25 +580,4 @@ class acp_search
|
||||
|
||||
$config->set('search_indexing_state', implode(',', $this->state), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises a search backend object
|
||||
*
|
||||
* @return false if no error occurred else an error message
|
||||
*/
|
||||
function init_search($type, &$search, &$error)
|
||||
{
|
||||
global $phpbb_root_path, $phpEx, $user, $auth, $config, $db, $phpbb_dispatcher;
|
||||
|
||||
if (!class_exists($type) || !method_exists($type, 'keyword_search'))
|
||||
{
|
||||
$error = $user->lang['NO_SUCH_SEARCH_MODULE'];
|
||||
return $error;
|
||||
}
|
||||
|
||||
$error = false;
|
||||
$search = new $type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
|
@@ -904,7 +904,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
|
||||
*/
|
||||
function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true)
|
||||
{
|
||||
global $db, $config, $phpbb_root_path, $phpEx, $auth, $user, $phpbb_container, $phpbb_dispatcher;
|
||||
global $db, $config, $phpbb_container, $phpbb_dispatcher;
|
||||
|
||||
// Notifications types to delete
|
||||
$delete_notifications_types = array(
|
||||
@@ -1086,20 +1086,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
|
||||
}
|
||||
|
||||
// Remove the message from the search index
|
||||
$search_type = $config['search_type'];
|
||||
|
||||
if (!class_exists($search_type))
|
||||
{
|
||||
trigger_error('NO_SUCH_SEARCH_MODULE');
|
||||
}
|
||||
|
||||
$error = false;
|
||||
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
|
||||
if ($error)
|
||||
{
|
||||
trigger_error($error);
|
||||
}
|
||||
$search_backend_factory = $phpbb_container->get('search.backend_factory');
|
||||
$search = $search_backend_factory->get_active();
|
||||
|
||||
$search->index_remove($post_ids, $poster_ids, $forum_ids);
|
||||
|
||||
|
@@ -2291,21 +2291,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data
|
||||
// Index message contents
|
||||
if ($update_search_index && $data_ary['enable_indexing'])
|
||||
{
|
||||
// Select the search method and do some additional checks to ensure it can actually be utilised
|
||||
$search_type = $config['search_type'];
|
||||
|
||||
if (!class_exists($search_type))
|
||||
{
|
||||
trigger_error('NO_SUCH_SEARCH_MODULE');
|
||||
}
|
||||
|
||||
$error = false;
|
||||
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
|
||||
if ($error)
|
||||
{
|
||||
trigger_error($error);
|
||||
}
|
||||
$search_backend_factory = $phpbb_container->get('search.backend_factory');
|
||||
$search = $search_backend_factory->get_active();
|
||||
|
||||
$search->index($mode, $data_ary['post_id'], $data_ary['message'], $subject, $poster_id, $data_ary['forum_id']);
|
||||
}
|
||||
|
@@ -1401,15 +1401,8 @@ function mcp_fork_topic($topic_ids)
|
||||
if (!isset($search_type) && $topic_row['enable_indexing'])
|
||||
{
|
||||
// Select the search method and do some additional checks to ensure it can actually be utilised
|
||||
$search_type = $config['search_type'];
|
||||
|
||||
if (!class_exists($search_type))
|
||||
{
|
||||
trigger_error('NO_SUCH_SEARCH_MODULE');
|
||||
}
|
||||
|
||||
$error = false;
|
||||
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
$search_backend_factory = $phpbb_container->get('search.backend_factory');
|
||||
$search = $search_backend_factory->get_active();
|
||||
$search_mode = 'post';
|
||||
|
||||
if ($error)
|
||||
|
@@ -561,7 +561,7 @@ function phpbb_get_num_ips_for_poster(\phpbb\db\driver\driver_interface $db, $po
|
||||
*/
|
||||
function change_poster(&$post_info, $userdata)
|
||||
{
|
||||
global $auth, $db, $config, $phpbb_root_path, $phpEx, $user, $phpbb_log, $phpbb_dispatcher;
|
||||
global $db, $config, $user, $phpbb_log, $phpbb_dispatcher;
|
||||
|
||||
if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
|
||||
{
|
||||
@@ -632,18 +632,12 @@ function change_poster(&$post_info, $userdata)
|
||||
}
|
||||
|
||||
// refresh search cache of this post
|
||||
$search_type = $config['search_type'];
|
||||
$search_backend_factory = $phpbb_container->get('search.backend_factory');
|
||||
$search = $search_backend_factory->get_active();
|
||||
|
||||
if (class_exists($search_type))
|
||||
if (method_exists($search, 'destroy_cache'))
|
||||
{
|
||||
// We do some additional checks in the module to ensure it can actually be utilised
|
||||
$error = false;
|
||||
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
|
||||
if (!$error && method_exists($search, 'destroy_cache'))
|
||||
{
|
||||
$search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
|
||||
}
|
||||
$search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
|
||||
}
|
||||
|
||||
$from_username = $post_info['username'];
|
||||
|
@@ -428,7 +428,7 @@ function mcp_topic_view($id, $mode, $action)
|
||||
*/
|
||||
function split_topic($action, $topic_id, $to_forum_id, $subject)
|
||||
{
|
||||
global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config, $phpbb_log, $request, $phpbb_dispatcher;
|
||||
global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config, $phpbb_log, $request;
|
||||
|
||||
$post_id_list = $request->variable('post_id_list', array(0));
|
||||
$forum_id = $request->variable('forum_id', 0);
|
||||
@@ -625,20 +625,8 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
|
||||
if ($first_post_data['enable_indexing'])
|
||||
{
|
||||
// Select the search method and do some additional checks to ensure it can actually be utilised
|
||||
$search_type = $config['search_type'];
|
||||
|
||||
if (!class_exists($search_type))
|
||||
{
|
||||
trigger_error('NO_SUCH_SEARCH_MODULE');
|
||||
}
|
||||
|
||||
$error = false;
|
||||
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
|
||||
|
||||
if ($error)
|
||||
{
|
||||
trigger_error($error);
|
||||
}
|
||||
$search_backend_factory = $phpbb_container->get('search.backend_factory');
|
||||
$search = $search_backend_factory->get_active();
|
||||
|
||||
$search->index('edit', $first_post_data['post_id'], $first_post_data['post_text'], $subject, $first_post_data['poster_id'], $first_post_data['forum_id']);
|
||||
}
|
||||
|
Reference in New Issue
Block a user