/**
  * Completely truncates all index tables, removes all index-related options
  *
  * @since 1.0
  */
 function purge_index()
 {
     global $wpdb;
     do_action('searchwp_log', 'purge_index()');
     $prefix = $wpdb->prefix . SEARCHWP_DBPREFIX;
     foreach ($this->tables as $table) {
         if ('log' !== $table['table']) {
             $tableName = $wpdb->prepare('%s', $prefix . $table['table']);
             if ("'" == substr($tableName, 0, 1) && "'" == substr($tableName, strlen($tableName) - 1)) {
                 $tableName = '`' . substr($tableName, 1, strlen($tableName) - 2) . '`';
             }
             $wpdb->query("TRUNCATE TABLE {$tableName}");
         }
     }
     // remove all metadata flags
     $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => '_' . SEARCHWP_PREFIX . 'last_index'));
     $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => '_' . SEARCHWP_PREFIX . 'attempts'));
     $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => '_' . SEARCHWP_PREFIX . 'skip'));
     $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => '_' . SEARCHWP_PREFIX . 'skip_doc_processing'));
     $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => '_' . SEARCHWP_PREFIX . 'review'));
     if (apply_filters('searchwp_purge_pdf_content', false)) {
         $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => SEARCHWP_PREFIX . 'content'));
     }
     $wpdb->delete($wpdb->prefix . 'postmeta', array('meta_key' => SEARCHWP_PREFIX . 'pdf_metadata'));
     // kill all the options related to the index
     searchwp_wake_up_indexer();
     searchwp_set_setting('initial_index_built', false);
     searchwp_set_setting('notices', array());
     searchwp_set_setting('valid_db_environment', false);
     searchwp_delete_option('indexnonce');
     delete_option('searchwp_transient');
     delete_option('swppurge_transient');
     // reset the counts
     if (class_exists('SearchWPIndexer')) {
         $indexer = new SearchWPIndexer();
         $indexer->update_running_counts();
     }
 }
 /**
  * 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();
     }
     */
 }
