/** * Grab instance of object. * @return SolrPower_Sync */ public static function get_instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * AJAX Callback * */ function options_load() { check_ajax_referer('solr_security', 'security'); $method = filter_input(INPUT_POST, 'method', FILTER_SANITIZE_STRING); if ($method === "load") { $type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING); $prev = filter_input(INPUT_POST, 'prev', FILTER_SANITIZE_STRING); if (isset($type)) { SolrPower_Sync::get_instance()->load_all_posts($prev, $type); die; } } die; }
/** * Setup for every test. */ function setUp() { parent::setUp(); // Delete the entire index. SolrPower_Sync::get_instance()->delete_all(); }
/** * Test to see if a two facets can be selected with the AND operator. * Should yield zero results. * @group 37 */ function test_multi_facet_and() { $this->__change_option('s4wp_default_operator', 'AND'); $this->__change_option('s4wp_facet_on_custom_fields', array('my_field')); $this->__change_option('s4wp_index_custom_fields', array('my_field')); $cat_id_one = wp_create_category('new_cat'); $cat_id_two = wp_create_category('smelly_cat'); $p_id = $this->__create_test_post(); update_post_meta($p_id, 'my_field', 'my_value'); wp_set_object_terms($p_id, $cat_id_one, 'category', true); $p_id_two = $this->__create_test_post(); wp_set_object_terms($p_id_two, $cat_id_two, 'category', true); SolrPower_Sync::get_instance()->load_all_posts(0, 'post', 100, false); $query = $this->__facet_query(array('facet' => array('my_field_str' => array('my_value'), 'categories' => array('smelly_cat^^')))); // This should return zero results because the result cannot contain both the custom field and the category. $this->assertEquals(0, $query->post_count); $this->assertEquals(0, $query->found_posts); wp_delete_category($cat_id_one); wp_delete_category($cat_id_two); }
/** * Tests to see if Solr indexes all posts. * @group 43 * @link https://github.com/pantheon-systems/solr-power/issues/43 */ function test_index_all_posts() { // Create 20 posts: $this->__create_multiple(20); // Delete index. SolrPower_Sync::get_instance()->delete_all(); // Index all posts: SolrPower_Sync::get_instance()->load_all_posts(0, 'post', 100, false); $search = $this->__run_test_query('post'); if (is_null($search)) { $this->assertTrue(false); } $search = $search->getData(); $search = $search['response']; // We should have 20 results. $this->assertEquals(absint($search['numFound']), 20); }
_e('All Indexed Pages Deleted!<br />' . esc_html($output), 'solr4wp'); ?> </strong></p></div> <?php } else { if (isset($_POST['s4wp_optimize']) and $_POST['s4wp_optimize']) { SolrPower_Api::get_instance()->optimize(); ?> <div id="message" class="updated fade"><p><strong><?php _e('Index Optimized!', 'solr4wp'); ?> </strong></p></div> <?php } else { if (isset($_POST['s4wp_init_blogs']) and $_POST['s4wp_init_blogs']) { SolrPower_Sync::get_instance()->copy_config_to_all_blogs(); } else { if (isset($_POST['s4wp_query']) && $_POST['solrQuery']) { $qry = filter_input(INPUT_POST, 'solrQuery', FILTER_SANITIZE_STRING); $offset = null; $count = null; $fq = null; $sortby = null; $order = null; $results = SolrPower_Api::get_instance()->query($qry, $offset, $count, $fq, $sortby, $order); if (isset($results)) { $plugin_s4wp_settings = solr_options(); $output_info = $plugin_s4wp_settings['s4wp_output_info']; $data = $results->getData(); $response = $data['response']; $header = $data['responseHeader'];
/** * Checks to see if any actions were taken on the settings page. */ function check_for_actions() { if (!isset($_POST['action']) || !current_user_can('manage_options')) { return; } $action = sanitize_text_field($_POST['action']); switch ($action) { case 'update': if (!$this->check_nonce('solr_update')) { return; } $this->save_options(); break; case 'ping': if (!$this->check_nonce('solr_ping')) { return; } if (SolrPower_Api::get_instance()->ping_server()) { $this->msg = __('Ping Success!', 'solr-for-wordpress-on-pantheon'); } else { $this->msg = __('Ping Failed!', 'solr-for-wordpress-on-pantheon'); } break; case 'init_blogs': if (!$this->check_nonce('solr_init_blogs')) { return; } SolrPower_Sync::get_instance()->copy_config_to_all_blogs(); $this->msg = __('Configuration has been copied to all blogs!', 'solr-for-wordpress-on-pantheon'); break; case 'optimize': if (!$this->check_nonce('solr_optimize')) { return; } SolrPower_Api::get_instance()->optimize(); $this->msg = __('Index Optimized!', 'solr-for-wordpress-on-pantheon'); break; case 'delete_all': if (!$this->check_nonce('solr_delete_all')) { return; } SolrPower_Sync::get_instance()->delete_all(); $this->msg = __('All Indexed Pages Deleted!', 'solr-for-wordpress-on-pantheon'); break; case 'repost_schema': if (!$this->check_nonce('solr_repost_schema')) { return; } SolrPower_Sync::get_instance()->delete_all(); $output = SolrPower_Api::get_instance()->submit_schema(); $this->msg = __('All Indexed Pages Deleted!<br />' . esc_html($output), 'solr-for-wordpress-on-pantheon'); break; case 'run_query': if (!$this->check_nonce('solr_run_query')) { return; } $this->run_query(); break; } }
} if (version_compare(PHP_VERSION, '5.4', '<')) { add_action('admin_notices', 'solr_power_PHP_admin_notice'); add_action('admin_init', 'solr_power__deactivate'); } elseif (false === getenv('PANTHEON_INDEX_HOST') || false === getenv('PANTHEON_INDEX_PORT')) { add_action('admin_notices', 'solr_power_env_variables_admin_notice'); add_action('admin_init', 'solr_power__deactivate'); } else { define('SOLR_POWER_PATH', untrailingslashit(plugin_dir_path(__FILE__))); define('SOLR_POWER_URL', plugin_dir_url(__FILE__)); require_once SOLR_POWER_PATH . '/vendor/autoload.php'; require_once SOLR_POWER_PATH . '/includes/legacy-functions.php'; SolrPower::get_instance(); SolrPower_Api::get_instance(); SolrPower_Options::get_instance(); SolrPower_Sync::get_instance(); SolrPower_WP_Query::get_instance(); function solr_options() { return SolrPower_Options::get_instance()->get_option(); } /** * Helper function to return Solr object. */ function get_solr() { return SolrPower_Api::get_instance()->get_solr(); } if (defined('WP_CLI') && true === WP_CLI) { WP_CLI::add_command('solr', 'SolrPower_CLI'); }