/**
  * use the config API to get the CloudSearch domain/index status
  *
  * @return array
  */
 public static function get_remote_status()
 {
     $domain = Lift_Search::get_domain_manager()->get_domain(Lift_Search::get_search_domain_name());
     if (!$domain) {
         return array('errors' => true, 'reason' => 'Domain has been deleted or the CloudSearch API request failed.', 'severity' => 2, 'status' => array('fatal' => true, 'text' => 'Domain has been deleted or the CloudSearch API request failed'));
     }
     $errors = false;
     $severity = 0;
     $reason = '';
     $text = 'active';
     $pending = !$domain->Created && !$domain->Deleted;
     $deleting = $domain->Deleted;
     $processing = $domain->Processing;
     $num_searchable_docs = $domain->NumSearchableDocs;
     $needs_indexing = $domain->RequiresIndexDocuments;
     $search_instance_count = $domain->SearchInstanceCount;
     $search_instance_type = $domain->SearchInstanceType;
     $search_partition_count = $domain->SearchPartitionCount;
     if ($deleting) {
         $severity = 2;
         $reason = 'CloudSearch domain being deleted';
         $text = 'being deleted';
     } else {
         if ($needs_indexing || $processing) {
             if (0 == $search_instance_count) {
                 $severity = 1;
                 $reason = 'CloudSearch domain loading';
                 $text = 'loading';
             } else {
                 if ($needs_indexing) {
                     $severity = 1;
                     $reason = 'CloudSearch domain needs indexing';
                     $text = 'needs indexing';
                 } else {
                     $severity = 1;
                     $reason = 'CloudSearch domain processing';
                     $text = 'processing';
                 }
             }
         } else {
             if ($pending) {
                 $severity = 1;
                 $reason = 'CloudSearch domain pending';
                 $text = 'pending';
             }
         }
     }
     if (0 != $severity) {
         $errors = true;
     }
     $status = compact('text', 'pending', 'deleting', 'processing', 'num_searchable_docs', 'needs_indexing', 'search_instance_count', 'search_instance_type', 'search_partition_count');
     $status['api_error'] = false;
     $status['text'] = $text;
     $results = array('errors' => $errors, 'severity' => $severity, 'reason' => $reason, 'status' => $status);
     return $results;
 }
