Update our schedule actions to “trash” status and let Action Scheduler handle cleanup.
This commit is contained in:
parent
04db0e2b8d
commit
d6fa5b58f6
|
@ -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,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue