/** * Detect whether the site is using HTTP Basic Auth, as that prevents the indexer from working * @since 2.3.4 * * @return bool */ function http_basic_auth() { $basic_auth = searchwp_get_setting('basic_auth'); // determine if the environment has already been verified; don't want redundant HTTP requests on every page load if ('no' === $basic_auth) { return; } // check to see if the credentials are already provided $http_basic_auth_creds = apply_filters('searchwp_basic_auth_creds', false); if (true == $basic_auth && is_array($http_basic_auth_creds) && isset($http_basic_auth_creds['username']) && isset($http_basic_auth_creds['password'])) { return; } $searchwp = SWP(); $response = $searchwp->get_indexer_communication_result(); if (!is_wp_error($response) && isset($response['response']['code']) && 401 === (int) $response['response']['code']) { searchwp_set_setting('basic_auth', true); ?> <div class="error" id="searchwp-http-basic-auth"> <p><?php echo sprintf(__('SearchWP has detected HTTP Basic Authentication, in order for the indexer to operate as expected you must provide credentials via the <a href="%s"><code>searchwp_basic_auth_creds</code></a> hook, or disable HTTP Basic Authentication.', 'searchwp'), 'https://searchwp.com/docs/hooks/searchwp_basic_auth_creds/'); ?> </p> </div> <?php } else { // flag the environment as 'good' if (!is_wp_error($response)) { searchwp_set_setting('basic_auth', 'no'); } } }
function implement_nag($args = array()) { $defaults = array('name' => 'nag', 'nonce' => ''); $args = wp_parse_args($args, $defaults); $searchwp = SWP(); if (empty($args['name'])) { return false; } if (empty($args['nonce'])) { $args['nonce'] = $args['name']; } $nag_name = sanitize_text_field($args['name']); $nonce_key = sanitize_text_field($args['nonce']); if (isset($_REQUEST[$nonce_key]) && wp_verify_nonce($_REQUEST[$nonce_key], $nag_name) && current_user_can($searchwp->settings_cap)) { // this key stores all the dismissed nags $dismissed = searchwp_get_setting('dismissed'); if (is_array($dismissed)) { if (isset($dismissed['nags']) && is_array($dismissed['nags'])) { $dismissed['nags'][] = $nag_name; } else { $dismissed['nags'] = array($nag_name); } } else { $dismissed = array('nags' => array($nag_name)); } searchwp_set_setting('dismissed', $dismissed); } $nags = searchwp_get_setting('nags', 'dismissed'); $nag_dismissed = is_array($nags) && in_array($nag_name, $nags); $dismissal_link = add_query_arg(array('page' => 'searchwp', $nonce_key => wp_create_nonce($nag_name))); return array('name' => $nag_name, 'nonce' => $nonce_key, 'dismissed' => $nag_dismissed, 'dismissal_link' => $dismissal_link); }
function wakeUpIndexer() { $running = searchwp_get_setting('running'); if ($running) { echo 'Indexer thought it was running. '; searchwp_set_setting('running', false); searchwp_set_setting('total', null, 'stats'); searchwp_set_setting('remaining', null, 'stats'); searchwp_set_setting('done', null, 'stats'); searchwp_set_setting('last_activity', null, 'stats'); } $this->triggerIndex(); echo 'Woken up.'; }
/** * Upgrade routines * * @since 1.0 */ private function upgrade() { global $wpdb, $searchwp; if (version_compare($this->last_version, '1.3.1', '<')) { // clean up misuse of cron schedule wp_clear_scheduled_hook('swp_cron_indexer'); } if (version_compare($this->last_version, '1.6.7', '<')) { // truncate logs table $prefix = $wpdb->prefix . SEARCHWP_DBPREFIX; $tableName = $prefix . 'log'; $wpdb->query("TRUNCATE TABLE {$tableName}"); } if (version_compare($this->last_version, '1.8', '<')) { // fix a possible issue with settings storage resulting in MySQL errors after update $settings = get_option(SEARCHWP_PREFIX . 'settings'); if (is_array($settings)) { // make sure additional array keys are present and defined foreach ($settings['engines'] as $engine_key => $engine_setting) { foreach ($settings['engines'][$engine_key] as $post_type => $post_type_settings) { if (is_array($settings['engines'][$engine_key][$post_type]) && isset($settings['engines'][$engine_key][$post_type]['options']) && !is_array($settings['engines'][$engine_key][$post_type]['options'])) { $settings['engines'][$engine_key][$post_type]['options'] = array('exclude' => false, 'attribute_to' => false, 'stem' => false); } } } } searchwp_update_option('settings', $settings); } // index cleanup and optimization if (version_compare($this->last_version, '1.9', '<')) { $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX termindex;"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX stemindex;"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'id'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX id;"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_index` WHERE Key_name = 'id'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_index DROP INDEX id;"); } $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));"); $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(stem(2));"); } // consolidate settings into one database record if (version_compare($this->last_version, '1.9.1', '<')) { $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N); if (empty($index_exists)) { $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N); if (empty($index_exists)) { $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(term(2));"); } $old_settings = searchwp_get_option('settings'); $engines = isset($old_settings['engines']) ? $old_settings['engines'] : array(); // clear out the old settings because we're using the same key searchwp_delete_option('settings'); // in with the new searchwp_generate_settings($engines); // delete the old options searchwp_delete_option('activated'); searchwp_delete_option('license_nag'); searchwp_delete_option('dismissed'); searchwp_delete_option('ignored_queries'); searchwp_delete_option('indexer_nag'); searchwp_delete_option('valid_db_environment'); searchwp_delete_option('running'); searchwp_delete_option('total'); searchwp_delete_option('remaining'); searchwp_delete_option('done'); searchwp_delete_option('in_process'); searchwp_delete_option('initial'); searchwp_delete_option('initial_notified'); searchwp_delete_option('purgeQueue'); searchwp_delete_option('processingPurgeQueue'); searchwp_delete_option('mysql_version_nag'); searchwp_delete_option('remote'); searchwp_delete_option('remote_meta'); searchwp_delete_option('paused'); searchwp_delete_option('nuke_on_delete'); searchwp_delete_option('indexnonce'); } if (version_compare($this->last_version, '1.9.2.2', '<')) { searchwp_add_option('progress', -1); } if (version_compare($this->last_version, '1.9.4', '<')) { // clean up a potential useless settings save $live_settings = searchwp_get_option('settings'); $update_settings_record = false; if (is_array($live_settings)) { foreach ($live_settings as $live_setting_key => $live_setting_value) { // none of our keys should be numeric (specifically going after a rogue 'running' setting that // may have been inadvertently set in 1.9.2, we just don't want it in there at all if (is_numeric($live_setting_key)) { unset($live_settings[$live_setting_key]); $update_settings_record = true; } // also update 'nuke_on_delete' to be a boolean if necessary if ('nuke_on_delete' === $live_setting_key) { $live_settings['nuke_on_delete'] = empty($live_setting_value) ? false : true; $update_settings_record = true; } } } if ($update_settings_record) { // save the cleaned up settings array searchwp_update_option('settings', $live_settings); $searchwp->settings = $live_settings; } } if (version_compare($this->last_version, '1.9.5', '<')) { // move indexer-specific settings to their own record as they're being constantly updated $live_settings = searchwp_get_option('settings'); $indexer_settings = array(); // whether the initial index has been built if (isset($live_settings['initial_index_built'])) { $indexer_settings['initial_index_built'] = (bool) $live_settings['initial_index_built']; unset($live_settings['initial_index_built']); } else { $indexer_settings['initial_index_built'] = false; } // all of the stats if (isset($live_settings['stats'])) { $indexer_settings['stats'] = $live_settings['stats']; unset($live_settings['stats']); } else { $indexer_settings['stats'] = array(); } // whether the indexer is running if (isset($live_settings['running'])) { $indexer_settings['running'] = (bool) $live_settings['running']; unset($live_settings['running']); } else { $indexer_settings['running'] = false; } // whether the indexer is paused (disabled) if (isset($live_settings['paused'])) { $indexer_settings['paused'] = (bool) $live_settings['paused']; unset($live_settings['paused']); } else { $indexer_settings['paused'] = false; } // whether the indexer is processing the purge queue if (isset($live_settings['processing_purge_queue'])) { $indexer_settings['processing_purge_queue'] = (bool) $live_settings['processing_purge_queue']; unset($live_settings['processing_purge_queue']); } else { $indexer_settings['processing_purge_queue'] = false; } // the purge queue will be moved to it's own option to avoid conflict if (isset($live_settings['purge_queue'])) { searchwp_add_option('purge_queue', $live_settings['purge_queue']); unset($live_settings['purge_queue']); } searchwp_update_option('settings', $live_settings); searchwp_add_option('indexer', $indexer_settings); } if (version_compare($this->last_version, '1.9.6', '<')) { // wake up the indexer if necessary $running = searchwp_get_setting('running'); if (empty($running)) { searchwp_set_setting('running', false); } } // make ignored queries for search stats per-user if (version_compare($this->last_version, '2.0.2', '<')) { $user_id = get_current_user_id(); if ($user_id) { $ignored_queries = searchwp_get_setting('ignored_queries'); update_user_meta($user_id, SEARCHWP_PREFIX . 'ignored_queries', $ignored_queries); } } // add 'busy' option if (version_compare($this->last_version, '2.1.5', '<')) { searchwp_add_option('busy', false); searchwp_add_option('doing_delta', false); } // force a wakeup if (version_compare($this->last_version, '2.2.1', '<')) { if (function_exists('searchwp_wake_up_indexer')) { searchwp_wake_up_indexer(); } } // add new 'waiting' flag, prep for possible new custom endpoint, clear out redundant post meta if (version_compare($this->last_version, '2.3', '<')) { searchwp_add_option('waiting', false); searchwp_set_setting('endpoint', ''); // now using last_index instead of indexed, we don't need separate records $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => '_' . SEARCHWP_PREFIX . 'indexed')); } if (version_compare($this->last_version, '2.4.5', '<')) { // implement our settings backup $live_settings = searchwp_get_option('settings'); $settings_backups = array(); $settings_backups[current_time('timestamp')] = $live_settings; searchwp_add_option('settings_backup', $settings_backups); // there was a bug triggered by a custom post type name of 'label' that caused issues // so we need to update all of the supplemental engine label keys to searchwp_engine_label // which will not trigger the issue because it is 21 characters in length and WordPress // requires post type names to be 20 characters or less if (isset($live_settings['engines'])) { foreach ($live_settings['engines'] as $live_settings_engine_key => $live_settings_engine_values) { if (isset($live_settings_engine_values['label'])) { $engine_label = $live_settings_engine_values['label']; unset($live_settings['engines'][$live_settings_engine_key]['label']); $live_settings['engines'][$live_settings_engine_key]['searchwp_engine_label'] = $engine_label; } } } searchwp_update_option('settings', $live_settings); } /** * The upgrade routine for 2.5.7 was designed to implement support for utf8mb4 as per WordPress 4.2, it even * used the same code to do so. Unfortunately the index key changes and charset changes can take a very (very) * long time depending on the power of the server and the size of the database tables. Unfortunately SearchWP's * tables are quite large, and the update routine took *way* too long on some test machines. While the update * was running, performance on the front end was erratic at best, primarily because the table updates caused * MySQL to utilize ~100% CPU, thus preventing other traffic from reaching the server. As a result, existing * installations of SearchWP will not be converted to utf8mb4, only fresh installations. The indexer and search * algorithm will actively strip out problematic characters (e.g. emoji) if the tables are not prepared for them. * if ( version_compare( $this->last_version, '2.5.7', '<' ) ) { require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); SWP()->indexer_pause(); // utf8mb4 index length limit is 191 @link https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ $wpdb->query( "ALTER TABLE {$wpdb->prefix}swp_cf DROP INDEX metakey, ADD INDEX metakey(metakey(191));" ); $wpdb->query( "ALTER TABLE {$wpdb->prefix}swp_log DROP INDEX queryindex, ADD INDEX queryindex(query(191));" ); $wpdb->query( "ALTER TABLE {$wpdb->prefix}swp_log DROP INDEX engineindex, ADD INDEX engineindex(engine(191));" ); // loop through tables and upgrade them to utf8mb4 $tables = array( $wpdb->prefix . 'swp_cf', $wpdb->prefix . 'swp_index', $wpdb->prefix . 'swp_log', $wpdb->prefix . 'swp_tax', $wpdb->prefix . 'swp_terms', ); $successful = true; foreach ( $tables as $table ) { // WordPress 4.2 added maybe_convert_table_to_utf8mb4() but // we don't necessarily have access to it (e.g. user is running <4.2) // but we also don't want to have to keep track of what WP version // is in play and have to continually compare that to whether this // upgrade routine has run so the function has been copied verbatim // for use here because utf8mb4 is fully backwards compatible so we're // going for the full upgrade by using a copy of that function $result = searchwp_maybe_convert_table_to_utf8mb4( $table ); if ( ( is_wp_error( $result ) || false === $result ) ) { // there was a problem $successful = false; } } if ( ! $successful ) { // there was a problem with the utf8mb4 upgrade but that doesn't necessarily // mean there is a show-stopping issue, just that the table is still utf8 // so log that the upgrade failed and indicate it in System Info searchwp_add_option( 'utf8mb4_upgrade_failed', true ); } SWP()->indexer_unpause(); } */ }
function searchwp_wake_up_indexer() { // reset all the flags used when indexing searchwp_set_setting('stats', array()); searchwp_set_setting('running', false); searchwp_update_option('busy', false); searchwp_update_option('doing_delta', false); }
/** * Callback for plugin activation, outputs admin notice * * @since 1.0 */ function activation() { if (false == searchwp_get_setting('activated')) { searchwp_set_setting('activated', 1); // reset the counts if (class_exists('SearchWPIndexer')) { $indexer = new SearchWPIndexer(); $indexer->update_running_counts(); } ?> <div class="updated"> <p><?php echo sprintf(__('SearchWP has been activated and the index is now being built. <a href="%s">View progress and settings</a>', 'searchwp'), esc_url(admin_url('options-general.php?page=searchwp'))); ?> </p> </div> <?php // trigger the initial indexing do_action('searchwp_log', 'Request index (activation)'); $this->trigger_index(); } }
/** * Checks the stored in-process post IDs and existing index to ensure a rogue parallel indexer is not running * * @since 1.9 */ function check_for_parallel_indexer() { global $wpdb; if (is_array($this->unindexedPosts) && count($this->unindexedPosts)) { // prevent parallel indexers $ids_to_index = array(); foreach ($this->unindexedPosts as $unindexed_post) { $ids_to_index[] = (int) $unindexed_post->ID; } reset($this->unindexedPosts); // check what's in process *right now* $in_process = searchwp_get_setting('in_process', 'stats'); if (is_array($in_process)) { $in_process = array_intersect($ids_to_index, $in_process); } // check the index too $ids_to_index_sql = implode(',', $ids_to_index); $index_table = $wpdb->prefix . SEARCHWP_DBPREFIX . 'index'; $ids_to_index_sql = "SELECT post_id FROM {$index_table} WHERE post_id IN ({$ids_to_index_sql}) GROUP BY post_id LIMIT 100"; $already_indexed = $wpdb->get_col($ids_to_index_sql); $already_indexed = array_map('absint', $already_indexed); // if it's in the index, force the indexed flag if (is_array($already_indexed) && !empty($already_indexed)) { foreach ($already_indexed as $already_indexed_key => $already_indexed_id) { do_action('searchwp_log', (int) $already_indexed_id . ' is already in the index'); // if we're not dealing with a term queue, mark this post as indexed if (!get_post_meta((int) $already_indexed_id, '_' . SEARCHWP_PREFIX . 'terms', true)) { update_post_meta((int) $already_indexed_id, '_' . SEARCHWP_PREFIX . 'indexed', true); } else { // this is a term chunk update, not a conflict unset($already_indexed[$already_indexed_key]); } } } // combine the two results so we have one collection of conflicts $conflicts = is_array($in_process) ? array_values(array_merge((array) $in_process, (array) $already_indexed)) : (array) $already_indexed; if (!empty($conflicts)) { do_action('searchwp_log', 'Parallel indexer detected when attempting to index: ' . implode(', ', $conflicts)); die; } searchwp_set_setting('in_process', $ids_to_index, 'stats'); } }
/** * Upgrade routines * * @since 1.0 */ private function upgrade() { global $wpdb, $searchwp; if (version_compare($this->last_version, '1.3.1', '<')) { // clean up misuse of cron schedule wp_clear_scheduled_hook('swp_cron_indexer'); } if (version_compare($this->last_version, '1.6.7', '<')) { // truncate logs table $prefix = $wpdb->prefix . SEARCHWP_DBPREFIX; $tableName = $prefix . 'log'; $wpdb->query("TRUNCATE TABLE {$tableName}"); } if (version_compare($this->last_version, '1.8', '<')) { // fix a possible issue with settings storage resulting in MySQL errors after update $settings = get_option(SEARCHWP_PREFIX . 'settings'); if (is_array($settings)) { // make sure additional array keys are present and defined foreach ($settings['engines'] as $engine_key => $engine_setting) { foreach ($settings['engines'][$engine_key] as $post_type => $post_type_settings) { if (is_array($settings['engines'][$engine_key][$post_type]) && !is_array($settings['engines'][$engine_key][$post_type]['options'])) { $settings['engines'][$engine_key][$post_type]['options'] = array('exclude' => false, 'attribute_to' => false, 'stem' => false); } } } } searchwp_update_option('settings', $settings); } // index cleanup and optimization if (version_compare($this->last_version, '1.9', '<')) { $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX termindex;"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX stemindex;"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'id'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_terms DROP INDEX id;"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_index` WHERE Key_name = 'id'", ARRAY_N); if (!empty($index_exists)) { $wpdb->query("ALTER TABLE {$wpdb->prefix}swp_index DROP INDEX id;"); } $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));"); $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(stem(2));"); } // consolidate settings into one database record if (version_compare($this->last_version, '1.9.1', '<')) { $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'termindex'", ARRAY_N); if (empty($index_exists)) { $wpdb->query("CREATE INDEX termindex ON {$wpdb->prefix}swp_terms(term(2));"); } $index_exists = $wpdb->get_results("SHOW INDEX FROM `{$wpdb->prefix}swp_terms` WHERE Key_name = 'stemindex'", ARRAY_N); if (empty($index_exists)) { $wpdb->query("CREATE INDEX stemindex ON {$wpdb->prefix}swp_terms(term(2));"); } $old_settings = searchwp_get_option('settings'); $engines = isset($old_settings['engines']) ? $old_settings['engines'] : array(); // clear out the old settings because we're using the same key searchwp_delete_option('settings'); // in with the new searchwp_generate_settings($engines); // delete the old options searchwp_delete_option('activated'); searchwp_delete_option('license_nag'); searchwp_delete_option('dismissed'); searchwp_delete_option('ignored_queries'); searchwp_delete_option('indexer_nag'); searchwp_delete_option('valid_db_environment'); searchwp_delete_option('running'); searchwp_delete_option('total'); searchwp_delete_option('remaining'); searchwp_delete_option('done'); searchwp_delete_option('in_process'); searchwp_delete_option('initial'); searchwp_delete_option('initial_notified'); searchwp_delete_option('purgeQueue'); searchwp_delete_option('processingPurgeQueue'); searchwp_delete_option('mysql_version_nag'); searchwp_delete_option('remote'); searchwp_delete_option('remote_meta'); searchwp_delete_option('paused'); searchwp_delete_option('nuke_on_delete'); searchwp_delete_option('indexnonce'); } if (version_compare($this->last_version, '1.9.2.2', '<')) { searchwp_add_option('progress', -1); } if (version_compare($this->last_version, '1.9.4', '<')) { // clean up a potential useless settings save $live_settings = searchwp_get_option('settings'); $update_settings_record = false; if (is_array($live_settings)) { foreach ($live_settings as $live_setting_key => $live_setting_value) { // none of our keys should be numeric (specifically going after a rogue 'running' setting that // may have been inadvertently set in 1.9.2, we just don't want it in there at all if (is_numeric($live_setting_key)) { unset($live_settings[$live_setting_key]); $update_settings_record = true; } // also update 'nuke_on_delete' to be a boolean if necessary if ('nuke_on_delete' === $live_setting_key) { $live_settings['nuke_on_delete'] = empty($live_setting_value) ? false : true; $update_settings_record = true; } } } if ($update_settings_record) { // save the cleaned up settings array searchwp_update_option('settings', $live_settings); $searchwp->settings = $live_settings; } } if (version_compare($this->last_version, '1.9.5', '<')) { // move indexer-specific settings to their own record as they're being constantly updated $live_settings = searchwp_get_option('settings'); $indexer_settings = array(); // whether the initial index has been built if (isset($live_settings['initial_index_built'])) { $indexer_settings['initial_index_built'] = (bool) $live_settings['initial_index_built']; unset($live_settings['initial_index_built']); } else { $indexer_settings['initial_index_built'] = false; } // all of the stats if (isset($live_settings['stats'])) { $indexer_settings['stats'] = $live_settings['stats']; unset($live_settings['stats']); } else { $indexer_settings['stats'] = array(); } // whether the indexer is running if (isset($live_settings['running'])) { $indexer_settings['running'] = (bool) $live_settings['running']; unset($live_settings['running']); } else { $indexer_settings['running'] = false; } // whether the indexer is paused (disabled) if (isset($live_settings['paused'])) { $indexer_settings['paused'] = (bool) $live_settings['paused']; unset($live_settings['paused']); } else { $indexer_settings['paused'] = false; } // whether the indexer is processing the purge queue if (isset($live_settings['processing_purge_queue'])) { $indexer_settings['processing_purge_queue'] = (bool) $live_settings['processing_purge_queue']; unset($live_settings['processing_purge_queue']); } else { $indexer_settings['processing_purge_queue'] = false; } // the purge queue will be moved to it's own option to avoid conflict if (isset($live_settings['purge_queue'])) { searchwp_add_option('purge_queue', $live_settings['purge_queue']); unset($live_settings['purge_queue']); } searchwp_update_option('settings', $live_settings); searchwp_add_option('indexer', $indexer_settings); } if (version_compare($this->last_version, '1.9.6', '<')) { // wake up the indexer if necessary $running = searchwp_get_setting('running'); if (empty($running)) { searchwp_set_setting('running', false); } } // make ignored queries for search stats per-user if (version_compare($this->last_version, '2.0.2', '<')) { $user_id = get_current_user_id(); if ($user_id) { $ignored_queries = searchwp_get_setting('ignored_queries'); update_user_meta($user_id, SEARCHWP_PREFIX . 'ignored_queries', $ignored_queries); } } // add 'busy' option if (version_compare($this->last_version, '2.1.5', '<')) { searchwp_add_option('busy', false); searchwp_add_option('doing_delta', false); } // force a wakeup if (version_compare($this->last_version, '2.2.1', '<')) { if (function_exists('searchwp_wake_up_indexer')) { searchwp_wake_up_indexer(); } } }
/** * Callback if user chose to restore conflict notices */ function conflict_notices_reset() { if ( ! $this->is_valid_action_request( 'conflict_notices_reset' ) ) { return; } $existing_dismissals = searchwp_get_setting( 'dismissed' ); $existing_dismissals['filter_conflicts'] = array(); searchwp_set_setting( 'dismissed', $existing_dismissals ); }
/** * Main (engines) settings view */ function render_view_engine() { // output a notice for the initial index being built $notices = searchwp_get_setting('notices'); $initial_notified = is_array($notices) && in_array('initial', $notices) ? true : false; if (searchwp_get_setting('initial_index_built') && !$initial_notified) { ?> <div class="updated"> <p><?php _e('Initial index has been built, the progress bar will be hidden until it is needed again.', 'searchwp'); ?> </p> </div> <?php if (is_array($notices)) { $notices[] = 'initial'; } else { $notices = array('initial'); } searchwp_set_setting('notices', $notices); ?> <?php } include dirname(__FILE__) . '/view-settings-engines.php'; }