PSR4-ify the Reports data store classes.

This commit is contained in:
Jeff Stieler 2019-08-05 12:14:25 -06:00
parent a67d577ad2
commit b7912bc579
35 changed files with 260 additions and 198 deletions

View File

@ -11,6 +11,11 @@ namespace Automattic\WooCommerce\Admin\API;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\API\Reports\Categories\DataStore as CategoriesDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsDataStore;
/**
* Leaderboards controller.
*
@ -73,7 +78,7 @@ class Leaderboards extends \WC_REST_Data_Controller {
* @param string $persisted_query URL query string.
*/
public function get_coupons_leaderboard( $per_page, $after, $before, $persisted_query ) {
$coupons_data_store = new \WC_Admin_Reports_Coupons_Data_Store();
$coupons_data_store = new CouponsDataStore();
$coupons_data = $per_page > 0 ? $coupons_data_store->get_data(
array(
'orderby' => 'orders_count',
@ -139,7 +144,7 @@ class Leaderboards extends \WC_REST_Data_Controller {
* @param string $persisted_query URL query string.
*/
public function get_categories_leaderboard( $per_page, $after, $before, $persisted_query ) {
$categories_data_store = new \WC_Admin_Reports_Categories_Data_Store();
$categories_data_store = new CategoriesDataStore();
$categories_data = $per_page > 0 ? $categories_data_store->get_data(
array(
'orderby' => 'items_sold',
@ -205,7 +210,7 @@ class Leaderboards extends \WC_REST_Data_Controller {
* @param string $persisted_query URL query string.
*/
public function get_customers_leaderboard( $per_page, $after, $before, $persisted_query ) {
$customers_data_store = new \WC_Admin_Reports_Customers_Data_Store();
$customers_data_store = new CustomersDataStore();
$customers_data = $per_page > 0 ? $customers_data_store->get_data(
array(
'orderby' => 'total_spend',
@ -269,7 +274,7 @@ class Leaderboards extends \WC_REST_Data_Controller {
* @param string $persisted_query URL query string.
*/
public function get_products_leaderboard( $per_page, $after, $before, $persisted_query ) {
$products_data_store = new \WC_Admin_Reports_Products_Data_Store();
$products_data_store = new ProductsDataStore();
$products_data = $per_page > 0 ? $products_data_store->get_data(
array(
'orderby' => 'items_sold',

View File

@ -236,7 +236,7 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
'sanitize_callback' => 'wp_parse_slug_list',
'validate_callback' => 'rest_validate_request_arg',
'items' => array(
'enum' => array_keys( \WC_Admin_Onboarding::get_allowed_industries() ),
'enum' => array_keys( WC_Admin_Onboarding::get_allowed_industries() ),
'type' => 'string',
),
),
@ -248,7 +248,7 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
'sanitize_callback' => 'wp_parse_slug_list',
'validate_callback' => 'rest_validate_request_arg',
'items' => array(
'enum' => array_keys( \WC_Admin_Onboarding::get_allowed_product_types() ),
'enum' => array_keys( WC_Admin_Onboarding::get_allowed_product_types() ),
'type' => 'string',
),
),

View File

@ -5,13 +5,14 @@
* @package WooCommerce Admin/Classes
*/
defined( 'ABSPATH' ) || exit;
namespace Automattic\WooCommerce\Admin\API\Reports\Categories;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Categories_Data_Store.
*/
class WC_Admin_Reports_Categories_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -207,7 +208,7 @@ class WC_Admin_Reports_Categories_Data_Store extends WC_Admin_Reports_Data_Store
*/
protected function include_extended_info( &$categories_data, $query_args ) {
foreach ( $categories_data as $key => $category_data ) {
$extended_info = new ArrayObject();
$extended_info = new \ArrayObject();
if ( $query_args['extended_info'] ) {
$extended_info['name'] = get_the_category_by_ID( $category_data['category_id'] );
}
@ -232,8 +233,8 @@ class WC_Admin_Reports_Categories_Data_Store extends WC_Admin_Reports_Data_Store
'page' => 1,
'order' => 'DESC',
'orderby' => 'date',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'categories' => array(),
'extended_info' => false,
@ -295,7 +296,7 @@ class WC_Admin_Reports_Categories_Data_Store extends WC_Admin_Reports_Data_Store
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
if ( null === $categories_data ) {
return new WP_Error( 'woocommerce_reports_categories_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ), array( 'status' => 500 ) );
return new \WP_Error( 'woocommerce_reports_categories_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ), array( 'status' => 500 ) );
}
$record_count = count( $categories_data );

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Coupons;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Coupons_Data_Store.
*/
class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -170,22 +172,22 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
*/
protected function include_extended_info( &$coupon_data, $query_args ) {
foreach ( $coupon_data as $idx => $coupon_datum ) {
$extended_info = new ArrayObject();
$extended_info = new \ArrayObject();
if ( $query_args['extended_info'] ) {
$coupon_id = $coupon_datum['coupon_id'];
$coupon = new WC_Coupon( $coupon_id );
$coupon = new \WC_Coupon( $coupon_id );
$gmt_timzone = new DateTimeZone( 'UTC' );
$gmt_timzone = new \DateTimeZone( 'UTC' );
$date_expires = $coupon->get_date_expires();
if ( null === $date_expires ) {
$date_expires = '';
$date_expires_gmt = '';
} else {
$date_expires = $date_expires->format( WC_Admin_Reports_Interval::$iso_datetime_format );
$date_expires_gmt = new DateTime( $date_expires );
$date_expires = $date_expires->format( \WC_Admin_Reports_Interval::$iso_datetime_format );
$date_expires_gmt = new \DateTime( $date_expires );
$date_expires_gmt->setTimezone( $gmt_timzone );
$date_expires_gmt = $date_expires_gmt->format( WC_Admin_Reports_Interval::$iso_datetime_format );
$date_expires_gmt = $date_expires_gmt->format( \WC_Admin_Reports_Interval::$iso_datetime_format );
}
$date_created = $coupon->get_date_created();
@ -193,10 +195,10 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
$date_created = '';
$date_created_gmt = '';
} else {
$date_created = $date_created->format( WC_Admin_Reports_Interval::$iso_datetime_format );
$date_created_gmt = new DateTime( $date_created );
$date_created = $date_created->format( \WC_Admin_Reports_Interval::$iso_datetime_format );
$date_created_gmt = new \DateTime( $date_created );
$date_created_gmt->setTimezone( $gmt_timzone );
$date_created_gmt = $date_created_gmt->format( WC_Admin_Reports_Interval::$iso_datetime_format );
$date_created_gmt = $date_created_gmt->format( \WC_Admin_Reports_Interval::$iso_datetime_format );
}
$extended_info = array(
@ -229,8 +231,8 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
'page' => 1,
'order' => 'DESC',
'orderby' => 'coupon_id',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'coupons' => array(),
'extended_info' => false,
@ -385,7 +387,7 @@ class WC_Admin_Reports_Coupons_Data_Store extends WC_Admin_Reports_Data_Store im
'order_id' => $order_id,
'coupon_id' => $coupon_id,
'discount_amount' => $coupon_item->get_discount(),
'date_created' => $order->get_date_created( 'edit' )->date( WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_created' => $order->get_date_created( 'edit' )->date( \WC_Admin_Reports_Interval::$sql_datetime_format ),
),
array(
'%d',

View File

@ -5,13 +5,14 @@
* @package WooCommerce Admin/Classes
*/
defined( 'ABSPATH' ) || exit;
namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats;
defined( 'ABSPATH' ) || exit;
/**
* WC_Reports_Coupons_Stats_Data_Store.
*/
class WC_Admin_Reports_Coupons_Stats_Data_Store extends WC_Admin_Reports_Coupons_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Mapping columns to data type to return correct response types.
@ -102,8 +103,8 @@ class WC_Admin_Reports_Coupons_Stats_Data_Store extends WC_Admin_Reports_Coupons
'page' => 1,
'order' => 'DESC',
'orderby' => 'date',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'interval' => 'week',
'coupons' => array(),
@ -142,7 +143,7 @@ class WC_Admin_Reports_Coupons_Stats_Data_Store extends WC_Admin_Reports_Coupons
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
$db_interval_count = count( $db_intervals );
$expected_interval_count = WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$expected_interval_count = \WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$total_pages = (int) ceil( $expected_interval_count / $intervals_query['per_page'] );
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
return $data;
@ -164,7 +165,7 @@ class WC_Admin_Reports_Coupons_Stats_Data_Store extends WC_Admin_Reports_Coupons
if ( null === $totals ) {
return $data;
}
$segmenter = new WC_Admin_Reports_Coupons_Stats_Segmenting( $query_args, $this->report_columns );
$segmenter = new \WC_Admin_Reports_Coupons_Stats_Segmenting( $query_args, $this->report_columns );
$totals[0]['segments'] = $segmenter->get_totals_segments( $totals_query, $table_name );
$totals = (object) $this->cast_numbers( $totals[0] );
@ -207,7 +208,7 @@ class WC_Admin_Reports_Coupons_Stats_Data_Store extends WC_Admin_Reports_Coupons
'page_no' => (int) $query_args['page'],
);
if ( WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
if ( \WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
$this->fill_in_missing_intervals( $db_intervals, $query_args['adj_after'], $query_args['adj_before'], $query_args['interval'], $data );
$this->sort_intervals( $data, $query_args['orderby'], $query_args['order'] );
$this->remove_extra_records( $data, $query_args['page'], $intervals_query['per_page'], $db_interval_count, $expected_interval_count, $query_args['orderby'], $query_args['order'] );

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Customers;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Customers_Data_Store.
*/
class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -169,14 +171,14 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
$column_name = $param_info['column'];
if ( ! empty( $query_args[ $before_arg ] ) ) {
$datetime = new DateTime( $query_args[ $before_arg ] );
$datetime_str = $datetime->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime = new \DateTime( $query_args[ $before_arg ] );
$datetime_str = $datetime->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
$subclauses[] = "{$column_name} <= '$datetime_str'";
}
if ( ! empty( $query_args[ $after_arg ] ) ) {
$datetime = new DateTime( $query_args[ $after_arg ] );
$datetime_str = $datetime->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime = new \DateTime( $query_args[ $after_arg ] );
$datetime_str = $datetime->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
$subclauses[] = "{$column_name} >= '$datetime_str'";
}
@ -347,8 +349,8 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
'page' => 1,
'order' => 'DESC',
'orderby' => 'date_registered',
'order_before' => WC_Admin_Reports_Interval::default_before(),
'order_after' => WC_Admin_Reports_Interval::default_after(),
'order_before' => \WC_Admin_Reports_Interval::default_before(),
'order_after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
);
$query_args = wp_parse_args( $query_args, $defaults );
@ -516,10 +518,10 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
// Add registered customer data.
if ( 0 !== $order->get_user_id() ) {
$user_id = $order->get_user_id();
$customer = new WC_Customer( $user_id );
$customer = new \WC_Customer( $user_id );
$data['user_id'] = $user_id;
$data['username'] = $customer->get_username( 'edit' );
$data['date_registered'] = $customer->get_date_created( 'edit' ) ? $customer->get_date_created( 'edit' )->date( WC_Admin_Reports_Interval::$sql_datetime_format ) : null;
$data['date_registered'] = $customer->get_date_created( 'edit' ) ? $customer->get_date_created( 'edit' )->date( \WC_Admin_Reports_Interval::$sql_datetime_format ) : null;
$format[] = '%d';
$format[] = '%s';
$format[] = '%s';
@ -611,7 +613,7 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
public static function update_registered_customer( $user_id ) {
global $wpdb;
$customer = new WC_Customer( $user_id );
$customer = new \WC_Customer( $user_id );
if ( ! self::is_valid_customer( $user_id ) ) {
return false;
@ -638,7 +640,7 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
'state' => $customer->get_billing_state( 'edit' ),
'postcode' => $customer->get_billing_postcode( 'edit' ),
'country' => $customer->get_billing_country( 'edit' ),
'date_registered' => $customer->get_date_created( 'edit' )->date( WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_registered' => $customer->get_date_created( 'edit' )->date( \WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_last_active' => $last_active ? date( 'Y-m-d H:i:s', $last_active ) : null,
);
$format = array(
@ -680,7 +682,7 @@ class WC_Admin_Reports_Customers_Data_Store extends WC_Admin_Reports_Data_Store
* @return bool
*/
protected static function is_valid_customer( $user_id ) {
$customer = new WC_Customer( $user_id );
$customer = new \WC_Customer( $user_id );
if ( absint( $customer->get_id() ) !== absint( $user_id ) ) {
return false;

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Customers\Stats;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Customers_Stats_Data_Store.
*/
class WC_Admin_Reports_Customers_Stats_Data_Store extends WC_Admin_Reports_Customers_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Mapping columns to data type to return correct response types.
*

View File

@ -5,6 +5,8 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -12,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* WC_Admin_Reports_Data_Store: Common parent for custom report data stores.
*/
class WC_Admin_Reports_Data_Store {
class DataStore {
/**
* Cache group for the reports.
@ -130,7 +132,7 @@ class WC_Admin_Reports_Data_Store {
*/
protected function fill_in_missing_intervals( $db_intervals, $start_datetime, $end_datetime, $time_interval, &$data ) {
// @todo This is ugly and messy.
$local_tz = new DateTimeZone( wc_timezone_string() );
$local_tz = new \DateTimeZone( wc_timezone_string() );
// At this point, we don't know when we can stop iterating, as the ordering can be based on any value.
$time_ids = array_flip( wp_list_pluck( $data->intervals, 'time_interval' ) );
$db_intervals = array_flip( $db_intervals );
@ -142,14 +144,14 @@ class WC_Admin_Reports_Data_Store {
// @todo Should 'products' be in intervals?
unset( $totals_arr['products'] );
while ( $start_datetime <= $end_datetime ) {
$next_start = WC_Admin_Reports_Interval::iterate( $start_datetime, $time_interval );
$time_id = WC_Admin_Reports_Interval::time_interval_id( $time_interval, $start_datetime );
$next_start = \WC_Admin_Reports_Interval::iterate( $start_datetime, $time_interval );
$time_id = \WC_Admin_Reports_Interval::time_interval_id( $time_interval, $start_datetime );
// Either create fill-zero interval or use data from db.
if ( $next_start > $end_datetime ) {
$interval_end = $end_datetime->format( 'Y-m-d H:i:s' );
} else {
$prev_end_timestamp = (int) $next_start->format( 'U' ) - 1;
$prev_end = new DateTime();
$prev_end = new \DateTime();
$prev_end->setTimestamp( $prev_end_timestamp );
$prev_end->setTimezone( $local_tz );
$interval_end = $prev_end->format( 'Y-m-d H:i:s' );
@ -181,11 +183,11 @@ class WC_Admin_Reports_Data_Store {
* @param array $defaults Array of default values.
*/
protected function normalize_timezones( &$query_args, $defaults ) {
$local_tz = new DateTimeZone( wc_timezone_string() );
$local_tz = new \DateTimeZone( wc_timezone_string() );
foreach ( array( 'before', 'after' ) as $query_arg_key ) {
if ( isset( $query_args[ $query_arg_key ] ) && is_string( $query_args[ $query_arg_key ] ) ) {
// Assume that unspecified timezone is a local timezone.
$datetime = new DateTime( $query_args[ $query_arg_key ], $local_tz );
$datetime = new \DateTime( $query_args[ $query_arg_key ], $local_tz );
// In case timezone was forced by using +HH:MM, convert to local timezone.
$datetime->setTimezone( $local_tz );
$query_args[ $query_arg_key ] = $datetime;
@ -310,7 +312,7 @@ class WC_Admin_Reports_Data_Store {
if ( $db_interval_count === $expected_interval_count ) {
return;
}
$local_tz = new DateTimeZone( wc_timezone_string() );
$local_tz = new \DateTimeZone( wc_timezone_string() );
if ( 'date' === strtolower( $query_args['orderby'] ) ) {
// page X in request translates to slightly different dates in the db, in case some
// records are missing from the db.
@ -327,7 +329,7 @@ class WC_Admin_Reports_Data_Store {
$start_iteration = 0;
break;
}
$new_start_date = WC_Admin_Reports_Interval::iterate( $new_start_date, $query_args['interval'] );
$new_start_date = \WC_Admin_Reports_Interval::iterate( $new_start_date, $query_args['interval'] );
$start_iteration ++;
}
@ -336,7 +338,7 @@ class WC_Admin_Reports_Data_Store {
if ( $new_end_date > $latest_end_date ) {
break;
}
$new_end_date = WC_Admin_Reports_Interval::iterate( $new_end_date, $query_args['interval'] );
$new_end_date = \WC_Admin_Reports_Interval::iterate( $new_end_date, $query_args['interval'] );
$end_iteration ++;
}
if ( $new_end_date > $latest_end_date ) {
@ -358,7 +360,7 @@ class WC_Admin_Reports_Data_Store {
$end_iteration = 0;
break;
}
$new_end_date = WC_Admin_Reports_Interval::iterate( $new_end_date, $query_args['interval'], true );
$new_end_date = \WC_Admin_Reports_Interval::iterate( $new_end_date, $query_args['interval'], true );
$end_iteration ++;
}
@ -367,7 +369,7 @@ class WC_Admin_Reports_Data_Store {
if ( $new_start_date < $earliest_start_date ) {
break;
}
$new_start_date = WC_Admin_Reports_Interval::iterate( $new_start_date, $query_args['interval'], true );
$new_start_date = \WC_Admin_Reports_Interval::iterate( $new_start_date, $query_args['interval'], true );
$start_iteration ++;
}
if ( $new_start_date < $earliest_start_date ) {
@ -382,8 +384,8 @@ class WC_Admin_Reports_Data_Store {
}
$query_args['adj_after'] = $new_start_date;
$query_args['adj_before'] = $new_end_date;
$adj_after = $new_start_date->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$adj_before = $new_end_date->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$adj_after = $new_start_date->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
$adj_before = $new_end_date->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
$intervals_query['where_time_clause'] = '';
$intervals_query['where_time_clause'] .= " AND {$table_name}.date_created <= '$adj_before'";
$intervals_query['where_time_clause'] .= " AND {$table_name}.date_created >= '$adj_after'";
@ -458,7 +460,7 @@ class WC_Admin_Reports_Data_Store {
* @return array
*/
protected static function get_excluded_report_order_statuses() {
$excluded_statuses = WC_Admin_Settings::get_option( 'woocommerce_excluded_report_order_statuses', array( 'pending', 'failed', 'cancelled' ) );
$excluded_statuses = \WC_Admin_Settings::get_option( 'woocommerce_excluded_report_order_statuses', array( 'pending', 'failed', 'cancelled' ) );
$excluded_statuses = array_merge( array( 'trash' ), $excluded_statuses );
return apply_filters( 'woocommerce_reports_excluded_order_statuses', $excluded_statuses );
}
@ -499,11 +501,11 @@ class WC_Admin_Reports_Data_Store {
* @param array $intervals Array of intervals extracted from SQL db.
*/
protected function update_interval_boundary_dates( $start_datetime, $end_datetime, $time_interval, &$intervals ) {
$local_tz = new DateTimeZone( wc_timezone_string() );
$local_tz = new \DateTimeZone( wc_timezone_string() );
foreach ( $intervals as $key => $interval ) {
$datetime = new DateTime( $interval['datetime_anchor'], $local_tz );
$datetime = new \DateTime( $interval['datetime_anchor'], $local_tz );
$prev_start = WC_Admin_Reports_Interval::iterate( $datetime, $time_interval, true );
$prev_start = \WC_Admin_Reports_Interval::iterate( $datetime, $time_interval, true );
// @todo Not sure if the +1/-1 here are correct, especially as they are applied before the ?: below.
$prev_start_timestamp = (int) $prev_start->format( 'U' ) + 1;
$prev_start->setTimestamp( $prev_start_timestamp );
@ -514,7 +516,7 @@ class WC_Admin_Reports_Data_Store {
$intervals[ $key ]['date_start'] = $prev_start->format( 'Y-m-d H:i:s' );
}
$next_end = WC_Admin_Reports_Interval::iterate( $datetime, $time_interval );
$next_end = \WC_Admin_Reports_Interval::iterate( $datetime, $time_interval );
$next_end_timestamp = (int) $next_end->format( 'U' ) - 1;
$next_end->setTimestamp( $next_end_timestamp );
if ( $end_datetime ) {
@ -537,15 +539,15 @@ class WC_Admin_Reports_Data_Store {
*/
protected function create_interval_subtotals( &$intervals ) {
foreach ( $intervals as $key => $interval ) {
$start_gmt = WC_Admin_Reports_Interval::convert_local_datetime_to_gmt( $interval['date_start'] );
$end_gmt = WC_Admin_Reports_Interval::convert_local_datetime_to_gmt( $interval['date_end'] );
$start_gmt = \WC_Admin_Reports_Interval::convert_local_datetime_to_gmt( $interval['date_start'] );
$end_gmt = \WC_Admin_Reports_Interval::convert_local_datetime_to_gmt( $interval['date_end'] );
// Move intervals result to subtotals object.
$intervals[ $key ] = array(
'interval' => $interval['time_interval'],
'date_start' => $interval['date_start'],
'date_start_gmt' => $start_gmt->format( WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_start_gmt' => $start_gmt->format( \WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_end' => $interval['date_end'],
'date_end_gmt' => $end_gmt->format( WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_end_gmt' => $end_gmt->format( \WC_Admin_Reports_Interval::$sql_datetime_format ),
);
unset( $interval['interval'] );
@ -573,9 +575,9 @@ class WC_Admin_Reports_Data_Store {
if ( isset( $query_args['before'] ) && '' !== $query_args['before'] ) {
if ( is_a( $query_args['before'], 'WC_DateTime' ) ) {
$datetime_str = $query_args['before']->date( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime_str = $query_args['before']->date( \WC_Admin_Reports_Interval::$sql_datetime_format );
} else {
$datetime_str = $query_args['before']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime_str = $query_args['before']->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
}
$sql_query['where_time_clause'] .= " AND {$table_name}.date_created <= '$datetime_str'";
@ -583,9 +585,9 @@ class WC_Admin_Reports_Data_Store {
if ( isset( $query_args['after'] ) && '' !== $query_args['after'] ) {
if ( is_a( $query_args['after'], 'WC_DateTime' ) ) {
$datetime_str = $query_args['after']->date( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime_str = $query_args['after']->date( \WC_Admin_Reports_Interval::$sql_datetime_format );
} else {
$datetime_str = $query_args['after']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime_str = $query_args['after']->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
}
$sql_query['where_time_clause'] .= " AND {$table_name}.date_created >= '$datetime_str'";
}
@ -708,7 +710,7 @@ class WC_Admin_Reports_Data_Store {
if ( isset( $query_args['interval'] ) && '' !== $query_args['interval'] ) {
$interval = $query_args['interval'];
$intervals_query['select_clause'] = WC_Admin_Reports_Interval::db_datetime_format( $interval, $table_name );
$intervals_query['select_clause'] = \WC_Admin_Reports_Interval::db_datetime_format( $interval, $table_name );
}
$intervals_query = array_merge( $intervals_query, $this->get_limit_sql_params( $query_args ) );

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Downloads;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Downloads_Data_Store.
*/
class WC_Admin_Reports_Downloads_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -255,13 +257,13 @@ class WC_Admin_Reports_Downloads_Data_Store extends WC_Admin_Reports_Data_Store
);
if ( $query_args['before'] ) {
$datetime_str = $query_args['before']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime_str = $query_args['before']->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
$sql_query['where_time_clause'] .= " AND {$table_name}.timestamp <= '$datetime_str'";
}
if ( $query_args['after'] ) {
$datetime_str = $query_args['after']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
$datetime_str = $query_args['after']->format( \WC_Admin_Reports_Interval::$sql_datetime_format );
$sql_query['where_time_clause'] .= " AND {$table_name}.timestamp >= '$datetime_str'";
}
@ -312,8 +314,8 @@ class WC_Admin_Reports_Downloads_Data_Store extends WC_Admin_Reports_Data_Store
'page' => 1,
'order' => 'DESC',
'orderby' => 'timestamp',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
);
$query_args = wp_parse_args( $query_args, $defaults );

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Downloads_Data_Store.
*/
class WC_Admin_Reports_Downloads_Stats_Data_Store extends WC_Admin_Reports_Downloads_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Mapping columns to data type to return correct response types.
@ -57,8 +59,8 @@ class WC_Admin_Reports_Downloads_Stats_Data_Store extends WC_Admin_Reports_Downl
'orderby' => 'date',
'fields' => '*',
'interval' => 'week',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
);
$query_args = wp_parse_args( $query_args, $defaults );
$this->normalize_timezones( $query_args, $defaults );
@ -95,7 +97,7 @@ class WC_Admin_Reports_Downloads_Stats_Data_Store extends WC_Admin_Reports_Downl
$db_records_count = count( $db_intervals );
$expected_interval_count = WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$expected_interval_count = \WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$total_pages = (int) ceil( $expected_interval_count / $intervals_query['per_page'] );
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
return array();
@ -118,7 +120,7 @@ class WC_Admin_Reports_Downloads_Stats_Data_Store extends WC_Admin_Reports_Downl
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
if ( null === $totals ) {
return new WP_Error( 'woocommerce_reports_downloads_stats_result_failed', __( 'Sorry, fetching downloads data failed.', 'woocommerce-admin' ) );
return new \WP_Error( 'woocommerce_reports_downloads_stats_result_failed', __( 'Sorry, fetching downloads data failed.', 'woocommerce-admin' ) );
}
if ( '' !== $selections ) {
@ -146,7 +148,7 @@ class WC_Admin_Reports_Downloads_Stats_Data_Store extends WC_Admin_Reports_Downl
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
if ( null === $intervals ) {
return new WP_Error( 'woocommerce_reports_downloads_stats_result_failed', __( 'Sorry, fetching downloads data failed.', 'woocommerce-admin' ) );
return new \WP_Error( 'woocommerce_reports_downloads_stats_result_failed', __( 'Sorry, fetching downloads data failed.', 'woocommerce-admin' ) );
}
$totals = (object) $this->cast_numbers( $totals[0] );

View File

@ -123,7 +123,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller {
*/
public function import_items( $request ) {
$query_args = $this->prepare_objects_query( $request );
$import = \WC_Admin_Reports_Sync::regenerate_report_data( $query_args['days'], $query_args['skip_existing'] );
$import = WC_Admin_Reports_Sync::regenerate_report_data( $query_args['days'], $query_args['skip_existing'] );
if ( is_wp_error( $import ) ) {
$result = array(
@ -239,7 +239,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller {
* @return WP_Error|WP_REST_Response
*/
public function cancel_import( $request ) {
\WC_Admin_Reports_Sync::clear_queued_actions();
WC_Admin_Reports_Sync::clear_queued_actions();
$result = array(
'status' => 'success',
@ -259,7 +259,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller {
* @return WP_Error|WP_REST_Response
*/
public function delete_imported_items( $request ) {
$delete = \WC_Admin_Reports_Sync::delete_report_data();
$delete = WC_Admin_Reports_Sync::delete_report_data();
if ( is_wp_error( $delete ) ) {
$result = array(
@ -287,7 +287,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller {
*/
public function get_import_status( $request ) {
$result = array(
'is_importing' => \WC_Admin_Reports_Sync::is_importing(),
'is_importing' => WC_Admin_Reports_Sync::is_importing(),
'customers_total' => (int) get_option( 'wc_admin_import_customers_total', 0 ),
'customers_count' => (int) get_option( 'wc_admin_import_customers_count', 0 ),
'orders_total' => (int) get_option( 'wc_admin_import_orders_total', 0 ),
@ -309,7 +309,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller {
*/
public function get_import_totals( $request ) {
$query_args = $this->prepare_objects_query( $request );
$totals = \WC_Admin_Reports_Sync::get_import_totals( $query_args['days'], $query_args['skip_existing'] );
$totals = WC_Admin_Reports_Sync::get_import_totals( $query_args['days'], $query_args['skip_existing'] );
$response = $this->prepare_item_for_response( $totals, $request );
$data = $this->prepare_response_for_collection( $response );

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Orders;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Orders_Data_Store.
*/
class WC_Admin_Reports_Orders_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Orders_Stats_Data_Store.
*/
class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -202,8 +204,8 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
'page' => 1,
'order' => 'DESC',
'orderby' => 'date',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'interval' => 'week',
'fields' => '*',
'segmentby' => '',
@ -270,7 +272,7 @@ 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 );
$segmenting = new \WC_Admin_Reports_Orders_Stats_Segmenting( $query_args, $this->report_columns );
$unique_coupons = $this->get_unique_coupon_count( $totals_query['from_clause'], $totals_query['where_time_clause'], $totals_query['where_clause'] );
$totals[0]['coupons_count'] = $unique_coupons;
$totals[0]['segments'] = $segmenting->get_totals_segments( $totals_query, $table_name );
@ -292,7 +294,7 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
); // WPCS: cache ok, DB call ok, , unprepared SQL ok.
$db_interval_count = count( $db_intervals );
$expected_interval_count = WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$expected_interval_count = \WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$total_pages = (int) ceil( $expected_interval_count / $intervals_query['per_page'] );
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
@ -327,7 +329,7 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
if ( null === $intervals ) {
return new WP_Error( 'woocommerce_reports_revenue_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
return new \WP_Error( 'woocommerce_reports_revenue_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
}
if ( isset( $intervals[0] ) ) {
@ -343,7 +345,7 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
'page_no' => (int) $query_args['page'],
);
if ( WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
if ( \WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
$this->fill_in_missing_intervals( $db_intervals, $query_args['adj_after'], $query_args['adj_before'], $query_args['interval'], $data );
$this->sort_intervals( $data, $query_args['orderby'], $query_args['order'] );
$this->remove_extra_records( $data, $query_args['page'], $intervals_query['per_page'], $db_interval_count, $expected_interval_count, $query_args['orderby'], $query_args['order'] );
@ -565,13 +567,13 @@ class WC_Admin_Reports_Orders_Stats_Data_Store extends WC_Admin_Reports_Data_Sto
* @return bool
*/
public static function is_returning_customer( $order ) {
$customer_id = WC_Admin_Reports_Customers_Data_Store::get_existing_customer_id_from_order( $order );
$customer_id = \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore::get_existing_customer_id_from_order( $order );
if ( ! $customer_id ) {
return false;
}
$oldest_orders = WC_Admin_Reports_Customers_Data_Store::get_oldest_orders( $customer_id );
$oldest_orders = \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore::get_oldest_orders( $customer_id );
if ( empty( $oldest_orders ) ) {
return false;

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Products;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Products_Data_Store.
*/
class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -187,7 +189,7 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
$product_names = array();
foreach ( $products_data as $key => $product_data ) {
$extended_info = new ArrayObject();
$extended_info = new \ArrayObject();
if ( $query_args['extended_info'] ) {
$product_id = $product_data['product_id'];
$product = wc_get_product( $product_id );
@ -255,8 +257,8 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
'page' => 1,
'order' => 'DESC',
'orderby' => 'date',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'categories' => array(),
'product_includes' => array(),
@ -429,7 +431,7 @@ class WC_Admin_Reports_Products_Data_Store extends WC_Admin_Reports_Data_Store i
'customer_id' => $order->get_report_customer_id(),
'product_qty' => $product_qty,
'product_net_revenue' => $net_revenue,
'date_created' => $order->get_date_created( 'edit' )->date( WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_created' => $order->get_date_created( 'edit' )->date( \WC_Admin_Reports_Interval::$sql_datetime_format ),
'coupon_amount' => $coupon_amount,
'tax_amount' => $tax_amount,
'shipping_amount' => $shipping_amount,

View File

@ -5,13 +5,14 @@
* @package WooCommerce Admin/Classes
*/
defined( 'ABSPATH' ) || exit;
namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats;
defined( 'ABSPATH' ) || exit;
/**
* WC_Reports_Products_Stats_Data_Store.
*/
class WC_Admin_Reports_Products_Stats_Data_Store extends WC_Admin_Reports_Products_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Mapping columns to data type to return correct response types.
@ -110,8 +111,8 @@ class WC_Admin_Reports_Products_Stats_Data_Store extends WC_Admin_Reports_Produc
'page' => 1,
'order' => 'DESC',
'orderby' => 'date',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'categories' => array(),
'interval' => 'week',
@ -144,7 +145,7 @@ class WC_Admin_Reports_Products_Stats_Data_Store extends WC_Admin_Reports_Produc
); // WPCS: cache ok, DB call ok, , unprepared SQL ok.
$db_interval_count = count( $db_intervals );
$expected_interval_count = WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$expected_interval_count = \WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$total_pages = (int) ceil( $expected_interval_count / $intervals_query['per_page'] );
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
return array();
@ -165,11 +166,11 @@ class WC_Admin_Reports_Products_Stats_Data_Store extends WC_Admin_Reports_Produc
ARRAY_A
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
$segmenter = new WC_Admin_Reports_Products_Stats_Segmenting( $query_args, $this->report_columns );
$segmenter = new \WC_Admin_Reports_Products_Stats_Segmenting( $query_args, $this->report_columns );
$totals[0]['segments'] = $segmenter->get_totals_segments( $totals_query, $table_name );
if ( null === $totals ) {
return new WP_Error( 'woocommerce_reports_products_stats_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
return new \WP_Error( 'woocommerce_reports_products_stats_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
}
if ( '' !== $selections ) {
@ -197,7 +198,7 @@ class WC_Admin_Reports_Products_Stats_Data_Store extends WC_Admin_Reports_Produc
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
if ( null === $intervals ) {
return new WP_Error( 'woocommerce_reports_products_stats_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
return new \WP_Error( 'woocommerce_reports_products_stats_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
}
$totals = (object) $this->cast_numbers( $totals[0] );
@ -210,7 +211,7 @@ class WC_Admin_Reports_Products_Stats_Data_Store extends WC_Admin_Reports_Produc
'page_no' => (int) $query_args['page'],
);
if ( WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
if ( \WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
$this->fill_in_missing_intervals( $db_intervals, $query_args['adj_after'], $query_args['adj_before'], $query_args['interval'], $data );
$this->sort_intervals( $data, $query_args['orderby'], $query_args['order'] );
$this->remove_extra_records( $data, $query_args['page'], $intervals_query['per_page'], $db_interval_count, $expected_interval_count, $query_args['orderby'], $query_args['order'] );

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Stock\Stats;
defined( 'ABSPATH' ) || exit;
/**
* WC_Reports_Stock_Stats_Data_Store.
*/
class WC_Admin_Reports_Stock_Stats_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Get stock counts for the whole store.
@ -122,7 +124,7 @@ class WC_Admin_Reports_Stock_Stats_Data_Store extends WC_Admin_Reports_Data_Stor
private function get_product_count() {
$query_args = array();
$query_args['post_type'] = array( 'product', 'product_variation' );
$query = new WP_Query();
$query = new \WP_Query();
$query->query( $query_args );
return intval( $query->found_posts );
}

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Taxes;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Taxes_Data_Store.
*/
class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -167,8 +169,8 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl
'page' => 1,
'order' => 'DESC',
'orderby' => 'tax_rate_id',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'taxes' => array(),
);
@ -325,7 +327,7 @@ class WC_Admin_Reports_Taxes_Data_Store extends WC_Admin_Reports_Data_Store impl
$wpdb->prefix . self::TABLE_NAME,
array(
'order_id' => $order->get_id(),
'date_created' => $order->get_date_created( 'edit' )->date( WC_Admin_Reports_Interval::$sql_datetime_format ),
'date_created' => $order->get_date_created( 'edit' )->date( \WC_Admin_Reports_Interval::$sql_datetime_format ),
'tax_rate_id' => $tax_item->get_rate_id(),
'shipping_tax' => $tax_item->get_shipping_tax_total(),
'order_tax' => $tax_item->get_tax_total(),

View File

@ -5,13 +5,14 @@
* @package WooCommerce Admin/Classes
*/
defined( 'ABSPATH' ) || exit;
namespace Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats;
defined( 'ABSPATH' ) || exit;
/**
* WC_Reports_Taxes_Stats_Data_Store.
*/
class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -152,8 +153,8 @@ class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Stor
'page' => 1,
'order' => 'DESC',
'orderby' => 'tax_rate_id',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'taxes' => array(),
);
@ -194,7 +195,7 @@ class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Stor
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
$db_interval_count = count( $db_intervals );
$expected_interval_count = WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$expected_interval_count = \WC_Admin_Reports_Interval::intervals_between( $query_args['after'], $query_args['before'], $query_args['interval'] );
$total_pages = (int) ceil( $expected_interval_count / $intervals_query['per_page'] );
if ( $query_args['page'] < 1 || $query_args['page'] > $total_pages ) {
@ -217,9 +218,9 @@ class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Stor
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
if ( null === $totals ) {
return new WP_Error( 'woocommerce_reports_taxes_stats_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
return new \WP_Error( 'woocommerce_reports_taxes_stats_result_failed', __( 'Sorry, fetching revenue data failed.', 'woocommerce-admin' ) );
}
$segmenter = new WC_Admin_Reports_Taxes_Stats_Segmenting( $query_args, $this->report_columns );
$segmenter = new \WC_Admin_Reports_Taxes_Stats_Segmenting( $query_args, $this->report_columns );
$totals[0]['segments'] = $segmenter->get_totals_segments( $totals_query, $table_name );
$this->update_intervals_sql_params( $intervals_query, $query_args, $db_interval_count, $expected_interval_count, $table_name );
@ -251,7 +252,7 @@ class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Stor
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
if ( null === $intervals ) {
return new WP_Error( 'woocommerce_reports_taxes_stats_result_failed', __( 'Sorry, fetching tax data failed.', 'woocommerce-admin' ) );
return new \WP_Error( 'woocommerce_reports_taxes_stats_result_failed', __( 'Sorry, fetching tax data failed.', 'woocommerce-admin' ) );
}
$totals = (object) $this->cast_numbers( $totals[0] );
@ -264,7 +265,7 @@ class WC_Admin_Reports_Taxes_Stats_Data_Store extends WC_Admin_Reports_Data_Stor
'page_no' => (int) $query_args['page'],
);
if ( WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
if ( \WC_Admin_Reports_Interval::intervals_missing( $expected_interval_count, $db_interval_count, $intervals_query['per_page'], $query_args['page'], $query_args['order'], $query_args['orderby'], count( $intervals ) ) ) {
$this->fill_in_missing_intervals( $db_intervals, $query_args['adj_after'], $query_args['adj_before'], $query_args['interval'], $data );
$this->sort_intervals( $data, $query_args['orderby'], $query_args['order'] );
$this->remove_extra_records( $data, $query_args['page'], $intervals_query['per_page'], $db_interval_count, $expected_interval_count, $query_args['orderby'], $query_args['order'] );

View File

@ -5,12 +5,14 @@
* @package WooCommerce Admin/Classes
*/
namespace Automattic\WooCommerce\Admin\API\Reports\Variations;
defined( 'ABSPATH' ) || exit;
/**
* WC_Admin_Reports_Products_Data_Store.
*/
class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store implements WC_Admin_Reports_Data_Store_Interface {
class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface {
/**
* Table used to get the data.
@ -167,7 +169,7 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
*/
protected function include_extended_info( &$products_data, $query_args ) {
foreach ( $products_data as $key => $product_data ) {
$extended_info = new ArrayObject();
$extended_info = new \ArrayObject();
if ( $query_args['extended_info'] ) {
$extended_attributes = apply_filters( 'woocommerce_rest_reports_variations_extended_attributes', $this->extended_attributes, $product_data );
$product = wc_get_product( $product_data['product_id'] );
@ -226,8 +228,8 @@ class WC_Admin_Reports_Variations_Data_Store extends WC_Admin_Reports_Data_Store
'page' => 1,
'order' => 'DESC',
'orderby' => 'date',
'before' => WC_Admin_Reports_Interval::default_before(),
'after' => WC_Admin_Reports_Interval::default_after(),
'before' => \WC_Admin_Reports_Interval::default_before(),
'after' => \WC_Admin_Reports_Interval::default_after(),
'fields' => '*',
'products' => array(),
'variations' => array(),

View File

@ -280,23 +280,23 @@ class WC_Admin_Api_Init {
return array_merge(
$data_stores,
array(
'report-revenue-stats' => 'WC_Admin_Reports_Orders_Stats_Data_Store',
'report-orders' => 'WC_Admin_Reports_Orders_Data_Store',
'report-orders-stats' => 'WC_Admin_Reports_Orders_Stats_Data_Store',
'report-products' => 'WC_Admin_Reports_Products_Data_Store',
'report-variations' => 'WC_Admin_Reports_Variations_Data_Store',
'report-products-stats' => 'WC_Admin_Reports_Products_Stats_Data_Store',
'report-categories' => 'WC_Admin_Reports_Categories_Data_Store',
'report-taxes' => 'WC_Admin_Reports_Taxes_Data_Store',
'report-taxes-stats' => 'WC_Admin_Reports_Taxes_Stats_Data_Store',
'report-coupons' => 'WC_Admin_Reports_Coupons_Data_Store',
'report-coupons-stats' => 'WC_Admin_Reports_Coupons_Stats_Data_Store',
'report-downloads' => 'WC_Admin_Reports_Downloads_Data_Store',
'report-downloads-stats' => 'WC_Admin_Reports_Downloads_Stats_Data_Store',
'admin-note' => 'WC_Admin_Notes_Data_Store',
'report-customers' => 'WC_Admin_Reports_Customers_Data_Store',
'report-customers-stats' => 'WC_Admin_Reports_Customers_Stats_Data_Store',
'report-stock-stats' => 'WC_Admin_Reports_Stock_Stats_Data_Store',
'report-revenue-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore',
'report-orders' => 'Automattic\WooCommerce\Admin\API\Reports\Orders\DataStore',
'report-orders-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore',
'report-products' => 'Automattic\WooCommerce\Admin\API\Reports\Products\DataStore',
'report-variations' => 'Automattic\WooCommerce\Admin\API\Reports\Variations\DataStore',
'report-products-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Products\Stats\DataStore',
'report-categories' => 'Automattic\WooCommerce\Admin\API\Reports\Categories\DataStore',
'report-taxes' => 'Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore',
'report-taxes-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\DataStore',
'report-coupons' => 'Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore',
'report-coupons-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\DataStore',
'report-downloads' => 'Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore',
'report-downloads-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats\DataStore',
'admin-note' => 'Automattic\WooCommerce\Admin\Notes\DataStore',
'report-customers' => 'Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore',
'report-customers-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\DataStore',
'report-stock-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Stock\Stats\DataStore',
)
);
}

View File

@ -5,14 +5,14 @@
* @package WooCommerce Admin/Classes
*/
defined( 'ABSPATH' ) || exit;
namespace Automattic\WooCommerce\Admin\Notes;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Note;
defined( 'ABSPATH' ) || exit;
/**
* WC Admin Note Data Store (Custom Tables)
*/
class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
class DataStore extends \WC_Data_Store_WP implements \WC_Object_Data_Store_Interface {
/**
* Method to create a new note in the database.
*
@ -112,7 +112,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
*/
do_action( 'woocommerce_admin_note_loaded', $note );
} else {
throw new Exception( __( 'Invalid data store for admin note.', 'woocommerce-admin' ) );
throw new \Exception( __( 'Invalid data store for admin note.', 'woocommerce-admin' ) );
}
}

View File

@ -11,6 +11,9 @@ namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore;
/**
* WC_Admin_Order class.
*/
@ -58,7 +61,7 @@ class WC_Admin_Order extends \WC_Order {
* @return int
*/
public function get_report_customer_id() {
return \WC_Admin_Reports_Customers_Data_Store::get_or_create_customer_from_order( $this );
return CustomersDataStore::get_or_create_customer_from_order( $this );
}
/**
@ -67,7 +70,7 @@ class WC_Admin_Order extends \WC_Order {
* @return bool
*/
public function is_returning_customer() {
return \WC_Admin_Reports_Orders_Stats_Data_Store::is_returning_customer( $this );
return OrdersStatsDataStore::is_returning_customer( $this );
}
/**

View File

@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
/**
* WC_Admin_Order_Refund class.
*/
@ -57,7 +59,7 @@ class WC_Admin_Order_Refund extends \WC_Order_Refund {
return false;
}
return \WC_Admin_Reports_Customers_Data_Store::get_or_create_customer_from_order( $parent_order );
return CustomersDataStore::get_or_create_customer_from_order( $parent_order );
}
/**

View File

@ -9,6 +9,12 @@ namespace Automattic\WooCommerce\Admin;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsDataStore;
use \Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore as TaxesDataStore;
/**
* WC_Admin_Reports_Sync Class.
*/
@ -313,11 +319,11 @@ class WC_Admin_Reports_Sync {
add_action( 'save_post', array( __CLASS__, 'schedule_single_order_import' ) );
add_action( 'woocommerce_refund_created', array( __CLASS__, 'schedule_single_order_import' ) );
\WC_Admin_Reports_Orders_Stats_Data_Store::init();
\WC_Admin_Reports_Customers_Data_Store::init();
\WC_Admin_Reports_Coupons_Data_Store::init();
\WC_Admin_Reports_Products_Data_Store::init();
\WC_Admin_Reports_Taxes_Data_Store::init();
OrdersStatsDataStore::init();
CustomersDataStore::init();
CouponsDataStore::init();
ProductsDataStore::init();
TaxesDataStore::init();
}
/**
@ -456,10 +462,10 @@ class WC_Admin_Reports_Sync {
$result = array_sum(
array(
\WC_Admin_Reports_Orders_Stats_Data_Store::sync_order( $order_id ),
\WC_Admin_Reports_Products_Data_Store::sync_order_products( $order_id ),
\WC_Admin_Reports_Coupons_Data_Store::sync_order_coupons( $order_id ),
\WC_Admin_Reports_Taxes_Data_Store::sync_order_taxes( $order_id ),
OrdersStatsDataStore::sync_order( $order_id ),
ProductsDataStore::sync_order_products( $order_id ),
CouponsDataStore::sync_order_coupons( $order_id ),
TaxesDataStore::sync_order_taxes( $order_id ),
)
);
@ -706,7 +712,7 @@ class WC_Admin_Reports_Sync {
foreach ( $customer_ids as $customer_id ) {
// @todo Schedule single customer update if this fails?
\WC_Admin_Reports_Customers_Data_Store::update_registered_customer( $customer_id );
CustomersDataStore::update_registered_customer( $customer_id );
}
$imported_count = get_option( 'wc_admin_import_customers_count', 0 );
@ -751,7 +757,7 @@ class WC_Admin_Reports_Sync {
);
foreach ( $customer_ids as $customer_id ) {
\WC_Admin_Reports_Customers_Data_Store::delete_customer( $customer_id );
CustomersDataStore::delete_customer( $customer_id );
}
wc_admin_record_tracks_event( 'delete_import_data_job_complete', array( 'type' => 'customer' ) );
@ -793,7 +799,7 @@ class WC_Admin_Reports_Sync {
);
foreach ( $order_ids as $order_id ) {
\WC_Admin_Reports_Orders_Stats_Data_Store::delete_order( $order_id );
OrdersStatsDataStore::delete_order( $order_id );
}
wc_admin_record_tracks_event( 'delete_import_data_job_complete', array( 'type' => 'order' ) );

View File

@ -7,6 +7,7 @@
*/
use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync;
use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore;
/**
* Class WC_Tests_API_Init
@ -41,7 +42,7 @@ class WC_Tests_API_Init extends WC_REST_Unit_Test_Case {
if (
0 === strpos( $query, 'REPLACE INTO' ) &&
false !== strpos( $query, WC_Admin_Reports_Orders_Stats_Data_Store::TABLE_NAME )
false !== strpos( $query, OrdersStatsDataStore::TABLE_NAME )
) {
remove_filter( 'query', array( $this, 'filter_order_query' ) );
return "DESCRIBE $wpdb->posts"; // Execute any random query.

View File

@ -5,6 +5,8 @@
* @package WooCommerce Admin\Tests\API
*/
use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore;
/**
* WC Tests API Orders
*/
@ -80,6 +82,6 @@ class WC_Tests_API_Orders extends WC_REST_Unit_Test_Case {
clean_post_cache( $order->get_id() );
// Trigger an order sync on the refund which should handle the missing parent order.
$this->assertTrue( WC_Admin_Reports_Orders_Stats_Data_Store::sync_order( $refund->get_id() ) );
$this->assertTrue( OrdersStatsDataStore::sync_order( $refund->get_id() ) );
}
}

View File

@ -6,6 +6,8 @@
* @since 3.5.0
*/
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
/**
* Reports Customers REST API Test Class
*
@ -103,7 +105,7 @@ class WC_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
* @since 3.5.0
*/
public function test_update_registered_customer_with_bad_user_id() {
$result = WC_Admin_Reports_Customers_Data_Store::update_registered_customer( 2 );
$result = CustomersDataStore::update_registered_customer( 2 );
$this->assertFalse( $result );
}
@ -424,7 +426,7 @@ class WC_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
* Test that bad order params don't cause PHP errors when retrieving customers.
*/
public function test_customer_retrieval_from_order_bad_order() {
$this->assertFalse( WC_Admin_Reports_Customers_Data_Store::get_existing_customer_id_from_order( false ) );
$this->assertFalse( WC_Admin_Reports_Customers_Data_Store::get_or_create_customer_from_order( false ) );
$this->assertFalse( CustomersDataStore::get_existing_customer_id_from_order( false ) );
$this->assertFalse( CustomersDataStore::get_or_create_customer_from_order( false ) );
}
}

View File

@ -6,6 +6,8 @@
* @since 3.5.0
*/
use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore;
/**
* Reports Orders REST API Test Class
*
@ -69,7 +71,7 @@ class WC_Tests_API_Reports_Orders extends WC_REST_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$expected_customer_id = WC_Admin_Reports_Customers_Data_Store::get_customer_id_by_user_id( 1 );
$expected_customer_id = CustomersDataStore::get_customer_id_by_user_id( 1 );
$response = $this->server->dispatch( new WP_REST_Request( 'GET', $this->endpoint ) );
$reports = $response->get_data();

View File

@ -17,9 +17,9 @@ class WC_Helper_Reports {
*/
public static function reset_stats_dbs() {
global $wpdb;
$wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Orders_Stats_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Products_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Coupons_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . WC_Admin_Reports_Customers_Data_Store::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore::TABLE_NAME ); // @codingStandardsIgnoreLine.
$wpdb->query( "DELETE FROM $wpdb->prefix" . \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore::TABLE_NAME ); // @codingStandardsIgnoreLine.
}
}

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tests\Coupons-stats
*/
use \Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\DataStore as CouponsStatsDataStore;
/**
* Class WC_Tests_Reports_Coupons_Stats
*/
@ -56,7 +58,7 @@ class WC_Tests_Reports_Coupons_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Coupons_Stats_Data_Store();
$data_store = new CouponsStatsDataStore();
$start_time = date( 'Y-m-d 00:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d 23:59:59', $order->get_date_created()->getOffsetTimestamp() );
$args = array(

View File

@ -6,6 +6,7 @@
*/
use \Automattic\WooCommerce\Admin\WC_Admin_Report_CSV_Exporter;
use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore;
/**
* Class WC_Tests_Reports_Coupons
@ -58,7 +59,7 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Coupons_Data_Store();
$data_store = new CouponsDataStore();
$start_time = date( 'Y-m-d 00:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d 23:59:59', $order->get_date_created()->getOffsetTimestamp() );
$args = array(

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tests\Orders
*/
use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore;
/**
* Class WC_Tests_Reports_Orders_Stats
*/
@ -46,7 +48,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:59:59', $order->get_date_created()->getOffsetTimestamp() );
@ -189,7 +191,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:59:59', $order->get_date_created()->getOffsetTimestamp() );
@ -354,7 +356,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:59:59', $order->get_date_created()->getOffsetTimestamp() );
@ -643,7 +645,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
// Test for the current hour.
$current_hour_start = new DateTime();
@ -894,7 +896,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
// Tests for before & after set to current hour.
$current_hour_start = new DateTime();
@ -3938,7 +3940,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
// Tests for before & after set to current hour.
$now = new DateTime();
@ -4502,7 +4504,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
// Tests for before & after set to current hour.
$current_hour_start = new DateTime();
@ -5275,7 +5277,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
global $wpdb;
$res = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}wc_order_stats" );
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
// Tests for before & after set to current hour.
// (this sets minutes for current hour to 0, seconds are left as they arem e.g. 15:23:43 becomes 15:00:43).
@ -6002,7 +6004,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$product->set_regular_price( 25 );
$product->save();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
// All empty in the beginning.
$query_args = array(
@ -6113,7 +6115,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case {
$product->set_regular_price( 25 );
$product->save();
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
// All empty in the beginning.
$query_args = array(

View File

@ -6,6 +6,8 @@
* @todo Finish up unit testing to verify bug-free product reports.
*/
use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsDataStore;
/**
* Reports product stats tests class
*
@ -40,7 +42,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Products_Data_Store();
$data_store = new ProductsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() + HOUR_IN_SECONDS );
$args = array(
@ -117,7 +119,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Products_Data_Store();
$data_store = new ProductsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:00:00', $order_2->get_date_created()->getOffsetTimestamp() + HOUR_IN_SECONDS );
// Test retrieving the stats through the data store, default order by date/time desc.
@ -218,7 +220,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Products_Data_Store();
$data_store = new ProductsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() + HOUR_IN_SECONDS );
$args = array(
@ -299,7 +301,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Products_Data_Store();
$data_store = new ProductsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() + HOUR_IN_SECONDS );
$args = array(
@ -381,7 +383,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Products_Data_Store();
$data_store = new ProductsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() + HOUR_IN_SECONDS );
$args = array(

View File

@ -6,6 +6,8 @@
* @todo Finish up unit testing to verify bug-free order reports.
*/
use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore;
/**
* Class WC_Admin_Tests_Reports_Revenue_Stats
*/
@ -43,7 +45,7 @@ class WC_Admin_Tests_Reports_Revenue_Stats extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
// /reports/revenue/stats is mapped to Orders_Data_Store.
$data_store = new WC_Admin_Reports_Orders_Stats_Data_Store();
$data_store = new OrdersStatsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:59:59', $order->get_date_created()->getOffsetTimestamp() );

View File

@ -6,6 +6,8 @@
* @todo Finish up unit testing to verify bug-free order reports.
*/
use \Automattic\WooCommerce\Admin\API\Reports\Variations\DataStore as VariationsDataStore;
/**
* Reports order stats tests class.
*
@ -41,7 +43,7 @@ class WC_Tests_Reports_Variations extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Variations_Data_Store();
$data_store = new VariationsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() + HOUR_IN_SECONDS );
$args = array(
@ -110,7 +112,7 @@ class WC_Tests_Reports_Variations extends WC_Unit_Test_Case {
WC_Helper_Queue::run_all_pending();
$data_store = new WC_Admin_Reports_Variations_Data_Store();
$data_store = new VariationsDataStore();
$start_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() );
$end_time = date( 'Y-m-d H:00:00', $order->get_date_created()->getOffsetTimestamp() + HOUR_IN_SECONDS );
$args = array(