Merge pull request woocommerce/woocommerce-admin#1459 from woocommerce/feature/754

Introduced new hooks for jetpack sync
This commit is contained in:
Claudio Sanches 2019-02-05 15:43:06 -02:00 committed by GitHub
commit 20ae502ddd
6 changed files with 94 additions and 12 deletions

View File

@ -44,6 +44,11 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
$this->save_actions( $note );
$note->apply_changes();
/**
* Fires when an admin note is created.
*
* @param int $note_id Note ID.
*/
do_action( 'woocommerce_new_note', $note_id );
}
@ -73,6 +78,12 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
$this->read_actions( $note );
$note->read_meta_data();
$note->set_object_read( true );
/**
* Fires when an admin note is loaded.
*
* @param int $note_id Note ID.
*/
do_action( 'woocommerce_admin_note_loaded', $note );
} elseif ( $note_row ) {
$note->set_name( $note_row->name );
@ -89,6 +100,12 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
$this->read_actions( $note );
$note->read_meta_data();
$note->set_object_read( true );
/**
* Fires when an admin note is loaded.
*
* @param int $note_id Note ID.
*/
do_action( 'woocommerce_admin_note_loaded', $note );
} else {
throw new Exception( __( 'Invalid data store for admin note.', 'wc-admin' ) );
@ -138,6 +155,12 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
$note->save_meta_data();
$this->save_actions( $note );
$note->apply_changes();
/**
* Fires when an admin note is updated.
*
* @param int $note_id Note ID.
*/
do_action( 'woocommerce_update_note', $note->get_id() );
}
@ -155,7 +178,13 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
$wpdb->delete( $wpdb->prefix . 'woocommerce_admin_note_actions', array( 'note_id' => $note_id ) );
$note->set_id( null );
}
do_action( 'woocommerce_trash_note', $note_id );
/**
* Fires when an admin note is updated.
*
* @param int $note_id Note ID.
*/
do_action( 'woocommerce_delete_note', $note_id );
}
/**

View File

@ -278,7 +278,7 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
$this->include_extended_info( $coupon_data, $query_args );
$coupon_data = array_map( array( $this, 'cast_numbers' ), $coupon_data );
$data = (object) array(
$data = (object) array(
'data' => $coupon_data,
'total' => $db_records_count,
'pages' => $total_pages,
@ -320,11 +320,12 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
$num_updated = 0;
foreach ( $coupon_items as $coupon_item ) {
$result = $wpdb->replace(
$coupon_id = wc_get_coupon_id_by_code( $coupon_item->get_code() );
$result = $wpdb->replace(
$wpdb->prefix . self::TABLE_NAME,
array(
'order_id' => $order_id,
'coupon_id' => wc_get_coupon_id_by_code( $coupon_item->get_code() ),
'coupon_id' => $coupon_id,
'discount_amount' => $coupon_item->get_discount(),
'date_created' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
),
@ -336,6 +337,14 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
)
);
/**
* Fires when coupon's reports are updated.
*
* @param int $coupon_id Coupon ID.
* @param int $order_id Order ID.
*/
do_action( 'woocommerce_reports_update_coupon', $coupon_id, $order_id );
$num_updated += intval( $result );
}

View File

@ -434,8 +434,16 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
'%s',
)
);
$customer_id = $wpdb->insert_id;
return $result ? $wpdb->insert_id : false;
/**
* Fires when customser's reports are created.
*
* @param int $customer_id Customer ID.
*/
do_action( 'woocommerce_reports_new_customer', $customer_id );
return $result ? $customer_id : false;
}
/**
@ -557,7 +565,15 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
$format[] = '%d';
}
return $wpdb->replace( $wpdb->prefix . self::TABLE_NAME, $data, $format );
$results = $wpdb->replace( $wpdb->prefix . self::TABLE_NAME, $data, $format );
/**
* Fires when customser's reports are updated.
*
* @param int $customer_id Customer ID.
*/
do_action( 'woocommerce_reports_update_customer', $customer_id );
return $results;
}
/**

View File

@ -244,10 +244,8 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
$unique_products = $this->get_unique_product_count( $totals_query['from_clause'], $totals_query['where_time_clause'], $totals_query['where_clause'] );
$totals[0]['products'] = $unique_products;
$segmenting = new WC_Admin_Reports_Orders_Stats_Segmenting( $query_args, $this->report_columns );
$totals[0]['segments'] = $segmenting->get_totals_segments( $totals_query, $table_name );
$totals = (object) $this->cast_numbers( $totals[0] );
$db_intervals = $wpdb->get_col(
@ -434,7 +432,7 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
if ( $customer_id ) {
$data['customer_id'] = $customer_id;
$format[] = '%d';
$format[] = '%d';
}
}
} else {
@ -442,13 +440,20 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
if ( $customer && $customer['customer_id'] ) {
$data['customer_id'] = $customer['customer_id'];
$format[] = '%d';
$format[] = '%d';
}
}
// Update or add the information to the DB.
$result = $wpdb->replace( $table_name, $data, $format );
/**
* Fires when order's stats reports are updated.
*
* @param int $order_id Order ID.
*/
do_action( 'woocommerce_reports_update_order_stats', $order->get_id() );
return ( 1 === $result );
}

View File

@ -354,6 +354,14 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
array( 'order_item_id' => $order_item_id ),
array( '%d' )
); // WPCS: cache ok, DB call ok.
/**
* Fires when product's reports are deleted.
*
* @param int $order_item_id Order Item ID.
* @param int $order_id Order ID.
*/
do_action( 'woocommerce_reports_delete_product', $order_item_id, $order->get_id() );
} else {
$result = $wpdb->replace(
$wpdb->prefix . self::TABLE_NAME,
@ -391,6 +399,14 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
'%f', // refund_amount.
)
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
/**
* Fires when product's reports are updated.
*
* @param int $order_item_id Order Item ID.
* @param int $order_id Order ID.
*/
do_action( 'woocommerce_reports_update_product', $order_item_id, $order->get_id() );
}
$num_updated += intval( $result );
@ -398,5 +414,4 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
return ( count( $order_items ) === $num_updated );
}
}

View File

@ -60,7 +60,7 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl
*/
public function __construct() {
global $wpdb;
$table_name = $wpdb->prefix . self::TABLE_NAME;
$table_name = $wpdb->prefix . self::TABLE_NAME;
// Avoid ambigious columns in SQL query.
$this->report_columns['tax_rate_id'] = $table_name . '.' . $this->report_columns['tax_rate_id'];
$this->report_columns['orders_count'] = str_replace( 'order_id', $table_name . '.order_id', $this->report_columns['orders_count'] );
@ -279,6 +279,14 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl
)
);
/**
* Fires when tax's reports are updated.
*
* @param int $tax_rate_id Tax Rate ID.
* @param int $order_id Order ID.
*/
do_action( 'woocommerce_reports_update_tax', $tax_item->get_rate_id(), $order->get_id() );
$num_updated += intval( $result );
}