[ticket/16737] Remove state and search properties

PHPBB3-16737
This commit is contained in:
rubencm 2021-03-24 22:54:42 +01:00
parent 558828b7e0
commit 31fac7bbf1
2 changed files with 37 additions and 58 deletions

View file

@ -2,20 +2,6 @@
<a id="maincontent"></a> <a id="maincontent"></a>
<script>
// <![CDATA[
/**
* Popup search progress bar
*/
function popup_progress_bar(progress_type)
{
close_waitscreen = 0;
// no scrollbars
popup('{UA_PROGRESS_BAR}&amp;type=' + progress_type, 400, 240, '_index');
}
// ]]>
</script>
<h1>{L_ACP_SEARCH_INDEX}</h1> <h1>{L_ACP_SEARCH_INDEX}</h1>
<p>{L_CONTINUE_EXPLAIN}</p> <p>{L_CONTINUE_EXPLAIN}</p>

View file

@ -21,15 +21,13 @@ if (!defined('IN_PHPBB'))
class acp_search class acp_search
{ {
var $u_action; public $u_action;
var $state;
var $search;
protected const STATE_SEARCH_TYPE = 0; protected const STATE_SEARCH_TYPE = 0;
protected const STATE_ACTION = 1; protected const STATE_ACTION = 1;
protected const STATE_POST_COUNTER = 2; protected const STATE_POST_COUNTER = 2;
function main($id, $mode) public function main($id, $mode)
{ {
global $user; global $user;
@ -208,19 +206,19 @@ class acp_search
]); ]);
} }
function index($id, $mode) public function index($id, $mode)
{ {
global $user, $template, $phpbb_log, $request; global $user, $template, $phpbb_log, $request;
global $config, $phpbb_admin_path, $phpEx, $phpbb_container; global $config, $phpbb_admin_path, $phpEx, $phpbb_container;
$action = $request->variable('action', ''); $action = $request->variable('action', '');
$this->state = explode(',', $config['search_indexing_state']); $state = explode(',', $config['search_indexing_state']);
if ($request->is_set_post('cancel')) if ($request->is_set_post('cancel'))
{ {
$action = ''; $action = '';
$this->state = array(); $state = array();
$this->save_state(); $this->save_state($state);
} }
$submit = $request->is_set_post('submit'); $submit = $request->is_set_post('submit');
@ -239,41 +237,41 @@ class acp_search
break; break;
case 'delete': case 'delete':
$this->state[self::STATE_ACTION] = 'delete'; $state[self::STATE_ACTION] = 'delete';
break; break;
case 'create': case 'create':
$this->state[self::STATE_ACTION] = 'create'; $state[self::STATE_ACTION] = 'create';
break; break;
default: default:
trigger_error('NO_ACTION', E_USER_ERROR); trigger_error('NO_ACTION', E_USER_ERROR);
} }
if (empty($this->state[self::STATE_SEARCH_TYPE])) if (empty($state[self::STATE_SEARCH_TYPE]))
{ {
$this->state[self::STATE_SEARCH_TYPE] = $request->variable('search_type', ''); $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[self::STATE_SEARCH_TYPE]); $search = $search_backend_factory->get($state[self::STATE_SEARCH_TYPE]);
$name = $this->search->get_name(); $name = $search->get_name();
$action = &$this->state[1]; $action = &$state[1];
$this->save_state(); $this->save_state($state);
switch ($action) switch ($action)
{ {
case 'delete': case 'delete':
try try
{ {
$this->state[self::STATE_POST_COUNTER] = $this->state[self::STATE_POST_COUNTER] ?? 0; $state[self::STATE_POST_COUNTER] = $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.... if ($status = $search->delete_index($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($state);
$u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete&hash=" . generate_link_hash('acp_search'), false); $u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete&hash=" . generate_link_hash('acp_search'), false);
meta_refresh(1, $u_action); meta_refresh(1, $u_action);
@ -282,15 +280,15 @@ class acp_search
} }
catch (Exception $e) catch (Exception $e)
{ {
$this->state = []; $state = [];
$this->save_state(); $this->save_state($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(); $search->tidy();
$this->state = []; $state = [];
$this->save_state(); $this->save_state($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));
trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . $this->close_popup_js()); trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . $this->close_popup_js());
@ -299,11 +297,11 @@ class acp_search
case 'create': case 'create':
try try
{ {
$this->state[self::STATE_POST_COUNTER] = $this->state[self::STATE_POST_COUNTER] ?? 0; $state[self::STATE_POST_COUNTER] = $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.... if ($status = $search->create_index($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($state);
$u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=create&hash=" . generate_link_hash('acp_search'), false); $u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=create&hash=" . generate_link_hash('acp_search'), false);
meta_refresh(1, $u_action); meta_refresh(1, $u_action);
@ -313,17 +311,17 @@ class acp_search
catch (Exception $e) catch (Exception $e)
{ {
// Error executing create_index // Error executing create_index
$this->state = []; $state = [];
$this->save_state(); $this->save_state($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);
} }
// Indexing have finished // Indexing have finished
$this->search->tidy(); $search->tidy();
$this->state = []; $state = [];
$this->save_state(); $this->save_state($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));
trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . $this->close_popup_js()); trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . $this->close_popup_js());
@ -359,16 +357,16 @@ class acp_search
'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=$mode&amp;action=progress_bar")), 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=$mode&amp;action=progress_bar")),
)); ));
if (isset($this->state[self::STATE_ACTION])) if (isset($state[self::STATE_ACTION]))
{ {
$this->tpl_name = 'acp_search_index'; $this->tpl_name = 'acp_search_index';
$this->page_title = 'ACP_SEARCH_INDEX'; $this->page_title = 'ACP_SEARCH_INDEX';
$template->assign_vars(array( $template->assign_vars(array(
'S_CONTINUE_INDEXING' => $this->state[1], 'S_CONTINUE_INDEXING' => $state[1],
'U_CONTINUE_INDEXING' => $this->u_action . '&amp;action=' . $this->state[self::STATE_ACTION] . '&amp;hash=' . generate_link_hash('acp_search'), 'U_CONTINUE_INDEXING' => $this->u_action . '&amp;action=' . $state[self::STATE_ACTION] . '&amp;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' => ($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']) 'L_CONTINUE_EXPLAIN' => ($state[self::STATE_ACTION] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN'])
); );
} }
} }
@ -406,13 +404,8 @@ class acp_search
{ {
global $config; global $config;
if ($state) ksort($state);
{
$this->state = $state;
}
ksort($this->state); $config->set('search_indexing_state', implode(',', $state), true);
$config->set('search_indexing_state', implode(',', $this->state), true);
} }
} }