From 89f41d845665bbd73f3801f3c8b5e94719aede9e Mon Sep 17 00:00:00 2001 From: rubencm Date: Wed, 24 Mar 2021 21:39:13 +0100 Subject: [PATCH 01/12] [ticket/16737] Remove dead code PHPBB3-16737 --- phpBB/includes/acp/acp_search.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index a5a89d62e8..45b17ba1f4 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -185,17 +185,6 @@ class acp_search } } - if ($updated) - { - if (method_exists($search, 'config_updated')) - { - if ($search->config_updated()) - { - trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING); - } - } - } - trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action)); } unset($cfg_array); From 381cf4b9f1e5a4d6d2950aecbd074e57011f5cfe Mon Sep 17 00:00:00 2001 From: rubencm Date: Wed, 24 Mar 2021 21:46:36 +0100 Subject: [PATCH 02/12] [ticket/16737] Remove dead code PHPBB3-16737 --- phpBB/includes/acp/acp_search.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 45b17ba1f4..cda3e6a69f 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -334,19 +334,11 @@ class acp_search $search_types = $phpbb_container->get('search.backend_collection'); - $search = null; - foreach ($search_types as $search) { $type = get_class($search); - $name = $search->get_name(); - - $data = array(); - if (method_exists($search, 'index_stats')) - { - $data = $search->index_stats(); - } + $data = $search->index_stats(); $statistics = array(); foreach ($data as $statistic => $value) From b78efaadc108c70d70a45d86787218a7a28ffe3e Mon Sep 17 00:00:00 2001 From: rubencm Date: Wed, 24 Mar 2021 22:25:36 +0100 Subject: [PATCH 03/12] [ticket/16737] Move template logic to template PHPBB3-16737 --- phpBB/adm/style/acp_search.html | 21 +++++++++++------- phpBB/includes/acp/acp_search.php | 37 +++++-------------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/phpBB/adm/style/acp_search.html b/phpBB/adm/style/acp_search.html index af7bb86be5..36f2268b84 100644 --- a/phpBB/adm/style/acp_search.html +++ b/phpBB/adm/style/acp_search.html @@ -113,7 +113,7 @@ - + {% if backend.S_STATS is not empty %}
@@ -135,18 +135,23 @@ - + {% for stat in backend.S_STATS | batch(2, '') %} - {backend.data.STATISTIC_1}{L_COLON} - {backend.data.VALUE_1} - {backend.data.STATISTIC_2}{L_COLON} - {backend.data.VALUE_2} + {% for key, value in stat %} + {% if value is not empty %} + {{ key }}{L_COLON} + {{ value }} + {% else %} + + + {% endif %} + {% endfor %} - + {% endfor %} - + {% endif %}

diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index cda3e6a69f..81053d1f33 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -189,7 +189,7 @@ class acp_search } unset($cfg_array); - $this->tpl_name = 'acp_search'; + $this->tpl_name = 'acp_search_settings'; $this->page_title = 'ACP_SEARCH_SETTINGS'; $template->assign_vars([ @@ -340,45 +340,18 @@ class acp_search $name = $search->get_name(); $data = $search->index_stats(); - $statistics = array(); - foreach ($data as $statistic => $value) - { - $n = count($statistics); - if ($n && count($statistics[$n - 1]) < 3) - { - $statistics[$n - 1] += array('statistic_2' => $statistic, 'value_2' => $value); - } - else - { - $statistics[] = array('statistic_1' => $statistic, 'value_1' => $value); - } - } - $template->assign_block_vars('backend', array( 'L_NAME' => $name, 'NAME' => $type, - 'S_ACTIVE' => ($type == $config['search_type']) ? true : false, + 'S_ACTIVE' => $type == $config['search_type'], 'S_HIDDEN_FIELDS' => build_hidden_fields(array('search_type' => $type)), 'S_INDEXED' => (bool) $search->index_created(), - 'S_STATS' => (bool) count($statistics)) - ); - - foreach ($statistics as $statistic) - { - $template->assign_block_vars('backend.data', array( - 'STATISTIC_1' => $statistic['statistic_1'], - 'VALUE_1' => $statistic['value_1'], - 'STATISTIC_2' => (isset($statistic['statistic_2'])) ? $statistic['statistic_2'] : '', - 'VALUE_2' => (isset($statistic['value_2'])) ? $statistic['value_2'] : '') - ); - } + 'S_STATS' => $data, + )); } - unset($search); - unset($statistics); - unset($data); - $this->tpl_name = 'acp_search'; + $this->tpl_name = 'acp_search_index'; $this->page_title = 'ACP_SEARCH_INDEX'; $template->assign_vars(array( From 558828b7e047e33b0fce5da2a4df8274e497263b Mon Sep 17 00:00:00 2001 From: rubencm Date: Wed, 24 Mar 2021 22:37:24 +0100 Subject: [PATCH 04/12] [ticket/16737] Divide acp_search in multiple files PHPBB3-16737 --- phpBB/adm/style/acp_search.html | 175 ------------------ phpBB/adm/style/acp_search_index.html | 80 ++++++++ .../style/acp_search_index_inprogress.html | 34 ++++ phpBB/adm/style/acp_search_settings.html | 78 ++++++++ phpBB/includes/acp/acp_search.php | 5 +- 5 files changed, 195 insertions(+), 177 deletions(-) delete mode 100644 phpBB/adm/style/acp_search.html create mode 100644 phpBB/adm/style/acp_search_index.html create mode 100644 phpBB/adm/style/acp_search_index_inprogress.html create mode 100644 phpBB/adm/style/acp_search_settings.html diff --git a/phpBB/adm/style/acp_search.html b/phpBB/adm/style/acp_search.html deleted file mode 100644 index 36f2268b84..0000000000 --- a/phpBB/adm/style/acp_search.html +++ /dev/null @@ -1,175 +0,0 @@ - - - - - -

{L_ACP_SEARCH_SETTINGS}

- -

{L_ACP_SEARCH_SETTINGS_EXPLAIN}

- - - -
- {L_GENERAL_SEARCH_SETTINGS} -
-

{L_YES_SEARCH_EXPLAIN}
-
-
-
-
-

{L_SEARCH_INTERVAL_EXPLAIN}
-
{L_SECONDS}
-
-
-

{L_SEARCH_GUEST_INTERVAL_EXPLAIN}
-
{L_SECONDS}
-
-
-

{L_LIMIT_SEARCH_LOAD_EXPLAIN}
-
-
-
-

{L_MIN_SEARCH_AUTHOR_CHARS_EXPLAIN}
-
-
-
-

{L_MAX_NUM_SEARCH_KEYWORDS_EXPLAIN}
-
-
-
-
- -
{{ lang('DEFAULT_SEARCH_RETURN_CHARS_EXPLAIN') }} -
-
-
-
-

{L_SEARCH_STORE_RESULTS_EXPLAIN}
-
{L_SECONDS}
-
-
- -
- {L_SEARCH_TYPE} -
-

{L_SEARCH_TYPE_EXPLAIN}
-
-
-
- - - -
- {backend.NAME} - {backend.SETTINGS} -
- - - -
- {L_ACP_SUBMIT_CHANGES} -

-   - -

- {S_FORM_TOKEN} -
-
- - - - - -

{L_ACP_SEARCH_INDEX}

- - -

{L_CONTINUE_EXPLAIN}

- -
-
- {L_ACP_SUBMIT_CHANGES} -

-   - -

- {S_FORM_TOKEN} -
-
- - -

{L_ACP_SEARCH_INDEX_EXPLAIN}

- - - - {% if backend.S_STATS is not empty %} - -
- -
- - {backend.S_HIDDEN_FIELDS} - - {L_INDEX_STATS}{L_COLON} {backend.L_NAME} ({L_ACTIVE}) - - - - - - - - - - - - - - {% for stat in backend.S_STATS | batch(2, '') %} - - {% for key, value in stat %} - {% if value is not empty %} - - - {% else %} - - - {% endif %} - {% endfor %} - - {% endfor %} - -
{backend.L_NAME} ({L_ACTIVE})
{L_STATISTIC}{L_VALUE}{L_STATISTIC}{L_VALUE}
{{ key }}{L_COLON}{{ value }}
- - {% endif %} - -

- - - - - - - -

- {S_FORM_TOKEN} -
- -
- - - - - - - diff --git a/phpBB/adm/style/acp_search_index.html b/phpBB/adm/style/acp_search_index.html new file mode 100644 index 0000000000..8ce882fa89 --- /dev/null +++ b/phpBB/adm/style/acp_search_index.html @@ -0,0 +1,80 @@ + + + + + + +

{L_ACP_SEARCH_INDEX}

+ +

{L_ACP_SEARCH_INDEX_EXPLAIN}

+ + + + {% if backend.S_STATS is not empty %} + +
+ +
+ + {backend.S_HIDDEN_FIELDS} + + {L_INDEX_STATS}{L_COLON} {backend.L_NAME} ({L_ACTIVE}) + + + + + + + + + + + + + + {% for stat in backend.S_STATS | batch(2, '') %} + + {% for key, value in stat %} + {% if value is not empty %} + + + {% else %} + + + {% endif %} + {% endfor %} + + {% endfor %} + +
{backend.L_NAME} ({L_ACTIVE})
{L_STATISTIC}{L_VALUE}{L_STATISTIC}{L_VALUE}
{{ key }}{L_COLON}{{ value }}
+ + {% endif %} + +

+ + + + + + + +

+ {S_FORM_TOKEN} +
+ +
+ + + diff --git a/phpBB/adm/style/acp_search_index_inprogress.html b/phpBB/adm/style/acp_search_index_inprogress.html new file mode 100644 index 0000000000..6d9630a35a --- /dev/null +++ b/phpBB/adm/style/acp_search_index_inprogress.html @@ -0,0 +1,34 @@ + + + + + + +

{L_ACP_SEARCH_INDEX}

+ +

{L_CONTINUE_EXPLAIN}

+ +
+
+ {L_ACP_SUBMIT_CHANGES} +

+   + +

+ {S_FORM_TOKEN} +
+
+ + diff --git a/phpBB/adm/style/acp_search_settings.html b/phpBB/adm/style/acp_search_settings.html new file mode 100644 index 0000000000..b468fd17ed --- /dev/null +++ b/phpBB/adm/style/acp_search_settings.html @@ -0,0 +1,78 @@ + + + + +

{L_ACP_SEARCH_SETTINGS}

+ +

{L_ACP_SEARCH_SETTINGS_EXPLAIN}

+ + + + diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 81053d1f33..28758cd91b 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -203,7 +203,6 @@ class acp_search 'S_SEARCH_TYPES' => $search_options, 'S_YES_SEARCH' => (bool) $config['load_search'], - 'S_SETTINGS' => true, 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), ]); @@ -355,7 +354,6 @@ class acp_search $this->page_title = 'ACP_SEARCH_INDEX'; $template->assign_vars(array( - 'S_INDEX' => true, 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), 'U_PROGRESS_BAR' => 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")), @@ -363,6 +361,9 @@ class acp_search if (isset($this->state[self::STATE_ACTION])) { + $this->tpl_name = 'acp_search_index'; + $this->page_title = 'ACP_SEARCH_INDEX'; + $template->assign_vars(array( 'S_CONTINUE_INDEXING' => $this->state[1], 'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $this->state[self::STATE_ACTION] . '&hash=' . generate_link_hash('acp_search'), From 31fac7bbf1dece11fbaca5c72ab9f123a65bd7f1 Mon Sep 17 00:00:00 2001 From: rubencm Date: Wed, 24 Mar 2021 22:54:42 +0100 Subject: [PATCH 05/12] [ticket/16737] Remove state and search properties PHPBB3-16737 --- .../style/acp_search_index_inprogress.html | 14 ---- phpBB/includes/acp/acp_search.php | 81 +++++++++---------- 2 files changed, 37 insertions(+), 58 deletions(-) diff --git a/phpBB/adm/style/acp_search_index_inprogress.html b/phpBB/adm/style/acp_search_index_inprogress.html index 6d9630a35a..b8206c8d46 100644 --- a/phpBB/adm/style/acp_search_index_inprogress.html +++ b/phpBB/adm/style/acp_search_index_inprogress.html @@ -2,20 +2,6 @@ - -

{L_ACP_SEARCH_INDEX}

{L_CONTINUE_EXPLAIN}

diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 28758cd91b..2d73913ac1 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -21,15 +21,13 @@ if (!defined('IN_PHPBB')) class acp_search { - var $u_action; - var $state; - var $search; + public $u_action; protected const STATE_SEARCH_TYPE = 0; protected const STATE_ACTION = 1; protected const STATE_POST_COUNTER = 2; - function main($id, $mode) + public function main($id, $mode) { 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 $config, $phpbb_admin_path, $phpEx, $phpbb_container; $action = $request->variable('action', ''); - $this->state = explode(',', $config['search_indexing_state']); + $state = explode(',', $config['search_indexing_state']); if ($request->is_set_post('cancel')) { $action = ''; - $this->state = array(); - $this->save_state(); + $state = array(); + $this->save_state($state); } $submit = $request->is_set_post('submit'); @@ -239,41 +237,41 @@ class acp_search break; case 'delete': - $this->state[self::STATE_ACTION] = 'delete'; + $state[self::STATE_ACTION] = 'delete'; break; case 'create': - $this->state[self::STATE_ACTION] = 'create'; + $state[self::STATE_ACTION] = 'create'; break; default: 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'); - $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) { case 'delete': try { - $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.... + $state[self::STATE_POST_COUNTER] = $state[self::STATE_POST_COUNTER] ?? 0; + if ($status = $search->delete_index($state[self::STATE_POST_COUNTER])) // Status is not null, so deleting is in progress.... { // 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); meta_refresh(1, $u_action); @@ -282,15 +280,15 @@ class acp_search } catch (Exception $e) { - $this->state = []; - $this->save_state(); + $state = []; + $this->save_state($state); trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); } - $this->search->tidy(); + $search->tidy(); - $this->state = []; - $this->save_state(); + $state = []; + $this->save_state($state); $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()); @@ -299,11 +297,11 @@ class acp_search case 'create': try { - $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.... + $state[self::STATE_POST_COUNTER] = $state[self::STATE_POST_COUNTER] ?? 0; + if ($status = $search->create_index($state[self::STATE_POST_COUNTER])) // Status is not null, so indexing is in progress.... { // 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); meta_refresh(1, $u_action); @@ -313,17 +311,17 @@ class acp_search catch (Exception $e) { // Error executing create_index - $this->state = []; - $this->save_state(); + $state = []; + $this->save_state($state); trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); } // Indexing have finished - $this->search->tidy(); + $search->tidy(); - $this->state = []; - $this->save_state(); + $state = []; + $this->save_state($state); $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()); @@ -359,16 +357,16 @@ 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[self::STATE_ACTION])) + if (isset($state[self::STATE_ACTION])) { $this->tpl_name = 'acp_search_index'; $this->page_title = 'ACP_SEARCH_INDEX'; $template->assign_vars(array( - 'S_CONTINUE_INDEXING' => $this->state[1], - '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']) + 'S_CONTINUE_INDEXING' => $state[1], + 'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $state[self::STATE_ACTION] . '&hash=' . generate_link_hash('acp_search'), + 'L_CONTINUE' => ($state[self::STATE_ACTION] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'], + '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; - if ($state) - { - $this->state = $state; - } + ksort($state); - ksort($this->state); - - $config->set('search_indexing_state', implode(',', $this->state), true); + $config->set('search_indexing_state', implode(',', $state), true); } } From cf8b797911eabd7685274ef1c2f6c31802d8450e Mon Sep 17 00:00:00 2001 From: rubencm Date: Thu, 25 Mar 2021 03:37:30 +0100 Subject: [PATCH 06/12] [ticket/16737] Rewrite acp_search index pages PHPBB3-16737 --- .../style/acp_search_index_inprogress.html | 1 + phpBB/includes/acp/acp_search.php | 516 +++++++++++------- phpBB/phpbb/search/backend/base.php | 8 + .../phpbb/search/backend/fulltext_sphinx.php | 8 + .../backend/search_backend_interface.php | 7 + phpBB/phpbb/storage/provider/local.php | 2 +- .../storage/provider/provider_interface.php | 4 +- 7 files changed, 337 insertions(+), 209 deletions(-) diff --git a/phpBB/adm/style/acp_search_index_inprogress.html b/phpBB/adm/style/acp_search_index_inprogress.html index b8206c8d46..0f2c2e6f77 100644 --- a/phpBB/adm/style/acp_search_index_inprogress.html +++ b/phpBB/adm/style/acp_search_index_inprogress.html @@ -4,6 +4,7 @@

{L_ACP_SEARCH_INDEX}

+{# todo: check the l_continue that is send from acp_search here #}

{L_CONTINUE_EXPLAIN}

diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 2d73913ac1..a3a304bb62 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -14,6 +14,16 @@ /** * @ignore */ + +use phpbb\config\config; +use phpbb\di\service_collection; +use phpbb\language\language; +use phpbb\log\log; +use phpbb\request\request; +use phpbb\search\search_backend_factory; +use phpbb\template\template; +use phpbb\user; + if (!defined('IN_PHPBB')) { exit; @@ -22,19 +32,88 @@ if (!defined('IN_PHPBB')) class acp_search { public $u_action; + public $tpl_name; + public $page_title; protected const STATE_SEARCH_TYPE = 0; protected const STATE_ACTION = 1; protected const STATE_POST_COUNTER = 2; - public function main($id, $mode) + /** + * @var config + */ + protected $config; + + /** + * @var language + */ + protected $language; + + /** + * @var log + */ + protected $log; + + /** + * @var request + */ + protected $request; + + /** + * @var service_collection + */ + protected $search_backend_collection; + + /** + * @var search_backend_factory + */ + protected $search_backend_factory; + + /** + * @var template + */ + protected $template; + + /** + * @var user + */ + protected $user; + + /** + * @var string + */ + protected $phpbb_admin_path; + + /** + * @var string + */ + protected $php_ex; + + public function __construct($p_master) { - global $user; + global $config, $phpbb_container, $language, $phpbb_log, $request, $template, $user, $phpbb_admin_path, $phpEx; - $user->add_lang('acp/search'); + $this->config = $config; + $this->language = $language; + $this->log = $phpbb_log; + $this->request = $request; + $this->search_backend_collection = $phpbb_container->get('search.backend_collection'); + $this->search_backend_factory = $phpbb_container->get('search.backend_factory'); + $this->template = $template; + $this->user = $user; + $this->phpbb_admin_path = $phpbb_admin_path; + $this->php_ex = $phpEx; + } - // For some this may be of help... - @ini_set('memory_limit', '128M'); + /** + * @param string $id + * @param string $mode + * @throws Exception + * @return void + */ + public function main(string $id, string $mode): void + { + $this->language->add_lang('acp/search'); switch ($mode) { @@ -48,21 +127,15 @@ class acp_search } } - function settings($id, $mode) + public function settings(string $id, string $mode): void { - global $user, $template, $phpbb_log, $request; - global $config, $phpbb_admin_path, $phpEx; - global $phpbb_container; + $submit = $this->request->is_set_post('submit'); - $submit = $request->is_set_post('submit'); - - if ($submit && !check_link_hash($request->variable('hash', ''), 'acp_search')) + if ($submit && !check_link_hash($this->request->variable('hash', ''), 'acp_search')) { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); } - $search_types = $phpbb_container->get('search.backend_collection'); - $settings = [ 'search_interval' => 'float', 'search_anonymous_interval' => 'float', @@ -74,18 +147,17 @@ class acp_search 'search_store_results' => 'integer', ]; - $search = null; $search_options = ''; - foreach ($search_types as $search) + foreach ($this->search_backend_collection as $search) { // Only show available search backends if ($search->is_available()) { $name = $search->get_name(); - $type = get_class($search); + $type = $search->get_type(); - $selected = ($config['search_type'] == $type) ? ' selected="selected"' : ''; + $selected = ($this->config['search_type'] == $type) ? ' selected="selected"' : ''; $identifier = substr($type, strrpos($type, '\\') + 1); $search_options .= ""; @@ -93,7 +165,7 @@ class acp_search if (!$submit) { - $template->assign_block_vars('backend', array( + $this->template->assign_block_vars('backend', array( 'NAME' => $name, 'SETTINGS' => $vars['tpl'], 'IDENTIFIER' => $identifier, @@ -105,14 +177,13 @@ class acp_search } } } - unset($search); - $cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => ''), true) : array(); - $updated = $request->variable('updated', false); + $cfg_array = (isset($_REQUEST['config'])) ? $this->request->variable('config', array('' => ''), true) : array(); + $updated = $this->request->variable('updated', false); - foreach ($settings as $config_name => $var_type) + foreach ($settings as $this->config_name => $var_type) { - if (!isset($cfg_array[$config_name])) + if (!isset($cfg_array[$this->config_name])) { continue; } @@ -120,23 +191,23 @@ class acp_search // e.g. integer:4:12 (min 4, max 12) $var_type = explode(':', $var_type); - $config_value = $cfg_array[$config_name]; - settype($config_value, $var_type[0]); + $this->config_value = $cfg_array[$this->config_name]; + settype($this->config_value, $var_type[0]); if (isset($var_type[1])) { - $config_value = max($var_type[1], $config_value); + $this->config_value = max($var_type[1], $this->config_value); } if (isset($var_type[2])) { - $config_value = min($var_type[2], $config_value); + $this->config_value = min($var_type[2], $this->config_value); } // only change config if anything was actually changed - if ($submit && ($config[$config_name] != $config_value)) + if ($submit && ($this->config[$this->config_name] != $this->config_value)) { - $config->set($config_name, $config_value); + $this->config->set($this->config_name, $this->config_value); $updated = true; } } @@ -146,25 +217,24 @@ class acp_search $extra_message = ''; if ($updated) { - $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_SEARCH'); + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CONFIG_SEARCH'); } - if (isset($cfg_array['search_type']) && ($cfg_array['search_type'] != $config['search_type'])) + if (isset($cfg_array['search_type']) && ($cfg_array['search_type'] != $this->config['search_type'])) { - $search_backend_factory = $phpbb_container->get('search.backend_factory'); - $search = $search_backend_factory->get($cfg_array['search_type']); + $search = $this->search_backend_factory->get($cfg_array['search_type']); if (confirm_box(true)) { // Initialize search backend, if $error is false means that everything is ok if (!($error = $search->init())) { - $config->set('search_type', $cfg_array['search_type']); + $this->config->set('search_type', $cfg_array['search_type']); if (!$updated) { - $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_SEARCH'); + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CONFIG_SEARCH'); } - $extra_message = '
' . $user->lang['SWITCHED_SEARCH_BACKEND'] . '
» ' . $user->lang['GO_TO_SEARCH_INDEX'] . ''; + $extra_message = '
' . $this->language->lang('SWITCHED_SEARCH_BACKEND') . '
php_ex, 'i=search&mode=index') . '">» ' . $this->language->lang('GO_TO_SEARCH_INDEX') . ''; } else { @@ -173,7 +243,7 @@ class acp_search } else { - confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array( + confirm_box(false, $this->language->lang('CONFIRM_SEARCH_BACKEND'), build_hidden_fields(array( 'i' => $id, 'mode' => $mode, 'submit' => true, @@ -183,215 +253,248 @@ class acp_search } } - trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action)); + trigger_error($this->language->lang('CONFIG_UPDATED') . $extra_message . adm_back_link($this->u_action)); } unset($cfg_array); $this->tpl_name = 'acp_search_settings'; $this->page_title = 'ACP_SEARCH_SETTINGS'; - $template->assign_vars([ - 'DEFAULT_SEARCH_RETURN_CHARS' => (int) $config['default_search_return_chars'], - 'LIMIT_SEARCH_LOAD' => (float) $config['limit_search_load'], - 'MIN_SEARCH_AUTHOR_CHARS' => (int) $config['min_search_author_chars'], - 'SEARCH_INTERVAL' => (float) $config['search_interval'], - 'SEARCH_GUEST_INTERVAL' => (float) $config['search_anonymous_interval'], - 'SEARCH_STORE_RESULTS' => (int) $config['search_store_results'], - 'MAX_NUM_SEARCH_KEYWORDS' => (int) $config['max_num_search_keywords'], + $this->template->assign_vars([ + 'DEFAULT_SEARCH_RETURN_CHARS' => (int) $this->config['default_search_return_chars'], + 'LIMIT_SEARCH_LOAD' => (float) $this->config['limit_search_load'], + 'MIN_SEARCH_AUTHOR_CHARS' => (int) $this->config['min_search_author_chars'], + 'SEARCH_INTERVAL' => (float) $this->config['search_interval'], + 'SEARCH_GUEST_INTERVAL' => (float) $this->config['search_anonymous_interval'], + 'SEARCH_STORE_RESULTS' => (int) $this->config['search_store_results'], + 'MAX_NUM_SEARCH_KEYWORDS' => (int) $this->config['max_num_search_keywords'], 'S_SEARCH_TYPES' => $search_options, - 'S_YES_SEARCH' => (bool) $config['load_search'], + 'S_YES_SEARCH' => (bool) $this->config['load_search'], 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), ]); } - public function index($id, $mode) + /** + * @param string $id + * @param string $mode + * @throws Exception + */ + public function index(string $id, string $mode): void { - global $user, $template, $phpbb_log, $request; - global $config, $phpbb_admin_path, $phpEx, $phpbb_container; + $action = $this->request->variable('action', ''); + $state = !empty($this->config['search_indexing_state']) ? explode(',', $this->config['search_indexing_state']) : []; - $action = $request->variable('action', ''); - $state = explode(',', $config['search_indexing_state']); - - if ($request->is_set_post('cancel')) - { - $action = ''; - $state = array(); - $this->save_state($state); - } - $submit = $request->is_set_post('submit'); - - if (!check_link_hash($request->variable('hash', ''), 'acp_search') && in_array($action, array('create', 'delete'))) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if ($action) + if($action) { switch ($action) { case 'progress_bar': - $type = $request->variable('type', ''); - $this->display_progress_bar($type); - break; - - case 'delete': - $state[self::STATE_ACTION] = 'delete'; + $this->display_progress_bar(); break; case 'create': - $state[self::STATE_ACTION] = 'create'; + case 'delete': + $this->index_action($id, $mode, $action, $state); break; default: trigger_error('NO_ACTION', E_USER_ERROR); } - - if (empty($state[self::STATE_SEARCH_TYPE])) + } + else + { + // If clicked to no continue with the indexing progress (acp_search_index_inprogress form) + if ($this->request->is_set_post('cancel')) { - $state[self::STATE_SEARCH_TYPE] = $request->variable('search_type', ''); + $state = []; + $this->save_state($state); } - $search_backend_factory = $phpbb_container->get('search.backend_factory'); - $search = $search_backend_factory->get($state[self::STATE_SEARCH_TYPE]); - - $name = $search->get_name(); - - $action = &$state[1]; - - $this->save_state($state); - - switch ($action) + if (!empty($state)) { - case 'delete': - try - { - $state[self::STATE_POST_COUNTER] = $state[self::STATE_POST_COUNTER] ?? 0; - if ($status = $search->delete_index($state[self::STATE_POST_COUNTER])) // Status is not null, so deleting is in progress.... - { - // save the current 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); - meta_refresh(1, $u_action); - trigger_error($user->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $status['row_count'], $status['post_counter']) . $user->lang('SEARCH_INDEX_DELETE_REDIRECT_RATE', $status['rows_per_second'])); - } - } - catch (Exception $e) - { - $state = []; - $this->save_state($state); - trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); - } - - $search->tidy(); - - $state = []; - $this->save_state($state); - - $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()); - break; - - case 'create': - try - { - $state[self::STATE_POST_COUNTER] = $state[self::STATE_POST_COUNTER] ?? 0; - if ($status = $search->create_index($state[self::STATE_POST_COUNTER])) // Status is not null, so indexing is in progress.... - { - // save the current 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); - meta_refresh(1, $u_action); - trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $status['row_count'], $status['post_counter']) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $status['rows_per_second'])); - } - } - catch (Exception $e) - { - // Error executing create_index - $state = []; - $this->save_state($state); - trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); - } - - // Indexing have finished - - $search->tidy(); - - $state = []; - $this->save_state($state); - - $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()); - break; + $this->index_inprogress($id, $mode, $state[self::STATE_ACTION]); + } + else + { + $this->index_overview($id, $mode); } - } - - $search_types = $phpbb_container->get('search.backend_collection'); - - foreach ($search_types as $search) - { - $type = get_class($search); - $name = $search->get_name(); - $data = $search->index_stats(); - - $template->assign_block_vars('backend', array( - 'L_NAME' => $name, - 'NAME' => $type, - - 'S_ACTIVE' => $type == $config['search_type'], - 'S_HIDDEN_FIELDS' => build_hidden_fields(array('search_type' => $type)), - 'S_INDEXED' => (bool) $search->index_created(), - 'S_STATS' => $data, - )); - } - - $this->tpl_name = 'acp_search_index'; - $this->page_title = 'ACP_SEARCH_INDEX'; - - $template->assign_vars(array( - 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), - 'U_PROGRESS_BAR' => 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($state[self::STATE_ACTION])) - { - $this->tpl_name = 'acp_search_index'; - $this->page_title = 'ACP_SEARCH_INDEX'; - - $template->assign_vars(array( - 'S_CONTINUE_INDEXING' => $state[1], - 'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $state[self::STATE_ACTION] . '&hash=' . generate_link_hash('acp_search'), - 'L_CONTINUE' => ($state[self::STATE_ACTION] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_DELETING_INDEX'], - 'L_CONTINUE_EXPLAIN' => ($state[self::STATE_ACTION] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_DELETING_INDEX_EXPLAIN']) - ); } } - function display_progress_bar($type) + /** + * @param string $id + * @param string $mode + * + * @throws Exception + */ + private function index_overview(string $id, string $mode): void { - global $template, $user; + $this->tpl_name = 'acp_search_index'; + $this->page_title = 'ACP_SEARCH_INDEX'; - $l_type = ($type == 'create') ? 'INDEXING_IN_PROGRESS' : 'DELETING_INDEX_IN_PROGRESS'; + foreach ($this->search_backend_collection as $search) + { + $this->template->assign_block_vars('backend', array( + 'L_NAME' => $search->get_name(), + 'NAME' => $search->get_type(), - adm_page_header($user->lang[$l_type]); + 'S_ACTIVE' => $search->get_type() === $this->config['search_type'], + 'S_HIDDEN_FIELDS' => build_hidden_fields(array('search_type' => $search->get_type())), + 'S_INDEXED' => $search->index_created(), + 'S_STATS' => $search->index_stats(), + )); + } - $template->set_filenames(array( + $this->template->assign_vars(array( + 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), + 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), + )); + } + + /** + * Form to continue or cancel indexing process + * + * @param string $id + * @param string $mode + * @param string $action Action in progress: 'create' or 'delete' + */ + private function index_inprogress(string $id, string $mode, string $action): void + { + $this->tpl_name = 'acp_search_inprogress'; + $this->page_title = 'ACP_SEARCH_INDEX'; + + $this->template->assign_vars(array( + 'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $action . '&hash=' . generate_link_hash('acp_search'), + 'L_CONTINUE' => ($action === 'create') ? $this->language->lang('CONTINUE_INDEXING') : $this->language->lang('CONTINUE_DELETING_INDEX'), + 'L_CONTINUE_EXPLAIN' => ($action === 'create') ? $this->language->lang('CONTINUE_INDEXING_EXPLAIN') : $this->language->lang('CONTINUE_DELETING_INDEX_EXPLAIN')) + ); + } + + private function index_action(string $id, string $mode, string $action, array $state): void + { + // For some this may be of help... + @ini_set('memory_limit', '128M'); + + if (!check_link_hash($this->request->variable('hash', ''), 'acp_search')) + { + trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Entering here for the first time + if (empty($state)) + { + if ($this->request->is_set_post('search_type', '')) { + $state = [ + self::STATE_SEARCH_TYPE => $this->request->variable('search_type', ''), + self::STATE_ACTION => $action, + self::STATE_POST_COUNTER => 0 + ]; + } + else + { + trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); + } + + $this->save_state($state); // Create new state in the database + } + + $type = $state[self::STATE_SEARCH_TYPE]; + $action = $state[self::STATE_ACTION]; + $post_counter = &$state[self::STATE_POST_COUNTER]; + + switch ($action) + { + case 'delete': + $search = $this->search_backend_factory->get($type); + + try + { + if ($status = $search->delete_index($post_counter)) // Status is not null, so deleting is in progress.... + { + $this->save_state($state); // update $post_counter in $state in the database + + $u_action = append_sid($this->phpbb_admin_path . "index." . $this->php_ex, "i=$id&mode=$mode&action=delete&hash=" . generate_link_hash('acp_search'), false); + meta_refresh(1, $u_action); + trigger_error($this->language->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $status['row_count'], $status['post_counter']) . $this->language->lang('SEARCH_INDEX_DELETE_REDIRECT_RATE', $status['rows_per_second'])); + } + } + catch (Exception $e) + { + $this->save_state([]); // Unexpected error, cancel action + trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); + } + + $search->tidy(); + + $this->save_state([]); // finished operation, cancel action + + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_REMOVED', false, array($search->get_name())); + trigger_error($this->language->lang('SEARCH_INDEX_REMOVED') . adm_back_link($this->u_action) . $this->close_popup_js()); + break; + + case 'create': + $search = $this->search_backend_factory->get($type); + + try + { + $search = $this->search_backend_factory->get($type); + + if ($status = $search->create_index($post_counter)) // Status is not null, so indexing is in progress.... + { + $this->save_state($state); // update $post_counter in $state in the database + + $u_action = append_sid($this->phpbb_admin_path . "index." . $this->php_ex, "i=$id&mode=$mode&action=create&hash=" . generate_link_hash('acp_search'), false); + meta_refresh(1, $u_action); + trigger_error($this->language->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $status['row_count'], $status['post_counter']) . $this->language->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $status['rows_per_second'])); + } + } + catch (Exception $e) + { + // Error executing create_index + $this->save_state([]); + trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); + } + + $search->tidy(); + + $this->save_state([]); // finished operation, cancel action + + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_CREATED', false, array($search->get_name())); + trigger_error($this->language->lang('SEARCH_INDEX_CREATED') . adm_back_link($this->u_action) . $this->close_popup_js()); + break; + } + } + + /** + * Popup window + */ + private function display_progress_bar(): void + { + $type = $this->request->variable('type', ''); + $l_type = ($type === 'create') ? 'INDEXING_IN_PROGRESS' : 'DELETING_INDEX_IN_PROGRESS'; + + adm_page_header($this->language->lang($l_type)); + + $this->template->set_filenames(array( 'body' => 'progress_bar.html') ); - $template->assign_vars(array( - 'L_PROGRESS' => $user->lang[$l_type], - 'L_PROGRESS_EXPLAIN' => $user->lang[$l_type . '_EXPLAIN']) - ); + $this->template->assign_vars(array( + 'L_PROGRESS' => $this->language->lang($l_type), + 'L_PROGRESS_EXPLAIN' => $this->language->lang($l_type . '_EXPLAIN'), + )); adm_page_footer(); } - function close_popup_js() + /** + * Javascript code for closing the waiting screen (is attached to the trigger_errors) + * + * @return string + */ + private function close_popup_js(): string { return "\n"; } - function save_state($state = false) + /** + * @param array $state + */ + private function save_state(array $state = []): void { - global $config; - ksort($state); - $config->set('search_indexing_state', implode(',', $state), true); + $this->config->set('search_indexing_state', implode(',', $state), true); } } diff --git a/phpBB/phpbb/search/backend/base.php b/phpBB/phpbb/search/backend/base.php index 0245c72c2a..a6bcb08850 100644 --- a/phpBB/phpbb/search/backend/base.php +++ b/phpBB/phpbb/search/backend/base.php @@ -480,4 +480,12 @@ abstract class base implements search_backend_interface return $max_post_id; } + + /** + * {@inheritdoc} + */ + public function get_type(): string + { + return static::class; + } } diff --git a/phpBB/phpbb/search/backend/fulltext_sphinx.php b/phpBB/phpbb/search/backend/fulltext_sphinx.php index cc6c0b8afe..1d7ff5f310 100644 --- a/phpBB/phpbb/search/backend/fulltext_sphinx.php +++ b/phpBB/phpbb/search/backend/fulltext_sphinx.php @@ -1022,4 +1022,12 @@ class fulltext_sphinx implements search_backend_interface return true; } + + /** + * {@inheritdoc} + */ + public function get_type(): string + { + return static::class; + } } diff --git a/phpBB/phpbb/search/backend/search_backend_interface.php b/phpBB/phpbb/search/backend/search_backend_interface.php index 1fdc138028..82ea0d03ff 100644 --- a/phpBB/phpbb/search/backend/search_backend_interface.php +++ b/phpBB/phpbb/search/backend/search_backend_interface.php @@ -193,4 +193,11 @@ interface search_backend_interface * @return array array containing template and config variables */ public function get_acp_options(): array; + + /** + * Gets backend class + * + * @return string + */ + public function get_type(): string; } diff --git a/phpBB/phpbb/storage/provider/local.php b/phpBB/phpbb/storage/provider/local.php index 8e0de2b6fd..93d3c7a6d0 100644 --- a/phpBB/phpbb/storage/provider/local.php +++ b/phpBB/phpbb/storage/provider/local.php @@ -26,7 +26,7 @@ class local implements provider_interface /** * {@inheritdoc} */ - public function get_adapter_class() + public function get_adapter_class(): string { return \phpbb\storage\adapter\local::class; } diff --git a/phpBB/phpbb/storage/provider/provider_interface.php b/phpBB/phpbb/storage/provider/provider_interface.php index 428b6eb187..484b660aa8 100644 --- a/phpBB/phpbb/storage/provider/provider_interface.php +++ b/phpBB/phpbb/storage/provider/provider_interface.php @@ -25,9 +25,9 @@ interface provider_interface /** * Gets adapter class * - * @return \phpbb\storage\adapter\adapter_interface + * @return string */ - public function get_adapter_class(); + public function get_adapter_class(): string; /** * Gets adapter options From 9b838115c6618917a82521dc9776023b8a2040a1 Mon Sep 17 00:00:00 2001 From: rubencm Date: Thu, 25 Mar 2021 03:54:29 +0100 Subject: [PATCH 07/12] [ticket/16737] Fix test PHPBB3-16737 --- phpBB/includes/acp/acp_search.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index a3a304bb62..b6832e6d1c 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -286,7 +286,7 @@ class acp_search $action = $this->request->variable('action', ''); $state = !empty($this->config['search_indexing_state']) ? explode(',', $this->config['search_indexing_state']) : []; - if($action) + if ($action) { switch ($action) { @@ -385,7 +385,8 @@ class acp_search // Entering here for the first time if (empty($state)) { - if ($this->request->is_set_post('search_type', '')) { + if ($this->request->is_set_post('search_type', '')) + { $state = [ self::STATE_SEARCH_TYPE => $this->request->variable('search_type', ''), self::STATE_ACTION => $action, From e84cef8dee5aaba7de55eff1572965e272cad41a Mon Sep 17 00:00:00 2001 From: rubencm Date: Thu, 25 Mar 2021 10:04:37 +0100 Subject: [PATCH 08/12] [ticket/16737] Improvements to in progress form PHPBB3-16737 --- .../style/acp_search_index_inprogress.html | 21 +++++++++++++++---- phpBB/includes/acp/acp_search.php | 14 +++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/phpBB/adm/style/acp_search_index_inprogress.html b/phpBB/adm/style/acp_search_index_inprogress.html index 0f2c2e6f77..fb84618c55 100644 --- a/phpBB/adm/style/acp_search_index_inprogress.html +++ b/phpBB/adm/style/acp_search_index_inprogress.html @@ -2,16 +2,29 @@ -

{L_ACP_SEARCH_INDEX}

+ + +

{L_CONTINUE}

-{# todo: check the l_continue that is send from acp_search here #}

{L_CONTINUE_EXPLAIN}

- +
{L_ACP_SUBMIT_CHANGES}

-   +  

{S_FORM_TOKEN} diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index b6832e6d1c..44fdd2fb2e 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -286,7 +286,7 @@ class acp_search $action = $this->request->variable('action', ''); $state = !empty($this->config['search_indexing_state']) ? explode(',', $this->config['search_indexing_state']) : []; - if ($action) + if ($action && !$this->request->is_set_post('cancel')) { switch ($action) { @@ -305,7 +305,7 @@ class acp_search } else { - // If clicked to no continue with the indexing progress (acp_search_index_inprogress form) + // If clicked to cancel the indexing progress (acp_search_index_inprogress form) if ($this->request->is_set_post('cancel')) { $state = []; @@ -362,14 +362,16 @@ class acp_search */ private function index_inprogress(string $id, string $mode, string $action): void { - $this->tpl_name = 'acp_search_inprogress'; + $this->tpl_name = 'acp_search_index_inprogress'; $this->page_title = 'ACP_SEARCH_INDEX'; $this->template->assign_vars(array( - 'U_CONTINUE_INDEXING' => $this->u_action . '&action=' . $action . '&hash=' . generate_link_hash('acp_search'), + 'U_ACTION' => $this->u_action . '&action=' . $action . '&hash=' . generate_link_hash('acp_search'), + 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), 'L_CONTINUE' => ($action === 'create') ? $this->language->lang('CONTINUE_INDEXING') : $this->language->lang('CONTINUE_DELETING_INDEX'), - 'L_CONTINUE_EXPLAIN' => ($action === 'create') ? $this->language->lang('CONTINUE_INDEXING_EXPLAIN') : $this->language->lang('CONTINUE_DELETING_INDEX_EXPLAIN')) - ); + 'L_CONTINUE_EXPLAIN' => ($action === 'create') ? $this->language->lang('CONTINUE_INDEXING_EXPLAIN') : $this->language->lang('CONTINUE_DELETING_INDEX_EXPLAIN'), + 'S_ACTION' => $action, + )); } private function index_action(string $id, string $mode, string $action, array $state): void From 4e1e7f03da96ffcadfae7da68986ffffb9bc50c2 Mon Sep 17 00:00:00 2001 From: rubencm Date: Thu, 25 Mar 2021 10:11:44 +0100 Subject: [PATCH 09/12] [ticket/16737] Use short array syntax PHPBB3-16737 --- phpBB/includes/acp/acp_search.php | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 44fdd2fb2e..a5ebd46f65 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -165,11 +165,11 @@ class acp_search if (!$submit) { - $this->template->assign_block_vars('backend', array( + $this->template->assign_block_vars('backend', [ 'NAME' => $name, 'SETTINGS' => $vars['tpl'], 'IDENTIFIER' => $identifier, - )); + ]); } else if (is_array($vars['config'])) { @@ -178,7 +178,7 @@ class acp_search } } - $cfg_array = (isset($_REQUEST['config'])) ? $this->request->variable('config', array('' => ''), true) : array(); + $cfg_array = (isset($_REQUEST['config'])) ? $this->request->variable('config', ['' => ''], true) : []; $updated = $this->request->variable('updated', false); foreach ($settings as $this->config_name => $var_type) @@ -243,13 +243,13 @@ class acp_search } else { - confirm_box(false, $this->language->lang('CONFIRM_SEARCH_BACKEND'), build_hidden_fields(array( + confirm_box(false, $this->language->lang('CONFIRM_SEARCH_BACKEND'), build_hidden_fields([ 'i' => $id, 'mode' => $mode, 'submit' => true, 'updated' => $updated, - 'config' => array('search_type' => $cfg_array['search_type']), - ))); + 'config' => ['search_type' => $cfg_array['search_type']], + ])); } } @@ -336,21 +336,21 @@ class acp_search foreach ($this->search_backend_collection as $search) { - $this->template->assign_block_vars('backend', array( + $this->template->assign_block_vars('backend', [ 'L_NAME' => $search->get_name(), 'NAME' => $search->get_type(), 'S_ACTIVE' => $search->get_type() === $this->config['search_type'], - 'S_HIDDEN_FIELDS' => build_hidden_fields(array('search_type' => $search->get_type())), + 'S_HIDDEN_FIELDS' => build_hidden_fields(['search_type' => $search->get_type()]), 'S_INDEXED' => $search->index_created(), 'S_STATS' => $search->index_stats(), - )); + ]); } - $this->template->assign_vars(array( + $this->template->assign_vars([ 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), - )); + ]); } /** @@ -365,13 +365,13 @@ class acp_search $this->tpl_name = 'acp_search_index_inprogress'; $this->page_title = 'ACP_SEARCH_INDEX'; - $this->template->assign_vars(array( + $this->template->assign_vars([ 'U_ACTION' => $this->u_action . '&action=' . $action . '&hash=' . generate_link_hash('acp_search'), 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), 'L_CONTINUE' => ($action === 'create') ? $this->language->lang('CONTINUE_INDEXING') : $this->language->lang('CONTINUE_DELETING_INDEX'), 'L_CONTINUE_EXPLAIN' => ($action === 'create') ? $this->language->lang('CONTINUE_INDEXING_EXPLAIN') : $this->language->lang('CONTINUE_DELETING_INDEX_EXPLAIN'), 'S_ACTION' => $action, - )); + ]); } private function index_action(string $id, string $mode, string $action, array $state): void @@ -433,7 +433,7 @@ class acp_search $this->save_state([]); // finished operation, cancel action - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_REMOVED', false, array($search->get_name())); + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_REMOVED', false, [$search->get_name()]); trigger_error($this->language->lang('SEARCH_INDEX_REMOVED') . adm_back_link($this->u_action) . $this->close_popup_js()); break; @@ -464,7 +464,7 @@ class acp_search $this->save_state([]); // finished operation, cancel action - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_CREATED', false, array($search->get_name())); + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_CREATED', false, [$search->get_name()]); trigger_error($this->language->lang('SEARCH_INDEX_CREATED') . adm_back_link($this->u_action) . $this->close_popup_js()); break; } @@ -480,14 +480,14 @@ class acp_search adm_page_header($this->language->lang($l_type)); - $this->template->set_filenames(array( - 'body' => 'progress_bar.html') - ); + $this->template->set_filenames([ + 'body' => 'progress_bar.html' + ]); - $this->template->assign_vars(array( + $this->template->assign_vars([ 'L_PROGRESS' => $this->language->lang($l_type), 'L_PROGRESS_EXPLAIN' => $this->language->lang($l_type . '_EXPLAIN'), - )); + ]); adm_page_footer(); } From e5d5c0e29f2f7c04e980aa820427f146e1b07a21 Mon Sep 17 00:00:00 2001 From: rubencm Date: Sat, 27 Mar 2021 20:37:06 +0100 Subject: [PATCH 10/12] [ticket/16737] Use twig syntax PHPBB3-16737 --- phpBB/adm/style/acp_search_index.html | 44 ++++----- .../style/acp_search_index_inprogress.html | 20 ++-- phpBB/adm/style/acp_search_settings.html | 66 ++++++------- phpBB/includes/acp/acp_search.php | 92 +++++++------------ 4 files changed, 98 insertions(+), 124 deletions(-) diff --git a/phpBB/adm/style/acp_search_index.html b/phpBB/adm/style/acp_search_index.html index 8ce882fa89..6a9b0c22db 100644 --- a/phpBB/adm/style/acp_search_index.html +++ b/phpBB/adm/style/acp_search_index.html @@ -1,4 +1,4 @@ - +{% include 'overall_header.html' %} @@ -11,36 +11,36 @@ { close_waitscreen = 0; // no scrollbars - popup('{UA_PROGRESS_BAR}&type=' + progress_type, 400, 240, '_index'); + popup('{{ UA_PROGRESS_BAR }}&type=' + progress_type, 400, 240, '_index'); } // ]]> -

{L_ACP_SEARCH_INDEX}

+

{{ lang('ACP_SEARCH_INDEX') }}

-

{L_ACP_SEARCH_INDEX_EXPLAIN}

+

{{ lang('ACP_SEARCH_INDEX_EXPLAIN') }}

- +{% for backend in loops.backend %} {% if backend.S_STATS is not empty %} - +
- {backend.S_HIDDEN_FIELDS} + {{ backend.S_HIDDEN_FIELDS }} - {L_INDEX_STATS}{L_COLON} {backend.L_NAME} ({L_ACTIVE}) + {{ lang('INDEX_STATS') }}{{ lang('COLON') }} {{ backend.NAME }} {% if backend.S_ACTIVE %}({{ lang('ACTIVE') }}) {% endif %} - + - - - - + + + + @@ -48,7 +48,7 @@ {% for key, value in stat %} {% if value is not empty %} - + {% else %} @@ -63,18 +63,18 @@ {% endif %}

- + {% if backend.S_INDEXED %} - - + + {% else %} - - + + {% endif %}

- {S_FORM_TOKEN} + {{ S_FORM_TOKEN }} - +{% endfor %} - +{% include 'overall_footer.html' %} diff --git a/phpBB/adm/style/acp_search_index_inprogress.html b/phpBB/adm/style/acp_search_index_inprogress.html index fb84618c55..3d9111192a 100644 --- a/phpBB/adm/style/acp_search_index_inprogress.html +++ b/phpBB/adm/style/acp_search_index_inprogress.html @@ -1,4 +1,4 @@ - +{% include 'overall_header.html' %} @@ -11,24 +11,24 @@ { close_waitscreen = 0; // no scrollbars - popup('{UA_PROGRESS_BAR}&type=' + progress_type, 400, 240, '_index'); + popup('{{ UA_PROGRESS_BAR }}&type=' + progress_type, 400, 240, '_index'); } // ]]> -

{L_CONTINUE}

+

{{ lang('CONTINUE') }}

-

{L_CONTINUE_EXPLAIN}

+

{{ lang('CONTINUE_EXPLAIN') }}

- +
- {L_ACP_SUBMIT_CHANGES} + {{ lang('ACP_SUBMIT_CHANGES') }}

-   - +   +

- {S_FORM_TOKEN} + {{ S_FORM_TOKEN }}
- +{% include 'overall_footer.html' %} diff --git a/phpBB/adm/style/acp_search_settings.html b/phpBB/adm/style/acp_search_settings.html index b468fd17ed..66f9838173 100644 --- a/phpBB/adm/style/acp_search_settings.html +++ b/phpBB/adm/style/acp_search_settings.html @@ -1,39 +1,39 @@ - +{% include 'overall_header.html' %} -

{L_ACP_SEARCH_SETTINGS}

+

{{ lang('ACP_SEARCH_SETTINGS') }}

-

{L_ACP_SEARCH_SETTINGS_EXPLAIN}

+

{{ lang('ACP_SEARCH_SETTINGS_EXPLAIN') }}

- +
- {L_GENERAL_SEARCH_SETTINGS} + {{ lang('GENERAL_SEARCH_SETTINGS') }}
-

{L_YES_SEARCH_EXPLAIN}
-
-
+

{{ lang('YES_SEARCH_EXPLAIN') }}
+
+
-

{L_SEARCH_INTERVAL_EXPLAIN}
-
{L_SECONDS}
+

{{ lang('SEARCH_INTERVAL_EXPLAIN') }}
+
{{ lang('SECONDS') }}
-

{L_SEARCH_GUEST_INTERVAL_EXPLAIN}
-
{L_SECONDS}
+

{{ lang('SEARCH_GUEST_INTERVAL_EXPLAIN') }}
+
{{ lang('SECONDS') }}
-

{L_LIMIT_SEARCH_LOAD_EXPLAIN}
-
+

{{ lang('LIMIT_SEARCH_LOAD_EXPLAIN') }}
+
-

{L_MIN_SEARCH_AUTHOR_CHARS_EXPLAIN}
-
+

{{ lang('MIN_SEARCH_AUTHOR_CHARS_EXPLAIN') }}
+
-

{L_MAX_NUM_SEARCH_KEYWORDS_EXPLAIN}
-
+

{{ lang('MAX_NUM_SEARCH_KEYWORDS_EXPLAIN') }}
+
@@ -43,36 +43,36 @@
-

{L_SEARCH_STORE_RESULTS_EXPLAIN}
-
{L_SECONDS}
+

{{ lang('SEARCH_STORE_RESULTS_EXPLAIN') }}
+
{{ lang('SECONDS') }}
- {L_SEARCH_TYPE} + {{ lang('SEARCH_TYPE') }}
-

{L_SEARCH_TYPE_EXPLAIN}
-
+

{{ lang('SEARCH_TYPE_EXPLAIN') }}
+
- +{% for backend in loops.backend %} -
- {backend.NAME} - {backend.SETTINGS} +
+ {{ backend.NAME }} + {{ backend.SETTINGS }}
- +{% endfor %}
- {L_ACP_SUBMIT_CHANGES} + {{ lang('ACP_SUBMIT_CHANGES') }}

-   - +   +

- {S_FORM_TOKEN} + {{ S_FORM_TOKEN }}
- +{% include 'overall_footer.html' %} diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index a5ebd46f65..e8a2e0971a 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -277,6 +277,8 @@ class acp_search } /** + * Execute action + * * @param string $id * @param string $mode * @throws Exception @@ -337,8 +339,8 @@ class acp_search foreach ($this->search_backend_collection as $search) { $this->template->assign_block_vars('backend', [ - 'L_NAME' => $search->get_name(), - 'NAME' => $search->get_type(), + 'NAME' => $search->get_name(), + 'TYPE' => $search->get_type(), 'S_ACTIVE' => $search->get_type() === $this->config['search_type'], 'S_HIDDEN_FIELDS' => build_hidden_fields(['search_type' => $search->get_type()]), @@ -407,67 +409,39 @@ class acp_search $action = $state[self::STATE_ACTION]; $post_counter = &$state[self::STATE_POST_COUNTER]; - switch ($action) + // Execute create/delete + $search = $this->search_backend_factory->get($type); + + try { - case 'delete': - $search = $this->search_backend_factory->get($type); + $status = ($action == 'create') ? $search->create_index($post_counter) : $search->delete_index($post_counter); + if ($status) // Status is not null, so action is in progress.... + { + $this->save_state($state); // update $post_counter in $state in the database - try - { - if ($status = $search->delete_index($post_counter)) // Status is not null, so deleting is in progress.... - { - $this->save_state($state); // update $post_counter in $state in the database + $u_action = append_sid($this->phpbb_admin_path . "index." . $this->php_ex, "i=$id&mode=$mode&action=$action&hash=" . generate_link_hash('acp_search'), false); + meta_refresh(1, $u_action); - $u_action = append_sid($this->phpbb_admin_path . "index." . $this->php_ex, "i=$id&mode=$mode&action=delete&hash=" . generate_link_hash('acp_search'), false); - meta_refresh(1, $u_action); - trigger_error($this->language->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $status['row_count'], $status['post_counter']) . $this->language->lang('SEARCH_INDEX_DELETE_REDIRECT_RATE', $status['rows_per_second'])); - } - } - catch (Exception $e) - { - $this->save_state([]); // Unexpected error, cancel action - trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); - } - - $search->tidy(); - - $this->save_state([]); // finished operation, cancel action - - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_REMOVED', false, [$search->get_name()]); - trigger_error($this->language->lang('SEARCH_INDEX_REMOVED') . adm_back_link($this->u_action) . $this->close_popup_js()); - break; - - case 'create': - $search = $this->search_backend_factory->get($type); - - try - { - $search = $this->search_backend_factory->get($type); - - if ($status = $search->create_index($post_counter)) // Status is not null, so indexing is in progress.... - { - $this->save_state($state); // update $post_counter in $state in the database - - $u_action = append_sid($this->phpbb_admin_path . "index." . $this->php_ex, "i=$id&mode=$mode&action=create&hash=" . generate_link_hash('acp_search'), false); - meta_refresh(1, $u_action); - trigger_error($this->language->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $status['row_count'], $status['post_counter']) . $this->language->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $status['rows_per_second'])); - } - } - catch (Exception $e) - { - // Error executing create_index - $this->save_state([]); - trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); - } - - $search->tidy(); - - $this->save_state([]); // finished operation, cancel action - - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SEARCH_INDEX_CREATED', false, [$search->get_name()]); - trigger_error($this->language->lang('SEARCH_INDEX_CREATED') . adm_back_link($this->u_action) . $this->close_popup_js()); - break; + $message_redirect = $this->language->lang(($action == 'create') ? 'SEARCH_INDEX_CREATE_REDIRECT' : 'SEARCH_INDEX_DELETE_REDIRECT', (int) $status['row_count'], $status['post_counter']); + $message_rate = $this->language->lang(($action == 'create') ? 'SEARCH_INDEX_CREATE_REDIRECT_RATE' : 'SEARCH_INDEX_DELETE_REDIRECT_RATE', $status['rows_per_second']); + trigger_error($message_redirect . $message_rate); + } } + catch (Exception $e) + { + $this->save_state([]); // Unexpected error, cancel action + trigger_error($e->getMessage() . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING); + } + + $search->tidy(); + + $this->save_state([]); // finished operation, cancel action + + $log_operation = ($action == 'create') ? 'LOG_SEARCH_INDEX_CREATED' : 'LOG_SEARCH_INDEX_REMOVED'; + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, $log_operation, false, [$search->get_name()]); + + $message = $this->language->lang(($action == 'create') ? 'SEARCH_INDEX_CREATED' : 'SEARCH_INDEX_REMOVED'); + trigger_error($message . adm_back_link($this->u_action) . $this->close_popup_js()); } /** From a168c0f545cc2d339aca5471c072cc4919b920a1 Mon Sep 17 00:00:00 2001 From: rubencm Date: Sat, 3 Apr 2021 21:48:10 +0200 Subject: [PATCH 11/12] [ticket/16737] Twig improvements, phpdoc and fix variable PHPBB3-16737 --- phpBB/adm/style/acp_search_index.html | 6 +-- phpBB/adm/style/acp_search_settings.html | 16 +++--- phpBB/includes/acp/acp_search.php | 68 +++++++++++------------- 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/phpBB/adm/style/acp_search_index.html b/phpBB/adm/style/acp_search_index.html index 6a9b0c22db..61ffb68d1d 100644 --- a/phpBB/adm/style/acp_search_index.html +++ b/phpBB/adm/style/acp_search_index.html @@ -20,7 +20,7 @@

{{ lang('ACP_SEARCH_INDEX_EXPLAIN') }}

-{% for backend in loops.backend %} +{% for backend in backends %} {% if backend.S_STATS is not empty %} @@ -30,7 +30,7 @@ {{ backend.S_HIDDEN_FIELDS }} - {{ lang('INDEX_STATS') }}{{ lang('COLON') }} {{ backend.NAME }} {% if backend.S_ACTIVE %}({{ lang('ACTIVE') }}) {% endif %} + {{ lang('INDEX_STATS') ~ lang('COLON') }} {{ backend.NAME }} {% if backend.S_ACTIVE %}({{ lang('ACTIVE') }}) {% endif %}
{backend.L_NAME} ({L_ACTIVE}) {{ backend.NAME }} {% if backend.S_ACTIVE %}({{ lang('ACTIVE') }}) {% endif %}
{L_STATISTIC}{L_VALUE}{L_STATISTIC}{L_VALUE}{{ lang('STATISTIC') }}{{ lang('VALUE') }}{{ lang('STATISTIC') }}{{ lang('VALUE') }}
{{ key }}{L_COLON}{{ key }}{{ lang('COLON') }} {{ value }}
@@ -48,7 +48,7 @@ {% for key, value in stat %} {% if value is not empty %} - + {% else %} diff --git a/phpBB/adm/style/acp_search_settings.html b/phpBB/adm/style/acp_search_settings.html index 66f9838173..fe899ec207 100644 --- a/phpBB/adm/style/acp_search_settings.html +++ b/phpBB/adm/style/acp_search_settings.html @@ -11,28 +11,28 @@
{{ lang('GENERAL_SEARCH_SETTINGS') }}
-

{{ lang('YES_SEARCH_EXPLAIN') }}
+

{{ lang('YES_SEARCH_EXPLAIN') }}
-

{{ lang('SEARCH_INTERVAL_EXPLAIN') }}
+

{{ lang('SEARCH_INTERVAL_EXPLAIN') }}
{{ lang('SECONDS') }}
-

{{ lang('SEARCH_GUEST_INTERVAL_EXPLAIN') }}
+

{{ lang('SEARCH_GUEST_INTERVAL_EXPLAIN') }}
{{ lang('SECONDS') }}
-

{{ lang('LIMIT_SEARCH_LOAD_EXPLAIN') }}
+

{{ lang('LIMIT_SEARCH_LOAD_EXPLAIN') }}
-

{{ lang('MIN_SEARCH_AUTHOR_CHARS_EXPLAIN') }}
+

{{ lang('MIN_SEARCH_AUTHOR_CHARS_EXPLAIN') }}
-

{{ lang('MAX_NUM_SEARCH_KEYWORDS_EXPLAIN') }}
+

{{ lang('MAX_NUM_SEARCH_KEYWORDS_EXPLAIN') }}
@@ -43,7 +43,7 @@
-

{{ lang('SEARCH_STORE_RESULTS_EXPLAIN') }}
+

{{ lang('SEARCH_STORE_RESULTS_EXPLAIN') }}
{{ lang('SECONDS') }}
@@ -51,7 +51,7 @@
{{ lang('SEARCH_TYPE') }}
-

{{ lang('SEARCH_TYPE_EXPLAIN') }}
+

{{ lang('SEARCH_TYPE_EXPLAIN') }}
diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index e8a2e0971a..111e33e2f3 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -39,54 +39,34 @@ class acp_search protected const STATE_ACTION = 1; protected const STATE_POST_COUNTER = 2; - /** - * @var config - */ + /** @var config */ protected $config; - /** - * @var language - */ + /** @var language */ protected $language; - /** - * @var log - */ + /** @var log */ protected $log; - /** - * @var request - */ + /** @var request */ protected $request; - /** - * @var service_collection - */ + /** @var service_collection */ protected $search_backend_collection; - /** - * @var search_backend_factory - */ + /** @var search_backend_factory */ protected $search_backend_factory; - /** - * @var template - */ + /** @var template */ protected $template; - /** - * @var user - */ + /** @var user */ protected $user; - /** - * @var string - */ + /** @var string */ protected $phpbb_admin_path; - /** - * @var string - */ + /** @var string */ protected $php_ex; public function __construct($p_master) @@ -127,6 +107,12 @@ class acp_search } } + /** + * Settings page + * + * @param string $id + * @param string $mode + */ public function settings(string $id, string $mode): void { $submit = $this->request->is_set_post('submit'); @@ -181,9 +167,9 @@ class acp_search $cfg_array = (isset($_REQUEST['config'])) ? $this->request->variable('config', ['' => ''], true) : []; $updated = $this->request->variable('updated', false); - foreach ($settings as $this->config_name => $var_type) + foreach ($settings as $config_name => $var_type) { - if (!isset($cfg_array[$this->config_name])) + if (!isset($cfg_array[$config_name])) { continue; } @@ -191,7 +177,7 @@ class acp_search // e.g. integer:4:12 (min 4, max 12) $var_type = explode(':', $var_type); - $this->config_value = $cfg_array[$this->config_name]; + $this->config_value = $cfg_array[$config_name]; settype($this->config_value, $var_type[0]); if (isset($var_type[1])) @@ -205,9 +191,9 @@ class acp_search } // only change config if anything was actually changed - if ($submit && ($this->config[$this->config_name] != $this->config_value)) + if ($submit && ($this->config[$config_name] != $this->config_value)) { - $this->config->set($this->config_name, $this->config_value); + $this->config->set($config_name, $this->config_value); $updated = true; } } @@ -277,7 +263,7 @@ class acp_search } /** - * Execute action + * Execute action depending on the action and state * * @param string $id * @param string $mode @@ -338,7 +324,7 @@ class acp_search foreach ($this->search_backend_collection as $search) { - $this->template->assign_block_vars('backend', [ + $this->template->assign_block_vars('backends', [ 'NAME' => $search->get_name(), 'TYPE' => $search->get_type(), @@ -376,6 +362,14 @@ class acp_search ]); } + /** + * Progress that do the indexing/index removal, updating the page continuously until is finished + * + * @param string $id + * @param string $mode + * @param string $action + * @param array $state + */ private function index_action(string $id, string $mode, string $action, array $state): void { // For some this may be of help... From fd7f957103e83d5b6d9b732d9c7d37e95672ee78 Mon Sep 17 00:00:00 2001 From: rubencm Date: Mon, 5 Apr 2021 23:24:00 +0200 Subject: [PATCH 12/12] [ticket/16737] Fix variable PHPBB3-16737 --- phpBB/includes/acp/acp_search.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 111e33e2f3..e2cbea4956 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -143,7 +143,7 @@ class acp_search $name = $search->get_name(); $type = $search->get_type(); - $selected = ($this->config['search_type'] == $type) ? ' selected="selected"' : ''; + $selected = ($this->config['search_type'] === $type) ? ' selected="selected"' : ''; $identifier = substr($type, strrpos($type, '\\') + 1); $search_options .= ""; @@ -177,23 +177,23 @@ class acp_search // e.g. integer:4:12 (min 4, max 12) $var_type = explode(':', $var_type); - $this->config_value = $cfg_array[$config_name]; - settype($this->config_value, $var_type[0]); + $config_value = $cfg_array[$config_name]; + settype($config_value, $var_type[0]); if (isset($var_type[1])) { - $this->config_value = max($var_type[1], $this->config_value); + $config_value = max($var_type[1], $config_value); } if (isset($var_type[2])) { - $this->config_value = min($var_type[2], $this->config_value); + $config_value = min($var_type[2], $config_value); } // only change config if anything was actually changed - if ($submit && ($this->config[$config_name] != $this->config_value)) + if ($submit && ($this->config[$config_name] !== $config_value)) { - $this->config->set($config_name, $this->config_value); + $this->config->set($config_name, $config_value); $updated = true; } } @@ -206,7 +206,7 @@ class acp_search $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CONFIG_SEARCH'); } - if (isset($cfg_array['search_type']) && ($cfg_array['search_type'] != $this->config['search_type'])) + if (isset($cfg_array['search_type']) && ($cfg_array['search_type'] !== $this->config['search_type'])) { $search = $this->search_backend_factory->get($cfg_array['search_type']); if (confirm_box(true)) @@ -220,7 +220,7 @@ class acp_search { $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_CONFIG_SEARCH'); } - $extra_message = '
' . $this->language->lang('SWITCHED_SEARCH_BACKEND') . '
php_ex, 'i=search&mode=index') . '">» ' . $this->language->lang('GO_TO_SEARCH_INDEX') . ''; + $extra_message = '
' . $this->language->lang('SWITCHED_SEARCH_BACKEND') . '
php_ex, 'i=search&mode=index') . '">» ' . $this->language->lang('GO_TO_SEARCH_INDEX') . ''; } else {
{{ backend.NAME }} {% if backend.S_ACTIVE %}({{ lang('ACTIVE') }}) {% endif %}
{{ key }}{{ lang('COLON') }}{{ key ~ lang('COLON') }} {{ value }}