From d6fa5b58f6a2e726432f054f7f428e2c80c72f6f Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 13 Mar 2019 11:48:38 -0600 Subject: [PATCH] =?UTF-8?q?Update=20our=20schedule=20actions=20to=20?= =?UTF-8?q?=E2=80=9Ctrash=E2=80=9D=20status=20and=20let=20Action=20Schedul?= =?UTF-8?q?er=20handle=20cleanup.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...s-wc-admin-actionscheduler-wppoststore.php | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-actionscheduler-wppoststore.php b/plugins/woocommerce-admin/includes/class-wc-admin-actionscheduler-wppoststore.php index ed144e8202a..fb4a579bcce 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-actionscheduler-wppoststore.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-actionscheduler-wppoststore.php @@ -37,31 +37,34 @@ class WC_Admin_ActionScheduler_WPPostStore extends ActionScheduler_wpPostStore { /** * Forcefully delete all pending WC Admin scheduled actions. * - * Directly deletes items from the database for performance. + * Directly trashes items from in database for performance. */ public function clear_pending_wcadmin_actions() { global $wpdb; - // Remove all scheduled action posts and their metadata. - $delete_pending_sql = - "DELETE p.*, pm.* FROM {$wpdb->posts} p - JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id - WHERE post_type = 'scheduled-action' - AND post_status = 'pending' - AND post_title LIKE 'wc-admin_%'"; + // Cancel all pending actions by trashing the posts. + // Action Scheduler will handle the cleanup. + $action_types = array( + WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION, + WC_Admin_Reports_Sync::QUEUE_DEPEDENT_ACTION, + WC_Admin_Reports_Sync::CUSTOMERS_BATCH_ACTION, + WC_Admin_Reports_Sync::ORDERS_BATCH_ACTION, + WC_Admin_Reports_Sync::ORDERS_LOOKUP_BATCH_INIT, + WC_Admin_Reports_Sync::SINGLE_ORDER_ACTION, + ); - // phpcs:ignore WordPress.DB.PreparedSQL - $wpdb->query( $delete_pending_sql ); - - // Delete all taxonomy data related to the WC Admin scheduled action group. - $group_term = get_term_by( 'slug', WC_Admin_Reports_Sync::QUEUE_GROUP, parent::GROUP_TAXONOMY ); - - if ( $group_term ) { - $wpdb->delete( $wpdb->term_relationships, array( 'term_taxonomy_id' => $group_term->term_taxonomy_id ), array( '%d' ) ); - $wpdb->delete( $wpdb->term_taxonomy, array( 'term_id' => $group_term->term_id ), array( '%d' ) ); - $wpdb->delete( $wpdb->terms, array( 'term_id' => $group_term->term_id ), array( '%d' ) ); - - clean_taxonomy_cache( parent::GROUP_TAXONOMY ); + foreach ( $action_types as $action_type ) { + $wpdb->update( + $wpdb->posts, + array( + 'post_status' => 'trash', + ), + array( + 'post_type' => 'scheduled-action', + 'post_status' => 'pending', + 'post_title' => $action_type, + ) + ); } } }