completed_message = __( 'Legacy data removed successfully.', 'easy-digital-downloads' ); $this->upgrade = 'v30_legacy_data_removed'; } /** * Retrieve the data pertaining to the current step and migrate as necessary. * * @since 3.0 * * @return bool True if data was migrated, false otherwise. */ public function get_data() { // Perform some database operations on the first step. if ( 1 === $this->step ) { // Drop customer `payment_ids` column. It's no longer needed. $customer_table = edd_get_component_interface( 'customer', 'table' ); if ( $customer_table instanceof \EDD\Database\Tables\Customers && $customer_table->column_exists( 'payment_ids' ) ) { $this->get_db()->query( "ALTER TABLE {$this->get_db()->edd_customers} DROP `payment_ids`" ); } // Delete unneeded meta. $this->get_db()->query( $this->get_db()->prepare( "DELETE FROM {$this->get_db()->edd_customermeta} WHERE meta_key = %s", esc_sql( 'additional_email' ) ) ); $this->get_db()->query( $this->get_db()->prepare( "DELETE FROM {$this->get_db()->usermeta} WHERE meta_key = %s", esc_sql( '_edd_user_address' ) ) ); } // First delete custom post types. $results = $this->get_db()->get_col( $this->get_db()->prepare( "SELECT id FROM {$this->get_db()->posts} WHERE post_type IN(%s, %s, %s) ORDER BY id ASC LIMIT %d", esc_sql( 'edd_payment' ), esc_sql( 'edd_discount' ), esc_sql( 'edd_log' ), $this->per_step ), 0 ); $data_was_deleted = false; if ( ! empty( $results ) ) { foreach ( $results as $result ) { wp_delete_post( $result, true ); } $data_was_deleted = true; } // Then delete order notes, stored in comments. $results = $this->get_db()->get_col( $this->get_db()->prepare( "SELECT comment_ID FROM {$this->get_db()->comments} WHERE comment_type = %s ORDER BY comment_ID ASC LIMIT %d", 'edd_payment_note', $this->per_step ) ); if ( ! empty( $results ) ) { foreach( $results as $result ) { wp_delete_comment( $result, true ); } $data_was_deleted = true; } return $data_was_deleted; } /** * Calculate the percentage completed. * * Because we're *deleting* records as we go, this percentage will not be accurate because we don't track * exactly how many we've deleted. So this percentage is really just best guess. * * @since 3.0 * * @return float Percentage. */ public function get_percentage_complete() { // Get post type total. $total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(id) AS count FROM {$this->get_db()->posts} WHERE post_type IN(%s, %s, %s)", esc_sql( 'edd_payment' ), esc_sql( 'edd_discount' ), esc_sql( 'edd_log' ) ) ); if ( empty( $total ) ) { $total = 0; } // Get order note total. $order_note_total = $this->get_db()->get_var( $this->get_db()->prepare( "SELECT COUNT(comment_ID) AS count FROM {$this->get_db()->comments} WHERE comment_type = %s", 'edd_payment_note' ) ); if ( empty( $order_note_total ) ) { $order_note_total = 0; } // Combine the two. $total += $order_note_total; // Estimate how many we've already done to improve the percentage. $number_done = $this->per_step * $this->step; $total += $number_done; $percentage = 100; if ( $total > 0 ) { $percentage = ( $number_done / $total ) * 100; } if ( $percentage > 100 ) { $percentage = 100; } return $percentage; } }