[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: services:
# Search backends # Search backends
search.fulltext.native: search.fulltext.mysql:
class: phpbb\search\backend\fulltext_native class: phpbb\search\backend\fulltext_mysql
arguments: arguments:
- '@config' - '@config'
- '@dbal.conn' - '@dbal.conn'
@ -14,8 +14,8 @@ services:
tags: tags:
- { name: search.backend } - { name: search.backend }
search.fulltext.mysql: search.fulltext.native:
class: phpbb\search\backend\fulltext_mysql class: phpbb\search\backend\fulltext_native
arguments: arguments:
- '@config' - '@config'
- '@dbal.conn' - '@dbal.conn'

View file

@ -25,6 +25,10 @@ class acp_search
var $state; var $state;
var $search; var $search;
protected const STATE_SEARCH_TYPE = 0;
protected const STATE_ACTION = 1;
protected const STATE_POST_COUNTER = 2;
function main($id, $mode) function main($id, $mode)
{ {
global $user; global $user;
@ -80,7 +84,6 @@ class acp_search
// Only show available search backends // Only show available search backends
if ($search->is_available()) if ($search->is_available())
{ {
$name = $search->get_name(); $name = $search->get_name();
$type = get_class($search); $type = get_class($search);
@ -252,25 +255,24 @@ class acp_search
break; break;
case 'delete': case 'delete':
$this->state[1] = 'delete'; $this->state[self::STATE_ACTION] = 'delete';
break; break;
case 'create': case 'create':
$this->state[1] = 'create'; $this->state[self::STATE_ACTION] = 'create';
break; break;
default: default:
trigger_error('NO_ACTION', E_USER_ERROR); 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'); $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(); $name = $this->search->get_name();
@ -283,8 +285,8 @@ class acp_search
case 'delete': case 'delete':
try try
{ {
$this->state[2] = $this->state[2] ?? 0; $this->state[self::STATE_POST_COUNTER] = $this->state[self::STATE_POST_COUNTER] ?? 0;
if ($status = $this->search->delete_index($this->state[2])) // Status is not null, so deleting is in progress.... 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 // save the current state
$this->save_state(); $this->save_state();
@ -296,14 +298,14 @@ class acp_search
} }
catch (Exception $e) catch (Exception $e)
{ {
$this->state = array(''); $this->state = [];
$this->save_state(); $this->save_state();
trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
} }
$this->search->tidy(); $this->search->tidy();
$this->state = array(''); $this->state = [];
$this->save_state(); $this->save_state();
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_SEARCH_INDEX_REMOVED', false, array($name)); $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': case 'create':
try try
{ {
$this->state[2] = $this->state[2] ?? 0; $this->state[self::STATE_POST_COUNTER] = $this->state[self::STATE_POST_COUNTER] ?? 0;
if ($status = $this->search->create_index($this->state[2])) // Status is not null, so indexing is in progress.... 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 // save the current state
$this->save_state(); $this->save_state();
@ -327,7 +329,7 @@ class acp_search
catch (Exception $e) catch (Exception $e)
{ {
// Error executing create_index // Error executing create_index
$this->state = array(''); $this->state = [];
$this->save_state(); $this->save_state();
trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); 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->search->tidy();
$this->state = array(''); $this->state = [];
$this->save_state(); $this->save_state();
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_SEARCH_INDEX_CREATED', false, array($name)); $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")), '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( $template->assign_vars(array(
'S_CONTINUE_INDEXING' => $this->state[1], 'S_CONTINUE_INDEXING' => $this->state[1],
'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[1] . '&hash=' . generate_link_hash('acp_search'), 'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[self::STATE_ACTION] . '&hash=' . generate_link_hash('acp_search'),
'L_CONTINUE' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'], 'L_CONTINUE' => ($this->state[self::STATE_ACTION] == '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']) '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; 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) function make_unique_filename($filename)
{ {
if (!strlen($filename)) if (!strlen($filename))

View file

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

View file

@ -224,8 +224,6 @@ class convertor
trigger_error('NO_SUCH_SEARCH_MODULE'); 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); include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
$message_parser = new \parse_message(); $message_parser = new \parse_message();

View file

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

View file

@ -79,7 +79,7 @@ abstract class base implements search_backend_interface
* *
* @return int self::SEARCH_RESULT_NOT_IN_CACHE or self::SEARCH_RESULT_IN_CACHE or self::SEARCH_RESULT_INCOMPLETE * @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))) if (!($stored_ids = $this->cache->get('_search_results_' . $search_key)))
{ {
@ -89,7 +89,7 @@ abstract class base implements search_backend_interface
else else
{ {
$result_count = $stored_ids[-1]; $result_count = $stored_ids[-1];
$reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false; $reverse_ids = $stored_ids[-2] != $sort_dir;
$complete = true; $complete = true;
// Change start parameter in case out of bounds // 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 // 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) if ($reverse_ids)
{ {
$start = $result_count - $start - $per_page; $start = $result_count - $start - $per_page;
@ -156,9 +156,9 @@ abstract class base implements search_backend_interface
* @param int $start indicates the first index of the page * @param int $start indicates the first index of the page
* @param string $sort_dir is either a or d representing ASC and DESC * @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; global $user;
@ -268,7 +268,7 @@ abstract class base implements search_backend_interface
* @param array $words * @param array $words
* @param array|bool $authors * @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 // clear all searches that searched for the specified words
if (count($words)) if (count($words))
@ -415,6 +415,8 @@ abstract class base implements search_backend_interface
'rows_per_second' => $rows_per_second, '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))); extract($this->phpbb_dispatcher->trigger_event('core.search_mysql_index_before', compact($vars)));
unset($split_text); unset($split_text, $split_title);
unset($split_title);
// destroy cached search results containing any of the words removed or added // destroy cached search results containing any of the words removed or added
$this->destroy_cache($words, array($poster_id)); $this->destroy_cache($words, array($poster_id));
@ -1146,7 +1145,7 @@ class fulltext_mysql extends base implements search_backend_interface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acp(): array public function get_acp_options(): array
{ {
$tpl = ' $tpl = '
<dl> <dl>

View file

@ -1996,7 +1996,7 @@ class fulltext_native extends base implements search_backend_interface
/** /**
* {@inheritdoc} * {@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 * if we need any options, copied from fulltext_native for now, will have to be adjusted or removed

View file

@ -1081,7 +1081,7 @@ class fulltext_postgres extends base implements search_backend_interface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acp(): array public function get_acp_options(): array
{ {
$tpl = ' $tpl = '
<dl> <dl>

View file

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

View file

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

View file

@ -48,7 +48,7 @@ class search_backend_factory
* *
* @return search_backend_interface * @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); return $this->search_backends->get_by_class($class);
} }

View file

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