From ee6e0a345e30f0fe19fcac0eec770e9003b733fc Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Mon, 29 Oct 2018 11:19:52 -0300 Subject: [PATCH] Revert "Monitor only memory limit while running the data migration" This reverts commit 923eeb2e43130575899823f078e6d0d86b3afe2f. --- includes/class-wc-background-updater.php | 4 ++-- includes/wc-update-functions.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/includes/class-wc-background-updater.php b/includes/class-wc-background-updater.php index b8b427127bd..45dddd505ed 100644 --- a/includes/class-wc-background-updater.php +++ b/includes/class-wc-background-updater.php @@ -137,7 +137,7 @@ class WC_Background_Updater extends WC_Background_Process { * * @return bool */ - public function is_memory_exceeded() { - return $this->memory_exceeded(); + public function is_batch_limit_exceeded() { + return $this->batch_limit_exceeded(); } } diff --git a/includes/wc-update-functions.php b/includes/wc-update-functions.php index 8d672151bfe..6de33999063 100644 --- a/includes/wc-update-functions.php +++ b/includes/wc-update-functions.php @@ -1893,7 +1893,7 @@ function wc_update_350_order_customer_id( $updater = false ) { $wpdb->update( $wpdb->posts, array( 'post_author' => 0 ), array( 'post_type' => 'shop_order_refund' ) ); } else { - // If running the update from the wp-admin, copy data in batches being careful not to use more memory than allowed. + // If running the update from the wp-admin, copy data in batches being careful not to use more memory than allowed and respecting PHP time limit. $admin_orders_sql = ''; // Get the list of orders that we don't want to change as they belong to user ID 1. @@ -1941,9 +1941,9 @@ function wc_update_350_order_customer_id( $updater = false ) { // Update post_author for a batch of orders. foreach ( $orders_meta_data as $order_meta ) { - // Stop update execution and re-enqueue it if near memory limit. - if ( $updater instanceof WC_Background_Updater && $updater->is_memory_exceeded() ) { - return true; + // Stop update execution and re-enqueue it if near memory and timeout limits. + if ( $updater instanceof WC_Background_Updater && $updater->is_batch_limit_exceeded() ) { + return -1; } $wpdb->update( $wpdb->posts, array( 'post_author' => $order_meta->customer_id ), array( 'ID' => $order_meta->post_id ) ); @@ -1952,9 +1952,9 @@ function wc_update_350_order_customer_id( $updater = false ) { // Set post_author to 0 instead of 1 on all shop_order_refunds. while ( true ) { - // Stop update execution and re-enqueue it if near memory limit. - if ( $updater instanceof WC_Background_Updater && $updater->is_memory_exceeded() ) { - return true; + // Stop update execution and re-enqueue it if near memory and timeout limits. + if ( $updater instanceof WC_Background_Updater && $updater->is_batch_limit_exceeded() ) { + return -1; } $updated_rows = $wpdb->query( "UPDATE {$wpdb->posts} SET post_author = 0 WHERE post_type = 'shop_order_refund' LIMIT 1000" );