Action Scheduler: fix potential endless sync

This commit is contained in:
Paul Sealock 2019-06-14 12:19:01 +12:00
parent 31f805f651
commit 18d535d65a
3 changed files with 30 additions and 1 deletions

View File

@ -432,6 +432,26 @@ class WC_Admin_Reports_Sync {
* @return void
*/
public static function orders_lookup_import_order( $order_id ) {
$order = wc_get_order( $order_id );
// If the order isn't found for some reason, skip the sync.
if ( ! $order ) {
return;
}
$type = $order->get_type();
// If the order isn't the right type, skip sync.
if ( 'shop_order' !== $type && 'shop_order_refund' !== $type ) {
return;
}
// If the order has no id or date created, skip sync.
if ( ! $order->get_id() || ! $order->get_date_created() ) {
return;
}
$result = array_sum(
array(
WC_Admin_Reports_Orders_Stats_Data_Store::sync_order( $order_id ),

View File

@ -358,6 +358,10 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
$order = wc_get_order( $order_id );
if ( ! $order ) {
return -1;
}
// Refunds don't affect coupon stats so return successfully if one is called here.
if ( 'shop_order_refund' === $order->get_type() ) {
return true;

View File

@ -311,7 +311,12 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl
*/
public static function sync_order_taxes( $order_id ) {
global $wpdb;
$order = wc_get_order( $order_id );
if ( ! $order ) {
return -1;
}
$tax_items = $order->get_items( 'tax' );
$num_updated = 0;