Skip to content

Commit

Permalink
Revert "Monitor only memory limit while running the data migration"
Browse files Browse the repository at this point in the history
This reverts commit 923eeb2.
  • Loading branch information
rodrigoprimo authored and claudiulodro committed Oct 31, 2018
1 parent cbbc1e1 commit 261d2a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions includes/class-wc-background-updater.php
Expand Up @@ -137,7 +137,7 @@ protected function complete() {
*
* @return bool
*/
public function is_memory_exceeded() {
return $this->memory_exceeded();
public function is_batch_limit_exceeded() {
return $this->batch_limit_exceeded();
}
}
14 changes: 7 additions & 7 deletions includes/wc-update-functions.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ) );
Expand All @@ -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" );
Expand Down

0 comments on commit 261d2a0

Please sign in to comment.