AP_Update_Helper::migrate_post_data()
Description #
Migrate question and answer.
Source #
File: admin/update.php
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | public function migrate_post_data() { $tasks = $this ->get_tasks(); if ( $tasks [ 'post_data' ] ) { return ; } global $wpdb ; $done = (int) get_option( 'anspress_updated_q_offset' , 0 ); $ids = $wpdb ->get_results( "SELECT SQL_CALC_FOUND_ROWS ID, post_type, post_parent, post_status FROM {$wpdb->posts} LEFT JOIN {$wpdb->ap_qameta} ON post_id = ID WHERE ptype IS NULL AND post_type IN ('question', 'answer') LIMIT {$done},50" ); $total_ids = $wpdb ->get_var( 'SELECT FOUND_ROWS()' ); // DB call okay, Db cache okay. if ( empty ( $ids ) ) { $options = get_option( 'anspress_updates' , [] ); $options [ 'post_data' ] = true; update_option( 'anspress_updates' , $options ); $this ->send( true, 'post_data' , __( 'Post data updated successfully' , 'anspress-question-answer' ), true ); } // Update answers count. foreach ( ( array ) $ids as $_post ) { if ( 'question' === $_post ->post_type ) { $this ->update_answers_count( $_post ); // Delete post meta. delete_post_meta( $_post ->ID, '_ap_answers' ); $this ->migrate_views( $_post ->ID ); $this ->subscribers( $_post ->ID ); $this ->change_closed_status( $_post ); $this ->best_answers( $_post ); ap_update_qameta_terms( $_post ->ID ); delete_post_meta( $_post ->ID, '_ap_participants' ); } if ( 'answer' === $_post ->post_type ) { delete_post_meta( $_post ->ID, '_ap_best_answer' ); } $this ->flags( $_post ->ID ); $this ->migrate_votes( $_post ->ID ); $this ->post_activities( $_post ); $this ->restore_last_updated( $_post ); } $done = $done + count ( $ids ); update_option( 'anspress_updated_q_offset' , $done ); $this ->send( true, 'post_data' , sprintf( __( 'Updated %1$d posts out of %2$d' , 'anspress-question-answer' ), count ( $done ), $total_ids ), true ); } |
Expand full source code Collapse full source code View on GitHub: admin/update.php:115
Add your comment