Exemplo n.º 3
0
 /**
  * Checks to see if the indexer has stalled with posts left to index
  *
  * @since 1.0
  */
 function checkIfStalled()
 {
     // if the last activity was over three minutes ago, let's reset and notify of an issue
     //		(it shouldn't take 3 minutes to index a chunk of posts)
     $last_activity = searchwp_get_setting('last_activity', 'stats');
     if (!is_null($last_activity) && false !== $last_activity) {
         if (current_time('timestamp') > $last_activity + 180) {
             // stalled
             do_action('searchwp_log', '---------- Indexer has stalled, jumpstarting');
             searchwp_wake_up_indexer();
         }
     } else {
         // if the last activity was null, reset the 'running' flag and update the timestamp
         searchwp_set_setting('running', false);
         searchwp_set_setting('last_activity', current_time('timestamp'), 'stats');
         searchwp_update_option('busy', false);
     }
 }
 function searchwp_check_for_stalled_indexer($threshold = 180)
 {
     $last_activity = searchwp_get_setting('last_activity', 'stats');
     $running = searchwp_get_setting('running');
     $doing_delta = searchwp_get_option('doing_delta');
     $busy = searchwp_get_option('busy');
     if (!is_null($last_activity) && false !== $last_activity) {
         if (current_time('timestamp') > $last_activity + absint($threshold) && ($running || $doing_delta || $busy)) {
             // stalled
             do_action('searchwp_log', '---------- Indexer has stalled, jumpstarting');
             searchwp_wake_up_indexer();
         }
     } else {
         // prior to version 2.2.2 the last activity was set to false once indexing was done
         // so if that timestamp is false but there is still a purge queue, we're going to
         // wake up the indexer by force
         $purge_queue = searchwp_get_option('purge_queue');
         if (!empty($purge_queue)) {
             searchwp_wake_up_indexer();
         } else {
             if (current_time('timestamp') > $last_activity + absint($threshold) && ($running || $doing_delta || $busy)) {
                 // stalled
                 do_action('searchwp_log', '---------- Indexer has stalled [alt], jumpstarting');
                 searchwp_wake_up_indexer();
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * 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 for Wake Indexer action
	 */
	function indexer_wake() {
		if ( ! $this->is_valid_action_request( 'indexer_wake' ) ) {
			return;
		}

		do_action( 'searchwp_log', 'Waking up the indexer' );
		searchwp_wake_up_indexer();
		SWP()->trigger_index();
	}
Exemplo n.º 7
0
    /**
     * Output the markup for the advanced settings page
     *
     * @since 1.0
     */
    function advancedSettings()
    {
        // do we need to purge the index?
        $purged = false;
        if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'swpadvanced') && (isset($_REQUEST['action']) && wp_verify_nonce($_REQUEST['action'], 'swppurgeindex')) && current_user_can($this->settings_cap)) {
            do_action('searchwp_log', 'Passed nonce, purge index');
            $this->purgeIndex();
            $purged = true;
        }
        // do we need to reset the stats?
        $resetStats = false;
        if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'swpadvanced') && (isset($_REQUEST['action']) && wp_verify_nonce($_REQUEST['action'], 'swppurgestats')) && current_user_can($this->settings_cap)) {
            do_action('searchwp_log', 'Passed nonce, reset stats');
            $this->resetStats();
            $resetStats = true;
        }
        // do we need to wake up the indexer?
        $wokenUp = false;
        if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'swpadvanced') && (isset($_REQUEST['action']) && wp_verify_nonce($_REQUEST['action'], 'swpwakeindexer')) && current_user_can($this->settings_cap)) {
            do_action('searchwp_log', 'Waking up the indexer');
            $running = searchwp_get_setting('running');
            if ($running) {
                do_action('searchwp_log', 'Resetting indexer');
                searchwp_wake_up_indexer();
            } else {
                // it's not running but the busy or delta flag(s) might need to get reset
                searchwp_update_option('busy', false);
                searchwp_update_option('doing_delta', false);
            }
            $this->triggerIndex();
            $wokenUp = true;
        }
        // determine the remote debugging status
        $remoteDebug = searchwp_get_setting('remote');
        if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'swpadvanced') && (isset($_REQUEST['action']) && wp_verify_nonce($_REQUEST['action'], 'swpremote')) && current_user_can($this->settings_cap)) {
            if ($remoteDebug) {
                do_action('searchwp_log', 'Turned off remote debugging');
                searchwp_set_setting('remote', false);
                searchwp_set_setting('remote_meta', false);
                $remoteDebug = false;
            } else {
                do_action('searchwp_log', 'Turned on remote debugging');
                $remoteDebugKey = sha1(site_url() . current_time('timestamp'));
                searchwp_set_setting('remote', $remoteDebugKey);
                $remoteDebug = $remoteDebugKey;
                $this->updateRemoteMeta();
            }
        }
        // determine the nuke status
        $nuke_on_delete = searchwp_get_setting('nuke_on_delete');
        if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'swpadvanced') && (isset($_REQUEST['action']) && wp_verify_nonce($_REQUEST['action'], 'swpnuke')) && current_user_can($this->settings_cap)) {
            if ($nuke_on_delete) {
                searchwp_set_setting('nuke_on_delete', false);
                $nuke_on_delete = false;
            } else {
                searchwp_set_setting('nuke_on_delete', true);
                $nuke_on_delete = true;
            }
        }
        // do we need to restore our notices?
        $reset_conflict_nags = false;
        if (isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'swpadvanced') && (isset($_REQUEST['action']) && wp_verify_nonce($_REQUEST['action'], 'swpresetconflictnags')) && current_user_can($this->settings_cap)) {
            do_action('searchwp_log', 'Passed nonce, reset conflict nags');
            $existing_dismissals = searchwp_get_setting('dismissed');
            $existing_dismissals['filter_conflicts'] = array();
            searchwp_set_setting('dismissed', $existing_dismissals);
            $reset_conflict_nags = true;
        }
        $nonce = isset($_REQUEST['nonce']) ? $_REQUEST['nonce'] : '0';
        ?>
		<div class="wrap">

			<div id="icon-searchwp" class="icon32">
				<img src="<?php 
        echo trailingslashit($this->url);
        ?>
assets/images/searchwp@2x.png" alt="SearchWP" width="21" height="32" />
			</div>

			<h2><?php 
        echo $this->pluginName . ' ' . __('Advanced Settings');
        ?>
