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); } }
/** * get a table with the current queue * * @return string */ public static function get_queue_list() { $page = isset($_GET['paged']) ? intval($_GET['paged']) : 1; $page = max(1, $page); $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()))); $meta_rows = $update_query->meta_rows; $num_pages = $update_query->num_pages; $html = '<h3><span class="alignright">Documents in Queue: <strong>' . $update_query->found_rows . '</strong></span>Documents to be Synced</h3>'; $html .= '<table class="wp-list-table widefat fixed posts"> <thead> <tr> <th class="column-date">Queue ID</th> <th class="column-title">Post</th> <th class="column-author">Last Author</th> <th class="column-categories">Time Queued</th> </tr> </thead>'; $pages = ''; if (count($meta_rows)) { foreach ($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']; $last_user = ''; if ($last_id = get_post_meta($post_id, '_edit_last', true)) { $last_user = get_userdata($last_id); } if ($meta_value['action'] == 'add') { $html .= '<tr>'; $html .= '<td class="column-date">' . $post_id . '</td>'; $html .= '<td class="column-title"><a href="' . esc_url(get_edit_post_link($post_id)) . '">' . esc_html(get_the_title($post_id)) . '</a></td>'; $html .= '<td class="column-author">' . (isset($last_user->display_name) ? $last_user->display_name : '') . '</td>'; $html .= '<td class="column-categories">' . mysql2date('D. M d Y g:ia', $meta_value['update_date']) . '</td>'; $html .= '</tr>'; } else { $html .= '<tr>'; $html .= '<td class="column-date">' . $post_id . '</td>'; $html .= '<td class="column-title">Deleted Post</td>'; $html .= '<td class="column-author"> </td>'; $html .= '<td class="column-categories">' . mysql2date('D. M d Y g:ia', $meta_value['update_date']) . '</td>'; $html .= '</tr>'; } default: continue; } } $big = 999999999; $pages = '<div class="tablenav bottom"><div class="tablenav-pages"><span class="pagination-links">'; $pages .= paginate_links(array('base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => max(1, $page), 'total' => $num_pages)); $pages .= '</span></div></div>'; } else { $html .= '<tr><td colspan="4">No Posts In Queue</td></tr>'; } $html .= '</table>'; $html .= $pages; return $html; }
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)); }