示例#2
0
 function _lift_deactivate()
 {
     if (class_exists('Left_Search')) {
         $domain_manager = Lift_Search::get_domain_manager();
         if ($domain_name = Lift_Search::get_search_domain_name()) {
             TAE_Async_Event::Unwatch('lift_domain_created_' . $domain_name);
             TAE_Async_Event::Unwatch('lift_needs_indexing_' . $domain_name);
         }
         //clean up options
         delete_option(Lift_Search::INITIAL_SETUP_COMPLETE_OPTION);
         delete_option(Lift_Search::SETTINGS_OPTION);
         delete_option('lift_db_version');
         delete_option(Lift_Document_Update_Queue::QUEUE_IDS_OPTION);
         if (class_exists('Voce_Error_Logging')) {
             Voce_Error_Logging::delete_logs(array('lift-search'));
         }
         Lift_Batch_Handler::_deactivation_cleanup();
         Lift_Document_Update_Queue::_deactivation_cleanup();
     }
 }
 /**
  * Pulls the next set of items from the queue and sends a batch from it
  * Callback for Batch Submission Cron
  *
  * @todo Add locking
  */
 public static function send_next_batch()
 {
     if (!self::ready_for_batch(Lift_Search::get_search_domain_name())) {
         delete_transient(self::BATCH_LOCK);
         Lift_Search::event_log('CloudSearch Not Ready for Batch ' . time(), 'The batch is locked or the search domain is either currently processing, needs indexing, or your domain does not have indexes set up.', array('send-queue', 'response-false', 'notice'));
         return;
     }
     $lock_key = md5(uniqid(microtime() . mt_rand(), true));
     if (!get_transient(self::BATCH_LOCK)) {
         set_transient(self::BATCH_LOCK, $lock_key, 300);
     }
     if (get_transient(self::BATCH_LOCK) !== $lock_key) {
         //another cron has this lock
         return;
     }
     update_option(self::LAST_CRON_TIME_OPTION, time());
     $closed_queue_id = Lift_Document_Update_Queue::get_closed_queue_id();
     $update_query = Lift_Document_Update_Queue::query_updates(array('per_page' => self::get_queue_all_set_size(), 'queue_ids' => array($closed_queue_id)));
     if (!count($update_query->meta_rows)) {
         //no documents queued up
         Lift_Document_Update_Queue::close_active_queue();
         delete_transient(self::BATCH_LOCK);
         return;
     }
     $batch = new Lift_Batch();
     $batched_meta_keys = array();
     $blog_id = get_current_blog_id();
     $site_id = lift_get_current_site_id();
     foreach ($update_query->meta_rows as $meta_row) {
         $update_data = get_post_meta($meta_row->post_id, $meta_row->meta_key, true);
         if ($update_data['document_type'] == 'post') {
             $action = $update_data['action'];
             if ($action == 'add') {
                 $post = get_post($update_data['document_id'], ARRAY_A);
                 $post_data = array('ID' => $update_data['document_id'], 'blog_id' => $blog_id, 'site_id' => $site_id);
                 foreach (Lift_Search::get_indexed_post_fields($post['post_type']) as $field) {
                     $post_data[$field] = isset($post[$field]) ? $post[$field] : null;
                 }
                 $sdf_field_data = apply_filters('lift_post_changes_to_data', $post_data, $update_data['fields'], $update_data['document_id']);
             } else {
                 $sdf_field_data = array('ID' => intval($update_data['document_id']));
             }
             $sdf_doc = Lift_Posts_To_SDF::format_post((object) $sdf_field_data, array('action' => $action, 'time' => time()));
             try {
                 $batch->add_document((object) $sdf_doc);
                 $batched_meta_keys[] = $meta_row->meta_key;
             } catch (Lift_Batch_Exception $e) {
                 if (isset($e->errors[0]['code']) && 500 == $e->errors[0]['code']) {
                     break;
                 }
                 Lift_Search::event_log('Batch Add Error ' . time(), json_encode($e), array('batch-add', 'error'));
                 //@todo log error, stop cron? --- update_option( self::$search_semaphore, 1 );
                 continue;
             }
         }
     }
     //send the batch
     $cloud_api = Lift_Search::get_search_api();
     if ($r = $cloud_api->sendBatch($batch)) {
         if ($r->status === "success") {
             $log_title = "Post Queue Sent ";
             $tag = 'success';
             foreach ($batched_meta_keys as $meta_key) {
                 delete_post_meta($closed_queue_id, $meta_key);
             }
         } else {
             $log_title = "Post Queue Send Error ";
             $tag = 'error';
         }
         Lift_Search::event_log($log_title . time(), json_encode($r), array('send-queue', 'response-true', $tag));
         //@todo delete sent queued items
     } else {
         $messages = $cloud_api->getErrorMessages();
         Lift_Search::event_log('Post Queue Error ' . time(), $messages, array('send-queue', 'response-false', 'error'));
     }
     delete_transient(self::BATCH_LOCK);
 }
 public function action__wp_ajax_lift_settings()
 {
     $current_state = array('credentials' => array('accessKey' => Lift_Search::get_access_key_id(), 'secretKey' => Lift_Search::get_secret_access_key()), 'domainname' => Lift_Search::get_search_domain_name(), 'region' => Lift_Search::get_domain_region(), 'last_sync' => Lift_Batch_Handler::get_last_cron_time(), 'next_sync' => Lift_Batch_Handler::get_next_cron_time(), 'batch_interval' => Lift_Search::get_batch_interval_display(), 'override_search' => Lift_Search::get_override_search(), 'nonce' => wp_create_nonce('lift_setting'));
     $c_state = array();
     foreach ($current_state as $id => $value) {
         $c_state[] = array('id' => $id, 'value' => $value);
     }
     $current_state = $c_state;
     $response = json_encode($current_state);
     header('Content-Type: application/json');
     die($response);
 }
示例#5
0
    public static function _print_api_nag()
    {
        $api_version = Lift_Search::api_version();
        $search_domain = Lift_Search::get_search_domain_name();
        if (!$search_domain) {
            return false;
        } elseif (!strtotime($api_version) || date('Y', strtotime($api_version)) <= 2011) {
            ?>
			<div class="error"><p>Your search domain is using a deprecated version of the API. Please consider updating to the new version by following these <a target="_BLANK" href="http://docs.aws.amazon.com/cloudsearch/latest/developerguide/migrating.html"><strong>instructions</strong></strong></a>.</p></div>
		<?php 
        }
    }