Пример #1
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);
 }
Пример #3
0
 public static function _upgrade_check()
 {
     global $wpdb;
     $current_db_version = get_option('lift_db_version', 0);
     $queue_all = false;
     $changed_schema_fields = array();
     if ($current_db_version < 2) {
         //queue storage changes
         $post_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} " . "WHERE post_type = %s", Lift_Document_Update_Queue::STORAGE_POST_TYPE));
         $queue_id = Lift_Document_Update_Queue::get_active_queue_id();
         foreach ($post_ids as $post_id) {
             if ($update_meta = get_post_meta($post_id, 'lift_content', true)) {
                 if (is_string($update_meta)) {
                     $update_meta = maybe_unserialize($update_meta);
                 }
                 //previous versions double serialized meta
                 $meta_key = 'lift_update_' . $update_meta['document_type'] . '_' . $update_meta['document_id'];
                 $new_meta = array('document_id' => $update_meta['document_id'], 'document_type' => $update_meta['document_type'], 'action' => $update_meta['action'], 'fields' => $update_meta['fields'], 'update_date_gmt' => get_post_time('Y-m-d H:i:s', true, $post_id), 'update_date' => get_post_time('Y-m-d H:i:s', false, $post_id));
                 update_post_meta($queue_id, $meta_key, $new_meta);
                 wp_delete_post($post_id);
             }
         }
         update_option('lift_db_version', 2);
     }
     if ($current_db_version < 4 && self::get_search_domain_name()) {
         //schema changes
         self::update_schema();
         update_option('lift_db_version', 4);
     }
     if ($current_db_version < 5) {
         wp_clear_scheduled_hook('lift_index_documents');
         wp_clear_scheduled_hook('lift_set_endpoints');
         update_option('lift_db_version', 5);
     }
 }
function lift_queue_deletion($document_id, $document_type = 'post')
{
    return Lift_Document_Update_Queue::queue_deletion($document_id, $document_type);
}
Пример #5
0
 public function action__wp_ajax_lift_update_queue()
 {
     $response = (object) array('error' => false);
     $page = max(abs($_GET['paged']), 1);
     $update_query = Lift_Document_Update_Queue::query_updates(array('page' => $page, 'per_page' => 10, 'queue_ids' => array(Lift_Document_Update_Queue::get_active_queue_id(), Lift_Document_Update_Queue::get_closed_queue_id())));
     $response->current_page = $page;
     $response->per_page = 10;
     $response->found_rows = $update_query->found_rows;
     $response->updates = array();
     foreach ($update_query->meta_rows as $meta_row) {
         $meta_value = get_post_meta($meta_row->post_id, $meta_row->meta_key, true);
         switch ($meta_value['document_type']) {
             case 'post':
                 $post_id = $meta_value['document_id'];
                 if ($meta_value['action'] == 'add') {
                     $last_user = '';
                     if ($last_id = get_post_meta($post_id, '_edit_last', true)) {
                         $last_user = get_userdata($last_id);
                     }
                     $response->updates[] = array('id' => $post_id, 'action' => 'add', 'title' => get_the_title($post_id), 'edit_url' => esc_url(get_edit_post_link($post_id)), 'author_name' => isset($last_user->display_name) ? $last_user->display_name : '', 'queue_date' => mysql2date('D. M d Y g:ia', $meta_value['update_date']));
                 } else {
                     $response->updates[] = array('id' => $post_id, 'action' => 'delete', 'title' => sprintf('Post Deletion (%d)', $post_id), 'edit_url' => '#', 'author_name' => '', 'queue_date' => mysql2date('D. M d Y g:ia', $meta_value['update_date']));
                 }
                 break;
             default:
                 continue;
         }
     }
     header('Content-Type: application/json');
     die(json_encode($response));
 }