</h2>

			<?php 
        if ($purged) {
            ?>
				<div id="setting-error-settings_updated" class="updated">
					<p><?php 
            _e('Index purged. <strong>The index will not be rebuilt until you initiate a reindex</strong>.', 'searchwp');
            ?>
						<a href="options-general.php?page=searchwp"><?php 
            _e('Initiate reindex', 'searchwp');
            ?>
</a></p>
				</div>
			<?php 
        }
        ?>

			<?php 
        if ($resetStats) {
            ?>
				<div id="setting-error-settings_updated" class="updated">
					<p><strong><?php 
            _e('Search Stats have been reset', 'searchwp');
            ?>
</strong></p>
				</div>
			<?php 
        }
        ?>

			<?php 
        if ($wokenUp) {
            ?>
				<div id="setting-error-settings_updated" class="updated">
					<p><strong><?php 
            _e('Attempted to wake up the indexer.', 'searchwp');
            ?>
</strong>
						<a href="options-general.php?page=searchwp"><?php 
            _e('View indexer progress', 'searchwp');
            ?>
</a></p>
				</div>
			<?php 
        }
        ?>

			<?php 
        if ($remoteDebug) {
            ?>
				<div id="setting-error-settings_updated" class="updated">
					<p><?php 
            _e('Remote Debugging is <strong>enabled</strong> with key', 'searchwp');
            ?>
 <code><?php 
            echo $remoteDebug;
            ?>
</code></p>
				</div>
			<?php 
        }
        ?>

			<?php 
        if ($nuke_on_delete) {
            ?>
				<div id="setting-error-settings_updated" class="updated">
					<p><?php 
            _e('Nuke on Delete is <strong>enabled</strong>', 'searchwp');
            ?>
</p>
				</div>
			<?php 
        }
        ?>

			<?php 
        if ($reset_conflict_nags) {
            ?>
				<div id="setting-error-settings_updated" class="updated">
					<p><strong><?php 
            _e('Conflict notifications have been restored, they will be visible on the <a href="options-general.php?page=searchwp">settings screen</a>', 'searchwp');
            ?>
</strong></p>
				</div>
			<?php 
        }
        ?>

			<h3><?php 
        _e('Purge index', 'searchwp');
        ?>
</h3>
			<p style="padding-bottom:23px;">
				<?php 
        _e('If you would like to <strong>completely wipe out the index and start fresh</strong>, you can do so.', 'searchwp');
        ?>
				<span class="description"><?php 
        _e('Search statistics will be left as is', 'searchwp');
        ?>
</span>
				<a style="margin-left:13px;" class="button" id="swp-purge-index" href="options-general.php?page=searchwp&amp;nonce=<?php 
        echo $nonce;
        ?>
&amp;action=<?php 
        echo wp_create_nonce('swppurgeindex');
        ?>
"><?php 
        _e('Purge Index', 'searchwp');
        ?>
</a>
			</p>

			<h3><?php 
        _e('Reset search stats', 'searchwp');
        ?>
</h3>
			<p style="padding-bottom:23px;">
				<?php 
        _e('If you would like to <strong>completely reset your Search Stats</strong>, you can do so.', 'searchwp');
        ?>
				<span class="description"><?php 
        _e('Existing index will be left as is', 'searchwp');
        ?>
</span>
				<a style="margin-left:13px;" class="button" id="swp-reset-stats" href="options-general.php?page=searchwp&amp;nonce=<?php 
        echo $nonce;
        ?>
&amp;action=<?php 
        echo wp_create_nonce('swppurgestats');
        ?>
"><?php 
        _e('Reset Stats', 'searchwp');
        ?>
</a>
			</p>

			<h3><?php 
        _e('Restore conflict notifications', 'searchwp');
        ?>
</h3>
			<p style="padding-bottom:23px;">
				<?php 
        _e('If you would like to reset all conflict notifications, you can restore them all at once.', 'searchwp');
        ?>
				<a style="margin-left:13px;" class="button" id="swp-reset-conflict-nags" href="options-general.php?page=searchwp&amp;nonce=<?php 
        echo $nonce;
        ?>
&amp;action=<?php 
        echo wp_create_nonce('swpresetconflictnags');
        ?>
"><?php 
        _e('Restore Conflict Notices', 'searchwp');
        ?>
