[ticket/15540] Code changes

PHPBB3-15540
This commit is contained in:
rubencm 2021-03-23 22:23:10 +01:00
parent 658a0489d0
commit 6ae68baa2e
14 changed files with 50 additions and 79 deletions

View file

@ -1,8 +1,8 @@
services:
# Search backends
search.fulltext.native:
class: phpbb\search\backend\fulltext_native
search.fulltext.mysql:
class: phpbb\search\backend\fulltext_mysql
arguments:
- '@config'
- '@dbal.conn'
@ -14,8 +14,8 @@ services:
tags:
- { name: search.backend }
search.fulltext.mysql:
class: phpbb\search\backend\fulltext_mysql
search.fulltext.native:
class: phpbb\search\backend\fulltext_native
arguments:
- '@config'
- '@dbal.conn'

View file

@ -25,6 +25,10 @@ class acp_search
var $state;
var $search;
protected const STATE_SEARCH_TYPE = 0;
protected const STATE_ACTION = 1;
protected const STATE_POST_COUNTER = 2;
function main($id, $mode)
{
global $user;
@ -80,7 +84,6 @@ class acp_search
// Only show available search backends
if ($search->is_available())
{
$name = $search->get_name();
$type = get_class($search);
@ -252,25 +255,24 @@ class acp_search
break;
case 'delete':
$this->state[1] = 'delete';
$this->state[self::STATE_ACTION] = 'delete';
break;
case 'create':
$this->state[1] = 'create';
$this->state[self::STATE_ACTION] = 'create';
break;
default:
trigger_error('NO_ACTION', E_USER_ERROR);
break;
}
if (empty($this->state[0]))
if (empty($this->state[self::STATE_SEARCH_TYPE]))
{
$this->state[0] = $request->variable('search_type', '');
$this->state[self::STATE_SEARCH_TYPE] = $request->variable('search_type', '');
}
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$this->search = $search_backend_factory->get($this->state[0]);
$this->search = $search_backend_factory->get($this->state[self::STATE_SEARCH_TYPE]);
$name = $this->search->get_name();
@ -283,8 +285,8 @@ class acp_search
case 'delete':
try
{
$this->state[2] = $this->state[2] ?? 0;
if ($status = $this->search->delete_index($this->state[2])) // Status is not null, so deleting is in progress....
$this->state[self::STATE_POST_COUNTER] = $this->state[self::STATE_POST_COUNTER] ?? 0;
if ($status = $this->search->delete_index($this->state[self::STATE_POST_COUNTER])) // Status is not null, so deleting is in progress....
{
// save the current state
$this->save_state();
@ -296,14 +298,14 @@ class acp_search
}
catch (Exception $e)
{
$this->state = array('');
$this->state = [];
$this->save_state();
trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
}
$this->search->tidy();
$this->state = array('');
$this->state = [];
$this->save_state();
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_SEARCH_INDEX_REMOVED', false, array($name));
@ -313,8 +315,8 @@ class acp_search
case 'create':
try
{
$this->state[2] = $this->state[2] ?? 0;
if ($status = $this->search->create_index($this->state[2])) // Status is not null, so indexing is in progress....
$this->state[self::STATE_POST_COUNTER] = $this->state[self::STATE_POST_COUNTER] ?? 0;
if ($status = $this->search->create_index($this->state[self::STATE_POST_COUNTER])) // Status is not null, so indexing is in progress....
{
// save the current state
$this->save_state();
@ -327,7 +329,7 @@ class acp_search
catch (Exception $e)
{
// Error executing create_index
$this->state = array('');
$this->state = [];
$this->save_state();
trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
}
@ -336,7 +338,7 @@ class acp_search
$this->search->tidy();
$this->state = array('');
$this->state = [];
$this->save_state();
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_SEARCH_INDEX_CREATED', false, array($name));
@ -409,13 +411,13 @@ class acp_search
'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=progress_bar")),
));
if (isset($this->state[1]))
if (isset($this->state[self::STATE_ACTION]))
{
$template->assign_vars(array(
'S_CONTINUE_INDEXING' => $this->state[1],
'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[1] . '&hash=' . generate_link_hash('acp_search'),
'L_CONTINUE' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'],
'L_CONTINUE_EXPLAIN' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[self::STATE_ACTION] . '&hash=' . generate_link_hash('acp_search'),
'L_CONTINUE' => ($this->state[self::STATE_ACTION] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'],
'L_CONTINUE_EXPLAIN' => ($this->state[self::STATE_ACTION] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
);
}
}

View file

@ -1039,34 +1039,6 @@ function set_user_options()
return $option_field;
}
/**
* Index messages on the fly as we convert them
* @todo naderman, can you check that this works with the new search plugins as it's use is currently disabled (and thus untested)
function search_indexing($message = '')
{
global $fulltext_search, $convert_row;
if (!isset($convert_row['post_id']))
{
return;
}
if (!$message)
{
if (!isset($convert_row['message']))
{
return;
}
$message = $convert_row['message'];
}
$title = (isset($convert_row['title'])) ? $convert_row['title'] : '';
$fulltext_search->index('post', $convert_row['post_id'], $message, $title, $convert_row['poster_id'], $convert_row['forum_id']);
}
*/
function make_unique_filename($filename)
{
if (!strlen($filename))

View file

@ -39,8 +39,6 @@ class convert
var $src_truncate_statement = 'DELETE FROM ';
var $truncate_statement = 'DELETE FROM ';
var $fulltext_search;
// Batch size, can be adjusted by the conversion file
// For big boards a value of 6000 seems to be optimal
var $batch_size = 2000;

View file

@ -224,8 +224,6 @@ class convertor
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$convert->fulltext_search = new $search_type($config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx);
include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
$message_parser = new \parse_message();

View file

@ -180,7 +180,7 @@ class create_search_index extends database_task
/**
* {@inheritdoc}
*/
public static function get_step_count() : int
static public function get_step_count() : int
{
return 1;
}

View file

@ -71,15 +71,15 @@ abstract class base implements search_backend_interface
* Retrieves cached search results
*
* @param string $search_key an md5 string generated from all the passed search options to identify the results
* @param int &$result_count will contain the number of all results for the search (not only for the current page)
* @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache
* @param int &$start indicates the first index of the page
* @param int &$result_count will contain the number of all results for the search (not only for the current page)
* @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache
* @param int &$start indicates the first index of the page
* @param int $per_page number of ids each page is supposed to contain
* @param string $sort_dir is either a or d representing ASC and DESC
*
* @return int self::SEARCH_RESULT_NOT_IN_CACHE or self::SEARCH_RESULT_IN_CACHE or self::SEARCH_RESULT_INCOMPLETE
*/
protected function obtain_ids(string $search_key, &$result_count, &$id_ary, &$start, $per_page, string $sort_dir): int
protected function obtain_ids(string $search_key, int &$result_count, array &$id_ary, int &$start, int $per_page, string $sort_dir): int
{
if (!($stored_ids = $this->cache->get('_search_results_' . $search_key)))
{
@ -89,7 +89,7 @@ abstract class base implements search_backend_interface
else
{
$result_count = $stored_ids[-1];
$reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false;
$reverse_ids = $stored_ids[-2] != $sort_dir;
$complete = true;
// Change start parameter in case out of bounds
@ -106,7 +106,7 @@ abstract class base implements search_backend_interface
}
// change the start to the actual end of the current request if the sort direction differs
// from the dirction in the cache and reverse the ids later
// from the direction in the cache and reverse the ids later
if ($reverse_ids)
{
$start = $result_count - $start - $per_page;
@ -151,14 +151,14 @@ abstract class base implements search_backend_interface
* @param string $keywords contains the keywords as entered by the user
* @param array $author_ary an array of author ids, if the author should be ignored during the search the array is empty
* @param int $result_count contains the number of all results for the search (not only for the current page)
* @param array &$id_ary contains a list of post or topic ids that shall be cached, the first element
* @param array &$id_ary contains a list of post or topic ids that shall be cached, the first element
* must have the absolute index $start in the result set.
* @param int $start indicates the first index of the page
* @param string $sort_dir is either a or d representing ASC and DESC
*
* @return null
* @return void
*/
protected function save_ids(string $search_key, string $keywords, $author_ary, int $result_count, &$id_ary, int $start, string $sort_dir)
protected function save_ids(string $search_key, string $keywords, array $author_ary, int $result_count, array &$id_ary, int $start, string $sort_dir): void
{
global $user;
@ -268,7 +268,7 @@ abstract class base implements search_backend_interface
* @param array $words
* @param array|bool $authors
*/
protected function destroy_cache($words, $authors = false): void
protected function destroy_cache(array $words, $authors = false): void
{
// clear all searches that searched for the specified words
if (count($words))
@ -415,6 +415,8 @@ abstract class base implements search_backend_interface
'rows_per_second' => $rows_per_second,
];
}
return null;
}
/**

View file

@ -880,8 +880,7 @@ class fulltext_mysql extends base implements search_backend_interface
);
extract($this->phpbb_dispatcher->trigger_event('core.search_mysql_index_before', compact($vars)));
unset($split_text);
unset($split_title);
unset($split_text, $split_title);
// destroy cached search results containing any of the words removed or added
$this->destroy_cache($words, array($poster_id));
@ -1146,7 +1145,7 @@ class fulltext_mysql extends base implements search_backend_interface
/**
* {@inheritdoc}
*/
public function acp(): array
public function get_acp_options(): array
{
$tpl = '
<dl>

View file

@ -1996,7 +1996,7 @@ class fulltext_native extends base implements search_backend_interface
/**
* {@inheritdoc}
*/
public function acp(): array
public function get_acp_options(): array
{
/**
* if we need any options, copied from fulltext_native for now, will have to be adjusted or removed

View file

@ -343,16 +343,16 @@ class fulltext_postgres extends base implements search_backend_interface
case 'u':
$sql_sort_table = USERS_TABLE . ' u, ';
$sql_sort_join = ($type == 'posts') ? ' AND u.user_id = p.poster_id ' : ' AND u.user_id = t.topic_poster ';
break;
break;
case 't':
$join_topic = true;
break;
break;
case 'f':
$sql_sort_table = FORUMS_TABLE . ' f, ';
$sql_sort_join = ' AND f.forum_id = p.forum_id ';
break;
break;
}
// Build some display specific sql strings
@ -1081,7 +1081,7 @@ class fulltext_postgres extends base implements search_backend_interface
/**
* {@inheritdoc}
*/
public function acp(): array
public function get_acp_options(): array
{
$tpl = '
<dl>

View file

@ -783,7 +783,7 @@ class fulltext_sphinx implements search_backend_interface
/**
* {@inheritdoc}
*/
public function acp(): array
public function get_acp_options(): array
{
$config_vars = array(
'fulltext_sphinx_data_path' => 'string',

View file

@ -192,5 +192,5 @@ interface search_backend_interface
*
* @return array array containing template and config variables
*/
public function acp(): array;
public function get_acp_options(): array;
}

View file

@ -44,11 +44,11 @@ class search_backend_factory
/**
* Obtains a specified search backend
*
* @param string $class
* @param string $class
*
* @return search_backend_interface
*/
public function get($class): search_backend_interface
public function get(string $class): search_backend_interface
{
return $this->search_backends->get_by_class($class);
}

View file

@ -29,7 +29,7 @@ $mode = $request->variable('mode', '');
$search_id = $request->variable('search_id', '');
$start = max($request->variable('start', 0), 0);
$post_id = $request->variable('p', 0);
$topic_id = (int) $request->variable('t', 0);
$topic_id = $request->variable('t', 0);
$view = $request->variable('view', '');
$submit = $request->variable('submit', false);