/** * Create a custom search index for the messages table. * * What it does: * - Called by ?action=admin;area=managesearch;sa=createmsgindex. * - Linked from the action_edit screen. * - Requires the admin_forum permission. * - Depending on the size of the message table, the process is divided in steps. * * @uses ManageSearch template, 'create_index', 'create_index_progress', and 'create_index_done' * sub-templates. */ public function action_create() { global $modSettings, $context, $txt, $db_show_debug; // Scotty, we need more time... @set_time_limit(600); if (function_exists('apache_reset_timeout')) { @apache_reset_timeout(); } $context[$context['admin_menu_name']]['current_subsection'] = 'method'; $context['page_title'] = $txt['search_index_custom']; $messages_per_batch = 50; $index_properties = array(2 => array('column_definition' => 'small', 'step_size' => 1000000), 4 => array('column_definition' => 'medium', 'step_size' => 1000000, 'max_size' => 16777215), 5 => array('column_definition' => 'large', 'step_size' => 100000000, 'max_size' => 2000000000)); // Resume building an index that was not completed if (isset($_REQUEST['resume']) && !empty($modSettings['search_custom_index_resume'])) { $context['index_settings'] = unserialize($modSettings['search_custom_index_resume']); $context['start'] = (int) $context['index_settings']['resume_at']; unset($context['index_settings']['resume_at']); $context['step'] = 1; } else { $context['index_settings'] = array('bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2); $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0; $context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; // Admin timeouts are painful when building these long indexes if ($_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) { $_SESSION['admin_time'] = time(); } } if ($context['step'] !== 0) { checkSession('request'); } // Step 0: let the user determine how they like their index. if ($context['step'] === 0) { $context['sub_template'] = 'create_index'; } require_once SUBSDIR . '/ManageSearch.subs.php'; // Logging may cause session issues with many queries $old_db_show_debug = $db_show_debug; $db_show_debug = false; // Step 1: insert all the words. if ($context['step'] === 1) { $context['sub_template'] = 'create_index_progress'; list($context['start'], $context['step'], $context['percentage']) = createSearchIndex($context['start'], $messages_per_batch, $index_properties[$context['index_settings']['bytes_per_word']]['column_definition'], $context['index_settings']); } elseif ($context['step'] === 2) { if ($context['index_settings']['bytes_per_word'] < 4) { $context['step'] = 3; } else { list($context['start'], $complete) = removeCommonWordsFromIndex($context['start'], $index_properties[$context['index_settings']['bytes_per_word']]); if ($complete) { $context['step'] = 3; } $context['sub_template'] = 'create_index_progress'; $context['percentage'] = 80 + round($context['start'] / $index_properties[$context['index_settings']['bytes_per_word']]['max_size'], 3) * 20; } } // Restore previous debug state $db_show_debug = $old_db_show_debug; // Step 3: everything done. if ($context['step'] === 3) { $context['sub_template'] = 'create_index_done'; updateSettings(array('search_index' => 'custom', 'search_custom_index_config' => serialize($context['index_settings']))); removeSettings('search_custom_index_resume'); } }
/** * Remove an integration hook function. * * What it does: * - Removes the given function from the given hook. * - Does nothing if the function is not available. * * @param string $hook * @param string $function * @param string $file */ function remove_integration_function($hook, $function, $file = '') { global $modSettings; $db = database(); $integration_call = !empty($file) && $file !== true ? $function . '|' . $file : $function; // Get the permanent functions. $request = $db->query('', ' SELECT value FROM {db_prefix}settings WHERE variable = {string:variable}', array('variable' => $hook)); list($current_functions) = $db->fetch_row($request); $db->free_result($request); // If we found entries for this hook if (!empty($current_functions)) { $current_functions = explode(',', $current_functions); if (in_array($integration_call, $current_functions)) { updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); if (empty($modSettings[$hook])) { removeSettings($hook); } } } // Turn the function list into something usable. $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); // You can only remove it if it's available. if (!in_array($integration_call, $functions)) { return; } $functions = array_diff($functions, array($integration_call)); $modSettings[$hook] = implode(',', $functions); }