</a>
			</p>

			<h3><?php 
        _e('Disable Indexer', 'searchwp');
        ?>
</h3>
			<p style="padding-bottom:23px;">
				<?php 
        _e('Disable the indexer. It will pick up where it left off when re-enabled.', 'searchwp');
        ?>
				<a style="margin-left:13px;" class="button" id="swp-indexer-pause" href="options-general.php?page=searchwp&amp;nonce=<?php 
        echo $nonce;
        ?>
&amp;action=<?php 
        echo wp_create_nonce('swppauseindexer');
        ?>
"><?php 
        _e('Toggle Indexer', 'searchwp');
        ?>
</a>
			</p>

			<h3><?php 
        _e('Wake Up Indexer', 'searchwp');
        ?>
</h3>
			<p style="padding-bottom:23px;">
				<?php 
        _e('If you believe the indexer has stalled, you can try to wake it up.', 'searchwp');
        ?>
				<a style="margin-left:13px;" class="button" id="swp-indexer-wake" href="options-general.php?page=searchwp&amp;nonce=<?php 
        echo $nonce;
        ?>
&amp;action=<?php 
        echo wp_create_nonce('swpwakeindexer');
        ?>
"><?php 
        _e('Wake Up Indexer', 'searchwp');
        ?>
</a>
			</p>

			<h3><?php 
        _e('Remote Debugging', 'searchwp');
        ?>
 <span class="description"><?php 
        _e('REQUIRES that this install to be publicly accessible', 'searchwp');
        ?>
</span></h3>
			<p style="padding-bottom:23px;">
				<?php 
        _e('To better assist with support requests, SearchWP facilitates remote debugging.', 'searchwp');
        ?>
				<a style="margin-left:13px;" class="button" id="swp-toggle-remote" href="options-general.php?page=searchwp&amp;nonce=<?php 
        echo $nonce;
        ?>
&amp;action=<?php 
        echo wp_create_nonce('swpremote');
        ?>
"><?php 
        _e('Toggle Remote Debugging', 'searchwp');
        ?>
</a>
			</p>

			<h3><?php 
        _e('Nuke on Delete', 'searchwp');
        ?>
 <span class="description"><?php 
        _e('Completely remove all traces of SearchWP when deleted via WordPress admin', 'searchwp');
        ?>
</span></h3>
			<p style="padding-bottom:23px;">
				<?php 
        $nuke_message = __('SearchWP can completely remove all traces of itself when you choose to Delete it using the Plugin menu.', 'searchwp');
        $nuke_button = __('Enable Nuke on Delete', 'searchwp');
        if ($nuke_on_delete) {
            $nuke_message = __('SearchWP has been configured to completely remove all traces of itself when you choose to Delete it using the Plugin menu.', 'searchwp');
            $nuke_button = __('Disable Nuke on Delete', 'searchwp');
        }
        ?>
				<?php 
        echo $nuke_message;
        ?>
				<a style="margin-left:13px;" class="button" id="swp-toggle-nuke" href="options-general.php?page=searchwp&amp;nonce=<?php 
        echo $nonce;
        ?>
&amp;action=<?php 
        echo wp_create_nonce('swpnuke');
        ?>
"><?php 
        echo $nuke_button;
        ?>
</a>
			</p>

			<p style="padding-top:20px;">
				<a class="button-primary" href="options-general.php?page=searchwp"><?php 
        _e('Back to Settings', 'searchwp');
        ?>
</a>
			</p>
			<script type="text/javascript">
				jQuery(document).ready(function ($) {
					$('#swp-purge-index').click(function () {
						if (confirm('<?php 
        _e("Are you SURE you want to delete the entire SearchWP index?", 'searchwp');
        ?>
')) {
							return confirm('<?php 
        _e("Are you completely sure? THIS CAN NOT BE UNDONE!", 'searchwp');
        ?>
');
						}
						return false;
					});
					$('#swp-reset-stats').click(function () {
						if (confirm('<?php 
        _e("Are you SURE you want to completely reset your Search Stats?", 'searchwp');
        ?>
')) {
							return confirm('<?php 
        _e("Are you completely sure? THIS CAN NOT BE UNDONE!", 'searchwp');
        ?>
');
						}
						return false;
					});
				});
			</script>
		</div>
	<?php 
    }