Line 53 | Line 53 |
---|
global $user, $template, $phpbb_log, $request; global $config, $phpbb_admin_path, $phpEx;
|
global $user, $template, $phpbb_log, $request; global $config, $phpbb_admin_path, $phpEx;
|
$submit = (isset($_POST['submit'])) ? true : false;
| $submit = $request->is_set_post('submit');
|
if ($submit && !check_link_hash($request->variable('hash', ''), 'acp_search')) {
| if ($submit && !check_link_hash($request->variable('hash', ''), 'acp_search')) {
|
Line 62 | Line 62 |
---|
$search_types = $this->get_search_types();
|
$search_types = $this->get_search_types();
|
$settings = array( 'search_interval' => 'float', 'search_anonymous_interval' => 'float', 'load_search' => 'bool', 'limit_search_load' => 'float', 'min_search_author_chars' => 'integer', 'max_num_search_keywords' => 'integer', 'search_store_results' => 'integer', );
| $settings = [ 'search_interval' => 'float', 'search_anonymous_interval' => 'float', 'load_search' => 'bool', 'limit_search_load' => 'float', 'min_search_author_chars' => 'integer', 'max_num_search_keywords' => 'integer', 'default_search_return_chars' => 'integer', 'search_store_results' => 'integer', ];
|
$search = null; $error = false;
| $search = null; $error = false;
|
Line 219 | Line 220 |
---|
$this->tpl_name = 'acp_search'; $this->page_title = 'ACP_SEARCH_SETTINGS';
|
$this->tpl_name = 'acp_search'; $this->page_title = 'ACP_SEARCH_SETTINGS';
|
$template->assign_vars(array( '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'],
| $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'],
|
'S_SEARCH_TYPES' => $search_options, 'S_YES_SEARCH' => (bool) $config['load_search'], 'S_SETTINGS' => true,
|
'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')) );
| 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), ]);
|
}
function index($id, $mode) {
|
}
function index($id, $mode) {
|
global $db, $user, $template, $phpbb_log, $request;
| global $db, $language, $user, $template, $phpbb_log, $request;
|
global $config, $phpbb_admin_path, $phpEx;
$action = $request->variable('action', ''); $this->state = explode(',', $config['search_indexing_state']);
|
global $config, $phpbb_admin_path, $phpEx;
$action = $request->variable('action', ''); $this->state = explode(',', $config['search_indexing_state']);
|
if (isset($_POST['cancel']))
| if ($request->is_set_post('cancel'))
|
{ $action = ''; $this->state = array(); $this->save_state(); }
|
{ $action = ''; $this->state = array(); $this->save_state(); }
|
$submit = $request->is_set_post('submit', false);
| $submit = $request->is_set_post('submit');
|
if (!check_link_hash($request->variable('hash', ''), 'acp_search') && in_array($action, array('create', 'delete'))) {
| if (!check_link_hash($request->variable('hash', ''), 'acp_search') && in_array($action, array('create', 'delete'))) {
|
Line 260 | Line 262 |
---|
{ switch ($action) {
|
{ switch ($action) {
|
case 'progress_bar': $type = $request->variable('type', ''); $this->display_progress_bar($type); break;
| |
case 'delete': $this->state[1] = 'delete'; break;
| case 'delete': $this->state[1] = 'delete'; break;
|
Line 309 | Line 306 |
---|
{ $this->state = array(''); $this->save_state();
|
{ $this->state = array(''); $this->save_state();
|
trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
| trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
|
}
|
}
|
| } else if ($submit) { meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search'))); $template->assign_vars([ 'S_INDEX_PROGRESS' => true, 'INDEXING_TITLE' => $language->lang('DELETING_INDEX_IN_PROGRESS'), 'INDEXING_EXPLAIN' => $language->lang('DELETING_INDEX_IN_PROGRESS_EXPLAIN'), 'INDEXING_PROGRESS_BAR' => $this->get_post_index_progress($post_counter), ]);
$this->tpl_name = 'acp_search'; $this->page_title = 'ACP_SEARCH_INDEX';
return;
|
} else { $starttime = microtime(true); $row_count = 0;
|
} else { $starttime = microtime(true); $row_count = 0;
|
while (still_on_time() && $post_counter <= $this->max_post_id)
| while (still_on_time() && $post_counter < $this->max_post_id)
|
{ $sql = 'SELECT post_id, poster_id, forum_id FROM ' . POSTS_TABLE . '
|
{ $sql = 'SELECT post_id, poster_id, forum_id FROM ' . POSTS_TABLE . '
|
WHERE post_id >= ' . (int) ($post_counter + 1) . ' AND post_id <= ' . (int) ($post_counter + $this->batch_size); $result = $db->sql_query($sql);
| WHERE post_id > ' . (int) $post_counter . ' ORDER BY post_id ASC'; $result = $db->sql_query_limit($sql, $this->batch_size);
|
$ids = $posters = $forum_ids = array(); while ($row = $db->sql_fetchrow($result))
| $ids = $posters = $forum_ids = array(); while ($row = $db->sql_fetchrow($result))
|
Line 337 | Line 349 |
---|
if (count($ids)) { $this->search->index_remove($ids, $posters, $forum_ids);
|
if (count($ids)) { $this->search->index_remove($ids, $posters, $forum_ids);
|
| $post_counter = $ids[count($ids) - 1];
|
}
|
}
|
$post_counter += $this->batch_size;
| |
} // save the current state $this->save_state();
|
} // save the current state $this->save_state();
|
if ($post_counter <= $this->max_post_id)
| if ($post_counter < $this->max_post_id)
|
{ $totaltime = microtime(true) - $starttime; $rows_per_second = $row_count / $totaltime; meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
|
{ $totaltime = microtime(true) - $starttime; $rows_per_second = $row_count / $totaltime; meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
|
trigger_error($user->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_DELETE_REDIRECT_RATE', $rows_per_second));
| $template->assign_vars([ 'S_INDEX_PROGRESS' => true, 'INDEXING_TITLE' => $language->lang('DELETING_INDEX_IN_PROGRESS'), 'INDEXING_EXPLAIN' => $language->lang('DELETING_INDEX_IN_PROGRESS_EXPLAIN'), 'INDEXING_PROGRESS' => $language->lang('SEARCH_INDEX_DELETE_REDIRECT', $row_count, $post_counter), 'INDEXING_RATE' => $language->lang('SEARCH_INDEX_DELETE_REDIRECT_RATE', $rows_per_second), 'INDEXING_PROGRESS_BAR' => $this->get_post_index_progress($post_counter), ]);
$this->tpl_name = 'acp_search'; $this->page_title = 'ACP_SEARCH_INDEX';
return;
|
} }
| } }
|
Line 359 | Line 383 |
---|
$this->save_state();
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_SEARCH_INDEX_REMOVED', false, array($name));
|
$this->save_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());
| trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action));
|
break;
case 'create':
| break;
case 'create':
|
Line 370 | Line 394 |
---|
{ $this->state = array(''); $this->save_state();
|
{ $this->state = array(''); $this->save_state();
|
trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
| trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
|
}
|
}
|
| } else if ($submit) { meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
$template->assign_vars([ 'S_INDEX_PROGRESS' => true, 'INDEXING_TITLE' => $language->lang('INDEXING_IN_PROGRESS'), 'INDEXING_EXPLAIN' => $language->lang('INDEXING_IN_PROGRESS_EXPLAIN'), 'INDEXING_PROGRESS_BAR' => $this->get_post_index_progress($post_counter), ]);
$this->tpl_name = 'acp_search'; $this->page_title = 'ACP_SEARCH_INDEX';
return;
|
} else {
| } else {
|
Line 387 | Line 427 |
---|
$starttime = microtime(true); $row_count = 0;
|
$starttime = microtime(true); $row_count = 0;
|
while (still_on_time() && $post_counter <= $this->max_post_id)
| while (still_on_time() && $post_counter < $this->max_post_id)
|
{ $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id FROM ' . POSTS_TABLE . '
|
{ $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id FROM ' . POSTS_TABLE . '
|
WHERE post_id >= ' . (int) ($post_counter + 1) . ' AND post_id <= ' . (int) ($post_counter + $this->batch_size); $result = $db->sql_query($sql);
| WHERE post_id > ' . (int) $post_counter . ' ORDER BY post_id ASC'; $result = $db->sql_query_limit($sql, $this->batch_size);
|
$buffer = $db->sql_buffer_nested_transactions();
| $buffer = $db->sql_buffer_nested_transactions();
|
Line 414 | Line 454 |
---|
$this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']); } $row_count++;
|
$this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']); } $row_count++;
|
| $post_counter = $row['post_id'];
|
} if (!$buffer) { $db->sql_freeresult($result); }
|
} if (!$buffer) { $db->sql_freeresult($result); }
|
$post_counter += $this->batch_size;
| |
} // save the current state $this->save_state();
| } // save the current state $this->save_state();
|
Line 432 | Line 471 |
---|
$this->search->tidy(); $config['num_posts'] = $num_posts;
|
$this->search->tidy(); $config['num_posts'] = $num_posts;
|
if ($post_counter <= $this->max_post_id)
| if ($post_counter < $this->max_post_id)
|
{ $totaltime = microtime(true) - $starttime; $rows_per_second = $row_count / $totaltime; meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
|
{ $totaltime = microtime(true) - $starttime; $rows_per_second = $row_count / $totaltime; meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
|
trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second));
| $template->assign_vars([ 'S_INDEX_PROGRESS' => true, 'INDEXING_TITLE' => $language->lang('INDEXING_IN_PROGRESS'), 'INDEXING_EXPLAIN' => $language->lang('INDEXING_IN_PROGRESS_EXPLAIN'), 'INDEXING_PROGRESS' => $language->lang('SEARCH_INDEX_CREATE_REDIRECT', $row_count, $post_counter), 'INDEXING_RATE' => $language->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second), 'INDEXING_PROGRESS_BAR' => $this->get_post_index_progress($post_counter), ]);
$this->tpl_name = 'acp_search'; $this->page_title = 'ACP_SEARCH_INDEX';
return;
|
} }
| } }
|
Line 447 | Line 498 |
---|
$this->save_state();
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_SEARCH_INDEX_CREATED', false, array($name));
|
$this->save_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());
| trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action));
|
break; } }
| break; } }
|
Line 516 | Line 567 |
---|
$template->assign_vars(array( 'S_INDEX' => true, 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'),
|
$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")),
| |
));
if (isset($this->state[1]))
| ));
if (isset($this->state[1]))
|
Line 525 | Line 574 |
---|
$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'),
|
$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']) );
| 'CONTINUE_PROGRESS' => (isset($this->state[2]) && $this->state[2] > 0) ? $this->get_post_index_progress($this->state[2]) : $this->get_post_index_progress(0) ));
|
}
|
}
|
}
function display_progress_bar($type) { global $template, $user;
$l_type = ($type == 'create') ? 'INDEXING_IN_PROGRESS' : 'DELETING_INDEX_IN_PROGRESS';
adm_page_header($user->lang[$l_type]);
$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']) );
adm_page_footer(); }
function close_popup_js() { return "<script type=\"text/javascript\">\n" . "// <![CDATA[\n" . " close_waitscreen = 1;\n" . "// ]]>\n" . "</script>\n";
| |
}
function get_search_types()
| }
function get_search_types()
|
Line 584 | Line 603 |
---|
$db->sql_freeresult($result);
return $max_post_id;
|
$db->sql_freeresult($result);
return $max_post_id;
|
| }
/** * Get progress stats of search index with HTML progress bar. * * @param int $post_counter Post ID of last post indexed. * @return array Returns array with progress bar data. */ function get_post_index_progress(int $post_counter) { global $db, $language;
$sql = 'SELECT COUNT(post_id) as done_count FROM ' . POSTS_TABLE . ' WHERE post_id <= ' . (int) $post_counter; $result = $db->sql_query($sql); $done_count = (int) $db->sql_fetchfield('done_count'); $db->sql_freeresult($result);
$sql = 'SELECT COUNT(post_id) as remain_count FROM ' . POSTS_TABLE . ' WHERE post_id > ' . (int) $post_counter; $result = $db->sql_query($sql); $remain_count = (int) $db->sql_fetchfield('remain_count'); $db->sql_freeresult($result);
$total_count = $done_count + $remain_count; $percent = ($done_count / $total_count) * 100;
return [ 'VALUE' => $done_count, 'TOTAL' => $total_count, 'PERCENTAGE' => $percent, 'REMAINING' => $remain_count, ];
|
}
function save_state($state = false)
| }
function save_state($state = false)
|