From 2752356c4d5fd1cfb94a094446d1ab09cc7ae173 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 29 Jul 2019 14:04:17 -0400 Subject: [PATCH 01/32] Load all classes with Composer's autoloader. --- plugins/woocommerce-admin/composer.json | 10 ++ plugins/woocommerce-admin/composer.lock | 7 +- .../includes/class-wc-admin-api-init.php | 111 ------------------ .../includes/class-wc-admin-events.php | 2 - .../includes/class-wc-admin-install.php | 2 - .../includes/class-wc-admin-loader.php | 16 +-- .../includes/class-wc-admin-reports-sync.php | 2 - .../export/class-wc-admin-report-exporter.php | 2 - .../class-wc-admin-activity-panel.php | 6 +- .../class-wc-admin-analytics-dashboard.php | 2 - .../analytics/class-wc-admin-analytics.php | 2 - .../class-wc-admin-onboarding-tasks.php | 2 - .../onboarding/class-wc-admin-onboarding.php | 13 +- .../class-wc-admin-notes-historical-data.php | 2 - .../class-wc-admin-notes-order-milestones.php | 2 - .../class-wc-admin-notes-welcome-message.php | 2 - ...wc-admin-notes-woo-subscriptions-notes.php | 2 - .../includes/notes/class-wc-admin-notes.php | 2 - .../woocommerce-admin/woocommerce-admin.php | 87 +++++++++----- 19 files changed, 79 insertions(+), 195 deletions(-) diff --git a/plugins/woocommerce-admin/composer.json b/plugins/woocommerce-admin/composer.json index 6a385364e2a..3e80f4cc30c 100644 --- a/plugins/woocommerce-admin/composer.json +++ b/plugins/woocommerce-admin/composer.json @@ -30,5 +30,15 @@ "phpcs": "Analyze code against the WordPress coding standards with PHP_CodeSniffer", "phpcbf": "Fix coding standards warnings/errors automatically with PHP Code Beautifier" } + }, + "autoload": { + "classmap": [ + "includes/" + ], + "files": [ + "includes/core-functions.php", + "includes/feature-config.php", + "includes/page-controller/page-controller-functions.php" + ] } } diff --git a/plugins/woocommerce-admin/composer.lock b/plugins/woocommerce-admin/composer.lock index 50811361dc2..6a39548b8d9 100644 --- a/plugins/woocommerce-admin/composer.lock +++ b/plugins/woocommerce-admin/composer.lock @@ -1,7 +1,7 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], "content-hash": "c4e5044bed13f99e535b3d692d12005c", @@ -1163,7 +1163,6 @@ "mock", "xunit" ], - "abandoned": true, "time": "2018-08-09T05:50:03+00:00" }, { @@ -1970,12 +1969,12 @@ "version": "1.2.1", "source": { "type": "git", - "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", "reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c", "reference": "f328bcafd97377e8e5e5d7b244d5ddbf301a3a5c", "shasum": "" }, diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php b/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php index c76cdad92dc..b2b26035d94 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php @@ -16,8 +16,6 @@ class WC_Admin_Api_Init { * Boostrap REST API. */ public function __construct() { - // Initialize classes. - add_action( 'plugins_loaded', array( $this, 'init_classes' ), 19 ); // Hook in data stores. add_filter( 'woocommerce_data_stores', array( 'WC_Admin_Api_Init', 'add_data_stores' ) ); // REST API extensions init. @@ -28,113 +26,10 @@ class WC_Admin_Api_Init { add_filter( 'woocommerce_rest_prepare_shop_order_object', array( __CLASS__, 'add_currency_symbol_to_order_response' ) ); } - /** - * Init classes. - */ - public function init_classes() { - // Interfaces. - require_once WC_ADMIN_ABSPATH . 'includes/interfaces/class-wc-admin-reports-data-store-interface.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-query.php'; - - // Common date time code. - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-interval.php'; - - // Exceptions. - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-parameter-exception.php'; - - // WC Class extensions. - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-order-trait.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-order.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-order-refund.php'; - - // Segmentation. - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-segmenting.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-orders-stats-segmenting.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-products-stats-segmenting.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-coupons-stats-segmenting.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-taxes-stats-segmenting.php'; - - // Query classes for reports. - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-revenue-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-orders-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-orders-stats-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-products-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-variations-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-products-stats-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-categories-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-taxes-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-taxes-stats-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-coupons-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-coupons-stats-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-downloads-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-downloads-stats-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-customers-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-customers-stats-query.php'; - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-reports-stock-stats-query.php'; - - // Data stores. - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-orders-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-products-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-variations-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-products-stats-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-categories-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-taxes-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-coupons-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-coupons-stats-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-downloads-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-customers-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-customers-stats-data-store.php'; - require_once WC_ADMIN_ABSPATH . 'includes/data-stores/class-wc-admin-reports-stock-stats-data-store.php'; - } - /** * Init REST API. */ public function rest_api_init() { - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-admin-notes-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-admin-note-action-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-coupons-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-data-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-data-countries-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-data-download-ips-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-leaderboards-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-orders-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-products-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-categories-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-variations-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-reviews-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-product-variations-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-setting-options-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-categories-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-coupons-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-coupons-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-customers-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-customers-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-downloads-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-downloads-files-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-downloads-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-import-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-orders-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-orders-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-products-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-variations-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-products-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-performance-indicators-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-taxes-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-taxes-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-stock-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-stock-stats-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-taxes-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-themes-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-customers-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-reports-export-controller.php'; - $controllers = array( 'WC_Admin_REST_Admin_Notes_Controller', 'WC_Admin_REST_Admin_Note_Action_Controller', @@ -176,10 +71,6 @@ class WC_Admin_Api_Init { ); if ( WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-onboarding-levels-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-onboarding-profile-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/api/class-wc-admin-rest-onboarding-plugins-controller.php'; - $controllers = array_merge( $controllers, array( @@ -425,5 +316,3 @@ class WC_Admin_Api_Init { return $response; } } - -new WC_Admin_Api_Init(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-events.php b/plugins/woocommerce-admin/includes/class-wc-admin-events.php index 851bb6d381a..2934174053a 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-events.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-events.php @@ -56,5 +56,3 @@ class WC_Admin_Events { WC_Admin_Notes_Mobile_App::possibly_add_mobile_app_note(); } } - -WC_Admin_Events::instance()->init(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-install.php b/plugins/woocommerce-admin/includes/class-wc-admin-install.php index f47cf4d861c..aa6185b7de0 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-install.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-install.php @@ -288,5 +288,3 @@ class WC_Admin_Install { } } } - -WC_Admin_Install::init(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php b/plugins/woocommerce-admin/includes/class-wc-admin-loader.php index 6e88c48d882..b7f7323a040 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-loader.php @@ -127,17 +127,13 @@ class WC_Admin_Loader { * Class loader for enabled WooCommerce Admin features/sections. */ public static function load_features() { - require_once WC_ADMIN_ABSPATH . 'includes/page-controller/class-wc-admin-page-controller.php'; - require_once WC_ADMIN_ABSPATH . 'includes/page-controller/page-controller-functions.php'; - $features = self::get_features(); foreach ( $features as $feature ) { - $feature = strtolower( $feature ); - $file = WC_ADMIN_FEATURES_PATH . $feature . '/class-wc-admin-' . $feature . '.php'; - if ( file_exists( $file ) ) { - require_once $file; - $feature = ucfirst( $feature ); - self::$classes[] = 'WC_Admin_' . $feature; + $feature = strtolower( str_replace( '-', '_', $feature ) ); + $feature = 'WC_Admin_' . ucwords( $feature, '_' ); + + if ( class_exists( $feature ) ) { + new $feature; } } } @@ -740,5 +736,3 @@ class WC_Admin_Loader { return apply_filters( 'wc_admin_get_user_data_fields', array() ); } } - -new WC_Admin_Loader(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php index c3f6e828e7a..4dbbd1f3d0e 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php @@ -797,5 +797,3 @@ class WC_Admin_Reports_Sync { wc_admin_record_tracks_event( 'delete_import_data_job_complete', array( 'type' => 'order' ) ); } } - -WC_Admin_Reports_Sync::init(); diff --git a/plugins/woocommerce-admin/includes/export/class-wc-admin-report-exporter.php b/plugins/woocommerce-admin/includes/export/class-wc-admin-report-exporter.php index cf592b29332..402d5630978 100644 --- a/plugins/woocommerce-admin/includes/export/class-wc-admin-report-exporter.php +++ b/plugins/woocommerce-admin/includes/export/class-wc-admin-report-exporter.php @@ -181,5 +181,3 @@ class WC_Admin_Report_Exporter { } } } - -WC_Admin_Report_Exporter::init(); diff --git a/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php b/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php index 3beb1e33562..8e75b5b8186 100644 --- a/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php +++ b/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php @@ -9,11 +9,11 @@ /** * Contains backend logic for the activity panel feature. */ -class WC_Admin_Activity_Panel { +class WC_Admin_Activity_Panels { /** * Class instance. * - * @var WC_Admin_Activity_Panel instance + * @var WC_Admin_Activity_Panels instance */ protected static $instance = null; @@ -69,5 +69,3 @@ class WC_Admin_Activity_Panel { WC_Admin_Notes_Settings_Notes::add_notes_for_settings_that_have_moved(); } } - -new WC_Admin_Activity_Panel(); diff --git a/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php b/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php index 1296079bd36..566e50c0a09 100644 --- a/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php +++ b/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php @@ -117,5 +117,3 @@ class WC_Admin_Analytics_Dashboard { array_unshift( $submenu['woocommerce'], $menu ); } } - -new WC_Admin_Analytics_Dashboard(); diff --git a/plugins/woocommerce-admin/includes/features/analytics/class-wc-admin-analytics.php b/plugins/woocommerce-admin/includes/features/analytics/class-wc-admin-analytics.php index 62fe08f28ac..2a629a5b3cf 100644 --- a/plugins/woocommerce-admin/includes/features/analytics/class-wc-admin-analytics.php +++ b/plugins/woocommerce-admin/includes/features/analytics/class-wc-admin-analytics.php @@ -152,5 +152,3 @@ class WC_Admin_Analytics { } } } - -new WC_Admin_Analytics(); diff --git a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding-tasks.php b/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding-tasks.php index 84784c58d1f..d30eab02046 100644 --- a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding-tasks.php +++ b/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding-tasks.php @@ -127,5 +127,3 @@ class WC_Admin_Onboarding_Tasks { return false; } } - -WC_Admin_Onboarding_Tasks::get_instance(); diff --git a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding.php b/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding.php index 6d621fa2c06..985d08d7b41 100644 --- a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding.php +++ b/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding.php @@ -49,7 +49,9 @@ class WC_Admin_Onboarding { return; } - $this->includes(); + // Include WC Admin Onboarding classes. + WC_Admin_Onboarding_Tasks::get_instance(); + add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after WC_Admin_Loader. add_action( 'woocommerce_theme_installed', array( $this, 'delete_themes_transient' ) ); add_action( 'after_switch_theme', array( $this, 'delete_themes_transient' ) ); @@ -59,13 +61,6 @@ class WC_Admin_Onboarding { add_filter( 'woocommerce_rest_prepare_themes', array( $this, 'add_uploaded_theme_data' ) ); } - /** - * Include WC Admin Onboarding classes. - */ - public function includes() { - require_once WC_ADMIN_FEATURES_PATH . 'onboarding/class-wc-admin-onboarding-tasks.php'; - } - /** * Returns true if the profiler should be displayed (not completed and not skipped). * @@ -386,5 +381,3 @@ class WC_Admin_Onboarding { $response = rest_do_request( $request ); } } - -WC_Admin_Onboarding::get_instance(); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-historical-data.php b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-historical-data.php index 030f6296a67..08d6e26bb5c 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-historical-data.php +++ b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-historical-data.php @@ -56,5 +56,3 @@ class WC_Admin_Notes_Historical_Data { $note->save(); } } - -new WC_Admin_Notes_Historical_Data(); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-order-milestones.php b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-order-milestones.php index e41779c5637..f963f3cae5e 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-order-milestones.php +++ b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-order-milestones.php @@ -319,5 +319,3 @@ class WC_Admin_Notes_Order_Milestones { $note->save(); } } - -new WC_Admin_Notes_Order_Milestones(); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-welcome-message.php b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-welcome-message.php index 0df1e0c860a..4623b43e179 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-welcome-message.php +++ b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-welcome-message.php @@ -48,5 +48,3 @@ class WC_Admin_Notes_Welcome_Message { $note->save(); } } - -new WC_Admin_Notes_Welcome_Message(); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php index 27a78d959a0..3ff9da04369 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php +++ b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php @@ -455,5 +455,3 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { } } } - -new WC_Admin_Notes_Woo_Subscriptions_Notes(); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes.php b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes.php index a211b680ea0..07423bbed1c 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes.php +++ b/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes.php @@ -181,5 +181,3 @@ class WC_Admin_Notes { } } } - -WC_Admin_Notes::init(); diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 25aa420e40b..4d430c9dbba 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -19,6 +19,51 @@ defined( 'ABSPATH' ) || exit; +/** + * Autoload packages. + * + * We want to fail gracefully if `composer install` has not been executed yet, so we are checking for the autoloader. + * If the autoloader is not present, let's log the failure and display a nice admin notice. + */ +$autoloader = __DIR__ . '/vendor/autoload.php'; +if ( is_readable( $autoloader ) ) { + require $autoloader; +} else { + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { + error_log( // phpcs:ignore + sprintf( + /* translators: 1: composer command. 2: plugin directory */ + esc_html__( 'Your installation of the WooCommerce Admin feature plugin is incomplete. Please run %1$s within the %2$s directory.', 'woocommerce-admin' ), + '`composer install`', + '`' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '`' + ) + ); + } + /** + * Outputs an admin notice if composer install has not been ran. + */ + add_action( + 'admin_notices', + function() { + ?> +
+

+ composer install', + '' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '' + ); + ?> +

+
+ init(); + new WC_Admin_Api_Init(); + WC_Admin_Report_Exporter::init(); // CRUD classes. - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-note.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes.php'; + WC_Admin_Notes::init(); // Admin note providers. // @todo These should be bundled in the features/ folder, but loading them from there currently has a load order issue. - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-new-sales-record.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-settings-notes.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-giving-feedback-notes.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-historical-data.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-order-milestones.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-mobile-app.php'; - require_once WC_ADMIN_ABSPATH . 'includes/notes/class-wc-admin-notes-welcome-message.php'; + new WC_Admin_Notes_Woo_Subscriptions_Notes(); + new WC_Admin_Notes_Historical_Data(); + new WC_Admin_Notes_Order_Milestones(); + new WC_Admin_Notes_Welcome_Message(); } /** @@ -181,11 +214,6 @@ class WC_Admin_Feature_Plugin { return $store_class; } - // Include our store class here instead of wc_admin_plugins_loaded() - // because ActionScheduler is hooked into `plugins_loaded` at a - // much higher priority. - require_once WC_ADMIN_ABSPATH . '/includes/class-wc-admin-actionscheduler-wppoststore.php'; - return 'WC_Admin_ActionScheduler_WPPostStore'; } @@ -210,7 +238,7 @@ class WC_Admin_Feature_Plugin { remove_action( 'admin_head', array( 'WC_Admin_Library', 'update_link_structure' ), 20 ); - require_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-loader.php'; + new WC_Admin_Loader(); add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ) ); add_action( 'admin_menu', array( $this, 'register_devdocs_page' ) ); @@ -293,9 +321,6 @@ class WC_Admin_Feature_Plugin { * @param array $features Array of feature slugs. */ public function replace_supported_features( $features ) { - if ( ! function_exists( 'wc_admin_get_feature_config' ) ) { - require_once WC_ADMIN_ABSPATH . '/includes/feature-config.php'; - } $feature_config = apply_filters( 'wc_admin_get_feature_config', wc_admin_get_feature_config() ); $features = array_keys( array_filter( $feature_config ) ); return $features; From 9c469a9f600732ac3475f20f23eb42e84db780b0 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 29 Jul 2019 16:44:09 -0600 Subject: [PATCH 02/32] Fix tests. --- .../woocommerce-admin/bin/generate-feature-config.php | 10 ++++++---- .../tests/api/reports-stock-stats.php | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/woocommerce-admin/bin/generate-feature-config.php b/plugins/woocommerce-admin/bin/generate-feature-config.php index 0fbe969a755..4dd23a67965 100644 --- a/plugins/woocommerce-admin/bin/generate-feature-config.php +++ b/plugins/woocommerce-admin/bin/generate-feature-config.php @@ -23,12 +23,14 @@ if ( 'core' !== $phase ) { $write = "features as $feature => $bool ) { - $write .= "\t\t'{$feature}' => " . ( $bool ? 'true' : 'false' ) . ",\n"; + $write .= "\t\t\t'{$feature}' => " . ( $bool ? 'true' : 'false' ) . ",\n"; } - $write .= "\t);\n"; + $write .= "\t\t);\n"; + $write .= "\t}\n"; $write .= "}\n"; $config_file = fopen( 'includes/feature-config.php', 'w' ); diff --git a/plugins/woocommerce-admin/tests/api/reports-stock-stats.php b/plugins/woocommerce-admin/tests/api/reports-stock-stats.php index a4e0e95d54e..a670839c2ae 100644 --- a/plugins/woocommerce-admin/tests/api/reports-stock-stats.php +++ b/plugins/woocommerce-admin/tests/api/reports-stock-stats.php @@ -94,6 +94,14 @@ class WC_Tests_API_Reports_Stock_Stats extends WC_REST_Unit_Test_Case { $backorder_stock->set_stock_status( 'onbackorder' ); $backorder_stock->save(); + // Clear caches + delete_transient( 'wc_admin_stock_count_lowstock' ); + delete_transient( 'wc_admin_stock_count_outofstock' ); + delete_transient( 'wc_admin_stock_count_onbackorder' ); + delete_transient( 'wc_admin_stock_count_lowstock' ); + delete_transient( 'wc_admin_stock_count_instock' ); + delete_transient( 'wc_admin_product_count' ); + $request = new WP_REST_Request( 'GET', $this->endpoint ); $response = $this->server->dispatch( $request ); $reports = $response->get_data(); From fab3d8e2cf50d8c3ad728d311013c9dfd1857caa Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 30 Jul 2019 14:05:25 -0600 Subject: [PATCH 03/32] Always run composer install in CI builds. --- plugins/woocommerce-admin/bin/travis.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/woocommerce-admin/bin/travis.sh b/plugins/woocommerce-admin/bin/travis.sh index bd11a7fe063..c4f9f1076c1 100755 --- a/plugins/woocommerce-admin/bin/travis.sh +++ b/plugins/woocommerce-admin/bin/travis.sh @@ -2,11 +2,12 @@ # usage: travis.sh before|after if [ $1 == 'before' ]; then - + cd "$WP_CORE_DIR/wp-content/plugins/woocommerce-admin/" if [[ ${RUN_PHPCS} == 1 ]]; then - cd "$WP_CORE_DIR/wp-content/plugins/woocommerce-admin/" - # This can (currently) only run for PHP 7.1+ composer install + else + npm run build:feature-config + composer install --no-dev fi fi From 54d0768892aa138188c49be77c9038ff395eadf1 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 31 Jul 2019 11:24:01 -0600 Subject: [PATCH 04/32] PSR-4ify WC_Admin_Order class. --- plugins/woocommerce-admin/composer.json | 5 ++++- .../includes/class-wc-admin-reports-sync.php | 2 ++ .../WC_Admin_Order.php} | 13 ++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-order.php => src/WC_Admin_Order.php} (83%) diff --git a/plugins/woocommerce-admin/composer.json b/plugins/woocommerce-admin/composer.json index 3e80f4cc30c..2e531d72cd1 100644 --- a/plugins/woocommerce-admin/composer.json +++ b/plugins/woocommerce-admin/composer.json @@ -39,6 +39,9 @@ "includes/core-functions.php", "includes/feature-config.php", "includes/page-controller/page-controller-functions.php" - ] + ], + "psr-4": { + "Automattic\\WooCommerce\\Admin\\": "src/" + } } } diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php index 4dbbd1f3d0e..521166d6952 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php @@ -7,6 +7,8 @@ defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\WC_Admin_Order; + /** * WC_Admin_Reports_Sync Class. */ diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-order.php b/plugins/woocommerce-admin/src/WC_Admin_Order.php similarity index 83% rename from plugins/woocommerce-admin/includes/class-wc-admin-order.php rename to plugins/woocommerce-admin/src/WC_Admin_Order.php index 705b82b3f19..4a10514b95e 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-order.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Order.php @@ -7,16 +7,18 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin; + defined( 'ABSPATH' ) || exit; /** * WC_Admin_Order class. */ -class WC_Admin_Order extends WC_Order { +class WC_Admin_Order extends \WC_Order { /** * Order traits. */ - use WC_Admin_Order_Trait; + use \WC_Admin_Order_Trait; /** * Holds refund amounts and quantities for the order. @@ -42,8 +44,9 @@ class WC_Admin_Order extends WC_Order { * @return string */ public static function order_class_name( $classname, $order_type, $order_id ) { + // @todo - Only substitute class when necessary (during sync). if ( 'WC_Order' === $classname ) { - return 'WC_Admin_Order'; + return '\Automattic\WooCommerce\Admin\WC_Admin_Order'; } else { return $classname; } @@ -55,7 +58,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 \WC_Admin_Reports_Customers_Data_Store::get_or_create_customer_from_order( $this ); } /** @@ -64,7 +67,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 \WC_Admin_Reports_Orders_Stats_Data_Store::is_returning_customer( $this ); } /** From 8602c03671d4e2e0e87bfe22fcf38859fb07239c Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 31 Jul 2019 11:30:49 -0600 Subject: [PATCH 05/32] PSR-4 ify WC_Admin_Order_Refund class. --- .../includes/class-wc-admin-reports-sync.php | 1 + .../WC_Admin_Order_Refund.php} | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-order-refund.php => src/WC_Admin_Order_Refund.php} (81%) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php index 521166d6952..6e7ba758d50 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php @@ -8,6 +8,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\WC_Admin_Order; +use \Automattic\WooCommerce\Admin\WC_Admin_Order_Refund; /** * WC_Admin_Reports_Sync Class. diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-order-refund.php b/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php similarity index 81% rename from plugins/woocommerce-admin/includes/class-wc-admin-order-refund.php rename to plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php index f2450ec34ba..bb914a17158 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-order-refund.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php @@ -7,16 +7,18 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin; + defined( 'ABSPATH' ) || exit; /** * WC_Admin_Order_Refund class. */ -class WC_Admin_Order_Refund extends WC_Order_Refund { +class WC_Admin_Order_Refund extends \WC_Order_Refund { /** * Order traits. */ - use WC_Admin_Order_Trait; + use \WC_Admin_Order_Trait; /** * Add filter(s) required to hook WC_Admin_Order_Refund class to substitute WC_Order_Refund. @@ -35,8 +37,9 @@ class WC_Admin_Order_Refund extends WC_Order_Refund { * @return string */ public static function order_class_name( $classname, $order_type, $order_id ) { + // @todo - Only substitute class when necessary (during sync). if ( 'WC_Order_Refund' === $classname ) { - return 'WC_Admin_Order_Refund'; + return '\Automattic\WooCommerce\Admin\WC_Admin_Order_Refund'; } else { return $classname; } @@ -54,7 +57,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 \WC_Admin_Reports_Customers_Data_Store::get_or_create_customer_from_order( $parent_order ); } /** From 24555e0e02ac5d05a55acfe0e3ff2f14b8aff89f Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 31 Jul 2019 11:42:21 -0600 Subject: [PATCH 06/32] PSR-4 ify the WC_Admin_Order_Trait class. --- plugins/woocommerce-admin/src/WC_Admin_Order.php | 2 +- plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php | 2 +- .../WC_Admin_Order_Trait.php} | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-order-trait.php => src/WC_Admin_Order_Trait.php} (98%) diff --git a/plugins/woocommerce-admin/src/WC_Admin_Order.php b/plugins/woocommerce-admin/src/WC_Admin_Order.php index 4a10514b95e..e1b3bc4eee9 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Order.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Order.php @@ -18,7 +18,7 @@ class WC_Admin_Order extends \WC_Order { /** * Order traits. */ - use \WC_Admin_Order_Trait; + use \Automattic\WooCommerce\Admin\WC_Admin_Order_Trait; /** * Holds refund amounts and quantities for the order. diff --git a/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php b/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php index bb914a17158..1c12478e835 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php @@ -18,7 +18,7 @@ class WC_Admin_Order_Refund extends \WC_Order_Refund { /** * Order traits. */ - use \WC_Admin_Order_Trait; + use \Automattic\WooCommerce\Admin\WC_Admin_Order_Trait; /** * Add filter(s) required to hook WC_Admin_Order_Refund class to substitute WC_Order_Refund. diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-order-trait.php b/plugins/woocommerce-admin/src/WC_Admin_Order_Trait.php similarity index 98% rename from plugins/woocommerce-admin/includes/class-wc-admin-order-trait.php rename to plugins/woocommerce-admin/src/WC_Admin_Order_Trait.php index bee2b37b6c0..759e2a612cc 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-order-trait.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Order_Trait.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin; + defined( 'ABSPATH' ) || exit; /** From 782bbe8891833949c2757e2781a1cae6c7cbbc25 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 31 Jul 2019 12:16:56 -0600 Subject: [PATCH 07/32] PSR-4ify the WC_Admin_Page_Controller class. --- .../includes/page-controller/page-controller-functions.php | 2 ++ .../WC_Admin_Page_Controller.php} | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) rename plugins/woocommerce-admin/{includes/page-controller/class-wc-admin-page-controller.php => src/WC_Admin_Page_Controller.php} (99%) diff --git a/plugins/woocommerce-admin/includes/page-controller/page-controller-functions.php b/plugins/woocommerce-admin/includes/page-controller/page-controller-functions.php index 1f55296953d..af227e5baf7 100644 --- a/plugins/woocommerce-admin/includes/page-controller/page-controller-functions.php +++ b/plugins/woocommerce-admin/includes/page-controller/page-controller-functions.php @@ -5,6 +5,8 @@ * @package Woocommerce Admin */ +use Automattic\WooCommerce\Admin\WC_Admin_Page_Controller; + /** * Connect an existing page to WooCommerce Admin. * Passthrough to WC_Admin_Page_Controller::connect_page(). diff --git a/plugins/woocommerce-admin/includes/page-controller/class-wc-admin-page-controller.php b/plugins/woocommerce-admin/src/WC_Admin_Page_Controller.php similarity index 99% rename from plugins/woocommerce-admin/includes/page-controller/class-wc-admin-page-controller.php rename to plugins/woocommerce-admin/src/WC_Admin_Page_Controller.php index cf6f64df70e..856bc838b11 100644 --- a/plugins/woocommerce-admin/includes/page-controller/class-wc-admin-page-controller.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Page_Controller.php @@ -5,6 +5,10 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin; + +defined( 'ABSPATH' ) || exit; + /** * WC_Admin_Page_Controller */ @@ -257,7 +261,7 @@ class WC_Admin_Page_Controller { ); // Tabs that have sections as well. - $wc_emails = WC_Emails::instance(); + $wc_emails = \WC_Emails::instance(); $wc_email_ids = array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ); $tabs_with_sections = apply_filters( From ca687692057a27c11a2a2757fe59035c7cc97d7e Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 31 Jul 2019 13:47:32 -0600 Subject: [PATCH 08/32] Update admin notes classes to PSR-4. --- ...c-admin-rest-admin-note-action-controller.php | 2 ++ ...lass-wc-admin-rest-admin-notes-controller.php | 3 +++ .../class-wc-admin-notes-data-store.php | 2 ++ .../class-wc-admin-activity-panel.php | 3 +++ .../Notes/WC_Admin_Note.php} | 10 ++++++---- .../Notes/WC_Admin_Notes.php} | 16 +++++++++------- .../WC_Admin_Notes_Giving_Feedback_Notes.php} | 4 +++- .../Notes/WC_Admin_Notes_Historical_Data.php} | 6 ++++-- .../Notes/WC_Admin_Notes_Mobile_App.php} | 4 +++- .../Notes/WC_Admin_Notes_New_Sales_Record.php} | 4 +++- .../Notes/WC_Admin_Notes_Order_Milestones.php} | 2 ++ .../Notes/WC_Admin_Notes_Settings_Notes.php} | 4 +++- .../Notes/WC_Admin_Notes_Welcome_Message.php} | 7 +++++-- .../WC_Admin_Notes_Woo_Subscriptions_Notes.php} | 16 +++++++++------- .../woocommerce-admin/tests/api/admin-notes.php | 3 +++ .../helpers/class-wc-helper-admin-notes.php | 2 ++ plugins/woocommerce-admin/woocommerce-admin.php | 6 ++++++ 17 files changed, 68 insertions(+), 26 deletions(-) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-note.php => src/Notes/WC_Admin_Note.php} (98%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes.php => src/Notes/WC_Admin_Notes.php} (93%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-giving-feedback-notes.php => src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php} (95%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-historical-data.php => src/Notes/WC_Admin_Notes_Historical_Data.php} (90%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-mobile-app.php => src/Notes/WC_Admin_Notes_Mobile_App.php} (94%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-new-sales-record.php => src/Notes/WC_Admin_Notes_New_Sales_Record.php} (96%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-order-milestones.php => src/Notes/WC_Admin_Notes_Order_Milestones.php} (99%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-settings-notes.php => src/Notes/WC_Admin_Notes_Settings_Notes.php} (93%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-welcome-message.php => src/Notes/WC_Admin_Notes_Welcome_Message.php} (90%) rename plugins/woocommerce-admin/{includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php => src/Notes/WC_Admin_Notes_Woo_Subscriptions_Notes.php} (97%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-note-action-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-note-action-controller.php index 9a7e84c0996..45a6b77072a 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-note-action-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-note-action-controller.php @@ -9,6 +9,8 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; + /** * REST API Admin Note Action controller class. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-notes-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-notes-controller.php index 46189e4aaf7..b5379ee548d 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-notes-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-notes-controller.php @@ -9,6 +9,9 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; + /** * REST API Admin Notes controller class. * diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php index 130c6da904e..ad00b9b335d 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php @@ -7,6 +7,8 @@ defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Note; + /** * WC Admin Note Data Store (Custom Tables) */ diff --git a/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php b/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php index 8e75b5b8186..b612a3c70d1 100644 --- a/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php +++ b/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php @@ -6,6 +6,9 @@ * @package Woocommerce Admin */ +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Settings_Notes; + /** * Contains backend logic for the activity panel feature. */ diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-note.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Note.php similarity index 98% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-note.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Note.php index 0c71d404c6f..5e520d50abd 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-note.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Note.php @@ -7,12 +7,14 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** * WC_Admin_Note class. */ -class WC_Admin_Note extends WC_Data { +class WC_Admin_Note extends \WC_Data { // Note types. const E_WC_ADMIN_NOTE_ERROR = 'error'; // used for presenting error conditions. @@ -53,7 +55,7 @@ class WC_Admin_Note extends WC_Data { 'title' => '-', 'content' => '-', 'icon' => 'info', - 'content_data' => new stdClass(), + 'content_data' => new \stdClass(), 'status' => self::E_WC_ADMIN_NOTE_UNACTIONED, 'source' => 'woocommerce', 'date_created' => '0000-00-00 00:00:00', @@ -76,7 +78,7 @@ class WC_Admin_Note extends WC_Data { $this->set_object_read( true ); } - $this->data_store = WC_Data_Store::load( 'admin-note' ); + $this->data_store = \WC_Data_Store::load( 'admin-note' ); if ( $this->get_id() > 0 ) { $this->data_store->read( $this ); } @@ -391,7 +393,7 @@ class WC_Admin_Note extends WC_Data { $allowed_type = false; // Make sure $content_data is stdClass Object or an array. - if ( ! ( $content_data instanceof stdClass ) ) { + if ( ! ( $content_data instanceof \stdClass ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note content_data prop must be an instance of stdClass.', 'woocommerce-admin' ) ); } diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php similarity index 93% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php index 07423bbed1c..2da6e6bef4b 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php @@ -5,6 +5,8 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\Notes; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -58,7 +60,7 @@ class WC_Admin_Notes { * @return array Array of arrays. */ public static function get_notes( $context = 'edit', $args = array() ) { - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $raw_notes = $data_store->get_notes( $args ); $notes = array(); foreach ( (array) $raw_notes as $raw_note ) { @@ -91,7 +93,7 @@ class WC_Admin_Notes { if ( false !== $note_id ) { try { return new WC_Admin_Note( $note_id ); - } catch ( Exception $e ) { + } catch ( \Exception $e ) { return false; } } @@ -106,7 +108,7 @@ class WC_Admin_Notes { * @return int */ public static function get_notes_count( $type = array(), $status = array() ) { - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); return $data_store->get_notes_count( $type, $status ); } @@ -116,7 +118,7 @@ class WC_Admin_Notes { * @param string $name Name to search for. */ public static function delete_notes_with_name( $name ) { - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $note_ids = $data_store->get_notes_with_name( $name ); foreach ( (array) $note_ids as $note_id ) { $note = new WC_Admin_Note( $note_id ); @@ -128,13 +130,13 @@ class WC_Admin_Notes { * Clear note snooze status if the reminder date has been reached. */ public static function unsnooze_notes() { - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $raw_notes = $data_store->get_notes( array( 'status' => array( WC_Admin_Note::E_WC_ADMIN_NOTE_SNOOZED ), ) ); - $now = new DateTime(); + $now = new \DateTime(); foreach ( $raw_notes as $raw_note ) { $note = new WC_Admin_Note( $raw_note ); @@ -170,7 +172,7 @@ class WC_Admin_Notes { * Clears all queued actions. */ public static function clear_queued_actions() { - $store = ActionScheduler::store(); + $store = \ActionScheduler::store(); if ( is_a( $store, 'WC_Admin_ActionScheduler_WPPostStore' ) ) { // If we're using our data store, call our bespoke deletion method. diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-giving-feedback-notes.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php similarity index 95% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-giving-feedback-notes.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php index 83e1e2add84..bec83a58332 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-giving-feedback-notes.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Giving_Feedback_Notes.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** @@ -26,7 +28,7 @@ class WC_Admin_Notes_Giving_Feedback_Notes { protected static function possibly_add_admin_giving_feedback_note() { $name = 'wc-admin-store-notice-giving-feedback'; - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); // We already have this note? Then exit, we're done. $note_ids = $data_store->get_notes_with_name( $name ); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-historical-data.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php similarity index 90% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-historical-data.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php index 08d6e26bb5c..7e6a67ae447 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-historical-data.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** @@ -19,13 +21,13 @@ class WC_Admin_Notes_Historical_Data { * Creates a note for regenerating historical data. */ public static function add_note() { - $is_upgrading = get_option( WC_Admin_Install::VERSION_OPTION ); + $is_upgrading = get_option( \WC_Admin_Install::VERSION_OPTION ); if ( $is_upgrading ) { return; } // First, see if orders exist and if we've already created this kind of note so we don't do it again. - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); $orders = wc_get_orders( array( diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-mobile-app.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Mobile_App.php similarity index 94% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-mobile-app.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Mobile_App.php index bf935f3e1c5..c2e7aeab6b1 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-mobile-app.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Mobile_App.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** @@ -38,7 +40,7 @@ class WC_Admin_Notes_Mobile_App { return; } - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); // We already have this note? Then exit, we're done. $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-new-sales-record.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_New_Sales_Record.php similarity index 96% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-new-sales-record.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_New_Sales_Record.php index e73f37a211e..283b883e325 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-new-sales-record.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_New_Sales_Record.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** @@ -24,7 +26,7 @@ class WC_Admin_Notes_New_Sales_Record { * @return floatval */ public static function sum_sales_for_date( $date ) { - $order_query = new WC_Order_Query( array( 'date_created' => $date ) ); + $order_query = new \WC_Order_Query( array( 'date_created' => $date ) ); $orders = $order_query->get_orders(); $total = 0; diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-order-milestones.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Order_Milestones.php similarity index 99% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-order-milestones.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Order_Milestones.php index f963f3cae5e..ba389b286ab 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-order-milestones.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Order_Milestones.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-settings-notes.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Settings_Notes.php similarity index 93% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-settings-notes.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Settings_Notes.php index 06c4b1a8c65..31caf056253 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-settings-notes.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Settings_Notes.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** @@ -26,7 +28,7 @@ class WC_Admin_Notes_Settings_Notes { protected static function possibly_add_notice_setting_moved_note() { $name = 'wc-admin-store-notice-setting-moved'; - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); // We already have this note? Then exit, we're done. $note_ids = $data_store->get_notes_with_name( $name ); diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-welcome-message.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php similarity index 90% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-welcome-message.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php index 4623b43e179..945cdcffde5 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-welcome-message.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php @@ -7,7 +7,10 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; + /** * WC_Admin_Notes_Welcome_Message. */ @@ -19,13 +22,13 @@ class WC_Admin_Notes_Welcome_Message { */ public static function add_welcome_note() { // Check if plugin is upgrading if yes then don't create this note. - $is_upgrading = get_option( WC_Admin_Install::VERSION_OPTION ); + $is_upgrading = get_option( \WC_Admin_Install::VERSION_OPTION ); if ( $is_upgrading ) { return; } // See if we've already created this kind of note so we don't do it again. - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); if ( ! empty( $note_ids ) ) { return; diff --git a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Woo_Subscriptions_Notes.php similarity index 97% rename from plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php rename to plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Woo_Subscriptions_Notes.php index 3ff9da04369..a97af6e4ae2 100644 --- a/plugins/woocommerce-admin/includes/notes/class-wc-admin-notes-woo-subscriptions-notes.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Woo_Subscriptions_Notes.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\Notes; + defined( 'ABSPATH' ) || exit; /** @@ -104,7 +106,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { */ public function check_connection() { if ( ! $this->is_connected() ) { - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $note_ids = $data_store->get_notes_with_name( self::CONNECTION_NOTE_NAME ); if ( ! empty( $note_ids ) ) { // We already have a connection note. Exit early. @@ -122,7 +124,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { * @return bool */ public function is_connected() { - $auth = WC_Helper_Options::get( 'auth' ); + $auth = \WC_Helper_Options::get( 'auth' ); return ( ! empty( $auth['access_token'] ) ); } @@ -136,7 +138,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { return false; } - $auth = WC_Helper_Options::get( 'auth' ); + $auth = \WC_Helper_Options::get( 'auth' ); return absint( $auth['site_id'] ); } @@ -154,7 +156,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { $product_ids = array(); if ( $this->is_connected() ) { - $subscriptions = WC_Helper::get_subscriptions(); + $subscriptions = \WC_Helper::get_subscriptions(); foreach ( (array) $subscriptions as $subscription ) { if ( in_array( $site_id, $subscription['connections'], true ) ) { @@ -216,7 +218,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { public function prune_inactive_subscription_notes() { $active_product_ids = $this->get_subscription_active_product_ids(); - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $note_ids = $data_store->get_notes_with_name( self::SUBSCRIPTION_NOTE_NAME ); foreach ( (array) $note_ids as $note_id ) { @@ -239,7 +241,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { public function find_note_for_product_id( $product_id ) { $product_id = intval( $product_id ); - $data_store = WC_Data_Store::load( 'admin-note' ); + $data_store = \WC_Data_Store::load( 'admin-note' ); $note_ids = $data_store->get_notes_with_name( self::SUBSCRIPTION_NOTE_NAME ); foreach ( (array) $note_ids as $note_id ) { $note = WC_Admin_Notes::get_note( $note_id ); @@ -418,7 +420,7 @@ class WC_Admin_Notes_Woo_Subscriptions_Notes { $this->prune_inactive_subscription_notes(); - $subscriptions = WC_Helper::get_subscriptions(); + $subscriptions = \WC_Helper::get_subscriptions(); $active_product_ids = $this->get_subscription_active_product_ids(); foreach ( (array) $subscriptions as $subscription ) { diff --git a/plugins/woocommerce-admin/tests/api/admin-notes.php b/plugins/woocommerce-admin/tests/api/admin-notes.php index e6124dc735d..b46b9bb7001 100644 --- a/plugins/woocommerce-admin/tests/api/admin-notes.php +++ b/plugins/woocommerce-admin/tests/api/admin-notes.php @@ -5,6 +5,9 @@ * @package WooCommerce\Tests\API */ +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; + /** * Class WC_Tests_API_Admin_Notes */ diff --git a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-admin-notes.php b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-admin-notes.php index 059871d4f78..3a384fdc502 100644 --- a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-admin-notes.php +++ b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-admin-notes.php @@ -5,6 +5,8 @@ * @package WooCommerce\Tests\Framework\Helpers */ +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note; + /** * Class WC_Helper_Admin_Notes. * diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 4d430c9dbba..48e7e9a7646 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -19,6 +19,12 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; +use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes; + /** * Autoload packages. * From ce7267b198a5edaaf74fbaec45d371f68ecc447d Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 1 Aug 2019 10:49:55 -0600 Subject: [PATCH 09/32] PSR-4ify the report exporter classes. --- ...c-admin-rest-reports-export-controller.php | 2 ++ .../WC_Admin_Report_CSV_Exporter.php} | 24 ++++++++++--------- .../WC_Admin_Report_Exporter.php} | 4 +++- .../class-wc-tests-reports-coupons.php | 2 ++ .../woocommerce-admin/woocommerce-admin.php | 1 + 5 files changed, 21 insertions(+), 12 deletions(-) rename plugins/woocommerce-admin/{includes/export/class-wc-admin-report-csv-exporter.php => src/WC_Admin_Report_CSV_Exporter.php} (88%) rename plugins/woocommerce-admin/{includes/export/class-wc-admin-report-exporter.php => src/WC_Admin_Report_Exporter.php} (97%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-export-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-export-controller.php index a9a9980d9dd..4291136bc5b 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-export-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-export-controller.php @@ -11,6 +11,8 @@ defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; + /** * Reports Export controller. * diff --git a/plugins/woocommerce-admin/includes/export/class-wc-admin-report-csv-exporter.php b/plugins/woocommerce-admin/src/WC_Admin_Report_CSV_Exporter.php similarity index 88% rename from plugins/woocommerce-admin/includes/export/class-wc-admin-report-csv-exporter.php rename to plugins/woocommerce-admin/src/WC_Admin_Report_CSV_Exporter.php index 887952edcb9..683778e0adb 100644 --- a/plugins/woocommerce-admin/includes/export/class-wc-admin-report-csv-exporter.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Report_CSV_Exporter.php @@ -5,6 +5,8 @@ * @package WooCommerce/Export */ +namespace Automattic\WooCommerce\Admin; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -19,7 +21,7 @@ if ( ! class_exists( 'WC_CSV_Batch_Exporter', false ) ) { /** * WC_Admin_Report_CSV_Exporter Class. */ -class WC_Admin_Report_CSV_Exporter extends WC_CSV_Batch_Exporter { +class WC_Admin_Report_CSV_Exporter extends \WC_CSV_Batch_Exporter { /** * Type of report being exported. * @@ -102,15 +104,15 @@ class WC_Admin_Report_CSV_Exporter extends WC_CSV_Batch_Exporter { */ protected function map_report_controller() { $controller_map = array( - 'products' => 'WC_Admin_REST_Reports_Products_Controller', - 'variations' => 'WC_Admin_REST_Reports_Variations_Controller', - 'orders' => 'WC_Admin_REST_Reports_Orders_Controller', - 'categories' => 'WC_Admin_REST_Reports_Categories_Controller', - 'taxes' => 'WC_Admin_REST_Reports_Taxes_Controller', - 'coupons' => 'WC_Admin_REST_Reports_Coupons_Controller', - 'stock' => 'WC_Admin_REST_Reports_Stock_Controller', - 'downloads' => 'WC_Admin_REST_Reports_Downloads_Controller', - 'customers' => 'WC_Admin_REST_Reports_Customers_Controller', + 'products' => '\WC_Admin_REST_Reports_Products_Controller', + 'variations' => '\WC_Admin_REST_Reports_Variations_Controller', + 'orders' => '\WC_Admin_REST_Reports_Orders_Controller', + 'categories' => '\WC_Admin_REST_Reports_Categories_Controller', + 'taxes' => '\WC_Admin_REST_Reports_Taxes_Controller', + 'coupons' => '\WC_Admin_REST_Reports_Coupons_Controller', + 'stock' => '\WC_Admin_REST_Reports_Stock_Controller', + 'downloads' => '\WC_Admin_REST_Reports_Downloads_Controller', + 'customers' => '\WC_Admin_REST_Reports_Customers_Controller', ); if ( isset( $controller_map[ $this->report_type ] ) ) { @@ -175,7 +177,7 @@ class WC_Admin_Report_CSV_Exporter extends WC_CSV_Batch_Exporter { * Prepare data for export. */ public function prepare_data_to_export() { - $request = new WP_REST_Request( 'GET', "/wc/v4/reports/{$this->report_type}" ); + $request = new \WP_REST_Request( 'GET', "/wc/v4/reports/{$this->report_type}" ); $params = $this->controller->get_collection_params(); $defaults = array(); diff --git a/plugins/woocommerce-admin/includes/export/class-wc-admin-report-exporter.php b/plugins/woocommerce-admin/src/WC_Admin_Report_Exporter.php similarity index 97% rename from plugins/woocommerce-admin/includes/export/class-wc-admin-report-exporter.php rename to plugins/woocommerce-admin/src/WC_Admin_Report_Exporter.php index 402d5630978..a9d91d0bfb0 100644 --- a/plugins/woocommerce-admin/includes/export/class-wc-admin-report-exporter.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Report_Exporter.php @@ -5,6 +5,8 @@ * @package WooCommerce/Export */ +namespace Automattic\WooCommerce\Admin; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -93,7 +95,7 @@ class WC_Admin_Report_Exporter { $report_batch_args = array( $export_id, $report_type, $report_args ); if ( 0 < $num_batches ) { - WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, self::REPORT_EXPORT_ACTION, $report_batch_args ); + \WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, self::REPORT_EXPORT_ACTION, $report_batch_args ); } return $total_rows; diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php index df46ff152ef..173e9b2b1cb 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php @@ -5,6 +5,8 @@ * @package WooCommerce\Tests\Coupons */ +use \Automattic\WooCommerce\Admin\WC_Admin_Report_CSV_Exporter; + /** * Class WC_Tests_Reports_Coupons */ diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 48e7e9a7646..a3d16a8aeb9 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -24,6 +24,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes; +use Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; /** * Autoload packages. From 55400474eee476bd568a0699dc1c48d079691711 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 1 Aug 2019 12:17:08 -0600 Subject: [PATCH 10/32] PSR-4ify the feature loading classes. --- ...s-wc-admin-rest-onboarding-profile-controller.php | 2 ++ .../includes/class-wc-admin-loader.php | 2 +- .../Features/WC_Admin_Activity_Panels.php} | 2 ++ .../Features/WC_Admin_Analytics.php} | 2 ++ .../Features/WC_Admin_Analytics_Dashboard.php} | 2 ++ .../Features/WC_Admin_Onboarding.php} | 12 +++++++----- .../Features/WC_Admin_Onboarding_Tasks.php} | 2 ++ 7 files changed, 18 insertions(+), 6 deletions(-) rename plugins/woocommerce-admin/{includes/features/activity-panel/class-wc-admin-activity-panel.php => src/Features/WC_Admin_Activity_Panels.php} (97%) rename plugins/woocommerce-admin/{includes/features/analytics/class-wc-admin-analytics.php => src/Features/WC_Admin_Analytics.php} (98%) rename plugins/woocommerce-admin/{includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php => src/Features/WC_Admin_Analytics_Dashboard.php} (98%) rename plugins/woocommerce-admin/{includes/features/onboarding/class-wc-admin-onboarding.php => src/Features/WC_Admin_Onboarding.php} (96%) rename plugins/woocommerce-admin/{includes/features/onboarding/class-wc-admin-onboarding-tasks.php => src/Features/WC_Admin_Onboarding_Tasks.php} (98%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php index 2633bccf08a..09acb7a202a 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php @@ -9,6 +9,8 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\Features\WC_Admin_Onboarding; + /** * Onboarding Profile controller. * diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php b/plugins/woocommerce-admin/includes/class-wc-admin-loader.php index b7f7323a040..90814cb2757 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-loader.php @@ -130,7 +130,7 @@ class WC_Admin_Loader { $features = self::get_features(); foreach ( $features as $feature ) { $feature = strtolower( str_replace( '-', '_', $feature ) ); - $feature = 'WC_Admin_' . ucwords( $feature, '_' ); + $feature = 'Automattic\WooCommerce\Admin\Features\WC_Admin_' . ucwords( $feature, '_' ); if ( class_exists( $feature ) ) { new $feature; diff --git a/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php b/plugins/woocommerce-admin/src/Features/WC_Admin_Activity_Panels.php similarity index 97% rename from plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php rename to plugins/woocommerce-admin/src/Features/WC_Admin_Activity_Panels.php index b612a3c70d1..33142fbb23e 100644 --- a/plugins/woocommerce-admin/includes/features/activity-panel/class-wc-admin-activity-panel.php +++ b/plugins/woocommerce-admin/src/Features/WC_Admin_Activity_Panels.php @@ -6,6 +6,8 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin\Features; + use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Settings_Notes; diff --git a/plugins/woocommerce-admin/includes/features/analytics/class-wc-admin-analytics.php b/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics.php similarity index 98% rename from plugins/woocommerce-admin/includes/features/analytics/class-wc-admin-analytics.php rename to plugins/woocommerce-admin/src/Features/WC_Admin_Analytics.php index 2a629a5b3cf..7b8cebc41a7 100644 --- a/plugins/woocommerce-admin/includes/features/analytics/class-wc-admin-analytics.php +++ b/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics.php @@ -6,6 +6,8 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin\Features; + /** * Contains backend logic for the Analytics feature. */ diff --git a/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php b/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics_Dashboard.php similarity index 98% rename from plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php rename to plugins/woocommerce-admin/src/Features/WC_Admin_Analytics_Dashboard.php index 566e50c0a09..1ac55134353 100644 --- a/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php +++ b/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics_Dashboard.php @@ -6,6 +6,8 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin\Features; + /** * Contains backend logic for the dashboard feature. */ diff --git a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding.php b/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php similarity index 96% rename from plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding.php rename to plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php index 985d08d7b41..662aff86b5f 100644 --- a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding.php +++ b/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php @@ -6,6 +6,8 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin\Features; + /** * Contains backend logic for the onboarding profile and checklist feature. */ @@ -228,9 +230,9 @@ class WC_Admin_Onboarding { } foreach ( $themes as $theme ) { - $directory = new RecursiveDirectoryIterator( $theme->theme_root . '/' . $theme->stylesheet ); - $iterator = new RecursiveIteratorIterator( $directory ); - $files = new RegexIterator( $iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH ); + $directory = new \RecursiveDirectoryIterator( $theme->theme_root . '/' . $theme->stylesheet ); + $iterator = new \RecursiveIteratorIterator( $directory ); + $files = new \RegexIterator( $iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH ); foreach ( $files as $file ) { $content = file_get_contents( $file[0] ); @@ -361,14 +363,14 @@ class WC_Admin_Onboarding { */ public static function reset_onboarding() { if ( - ! WC_Admin_Loader::is_admin_page() || + ! \WC_Admin_Loader::is_admin_page() || ! isset( $_GET['reset_onboarding'] ) || // WPCS: CSRF ok. 1 !== absint( $_GET['reset_onboarding'] ) // WPCS: CSRF ok. ) { return; } - $request = new WP_REST_Request( 'POST', '/wc-admin/v1/onboarding/profile' ); + $request = new \WP_REST_Request( 'POST', '/wc-admin/v1/onboarding/profile' ); $request->set_headers( array( 'content-type' => 'application/json' ) ); $request->set_body( wp_json_encode( diff --git a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding-tasks.php b/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding_Tasks.php similarity index 98% rename from plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding-tasks.php rename to plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding_Tasks.php index d30eab02046..e6f5d3438c9 100644 --- a/plugins/woocommerce-admin/includes/features/onboarding/class-wc-admin-onboarding-tasks.php +++ b/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding_Tasks.php @@ -6,6 +6,8 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin\Features; + /** * Contains the logic for completing onboarding tasks. */ From e509e51552c3708ef3d9844a9150d5288048b4ae Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 1 Aug 2019 16:06:00 -0600 Subject: [PATCH 11/32] PSR-4ify the sync class. --- ...c-admin-rest-reports-import-controller.php | 2 + .../src/WC_Admin_Report_Exporter.php | 2 +- .../WC_Admin_Reports_Sync.php} | 37 +++++++++---------- plugins/woocommerce-admin/tests/api-init.php | 2 + .../tests/api/reports-import.php | 2 + .../woocommerce-admin/tests/batch-queue.php | 2 + .../tests/queue-priority.php | 2 + .../woocommerce-admin/woocommerce-admin.php | 1 + 8 files changed, 30 insertions(+), 20 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-sync.php => src/WC_Admin_Reports_Sync.php} (95%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-import-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-import-controller.php index 1958d17aa39..a1812d66d94 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-import-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-import-controller.php @@ -9,6 +9,8 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; + /** * Reports Imports controller. * diff --git a/plugins/woocommerce-admin/src/WC_Admin_Report_Exporter.php b/plugins/woocommerce-admin/src/WC_Admin_Report_Exporter.php index a9d91d0bfb0..3330dc4da1e 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Report_Exporter.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Report_Exporter.php @@ -95,7 +95,7 @@ class WC_Admin_Report_Exporter { $report_batch_args = array( $export_id, $report_type, $report_args ); if ( 0 < $num_batches ) { - \WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, self::REPORT_EXPORT_ACTION, $report_batch_args ); + WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, self::REPORT_EXPORT_ACTION, $report_batch_args ); } return $total_rows; diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php b/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php similarity index 95% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php rename to plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php index 6e7ba758d50..c70e9fc44c7 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-sync.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php @@ -5,10 +5,9 @@ * @package WooCommerce Admin/Classes */ -defined( 'ABSPATH' ) || exit; +namespace Automattic\WooCommerce\Admin; -use \Automattic\WooCommerce\Admin\WC_Admin_Order; -use \Automattic\WooCommerce\Admin\WC_Admin_Order_Refund; +defined( 'ABSPATH' ) || exit; /** * WC_Admin_Reports_Sync Class. @@ -127,7 +126,7 @@ class WC_Admin_Reports_Sync { */ public static function regenerate_report_data( $days, $skip_existing ) { if ( self::is_importing() ) { - return new WP_Error( 'wc_admin_import_in_progress', __( 'An import is already in progress. Please allow the previous import to complete before beginning a new one.', 'woocommerce-admin' ) ); + return new \WP_Error( 'wc_admin_import_in_progress', __( 'An import is already in progress. Please allow the previous import to complete before beginning a new one.', 'woocommerce-admin' ) ); } self::reset_import_stats( $days, $skip_existing ); @@ -154,7 +153,7 @@ class WC_Admin_Reports_Sync { $previous_import_date = get_option( 'wc_admin_imported_from_date' ); $current_import_date = $days ? date( 'Y-m-d 00:00:00', time() - ( DAY_IN_SECONDS * $days ) ) : -1; - if ( ! $previous_import_date || -1 === $current_import_date || new DateTime( $previous_import_date ) > new DateTime( $current_import_date ) ) { + if ( ! $previous_import_date || -1 === $current_import_date || new \DateTime( $previous_import_date ) > new \DateTime( $current_import_date ) ) { update_option( 'wc_admin_imported_from_date', $current_import_date ); } } @@ -208,7 +207,7 @@ class WC_Admin_Reports_Sync { * Clears all queued actions. */ public static function clear_queued_actions() { - $store = ActionScheduler::store(); + $store = \ActionScheduler::store(); if ( is_a( $store, 'WC_Admin_ActionScheduler_WPPostStore' ) ) { // If we're using our data store, call our bespoke deletion method. @@ -314,11 +313,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(); + \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(); } /** @@ -457,10 +456,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 ), + \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 ), ) ); @@ -630,7 +629,7 @@ class WC_Admin_Reports_Sync { add_action( 'pre_user_query', array( __CLASS__, 'exclude_existing_customers_from_query' ) ); } - $customer_query = new WP_User_Query( $query_args ); + $customer_query = new \WP_User_Query( $query_args ); remove_action( 'pre_user_query', array( __CLASS__, 'exclude_existing_customers_from_query' ) ); @@ -707,7 +706,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 ); + \WC_Admin_Reports_Customers_Data_Store::update_registered_customer( $customer_id ); } $imported_count = get_option( 'wc_admin_import_customers_count', 0 ); @@ -752,7 +751,7 @@ class WC_Admin_Reports_Sync { ); foreach ( $customer_ids as $customer_id ) { - WC_Admin_Reports_Customers_Data_Store::delete_customer( $customer_id ); + \WC_Admin_Reports_Customers_Data_Store::delete_customer( $customer_id ); } wc_admin_record_tracks_event( 'delete_import_data_job_complete', array( 'type' => 'customer' ) ); @@ -794,7 +793,7 @@ class WC_Admin_Reports_Sync { ); foreach ( $order_ids as $order_id ) { - WC_Admin_Reports_Orders_Stats_Data_Store::delete_order( $order_id ); + \WC_Admin_Reports_Orders_Stats_Data_Store::delete_order( $order_id ); } wc_admin_record_tracks_event( 'delete_import_data_job_complete', array( 'type' => 'order' ) ); diff --git a/plugins/woocommerce-admin/tests/api-init.php b/plugins/woocommerce-admin/tests/api-init.php index 29163dbedb1..dd5eace6682 100644 --- a/plugins/woocommerce-admin/tests/api-init.php +++ b/plugins/woocommerce-admin/tests/api-init.php @@ -6,6 +6,8 @@ * @since 3.5.0 */ +use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; + /** * Class WC_Tests_API_Init */ diff --git a/plugins/woocommerce-admin/tests/api/reports-import.php b/plugins/woocommerce-admin/tests/api/reports-import.php index 21b46108022..3b717bcf4d7 100644 --- a/plugins/woocommerce-admin/tests/api/reports-import.php +++ b/plugins/woocommerce-admin/tests/api/reports-import.php @@ -5,6 +5,8 @@ * @package WooCommerce\Tests\API */ +use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; + /** * Reports Import REST API Test Class * diff --git a/plugins/woocommerce-admin/tests/batch-queue.php b/plugins/woocommerce-admin/tests/batch-queue.php index 266cfa975f6..925c7702b09 100644 --- a/plugins/woocommerce-admin/tests/batch-queue.php +++ b/plugins/woocommerce-admin/tests/batch-queue.php @@ -6,6 +6,8 @@ * @since 3.5.0 */ +use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; + /** * Reports Generation Batch Queue Test Class * diff --git a/plugins/woocommerce-admin/tests/queue-priority.php b/plugins/woocommerce-admin/tests/queue-priority.php index 683b0ad3a0b..c1ecf264221 100644 --- a/plugins/woocommerce-admin/tests/queue-priority.php +++ b/plugins/woocommerce-admin/tests/queue-priority.php @@ -6,6 +6,8 @@ * @since 3.5.0 */ +use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; + /** * Reports Generation Batch Queue Prioritizaion Test Class * diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index a3d16a8aeb9..9d64d89574b 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -25,6 +25,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes; use Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; +use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; /** * Autoload packages. From 416ab0965303d28b7ef736059b6e04ab7b252600 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 1 Aug 2019 17:03:40 -0600 Subject: [PATCH 12/32] PSR-4ify the action schedule post store subclass. --- plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php | 2 +- .../WC_Admin_ActionScheduler_WPPostStore.php} | 6 ++++-- plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php | 2 +- plugins/woocommerce-admin/tests/queue-priority.php | 1 + plugins/woocommerce-admin/woocommerce-admin.php | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-actionscheduler-wppoststore.php => src/WC_Admin_ActionScheduler_WPPostStore.php} (86%) diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php index 2da6e6bef4b..741864e8269 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php @@ -174,7 +174,7 @@ class WC_Admin_Notes { public static function clear_queued_actions() { $store = \ActionScheduler::store(); - if ( is_a( $store, 'WC_Admin_ActionScheduler_WPPostStore' ) ) { + if ( is_a( $store, 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore' ) ) { // If we're using our data store, call our bespoke deletion method. $action_types = array( self::UNSNOOZE_HOOK ); $store->clear_pending_wcadmin_actions( $action_types ); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-actionscheduler-wppoststore.php b/plugins/woocommerce-admin/src/WC_Admin_ActionScheduler_WPPostStore.php similarity index 86% rename from plugins/woocommerce-admin/includes/class-wc-admin-actionscheduler-wppoststore.php rename to plugins/woocommerce-admin/src/WC_Admin_ActionScheduler_WPPostStore.php index b3bfe6178d6..f2348e9b956 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-actionscheduler-wppoststore.php +++ b/plugins/woocommerce-admin/src/WC_Admin_ActionScheduler_WPPostStore.php @@ -5,10 +5,12 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin; + /** * Class WC Admin Action Scheduler Store. */ -class WC_Admin_ActionScheduler_WPPostStore extends ActionScheduler_wpPostStore { +class WC_Admin_ActionScheduler_WPPostStore extends \ActionScheduler_wpPostStore { /** * Action scheduler job priority (lower numbers are claimed first). */ @@ -24,7 +26,7 @@ class WC_Admin_ActionScheduler_WPPostStore extends ActionScheduler_wpPostStore { * @param DateTime $scheduled_date Action schedule. * @return array Post data array for usage in wp_insert_post(). */ - protected function create_post_array( ActionScheduler_Action $action, DateTime $scheduled_date = null ) { + protected function create_post_array( \ActionScheduler_Action $action, \DateTime $scheduled_date = null ) { $postdata = parent::create_post_array( $action, $scheduled_date ); if ( 0 === strpos( $postdata['post_title'], 'wc-admin_' ) ) { diff --git a/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php b/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php index c70e9fc44c7..286640e7eba 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php @@ -209,7 +209,7 @@ class WC_Admin_Reports_Sync { public static function clear_queued_actions() { $store = \ActionScheduler::store(); - if ( is_a( $store, 'WC_Admin_ActionScheduler_WPPostStore' ) ) { + if ( is_a( $store, 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore' ) ) { // If we're using our data store, call our bespoke deletion method. $action_types = array( self::QUEUE_BATCH_ACTION, diff --git a/plugins/woocommerce-admin/tests/queue-priority.php b/plugins/woocommerce-admin/tests/queue-priority.php index c1ecf264221..4821d6b0255 100644 --- a/plugins/woocommerce-admin/tests/queue-priority.php +++ b/plugins/woocommerce-admin/tests/queue-priority.php @@ -7,6 +7,7 @@ */ use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; +use Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_wpPostStore; /** * Reports Generation Batch Queue Prioritizaion Test Class diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 9d64d89574b..9ae8445c79f 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -222,7 +222,7 @@ class WC_Admin_Feature_Plugin { return $store_class; } - return 'WC_Admin_ActionScheduler_WPPostStore'; + return 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore'; } /** From f871c960703d904711fab124546662f181a406e4 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Thu, 1 Aug 2019 22:25:13 -0600 Subject: [PATCH 13/32] PSR-4ify the theme upgrader subclasses. --- .../includes/api/class-wc-admin-rest-themes-controller.php | 3 +++ .../WC_Admin_Theme_Upgrader.php} | 4 +++- .../WC_Admin_Theme_Upgrader_Skin.php} | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-theme-upgrader.php => src/WC_Admin_Theme_Upgrader.php} (95%) rename plugins/woocommerce-admin/{includes/class-wc-admin-theme-upgrader-skin.php => src/WC_Admin_Theme_Upgrader_Skin.php} (83%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php index df7782cfcb7..9f5e2812bdb 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php @@ -9,6 +9,9 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader; +use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader_Skin; + /** * Themes controller. * diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-theme-upgrader.php b/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader.php similarity index 95% rename from plugins/woocommerce-admin/includes/class-wc-admin-theme-upgrader.php rename to plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader.php index 6c9b9a64b43..ea67c9067a2 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-theme-upgrader.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader.php @@ -5,12 +5,14 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin; + defined( 'ABSPATH' ) || exit; /** * WC_Admin_Theme_Upgrader Class. */ -class WC_Admin_Theme_Upgrader extends Theme_Upgrader { +class WC_Admin_Theme_Upgrader extends \Theme_Upgrader { /** * Install a theme package. * diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-theme-upgrader-skin.php b/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader_Skin.php similarity index 83% rename from plugins/woocommerce-admin/includes/class-wc-admin-theme-upgrader-skin.php rename to plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader_Skin.php index bf533c39767..9de76267de4 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-theme-upgrader-skin.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader_Skin.php @@ -5,12 +5,14 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin; + defined( 'ABSPATH' ) || exit; /** * WC_Admin_Theme_Upgrader_Skin Class. */ -class WC_Admin_Theme_Upgrader_Skin extends Theme_Upgrader_Skin { +class WC_Admin_Theme_Upgrader_Skin extends \Theme_Upgrader_Skin { /** * Hide the skin header display. */ From 9d2757f1b28fdc7e7fd050e4c801dada99840bf7 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Fri, 2 Aug 2019 12:05:18 -0600 Subject: [PATCH 14/32] PSR4-ify the API init class and Notes controllers. --- .../API/Notes/Actions/Controller.php} | 12 ++++++----- .../API/Notes/Controller.php} | 20 ++++++++++--------- .../API/WC_Admin_Api_Init.php} | 12 ++++++----- .../woocommerce-admin/woocommerce-admin.php | 1 + 4 files changed, 26 insertions(+), 19 deletions(-) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-admin-note-action-controller.php => src/API/Notes/Actions/Controller.php} (92%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-admin-notes-controller.php => src/API/Notes/Controller.php} (94%) rename plugins/woocommerce-admin/{includes/class-wc-admin-api-init.php => src/API/WC_Admin_Api_Init.php} (97%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-note-action-controller.php b/plugins/woocommerce-admin/src/API/Notes/Actions/Controller.php similarity index 92% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-note-action-controller.php rename to plugins/woocommerce-admin/src/API/Notes/Actions/Controller.php index 45a6b77072a..d3b390fb20b 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-note-action-controller.php +++ b/plugins/woocommerce-admin/src/API/Notes/Actions/Controller.php @@ -7,9 +7,11 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Notes\Actions; + defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; /** * REST API Admin Note Action controller class. @@ -17,7 +19,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; * @package WooCommerce/API * @extends WC_REST_CRUD_Controller */ -class WC_Admin_REST_Admin_Note_Action_Controller extends WC_Admin_REST_Admin_Notes_Controller { +class Controller extends \Automattic\WooCommerce\Admin\API\Notes\Controller { /** * Register the routes for admin notes. @@ -38,7 +40,7 @@ class WC_Admin_REST_Admin_Note_Action_Controller extends WC_Admin_REST_Admin_Not ), ), array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'trigger_note_action' ), // @todo - double check these permissions for taking note actions. 'permission_callback' => array( $this, 'get_item_permissions_check' ), @@ -58,7 +60,7 @@ class WC_Admin_REST_Admin_Note_Action_Controller extends WC_Admin_REST_Admin_Not $note = WC_Admin_Notes::get_note( $request->get_param( 'note_id' ) ); if ( ! $note ) { - return new WP_Error( + return new \WP_Error( 'woocommerce_admin_notes_invalid_id', __( 'Sorry, there is no resource with that ID.', 'woocommerce-admin' ), array( 'status' => 404 ) @@ -77,7 +79,7 @@ class WC_Admin_REST_Admin_Note_Action_Controller extends WC_Admin_REST_Admin_Not } if ( ! $triggered_action ) { - return new WP_Error( + return new \WP_Error( 'woocommerce_admin_note_action_invalid_id', __( 'Sorry, there is no resource with that ID.', 'woocommerce-admin' ), array( 'status' => 404 ) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-notes-controller.php b/plugins/woocommerce-admin/src/API/Notes/Controller.php similarity index 94% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-notes-controller.php rename to plugins/woocommerce-admin/src/API/Notes/Controller.php index b5379ee548d..612c453b76f 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-admin-notes-controller.php +++ b/plugins/woocommerce-admin/src/API/Notes/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Notes; + defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Note; @@ -18,7 +20,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; * @package WooCommerce/API * @extends WC_REST_CRUD_Controller */ -class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { +class Controller extends \WC_REST_CRUD_Controller { /** * Endpoint namespace. @@ -43,7 +45,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -63,12 +65,12 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { ), ), array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_items_permissions_check' ), ), @@ -87,7 +89,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { $note = WC_Admin_Notes::get_note( $request->get_param( 'id' ) ); if ( ! $note ) { - return new WP_Error( + return new \WP_Error( 'woocommerce_admin_notes_invalid_id', __( 'Sorry, there is no resource with that ID.', 'woocommerce-admin' ), array( 'status' => 404 ) @@ -170,7 +172,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { */ public function get_item_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -184,7 +186,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { */ public function get_items_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -200,7 +202,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { $note = WC_Admin_Notes::get_note( $request->get_param( 'id' ) ); if ( ! $note ) { - return new WP_Error( + return new \WP_Error( 'woocommerce_admin_notes_invalid_id', __( 'Sorry, there is no resource with that ID.', 'woocommerce-admin' ), array( 'status' => 404 ) @@ -233,7 +235,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller { */ public function update_items_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php similarity index 97% rename from plugins/woocommerce-admin/includes/class-wc-admin-api-init.php rename to plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php index b2b26035d94..fbc9be7f915 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-api-init.php +++ b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php @@ -5,6 +5,8 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -17,10 +19,10 @@ class WC_Admin_Api_Init { */ public function __construct() { // Hook in data stores. - add_filter( 'woocommerce_data_stores', array( 'WC_Admin_Api_Init', 'add_data_stores' ) ); + add_filter( 'woocommerce_data_stores', array( __CLASS__, 'add_data_stores' ) ); // REST API extensions init. add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); - add_filter( 'rest_endpoints', array( 'WC_Admin_Api_Init', 'filter_rest_endpoints' ), 10, 1 ); + add_filter( 'rest_endpoints', array( __CLASS__, 'filter_rest_endpoints' ), 10, 1 ); // Add currency symbol to orders endpoint response. add_filter( 'woocommerce_rest_prepare_shop_order_object', array( __CLASS__, 'add_currency_symbol_to_order_response' ) ); @@ -31,8 +33,8 @@ class WC_Admin_Api_Init { */ public function rest_api_init() { $controllers = array( - 'WC_Admin_REST_Admin_Notes_Controller', - 'WC_Admin_REST_Admin_Note_Action_Controller', + 'Automattic\WooCommerce\Admin\API\Notes\Controller', + 'Automattic\WooCommerce\Admin\API\Notes\Actions\Controller', 'WC_Admin_REST_Coupons_Controller', 'WC_Admin_REST_Customers_Controller', 'WC_Admin_REST_Data_Controller', @@ -70,7 +72,7 @@ class WC_Admin_Api_Init { 'WC_Admin_REST_Themes_Controller', ); - if ( WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { + if ( \WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { $controllers = array_merge( $controllers, array( diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 9ae8445c79f..2e350b8fdaa 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -26,6 +26,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes; use Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; +use Automattic\WooCommerce\Admin\API\WC_Admin_Api_Init; /** * Autoload packages. From 25ac10e5d531199e0b10e49b464c94966e343d21 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Fri, 2 Aug 2019 12:05:38 -0600 Subject: [PATCH 15/32] Fix namespaces for Notes classes used in installation routine. --- plugins/woocommerce-admin/includes/class-wc-admin-install.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-install.php b/plugins/woocommerce-admin/includes/class-wc-admin-install.php index aa6185b7de0..57fb60b7481 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-install.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-install.php @@ -7,6 +7,9 @@ defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; + /** * WC_Admin_Install Class. */ From fe3dc0dd7cb6c402d8f8c896d89a2c99cff891e0 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Fri, 2 Aug 2019 12:17:59 -0600 Subject: [PATCH 16/32] Reorganize API classes. --- .../src/API/{Notes/Actions/Controller.php => NoteActions.php} | 4 ++-- .../src/API/{Notes/Controller.php => Notes.php} | 4 ++-- plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) rename plugins/woocommerce-admin/src/API/{Notes/Actions/Controller.php => NoteActions.php} (96%) rename plugins/woocommerce-admin/src/API/{Notes/Controller.php => Notes.php} (99%) diff --git a/plugins/woocommerce-admin/src/API/Notes/Actions/Controller.php b/plugins/woocommerce-admin/src/API/NoteActions.php similarity index 96% rename from plugins/woocommerce-admin/src/API/Notes/Actions/Controller.php rename to plugins/woocommerce-admin/src/API/NoteActions.php index d3b390fb20b..42c72770246 100644 --- a/plugins/woocommerce-admin/src/API/Notes/Actions/Controller.php +++ b/plugins/woocommerce-admin/src/API/NoteActions.php @@ -7,7 +7,7 @@ * @package WooCommerce Admin/API */ -namespace Automattic\WooCommerce\Admin\API\Notes\Actions; +namespace Automattic\WooCommerce\Admin\API; defined( 'ABSPATH' ) || exit; @@ -19,7 +19,7 @@ use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; * @package WooCommerce/API * @extends WC_REST_CRUD_Controller */ -class Controller extends \Automattic\WooCommerce\Admin\API\Notes\Controller { +class NoteActions extends Notes { /** * Register the routes for admin notes. diff --git a/plugins/woocommerce-admin/src/API/Notes/Controller.php b/plugins/woocommerce-admin/src/API/Notes.php similarity index 99% rename from plugins/woocommerce-admin/src/API/Notes/Controller.php rename to plugins/woocommerce-admin/src/API/Notes.php index 612c453b76f..21bbbac03a0 100644 --- a/plugins/woocommerce-admin/src/API/Notes/Controller.php +++ b/plugins/woocommerce-admin/src/API/Notes.php @@ -7,7 +7,7 @@ * @package WooCommerce Admin/API */ -namespace Automattic\WooCommerce\Admin\API\Notes; +namespace Automattic\WooCommerce\Admin\API; defined( 'ABSPATH' ) || exit; @@ -20,7 +20,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; * @package WooCommerce/API * @extends WC_REST_CRUD_Controller */ -class Controller extends \WC_REST_CRUD_Controller { +class Notes extends \WC_REST_CRUD_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php index fbc9be7f915..47b1481e6a1 100644 --- a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php +++ b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php @@ -33,8 +33,8 @@ class WC_Admin_Api_Init { */ public function rest_api_init() { $controllers = array( - 'Automattic\WooCommerce\Admin\API\Notes\Controller', - 'Automattic\WooCommerce\Admin\API\Notes\Actions\Controller', + 'Automattic\WooCommerce\Admin\API\Notes', + 'Automattic\WooCommerce\Admin\API\NoteActions', 'WC_Admin_REST_Coupons_Controller', 'WC_Admin_REST_Customers_Controller', 'WC_Admin_REST_Data_Controller', From b71d8c23c8194c593aa5867ad6aae643fb680fd7 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Fri, 2 Aug 2019 12:54:09 -0600 Subject: [PATCH 17/32] PSR4-ify core API subclasses. --- .../API/Coupons.php} | 4 +- .../API/Customers.php} | 4 +- .../API/Data.php} | 4 +- .../API/DataCountries.php} | 4 +- .../API/DataDownloadIPs.php} | 8 +- .../API/Leaderboards.php} | 16 ++-- .../API/OnboardingLevels.php} | 6 +- .../API/OnboardingPlugins.php} | 30 ++++--- .../API/OnboardingProfile.php} | 16 ++-- .../API/Orders.php} | 4 +- .../API/ProductCategories.php} | 4 +- .../API/ProductReviews.php} | 4 +- .../API/ProductVariations.php} | 4 +- .../API/Products.php} | 4 +- .../API/SettingOptions.php} | 4 +- .../API/Taxes.php} | 4 +- .../API/Themes.php} | 14 +-- .../src/API/WC_Admin_Api_Init.php | 88 +++++++++---------- .../tests/api/onboarding-profile.php | 4 +- 19 files changed, 131 insertions(+), 95 deletions(-) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-coupons-controller.php => src/API/Coupons.php} (95%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-customers-controller.php => src/API/Customers.php} (89%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-data-controller.php => src/API/Data.php} (90%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-data-countries-controller.php => src/API/DataCountries.php} (78%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-data-download-ips-controller.php => src/API/DataDownloadIPs.php} (91%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-leaderboards-controller.php => src/API/Leaderboards.php} (96%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-onboarding-levels-controller.php => src/API/OnboardingLevels.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-onboarding-plugins-controller.php => src/API/OnboardingPlugins.php} (88%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-onboarding-profile-controller.php => src/API/OnboardingProfile.php} (94%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-orders-controller.php => src/API/Orders.php} (95%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-product-categories-controller.php => src/API/ProductCategories.php} (76%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-product-reviews-controller.php => src/API/ProductReviews.php} (91%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-product-variations-controller.php => src/API/ProductVariations.php} (96%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-products-controller.php => src/API/Products.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-setting-options-controller.php => src/API/SettingOptions.php} (77%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-taxes-controller.php => src/API/Taxes.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-themes-controller.php => src/API/Themes.php} (89%) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-coupons-controller.php b/plugins/woocommerce-admin/src/API/Coupons.php similarity index 95% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-coupons-controller.php rename to plugins/woocommerce-admin/src/API/Coupons.php index dfde5b3ae8a..5107077bf45 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-coupons-controller.php +++ b/plugins/woocommerce-admin/src/API/Coupons.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Coupons_Controller */ -class WC_Admin_REST_Coupons_Controller extends WC_REST_Coupons_Controller { +class Coupons extends \WC_REST_Coupons_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-customers-controller.php b/plugins/woocommerce-admin/src/API/Customers.php similarity index 89% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-customers-controller.php rename to plugins/woocommerce-admin/src/API/Customers.php index d7cc898c812..ee76e5fd42e 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-customers-controller.php +++ b/plugins/woocommerce-admin/src/API/Customers.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_Admin_REST_Reports_Customers_Controller */ -class WC_Admin_REST_Customers_Controller extends WC_Admin_REST_Reports_Customers_Controller { +class Customers extends \WC_Admin_REST_Reports_Customers_Controller { /** * Route base. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-controller.php b/plugins/woocommerce-admin/src/API/Data.php similarity index 90% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-controller.php rename to plugins/woocommerce-admin/src/API/Data.php index d83006728ce..729ca36b073 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-controller.php +++ b/plugins/woocommerce-admin/src/API/Data.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Data_Controller extends WC_REST_Data_Controller { +class Data extends \WC_REST_Data_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-countries-controller.php b/plugins/woocommerce-admin/src/API/DataCountries.php similarity index 78% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-countries-controller.php rename to plugins/woocommerce-admin/src/API/DataCountries.php index f4f7ea0bda8..4916f67cbd5 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-countries-controller.php +++ b/plugins/woocommerce-admin/src/API/DataCountries.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Countries_Controller */ -class WC_Admin_REST_Data_Countries_Controller extends WC_REST_Data_Countries_Controller { +class DataCountries extends \WC_REST_Data_Countries_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-download-ips-controller.php b/plugins/woocommerce-admin/src/API/DataDownloadIPs.php similarity index 91% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-download-ips-controller.php rename to plugins/woocommerce-admin/src/API/DataDownloadIPs.php index 8f264f0d417..b1a5a2c0563 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-data-download-ips-controller.php +++ b/plugins/woocommerce-admin/src/API/DataDownloadIPs.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller { +class DataDownloadIPs extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -41,7 +43,7 @@ class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), @@ -70,7 +72,7 @@ class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller ) ); } else { - return new WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce-admin' ), array( 'status' => 400 ) ); + return new \WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce-admin' ), array( 'status' => 400 ) ); } $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-leaderboards-controller.php b/plugins/woocommerce-admin/src/API/Leaderboards.php similarity index 96% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-leaderboards-controller.php rename to plugins/woocommerce-admin/src/API/Leaderboards.php index 514be3adb95..2d6839b52d2 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-leaderboards-controller.php +++ b/plugins/woocommerce-admin/src/API/Leaderboards.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { +class Leaderboards extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -39,7 +41,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -53,7 +55,7 @@ class WC_Admin_REST_Leaderboards_Controller extends WC_REST_Data_Controller { '/' . $this->rest_base . '/allowed', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_allowed_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), @@ -71,7 +73,7 @@ class WC_Admin_REST_Leaderboards_Controller 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 \WC_Admin_Reports_Coupons_Data_Store(); $coupons_data = $per_page > 0 ? $coupons_data_store->get_data( array( 'orderby' => 'orders_count', @@ -137,7 +139,7 @@ class WC_Admin_REST_Leaderboards_Controller 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 \WC_Admin_Reports_Categories_Data_Store(); $categories_data = $per_page > 0 ? $categories_data_store->get_data( array( 'orderby' => 'items_sold', @@ -203,7 +205,7 @@ class WC_Admin_REST_Leaderboards_Controller 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 \WC_Admin_Reports_Customers_Data_Store(); $customers_data = $per_page > 0 ? $customers_data_store->get_data( array( 'orderby' => 'total_spend', @@ -267,7 +269,7 @@ class WC_Admin_REST_Leaderboards_Controller 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 \WC_Admin_Reports_Products_Data_Store(); $products_data = $per_page > 0 ? $products_data_store->get_data( array( 'orderby' => 'items_sold', diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-levels-controller.php b/plugins/woocommerce-admin/src/API/OnboardingLevels.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-levels-controller.php rename to plugins/woocommerce-admin/src/API/OnboardingLevels.php index 29622add12e..8a16c9bafdf 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-levels-controller.php +++ b/plugins/woocommerce-admin/src/API/OnboardingLevels.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Onboarding_Levels_Controller extends WC_REST_Data_Controller { +class OnboardingLevels extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -39,7 +41,7 @@ class WC_Admin_REST_Onboarding_Levels_Controller extends WC_REST_Data_Controller '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-plugins-controller.php b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php similarity index 88% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-plugins-controller.php rename to plugins/woocommerce-admin/src/API/OnboardingPlugins.php index b222447b6f0..e999d9d232d 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-plugins-controller.php +++ b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controller { +class OnboardingPlugins extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -39,7 +41,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base . '/install', array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'install_plugin' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), ), @@ -52,7 +54,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base . '/activate', array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'activate_plugin' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), ), @@ -65,7 +67,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base . '/connect-jetpack', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'connect_jetpack' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), ), @@ -108,7 +110,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle */ public function update_item_permissions_check( $request ) { if ( ! current_user_can( 'install_plugins' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot manage plugins.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot manage plugins.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } @@ -136,7 +138,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle $allowed_plugins = $this->get_allowed_plugins(); $plugin = sanitize_title_with_dashes( $request['plugin'] ); if ( ! in_array( $plugin, array_keys( $allowed_plugins ), true ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); } require_once ABSPATH . 'wp-admin/includes/plugin.php'; @@ -170,14 +172,14 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle ); if ( is_wp_error( $api ) ) { - return new WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); + return new \WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); } - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); + $upgrader = new \Plugin_Upgrader( new \Automatic_Upgrader_Skin() ); $result = $upgrader->install( $api->download_link ); if ( is_wp_error( $result ) || is_null( $result ) ) { - return new WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); + return new \WP_Error( 'woocommerce_rest_plugin_install', __( 'The requested plugin could not be installed.', 'woocommerce-admin' ), 500 ); } return array( @@ -197,7 +199,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle $allowed_plugins = $this->get_allowed_plugins(); $plugin = sanitize_title_with_dashes( $request['plugin'] ); if ( ! in_array( $plugin, array_keys( $allowed_plugins ), true ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); } require_once ABSPATH . 'wp-admin/includes/plugin.php'; @@ -207,12 +209,12 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle $installed_plugins = get_plugins(); if ( ! in_array( $path, array_keys( $installed_plugins ), true ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce-admin' ), 404 ); } $result = activate_plugin( $path ); if ( ! is_null( $result ) ) { - return new WP_Error( 'woocommerce_rest_invalid_plugin', __( 'The requested plugin could not be activated.', 'woocommerce-admin' ), 500 ); + return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'The requested plugin could not be activated.', 'woocommerce-admin' ), 500 ); } return( array( @@ -229,7 +231,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle */ public function connect_jetpack() { if ( ! class_exists( 'Jetpack' ) ) { - return new WP_Error( 'woocommerce_rest_jetpack_not_active', __( 'Jetpack is not installed or active.', 'woocommerce-admin' ), 404 ); + return new \WP_Error( 'woocommerce_rest_jetpack_not_active', __( 'Jetpack is not installed or active.', 'woocommerce-admin' ), 404 ); } $next_step_slug = apply_filters( 'woocommerce_onboarding_after_jetpack_step', 'store-details' ); @@ -243,7 +245,7 @@ class WC_Admin_REST_Onboarding_Plugins_Controller extends WC_REST_Data_Controlle ) ); - $connect_url = Jetpack::init()->build_connect_url( true, $redirect_url, 'woocommerce-setup-wizard' ); + $connect_url = \Jetpack::init()->build_connect_url( true, $redirect_url, 'woocommerce-setup-wizard' ); // Redirect to local calypso instead of production. if ( defined( 'WOOCOMMERCE_CALYPSO_LOCAL' ) && WOOCOMMERCE_CALYPSO_LOCAL ) { diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php b/plugins/woocommerce-admin/src/API/OnboardingProfile.php similarity index 94% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php rename to plugins/woocommerce-admin/src/API/OnboardingProfile.php index 09acb7a202a..268ed3bf103 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php +++ b/plugins/woocommerce-admin/src/API/OnboardingProfile.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\Features\WC_Admin_Onboarding; @@ -17,7 +19,7 @@ use Automattic\WooCommerce\Admin\Features\WC_Admin_Onboarding; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controller { +class OnboardingProfile extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -41,7 +43,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), @@ -53,7 +55,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_items' ), 'permission_callback' => array( $this, 'update_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -71,7 +73,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle */ public function get_items_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -85,7 +87,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle */ public function update_items_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -234,7 +236,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle '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', ), ), @@ -246,7 +248,7 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle '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', ), ), diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-orders-controller.php b/plugins/woocommerce-admin/src/API/Orders.php similarity index 95% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-orders-controller.php rename to plugins/woocommerce-admin/src/API/Orders.php index e9f13eb08f3..e358202b407 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-orders-controller.php +++ b/plugins/woocommerce-admin/src/API/Orders.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Orders_Controller */ -class WC_Admin_REST_Orders_Controller extends WC_REST_Orders_Controller { +class Orders extends \WC_REST_Orders_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-categories-controller.php b/plugins/woocommerce-admin/src/API/ProductCategories.php similarity index 76% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-categories-controller.php rename to plugins/woocommerce-admin/src/API/ProductCategories.php index 672cd0c22ca..efa01a517bc 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-categories-controller.php +++ b/plugins/woocommerce-admin/src/API/ProductCategories.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Product_Categories_Controller */ -class WC_Admin_REST_Product_Categories_Controller extends WC_REST_Product_Categories_Controller { +class ProductCategories extends \WC_REST_Product_Categories_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-reviews-controller.php b/plugins/woocommerce-admin/src/API/ProductReviews.php similarity index 91% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-reviews-controller.php rename to plugins/woocommerce-admin/src/API/ProductReviews.php index ba3fc9245f4..7ce0a811c25 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-reviews-controller.php +++ b/plugins/woocommerce-admin/src/API/ProductReviews.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Product_Reviews_Controller */ -class WC_Admin_REST_Product_Reviews_Controller extends WC_REST_Product_Reviews_Controller { +class ProductReviews extends \WC_REST_Product_Reviews_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-variations-controller.php b/plugins/woocommerce-admin/src/API/ProductVariations.php similarity index 96% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-variations-controller.php rename to plugins/woocommerce-admin/src/API/ProductVariations.php index 92f4d866a28..0ec84ae0709 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-product-variations-controller.php +++ b/plugins/woocommerce-admin/src/API/ProductVariations.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Product_Variations_Controller */ -class WC_Admin_REST_Product_Variations_Controller extends WC_REST_Product_Variations_Controller { +class ProductVariations extends \WC_REST_Product_Variations_Controller { /** * Endpoint namespace. * diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-products-controller.php b/plugins/woocommerce-admin/src/API/Products.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-products-controller.php rename to plugins/woocommerce-admin/src/API/Products.php index 1ed532c6320..2c3b2363905 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-products-controller.php +++ b/plugins/woocommerce-admin/src/API/Products.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Products_Controller */ -class WC_Admin_REST_Products_Controller extends WC_REST_Products_Controller { +class Products extends \WC_REST_Products_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-setting-options-controller.php b/plugins/woocommerce-admin/src/API/SettingOptions.php similarity index 77% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-setting-options-controller.php rename to plugins/woocommerce-admin/src/API/SettingOptions.php index bfa1a2fe6ec..64567cbc492 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-setting-options-controller.php +++ b/plugins/woocommerce-admin/src/API/SettingOptions.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Setting_Options_Controller */ -class WC_Admin_REST_Setting_Options_Controller extends WC_REST_Setting_Options_Controller { +class SettingOptions extends \WC_REST_Setting_Options_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-taxes-controller.php b/plugins/woocommerce-admin/src/API/Taxes.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-taxes-controller.php rename to plugins/woocommerce-admin/src/API/Taxes.php index 06698aa8eb1..3a1560a7610 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-taxes-controller.php +++ b/plugins/woocommerce-admin/src/API/Taxes.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Taxes_Controller */ -class WC_Admin_REST_Taxes_Controller extends WC_REST_Taxes_Controller { +class Taxes extends \WC_REST_Taxes_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php b/plugins/woocommerce-admin/src/API/Themes.php similarity index 89% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php rename to plugins/woocommerce-admin/src/API/Themes.php index 9f5e2812bdb..82163b211a6 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-themes-controller.php +++ b/plugins/woocommerce-admin/src/API/Themes.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API; + defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader; @@ -18,7 +20,7 @@ use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader_Skin; * @package WooCommerce Admin/API * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { +class Themes extends \WC_REST_Data_Controller { /** * Endpoint namespace. * @@ -42,7 +44,7 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'upload_theme' ), 'permission_callback' => array( $this, 'upload_theme_permissions_check' ), 'args' => $this->get_collection_params(), @@ -60,7 +62,7 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { */ public function upload_theme_permissions_check( $request ) { if ( ! current_user_can( 'upload_themes' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you are not allowed to install themes on this site.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you are not allowed to install themes on this site.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; @@ -74,7 +76,7 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { */ public function upload_theme( $request ) { if ( ! isset( $_FILES['pluginzip'] ) || ! is_uploaded_file( $_FILES['pluginzip']['tmp_name'] ) || ! is_file( $_FILES['pluginzip']['tmp_name'] ) ) { // WPCS: sanitization ok. - return new WP_Error( 'woocommerce_rest_invalid_file', __( 'Specified file failed upload test.', 'woocommerce-admin' ) ); + return new \WP_Error( 'woocommerce_rest_invalid_file', __( 'Specified file failed upload test.', 'woocommerce-admin' ) ); } include_once ABSPATH . 'wp-admin/includes/file.php'; @@ -83,8 +85,8 @@ class WC_Admin_REST_Themes_Controller extends WC_REST_Data_Controller { include_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-theme-upgrader-skin.php'; $_GET['package'] = true; - $file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' ); - $upgrader = new WC_Admin_Theme_Upgrader( new WC_Admin_Theme_Upgrader_Skin() ); + $file_upload = new \File_Upload_Upgrader( 'pluginzip', 'package' ); + $upgrader = new \WC_Admin_Theme_Upgrader( new \WC_Admin_Theme_Upgrader_Skin() ); $install = $upgrader->install( $file_upload->package ); if ( $install || is_wp_error( $install ) ) { diff --git a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php index 47b1481e6a1..60f17b85c1c 100644 --- a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php +++ b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php @@ -35,20 +35,20 @@ class WC_Admin_Api_Init { $controllers = array( 'Automattic\WooCommerce\Admin\API\Notes', 'Automattic\WooCommerce\Admin\API\NoteActions', - 'WC_Admin_REST_Coupons_Controller', - 'WC_Admin_REST_Customers_Controller', - 'WC_Admin_REST_Data_Controller', - 'WC_Admin_REST_Data_Countries_Controller', - 'WC_Admin_REST_Data_Download_Ips_Controller', - 'WC_Admin_REST_Leaderboards_Controller', - 'WC_Admin_REST_Orders_Controller', - 'WC_Admin_REST_Products_Controller', - 'WC_Admin_REST_Product_Categories_Controller', - 'WC_Admin_REST_Product_Variations_Controller', - 'WC_Admin_REST_Product_Reviews_Controller', - 'WC_Admin_REST_Product_Variations_Controller', + 'Automattic\WooCommerce\Admin\API\Coupons', + 'Automattic\WooCommerce\Admin\API\Customers', + 'Automattic\WooCommerce\Admin\API\Data', + 'Automattic\WooCommerce\Admin\API\DataCountries', + 'Automattic\WooCommerce\Admin\API\DataDownloadIPs', + 'Automattic\WooCommerce\Admin\API\Leaderboards', + 'Automattic\WooCommerce\Admin\API\Orders', + 'Automattic\WooCommerce\Admin\API\Products', + 'Automattic\WooCommerce\Admin\API\ProductCategories', + 'Automattic\WooCommerce\Admin\API\ProductVariations', + 'Automattic\WooCommerce\Admin\API\ProductReviews', + 'Automattic\WooCommerce\Admin\API\ProductVariations', 'WC_Admin_REST_Reports_Controller', - 'WC_Admin_REST_Setting_Options_Controller', + 'Automattic\WooCommerce\Admin\API\SettingOptions', 'WC_Admin_REST_Reports_Import_Controller', 'WC_Admin_REST_Reports_Export_Controller', 'WC_Admin_REST_Reports_Products_Controller', @@ -68,17 +68,17 @@ class WC_Admin_Api_Init { 'WC_Admin_REST_Reports_Downloads_Stats_Controller', 'WC_Admin_REST_Reports_Customers_Controller', 'WC_Admin_REST_Reports_Customers_Stats_Controller', - 'WC_Admin_REST_Taxes_Controller', - 'WC_Admin_REST_Themes_Controller', + 'Automattic\WooCommerce\Admin\API\Taxes', + 'Automattic\WooCommerce\Admin\API\Themes', ); if ( \WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { $controllers = array_merge( $controllers, array( - 'WC_Admin_REST_Onboarding_Levels_Controller', - 'WC_Admin_REST_Onboarding_Profile_Controller', - 'WC_Admin_REST_Onboarding_Plugins_Controller', + 'Automattic\WooCommerce\Admin\API\OnboardingLevels', + 'Automattic\WooCommerce\Admin\API\OnboardingProfile', + 'Automattic\WooCommerce\Admin\API\OnboardingPlugins', ) ); } @@ -133,8 +133,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['/wc/v4/coupons'] ) && isset( $endpoints['/wc/v4/coupons'][3] ) && isset( $endpoints['/wc/v4/coupons'][2] ) - && $endpoints['/wc/v4/coupons'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller - && $endpoints['/wc/v4/coupons'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller + && $endpoints['/wc/v4/coupons'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/coupons'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/coupons'][0] = $endpoints['/wc/v4/coupons'][2]; $endpoints['/wc/v4/coupons'][1] = $endpoints['/wc/v4/coupons'][3]; @@ -144,8 +144,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['/wc/v4/customers'] ) && isset( $endpoints['/wc/v4/customers'][3] ) && isset( $endpoints['/wc/v4/customers'][2] ) - && $endpoints['/wc/v4/customers'][2]['callback'][0] instanceof WC_Admin_REST_Customers_Controller - && $endpoints['/wc/v4/customers'][3]['callback'][0] instanceof WC_Admin_REST_Customers_Controller + && $endpoints['/wc/v4/customers'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Customers + && $endpoints['/wc/v4/customers'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Customers ) { $endpoints['/wc/v4/customers'][0] = $endpoints['/wc/v4/customers'][2]; $endpoints['/wc/v4/customers'][1] = $endpoints['/wc/v4/customers'][3]; @@ -156,9 +156,9 @@ class WC_Admin_Api_Init { && isset( $endpoints['/wc/v4/orders/(?P[\d]+)'][5] ) && isset( $endpoints['/wc/v4/orders/(?P[\d]+)'][4] ) && isset( $endpoints['/wc/v4/orders/(?P[\d]+)'][3] ) - && $endpoints['/wc/v4/orders/(?P[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller - && $endpoints['/wc/v4/orders/(?P[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Orders_Controller - && $endpoints['/wc/v4/orders/(?P[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Orders_Controller + && $endpoints['/wc/v4/orders/(?P[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/orders/(?P[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/orders/(?P[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/orders/(?P[\d]+)'][0] = $endpoints['/wc/v4/orders/(?P[\d]+)'][3]; $endpoints['/wc/v4/orders/(?P[\d]+)'][1] = $endpoints['/wc/v4/orders/(?P[\d]+)'][4]; @@ -169,8 +169,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['/wc/v4/orders'] ) && isset( $endpoints['/wc/v4/orders'][3] ) && isset( $endpoints['/wc/v4/orders'][2] ) - && $endpoints['/wc/v4/orders'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller - && $endpoints['/wc/v4/orders'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller + && $endpoints['/wc/v4/orders'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/orders'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/orders'][0] = $endpoints['/wc/v4/orders'][2]; $endpoints['/wc/v4/orders'][1] = $endpoints['/wc/v4/orders'][3]; @@ -179,7 +179,7 @@ class WC_Admin_Api_Init { // Override /wc/v4/data. if ( isset( $endpoints['/wc/v4/data'] ) && isset( $endpoints['/wc/v4/data'][1] ) - && $endpoints['/wc/v4/data'][1]['callback'][0] instanceof WC_Admin_REST_Data_Controller + && $endpoints['/wc/v4/data'][1]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Data ) { $endpoints['/wc/v4/data'][0] = $endpoints['/wc/v4/data'][1]; } @@ -188,8 +188,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['/wc/v4/products'] ) && isset( $endpoints['/wc/v4/products'][3] ) && isset( $endpoints['/wc/v4/products'][2] ) - && $endpoints['/wc/v4/products'][2]['callback'][0] instanceof WC_Admin_REST_Products_Controller - && $endpoints['/wc/v4/products'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller + && $endpoints['/wc/v4/products'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products + && $endpoints['/wc/v4/products'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products ) { $endpoints['/wc/v4/products'][0] = $endpoints['/wc/v4/products'][2]; $endpoints['/wc/v4/products'][1] = $endpoints['/wc/v4/products'][3]; @@ -200,9 +200,9 @@ class WC_Admin_Api_Init { && isset( $endpoints['/wc/v4/products/(?P[\d]+)'][5] ) && isset( $endpoints['/wc/v4/products/(?P[\d]+)'][4] ) && isset( $endpoints['/wc/v4/products/(?P[\d]+)'][3] ) - && $endpoints['/wc/v4/products/(?P[\d]+)'][3]['callback'][0] instanceof WC_Admin_REST_Products_Controller - && $endpoints['/wc/v4/products/(?P[\d]+)'][4]['callback'][0] instanceof WC_Admin_REST_Products_Controller - && $endpoints['/wc/v4/products/(?P[\d]+)'][5]['callback'][0] instanceof WC_Admin_REST_Products_Controller + && $endpoints['/wc/v4/products/(?P[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products + && $endpoints['/wc/v4/products/(?P[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products + && $endpoints['/wc/v4/products/(?P[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products ) { $endpoints['/wc/v4/products/(?P[\d]+)'][0] = $endpoints['/wc/v4/products/(?P[\d]+)'][3]; $endpoints['/wc/v4/products/(?P[\d]+)'][1] = $endpoints['/wc/v4/products/(?P[\d]+)'][4]; @@ -213,8 +213,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['/wc/v4/products/categories'] ) && isset( $endpoints['/wc/v4/products/categories'][3] ) && isset( $endpoints['/wc/v4/products/categories'][2] ) - && $endpoints['/wc/v4/products/categories'][2]['callback'][0] instanceof WC_Admin_REST_Product_categories_Controller - && $endpoints['/wc/v4/products/categories'][3]['callback'][0] instanceof WC_Admin_REST_Product_categories_Controller + && $endpoints['/wc/v4/products/categories'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductCategories + && $endpoints['/wc/v4/products/categories'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductCategories ) { $endpoints['/wc/v4/products/categories'][0] = $endpoints['/wc/v4/products/categories'][2]; $endpoints['/wc/v4/products/categories'][1] = $endpoints['/wc/v4/products/categories'][3]; @@ -224,8 +224,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['/wc/v4/products/reviews'] ) && isset( $endpoints['/wc/v4/products/reviews'][3] ) && isset( $endpoints['/wc/v4/products/reviews'][2] ) - && $endpoints['/wc/v4/products/reviews'][2]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller - && $endpoints['/wc/v4/products/reviews'][3]['callback'][0] instanceof WC_Admin_REST_Product_Reviews_Controller + && $endpoints['/wc/v4/products/reviews'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductReviews + && $endpoints['/wc/v4/products/reviews'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductReviews ) { $endpoints['/wc/v4/products/reviews'][0] = $endpoints['/wc/v4/products/reviews'][2]; $endpoints['/wc/v4/products/reviews'][1] = $endpoints['/wc/v4/products/reviews'][3]; @@ -235,8 +235,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['products/(?P[\d]+)/variations'] ) && isset( $endpoints['products/(?P[\d]+)/variations'][3] ) && isset( $endpoints['products/(?P[\d]+)/variations'][2] ) - && $endpoints['products/(?P[\d]+)/variations'][2]['callback'][0] instanceof WC_Admin_REST_Product_Variations_Controller - && $endpoints['products/(?P[\d]+)/variations'][3]['callback'][0] instanceof WC_Admin_REST_Product_Variations_Controller + && $endpoints['products/(?P[\d]+)/variations'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations + && $endpoints['products/(?P[\d]+)/variations'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations ) { $endpoints['products/(?P[\d]+)/variations'][0] = $endpoints['products/(?P[\d]+)/variations'][2]; $endpoints['products/(?P[\d]+)/variations'][1] = $endpoints['products/(?P[\d]+)/variations'][3]; @@ -246,8 +246,8 @@ class WC_Admin_Api_Init { if ( isset( $endpoints['/wc/v4/taxes'] ) && isset( $endpoints['/wc/v4/taxes'][3] ) && isset( $endpoints['/wc/v4/taxes'][2] ) - && $endpoints['/wc/v4/taxes'][2]['callback'][0] instanceof WC_Admin_REST_Orders_Controller - && $endpoints['/wc/v4/taxes'][3]['callback'][0] instanceof WC_Admin_REST_Orders_Controller + && $endpoints['/wc/v4/taxes'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders + && $endpoints['/wc/v4/taxes'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders ) { $endpoints['/wc/v4/taxes'][0] = $endpoints['/wc/v4/taxes'][2]; $endpoints['/wc/v4/taxes'][1] = $endpoints['/wc/v4/taxes'][3]; @@ -258,9 +258,9 @@ class WC_Admin_Api_Init { && isset( $endpoints['/wc/v4/settings/(?P[\w-]+)'][5] ) && isset( $endpoints['/wc/v4/settings/(?P[\w-]+)'][4] ) && isset( $endpoints['/wc/v4/settings/(?P[\w-]+)'][3] ) - && $endpoints['/wc/v4/settings/(?P[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller - && $endpoints['/wc/v4/settings/(?P[\w-]+)'][4]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller - && $endpoints['/wc/v4/settings/(?P[\w-]+)'][5]['callback'][0] instanceof WC_Admin_REST_Setting_Options_Controller + && $endpoints['/wc/v4/settings/(?P[\w-]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions + && $endpoints['/wc/v4/settings/(?P[\w-]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions + && $endpoints['/wc/v4/settings/(?P[\w-]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions ) { $endpoints['/wc/v4/settings/(?P[\w-]+)'][0] = $endpoints['/wc/v4/settings/(?P[\w-]+)'][3]; $endpoints['/wc/v4/settings/(?P[\w-]+)'][1] = $endpoints['/wc/v4/settings/(?P[\w-]+)'][4]; diff --git a/plugins/woocommerce-admin/tests/api/onboarding-profile.php b/plugins/woocommerce-admin/tests/api/onboarding-profile.php index cf75477a02a..1baf66c889e 100644 --- a/plugins/woocommerce-admin/tests/api/onboarding-profile.php +++ b/plugins/woocommerce-admin/tests/api/onboarding-profile.php @@ -5,6 +5,8 @@ * @package WooCommerce Admin\Tests\API */ +use \Automattic\WooCommerce\Admin\API\OnboardingProfile; + /** * WC Tests API Onboarding Profile */ @@ -42,7 +44,7 @@ class WC_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case { $this->assertEquals( 200, $response->get_status() ); - $properties = WC_Admin_REST_Onboarding_Profile_Controller::get_profile_properties(); + $properties = OnboardingProfile::get_profile_properties(); foreach ( $properties as $key => $property ) { $this->assertArrayHasKey( $key, $properties ); } From a67d577ad2f87b142a29b32b684bc776a1dba6f5 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Fri, 2 Aug 2019 20:26:35 -0600 Subject: [PATCH 18/32] PSR-4ify all Report Controller classes. --- .../woocommerce-admin/src/API/Customers.php | 2 +- .../API/Reports/Categories/Controller.php} | 10 +++-- .../API/Reports/Controller.php} | 8 ++-- .../API/Reports/Coupons/Controller.php} | 6 ++- .../API/Reports/Coupons/Stats/Controller.php} | 10 +++-- .../API/Reports/Customers/Controller.php} | 10 +++-- .../Reports/Customers/Stats/Controller.php} | 10 +++-- .../API/Reports/Downloads/Controller.php} | 11 ++--- .../Reports/Downloads/Files/Controller.php} | 4 +- .../Reports/Downloads/Stats/Controller.php} | 6 ++- .../API/Reports/Export/Controller.php} | 12 +++--- .../API/Reports/Import/Controller.php} | 28 +++++++------ .../API/Reports/Orders/Controller.php} | 8 ++-- .../API/Reports/Orders/Stats/Controller.php} | 12 +++--- .../PerformanceIndicators/Controller.php} | 18 ++++---- .../API/Reports/Products/Controller.php} | 6 ++- .../Reports/Products/Stats/Controller.php} | 14 ++++--- .../API/Reports/Revenue/Stats/Controller.php} | 10 +++-- .../API/Reports/Stock/Controller.php} | 8 ++-- .../API/Reports/Stock/Stats/Controller.php} | 6 ++- .../API/Reports/Taxes/Controller.php} | 6 ++- .../API/Reports/Taxes/Stats/Controller.php} | 10 +++-- .../API/Reports/Variations/Controller.php} | 6 ++- .../src/API/WC_Admin_Api_Init.php | 42 +++++++++---------- .../src/WC_Admin_Report_CSV_Exporter.php | 18 ++++---- 25 files changed, 162 insertions(+), 119 deletions(-) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-categories-controller.php => src/API/Reports/Categories/Controller.php} (95%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-controller.php => src/API/Reports/Controller.php} (95%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-coupons-controller.php => src/API/Reports/Coupons/Controller.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-coupons-stats-controller.php => src/API/Reports/Coupons/Stats/Controller.php} (96%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-customers-controller.php => src/API/Reports/Customers/Controller.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-customers-stats-controller.php => src/API/Reports/Customers/Stats/Controller.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-downloads-controller.php => src/API/Reports/Downloads/Controller.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-downloads-files-controller.php => src/API/Reports/Downloads/Files/Controller.php} (80%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-downloads-stats-controller.php => src/API/Reports/Downloads/Stats/Controller.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-export-controller.php => src/API/Reports/Export/Controller.php} (94%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-import-controller.php => src/API/Reports/Import/Controller.php} (88%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-orders-controller.php => src/API/Reports/Orders/Controller.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-orders-stats-controller.php => src/API/Reports/Orders/Stats/Controller.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-performance-indicators-controller.php => src/API/Reports/PerformanceIndicators/Controller.php} (94%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-products-controller.php => src/API/Reports/Products/Controller.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-products-stats-controller.php => src/API/Reports/Products/Stats/Controller.php} (96%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php => src/API/Reports/Revenue/Stats/Controller.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-stock-controller.php => src/API/Reports/Stock/Controller.php} (98%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-stock-stats-controller.php => src/API/Reports/Stock/Stats/Controller.php} (95%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-taxes-controller.php => src/API/Reports/Taxes/Controller.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-taxes-stats-controller.php => src/API/Reports/Taxes/Stats/Controller.php} (97%) rename plugins/woocommerce-admin/{includes/api/class-wc-admin-rest-reports-variations-controller.php => src/API/Reports/Variations/Controller.php} (98%) diff --git a/plugins/woocommerce-admin/src/API/Customers.php b/plugins/woocommerce-admin/src/API/Customers.php index ee76e5fd42e..1899e40e2b3 100644 --- a/plugins/woocommerce-admin/src/API/Customers.php +++ b/plugins/woocommerce-admin/src/API/Customers.php @@ -17,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_Admin_REST_Reports_Customers_Controller */ -class Customers extends \WC_Admin_REST_Reports_Customers_Controller { +class Customers extends \Automattic\WooCommerce\Admin\API\Reports\Customers\Controller { /** * Route base. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-categories-controller.php b/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php similarity index 95% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-categories-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php index 9d8161151db..ae6b2ae13b3 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-categories-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php @@ -7,15 +7,17 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Categories; + defined( 'ABSPATH' ) || exit; /** * REST API Reports categories controller class. * * @package WooCommerce/API - * @extends WC_Admin_REST_Reports_Controller + * @extends \Automattic\WooCommerce\Admin\API\Reports\Controller */ -class WC_Admin_REST_Reports_Categories_Controller extends WC_Admin_REST_Reports_Controller { +class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { /** * Endpoint namespace. @@ -62,7 +64,7 @@ class WC_Admin_REST_Reports_Categories_Controller extends WC_Admin_REST_Reports_ */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $categories_query = new WC_Admin_Reports_Categories_Query( $query_args ); + $categories_query = new \WC_Admin_Reports_Categories_Query( $query_args ); $report_data = $categories_query->get_data(); if ( is_wp_error( $report_data ) ) { @@ -70,7 +72,7 @@ class WC_Admin_REST_Reports_Categories_Controller extends WC_Admin_REST_Reports_ } if ( ! isset( $report_data->data ) || ! isset( $report_data->page_no ) || ! isset( $report_data->pages ) ) { - return new WP_Error( 'woocommerce_rest_reports_categories_invalid_response', __( 'Invalid response from data store.', 'woocommerce-admin' ), array( 'status' => 500 ) ); + return new \WP_Error( 'woocommerce_rest_reports_categories_invalid_response', __( 'Invalid response from data store.', 'woocommerce-admin' ), array( 'status' => 500 ) ); } $out_data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-controller.php b/plugins/woocommerce-admin/src/API/Reports/Controller.php similarity index 95% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Controller.php index 443e149c5c0..04748c7d31d 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce Admin/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -40,7 +42,7 @@ class WC_Admin_REST_Reports_Controller extends WC_REST_Reports_Controller { '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -58,7 +60,7 @@ class WC_Admin_REST_Reports_Controller extends WC_REST_Reports_Controller { */ public function get_items_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-coupons-controller.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Controller.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-coupons-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Coupons/Controller.php index 20a7f1020af..bddd6ffcb41 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-coupons-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Coupons; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Coupons_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -58,7 +60,7 @@ class WC_Admin_REST_Reports_Coupons_Controller extends WC_REST_Reports_Controlle */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $coupons_query = new WC_Admin_Reports_Coupons_Query( $query_args ); + $coupons_query = new \WC_Admin_Reports_Coupons_Query( $query_args ); $report_data = $coupons_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-coupons-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php similarity index 96% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-coupons-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php index fbc4b6383a6..abc31a3f217 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-coupons-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Coupons_Stats_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -61,11 +63,11 @@ class WC_Admin_REST_Reports_Coupons_Stats_Controller extends WC_REST_Reports_Con */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $coupons_query = new WC_Admin_Reports_Coupons_Stats_Query( $query_args ); + $coupons_query = new \WC_Admin_Reports_Coupons_Stats_Query( $query_args ); try { $report_data = $coupons_query->get_data(); - } catch ( WC_Admin_Reports_Parameter_Exception $e ) { - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); + } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } $out_data = array( diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-controller.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php index fc7ec557173..91d054e955c 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Customers; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -71,9 +73,9 @@ class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Control $args['customers'] = $request['customers']; $between_params_numeric = array( 'orders_count', 'total_spend', 'avg_order_value' ); - $normalized_params_numeric = WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); + $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); $between_params_date = array( 'last_active', 'registered' ); - $normalized_params_date = WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); + $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); $args = array_merge( $args, $normalized_params_numeric, $normalized_params_date ); return $args; @@ -87,7 +89,7 @@ class WC_Admin_REST_Reports_Customers_Controller extends WC_REST_Reports_Control */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $customers_query = new WC_Admin_Reports_Customers_Query( $query_args ); + $customers_query = new \WC_Admin_Reports_Customers_Query( $query_args ); $report_data = $customers_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php index 0012807e565..a845e9b9169 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-customers-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Customers\Stats; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Customers_Stats_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. * @@ -63,9 +65,9 @@ class WC_Admin_REST_Reports_Customers_Stats_Controller extends WC_REST_Reports_C $args['customers'] = $request['customers']; $between_params_numeric = array( 'orders_count', 'total_spend', 'avg_order_value' ); - $normalized_params_numeric = WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); + $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); $between_params_date = array( 'last_active', 'registered' ); - $normalized_params_date = WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); + $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); $args = array_merge( $args, $normalized_params_numeric, $normalized_params_date ); return $args; @@ -79,7 +81,7 @@ class WC_Admin_REST_Reports_Customers_Stats_Controller extends WC_REST_Reports_C */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $customers_query = new WC_Admin_Reports_Customers_Stats_Query( $query_args ); + $customers_query = new \WC_Admin_Reports_Customers_Stats_Query( $query_args ); $report_data = $customers_query->get_data(); $out_data = array( 'totals' => $report_data, diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-controller.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Controller.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Downloads/Controller.php index 2b23d52b27c..85990d4e538 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Controller.php @@ -7,16 +7,17 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Downloads; + defined( 'ABSPATH' ) || exit; /** * REST API Reports downloads controller class. * * @package WooCommerce/API - * @extends WC_REST_Reports_Controller + * @extends Automattic\WooCommerce\Admin\API\Reports\Controller */ -class WC_Admin_REST_Reports_Downloads_Controller extends WC_Admin_REST_Reports_Controller { - +class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { /** * Endpoint namespace. * @@ -46,7 +47,7 @@ class WC_Admin_REST_Reports_Downloads_Controller extends WC_Admin_REST_Reports_C } } - $reports = new WC_Admin_Reports_Downloads_Query( $args ); + $reports = new \WC_Admin_Reports_Downloads_Query( $args ); $downloads_data = $reports->get_data(); $data = array(); @@ -109,7 +110,7 @@ class WC_Admin_REST_Reports_Downloads_Controller extends WC_Admin_REST_Reports_C $filename = basename( $file_path ); $response->data['file_name'] = apply_filters( 'woocommerce_file_download_filename', $filename, $product_id ); $response->data['file_path'] = $file_path; - $customer = new WC_Customer( $data['user_id'] ); + $customer = new \WC_Customer( $data['user_id'] ); $response->data['username'] = $customer->get_username(); $response->data['order_number'] = $this->get_order_number( $data['order_id'] ); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-files-controller.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Files/Controller.php similarity index 80% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-files-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Downloads/Files/Controller.php index d0f54fbdc66..d84cab581e3 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-files-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Files/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Downloads\Files; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Downloads_Files_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Controller.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Controller.php index f627a57894f..33ace0de433 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-downloads-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Downloads_Stats_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -67,7 +69,7 @@ class WC_Admin_REST_Reports_Downloads_Stats_Controller extends WC_REST_Reports_C */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $downloads_query = new WC_Admin_Reports_Downloads_Stats_Query( $query_args ); + $downloads_query = new \WC_Admin_Reports_Downloads_Stats_Query( $query_args ); $report_data = $downloads_query->get_data(); $out_data = array( diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-export-controller.php b/plugins/woocommerce-admin/src/API/Reports/Export/Controller.php similarity index 94% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-export-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Export/Controller.php index 4291136bc5b..e07a9b02d19 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-export-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Export/Controller.php @@ -9,6 +9,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Export; + defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; @@ -17,9 +19,9 @@ use \Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; * Reports Export controller. * * @package WooCommerce Admin/API - * @extends WC_REST_Data_Controller + * @extends \Automattic\WooCommerce\Admin\API\Reports\Controller */ -class WC_Admin_REST_Reports_Export_Controller extends WC_Admin_REST_Reports_Controller { +class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { /** * Endpoint namespace. * @@ -43,7 +45,7 @@ class WC_Admin_REST_Reports_Export_Controller extends WC_Admin_REST_Reports_Cont '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'export_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_export_collection_params(), @@ -57,7 +59,7 @@ class WC_Admin_REST_Reports_Export_Controller extends WC_Admin_REST_Reports_Cont '/' . $this->rest_base . '/(?P[a-z0-9]+)/status', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'export_status' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), ), @@ -197,7 +199,7 @@ class WC_Admin_REST_Reports_Export_Controller extends WC_Admin_REST_Reports_Cont $percentage = WC_Admin_Report_Exporter::get_export_percentage_complete( $report_type, $export_id ); if ( false === $percentage ) { - return new WP_Error( + return new \WP_Error( 'woocommerce_admin_reports_export_invalid_id', __( 'Sorry, there is no export with that ID.', 'woocommerce-admin' ), array( 'status' => 404 ) diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-import-controller.php b/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php similarity index 88% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-import-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Import/Controller.php index a1812d66d94..11d7604abd0 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-import-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Import; + defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; @@ -15,9 +17,9 @@ use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; * Reports Imports controller. * * @package WooCommerce Admin/API - * @extends WC_REST_Data_Controller + * @extends \Automattic\WooCommerce\Admin\API\Reports\Controller */ -class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Controller { +class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { /** * Endpoint namespace. * @@ -41,7 +43,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'import_items' ), 'permission_callback' => array( $this, 'import_permissions_check' ), 'args' => $this->get_import_collection_params(), @@ -54,7 +56,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont '/' . $this->rest_base . '/cancel', array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'cancel_import' ), 'permission_callback' => array( $this, 'import_permissions_check' ), ), @@ -66,7 +68,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont '/' . $this->rest_base . '/delete', array( array( - 'methods' => WP_REST_Server::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => array( $this, 'delete_imported_items' ), 'permission_callback' => array( $this, 'import_permissions_check' ), ), @@ -78,7 +80,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont '/' . $this->rest_base . '/status', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_import_status' ), 'permission_callback' => array( $this, 'import_permissions_check' ), ), @@ -90,7 +92,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont '/' . $this->rest_base . '/totals', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_import_totals' ), 'permission_callback' => array( $this, 'import_permissions_check' ), 'args' => $this->get_import_collection_params(), @@ -108,7 +110,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont */ public function import_permissions_check( $request ) { if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); + return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce-admin' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } @@ -121,7 +123,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont */ 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( @@ -237,7 +239,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont * @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', @@ -257,7 +259,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont * @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( @@ -285,7 +287,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont */ 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 ), @@ -307,7 +309,7 @@ class WC_Admin_REST_Reports_Import_Controller extends WC_Admin_REST_Reports_Cont */ 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 ); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-orders-controller.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Controller.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-orders-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Orders/Controller.php index a5e9d881bb9..f63ccb61b84 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-orders-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Controller.php @@ -7,15 +7,17 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Orders; + defined( 'ABSPATH' ) || exit; /** * REST API Reports orders controller class. * * @package WooCommerce/API - * @extends WC_Admin_REST_Reports_Controller + * @extends \Automattic\WooCommerce\Admin\API\Reports\Controller */ -class WC_Admin_REST_Reports_Orders_Controller extends WC_Admin_REST_Reports_Controller { +class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { /** * Endpoint namespace. @@ -69,7 +71,7 @@ class WC_Admin_REST_Reports_Orders_Controller extends WC_Admin_REST_Reports_Cont */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $orders_query = new WC_Admin_Reports_Orders_Query( $query_args ); + $orders_query = new \WC_Admin_Reports_Orders_Query( $query_args ); $report_data = $orders_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-orders-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-orders-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php index 73e9829264c..60fd6dde22c 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-orders-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php @@ -7,15 +7,17 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats; + defined( 'ABSPATH' ) || exit; /** * REST API Reports orders stats controller class. * * @package WooCommerce/API - * @extends WC_Admin_REST_Reports_Controller + * @extends \Automattic\WooCommerce\Admin\API\Reports\Controller */ -class WC_Admin_REST_Reports_Orders_Stats_Controller extends WC_Admin_REST_Reports_Controller { +class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { /** * Endpoint namespace. @@ -70,11 +72,11 @@ class WC_Admin_REST_Reports_Orders_Stats_Controller extends WC_Admin_REST_Report */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $orders_query = new WC_Admin_Reports_Orders_Stats_Query( $query_args ); + $orders_query = new \WC_Admin_Reports_Orders_Stats_Query( $query_args ); try { $report_data = $orders_query->get_data(); - } catch ( WC_Admin_Reports_Parameter_Exception $e ) { - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); + } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } $out_data = array( diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-performance-indicators-controller.php b/plugins/woocommerce-admin/src/API/Reports/PerformanceIndicators/Controller.php similarity index 94% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-performance-indicators-controller.php rename to plugins/woocommerce-admin/src/API/Reports/PerformanceIndicators/Controller.php index ef109601420..025955e1139 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-performance-indicators-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/PerformanceIndicators/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -68,7 +70,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re '/' . $this->rest_base, array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -82,7 +84,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re '/' . $this->rest_base . '/allowed', array( array( - 'methods' => WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_allowed_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), @@ -117,7 +119,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re return true; } - $request = new WP_REST_Request( 'GET', '/wc/v4/reports' ); + $request = new \WP_REST_Request( 'GET', '/wc/v4/reports' ); $response = rest_do_request( $request ); if ( is_wp_error( $response ) ) { @@ -125,7 +127,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re } if ( 200 !== $response->get_status() ) { - return new WP_Error( 'woocommerce_reports_performance_indicators_result_failed', __( 'Sorry, fetching performance indicators failed.', 'woocommerce-admin' ) ); + return new \WP_Error( 'woocommerce_reports_performance_indicators_result_failed', __( 'Sorry, fetching performance indicators failed.', 'woocommerce-admin' ) ); } $endpoints = $response->get_data(); @@ -133,7 +135,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re foreach ( $endpoints as $endpoint ) { if ( '/stats' === substr( $endpoint['slug'], -6 ) ) { - $request = new WP_REST_Request( 'OPTIONS', $endpoint['path'] ); + $request = new \WP_REST_Request( 'OPTIONS', $endpoint['path'] ); $response = rest_do_request( $request ); if ( is_wp_error( $response ) ) { @@ -272,7 +274,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re $query_args = $this->prepare_reports_query( $request ); if ( empty( $query_args['stats'] ) ) { - return new WP_Error( 'woocommerce_reports_performance_indicators_empty_query', __( 'A list of stats to query must be provided.', 'woocommerce-admin' ), 400 ); + return new \WP_Error( 'woocommerce_reports_performance_indicators_empty_query', __( 'A list of stats to query must be provided.', 'woocommerce-admin' ), 400 ); } $stats = array(); @@ -288,7 +290,7 @@ class WC_Admin_REST_Reports_Performance_Indicators_Controller extends WC_REST_Re } $request_url = $this->endpoints[ $report ]; - $request = new WP_REST_Request( 'GET', $request_url ); + $request = new \WP_REST_Request( 'GET', $request_url ); $request->set_param( 'before', $query_args['before'] ); $request->set_param( 'after', $query_args['after'] ); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-controller.php b/plugins/woocommerce-admin/src/API/Reports/Products/Controller.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Products/Controller.php index 89432475566..7a5a938971e 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Products; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -60,7 +62,7 @@ class WC_Admin_REST_Reports_Products_Controller extends WC_REST_Reports_Controll } } - $reports = new WC_Admin_Reports_Products_Query( $args ); + $reports = new \WC_Admin_Reports_Products_Query( $args ); $products_data = $reports->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php similarity index 96% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php index fd9fd4bd390..a0a3e36bce9 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-products-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -75,11 +77,11 @@ class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Co } } - $query = new WC_Admin_Reports_Products_Stats_Query( $query_args ); + $query = new \WC_Admin_Reports_Products_Stats_Query( $query_args ); try { $report_data = $query->get_data(); - } catch ( WC_Admin_Reports_Parameter_Exception $e ) { - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); + } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } $out_data = array( @@ -285,9 +287,9 @@ class WC_Admin_REST_Reports_Products_Stats_Controller extends WC_REST_Reports_Co */ public function set_default_report_data( $results ) { if ( empty( $results ) ) { - $results = new stdClass(); + $results = new \stdClass(); $results->total = 0; - $results->totals = new stdClass(); + $results->totals = new \stdClass(); $results->totals->items_sold = 0; $results->totals->net_revenue = 0; $results->totals->orders_count = 0; diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php index 5d0a3f8f743..d9ff6d55315 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-revenue-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Revenue\Stats; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Revenue_Stats_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -59,11 +61,11 @@ class WC_Admin_REST_Reports_Revenue_Stats_Controller extends WC_REST_Reports_Con */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $reports_revenue = new WC_Admin_Reports_Revenue_Query( $query_args ); + $reports_revenue = new \WC_Admin_Reports_Revenue_Query( $query_args ); try { $report_data = $reports_revenue->get_data(); - } catch ( WC_Admin_Reports_Parameter_Exception $e ) { - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); + } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } $out_data = array( diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-stock-controller.php b/plugins/woocommerce-admin/src/API/Reports/Stock/Controller.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-stock-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Stock/Controller.php index 20d6716ada7..f3cf408c8b5 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-stock-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Stock/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Stock; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Stock_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -77,14 +79,14 @@ class WC_Admin_REST_Reports_Stock_Controller extends WC_REST_Reports_Controller * @return array */ protected function get_products( $query_args ) { - $query = new WP_Query(); + $query = new \WP_Query(); $result = $query->query( $query_args ); $total_posts = $query->found_posts; if ( $total_posts < 1 ) { // Out-of-bounds, run the query again without LIMIT for total count. unset( $query_args['paged'] ); - $count_query = new WP_Query(); + $count_query = new \WP_Query(); $count_query->query( $query_args ); $total_posts = $count_query->found_posts; } diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-stock-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Controller.php similarity index 95% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-stock-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Controller.php index c4782dd8e9d..83e9df9b0b7 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-stock-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Stock\Stats; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Stock_Stats_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -38,7 +40,7 @@ class WC_Admin_REST_Reports_Stock_Stats_Controller extends WC_REST_Reports_Contr * @return array|WP_Error */ public function get_items( $request ) { - $stock_query = new WC_Admin_Reports_Stock_Stats_Query(); + $stock_query = new \WC_Admin_Reports_Stock_Stats_Query(); $report_data = $stock_query->get_data(); $out_data = array( 'totals' => $report_data, diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-taxes-controller.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Controller.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-taxes-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Taxes/Controller.php index a471bf75351..29d083a4e93 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-taxes-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Taxes; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Taxes_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -58,7 +60,7 @@ class WC_Admin_REST_Reports_Taxes_Controller extends WC_REST_Reports_Controller */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $taxes_query = new WC_Admin_Reports_Taxes_Query( $query_args ); + $taxes_query = new \WC_Admin_Reports_Taxes_Query( $query_args ); $report_data = $taxes_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-taxes-stats-controller.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Controller.php similarity index 97% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-taxes-stats-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Controller.php index c6c3b23cfb0..136bc159ee2 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-taxes-stats-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -46,9 +48,9 @@ class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Contr */ public function set_default_report_data( $results ) { if ( empty( $results ) ) { - $results = new stdClass(); + $results = new \stdClass(); $results->total = 0; - $results->totals = new stdClass(); + $results->totals = new \stdClass(); $results->totals->tax_codes = 0; $results->totals->total_tax = 0; $results->totals->order_tax = 0; @@ -90,7 +92,7 @@ class WC_Admin_REST_Reports_Taxes_Stats_Controller extends WC_REST_Reports_Contr */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $taxes_query = new WC_Admin_Reports_Taxes_Stats_Query( $query_args ); + $taxes_query = new \WC_Admin_Reports_Taxes_Stats_Query( $query_args ); $report_data = $taxes_query->get_data(); $out_data = array( diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-variations-controller.php b/plugins/woocommerce-admin/src/API/Reports/Variations/Controller.php similarity index 98% rename from plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-variations-controller.php rename to plugins/woocommerce-admin/src/API/Reports/Variations/Controller.php index a64e187e9da..98eae81d7af 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-reports-variations-controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Variations/Controller.php @@ -7,6 +7,8 @@ * @package WooCommerce Admin/API */ +namespace Automattic\WooCommerce\Admin\API\Reports\Variations; + defined( 'ABSPATH' ) || exit; /** @@ -15,7 +17,7 @@ defined( 'ABSPATH' ) || exit; * @package WooCommerce/API * @extends WC_REST_Reports_Controller */ -class WC_Admin_REST_Reports_Variations_Controller extends WC_REST_Reports_Controller { +class Controller extends \WC_REST_Reports_Controller { /** * Endpoint namespace. @@ -60,7 +62,7 @@ class WC_Admin_REST_Reports_Variations_Controller extends WC_REST_Reports_Contro } } - $reports = new WC_Admin_Reports_Variations_Query( $args ); + $reports = new \WC_Admin_Reports_Variations_Query( $args ); $products_data = $reports->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php index 60f17b85c1c..e022d2dd323 100644 --- a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php +++ b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php @@ -47,27 +47,27 @@ class WC_Admin_Api_Init { 'Automattic\WooCommerce\Admin\API\ProductVariations', 'Automattic\WooCommerce\Admin\API\ProductReviews', 'Automattic\WooCommerce\Admin\API\ProductVariations', - 'WC_Admin_REST_Reports_Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Controller', 'Automattic\WooCommerce\Admin\API\SettingOptions', - 'WC_Admin_REST_Reports_Import_Controller', - 'WC_Admin_REST_Reports_Export_Controller', - 'WC_Admin_REST_Reports_Products_Controller', - 'WC_Admin_REST_Reports_Variations_Controller', - 'WC_Admin_REST_Reports_Products_Stats_Controller', - 'WC_Admin_REST_Reports_Revenue_Stats_Controller', - 'WC_Admin_REST_Reports_Orders_Controller', - 'WC_Admin_REST_Reports_Orders_Stats_Controller', - 'WC_Admin_REST_Reports_Categories_Controller', - 'WC_Admin_REST_Reports_Taxes_Controller', - 'WC_Admin_REST_Reports_Taxes_Stats_Controller', - 'WC_Admin_REST_Reports_Coupons_Controller', - 'WC_Admin_REST_Reports_Coupons_Stats_Controller', - 'WC_Admin_REST_Reports_Stock_Controller', - 'WC_Admin_REST_Reports_Stock_Stats_Controller', - 'WC_Admin_REST_Reports_Downloads_Controller', - 'WC_Admin_REST_Reports_Downloads_Stats_Controller', - 'WC_Admin_REST_Reports_Customers_Controller', - 'WC_Admin_REST_Reports_Customers_Stats_Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Import\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Export\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Products\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Variations\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Products\Stats\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Revenue\Stats\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Orders\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Categories\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Taxes\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Coupons\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Stock\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Stock\Stats\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Downloads\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Customers\Controller', + 'Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\Controller', 'Automattic\WooCommerce\Admin\API\Taxes', 'Automattic\WooCommerce\Admin\API\Themes', ); @@ -84,7 +84,7 @@ class WC_Admin_Api_Init { } // The performance indicators controller must be registered last, after other /stats endpoints have been registered. - $controllers[] = 'WC_Admin_REST_Reports_Performance_Indicators_Controller'; + $controllers[] = 'Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators\Controller'; $controllers = apply_filters( 'woocommerce_admin_rest_controllers', $controllers ); diff --git a/plugins/woocommerce-admin/src/WC_Admin_Report_CSV_Exporter.php b/plugins/woocommerce-admin/src/WC_Admin_Report_CSV_Exporter.php index 683778e0adb..4ba9b3503be 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Report_CSV_Exporter.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Report_CSV_Exporter.php @@ -104,15 +104,15 @@ class WC_Admin_Report_CSV_Exporter extends \WC_CSV_Batch_Exporter { */ protected function map_report_controller() { $controller_map = array( - 'products' => '\WC_Admin_REST_Reports_Products_Controller', - 'variations' => '\WC_Admin_REST_Reports_Variations_Controller', - 'orders' => '\WC_Admin_REST_Reports_Orders_Controller', - 'categories' => '\WC_Admin_REST_Reports_Categories_Controller', - 'taxes' => '\WC_Admin_REST_Reports_Taxes_Controller', - 'coupons' => '\WC_Admin_REST_Reports_Coupons_Controller', - 'stock' => '\WC_Admin_REST_Reports_Stock_Controller', - 'downloads' => '\WC_Admin_REST_Reports_Downloads_Controller', - 'customers' => '\WC_Admin_REST_Reports_Customers_Controller', + 'products' => 'Automattic\WooCommerce\Admin\API\Reports\Products\Controller', + 'variations' => 'Automattic\WooCommerce\Admin\API\Reports\Variations\Controller', + 'orders' => 'Automattic\WooCommerce\Admin\API\Reports\Orders\Controller', + 'categories' => 'Automattic\WooCommerce\Admin\API\Reports\Categories\Controller', + 'taxes' => 'Automattic\WooCommerce\Admin\API\Reports\Taxes\Controller', + 'coupons' => 'Automattic\WooCommerce\Admin\API\Reports\Coupons\Controller', + 'stock' => 'Automattic\WooCommerce\Admin\API\Reports\Stock\Controller', + 'downloads' => 'Automattic\WooCommerce\Admin\API\Reports\Downloads\Controller', + 'customers' => 'Automattic\WooCommerce\Admin\API\Reports\Customers\Controller', ); if ( isset( $controller_map[ $this->report_type ] ) ) { From b7912bc579ca1e59b675eaa604f2d73dafabd550 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 5 Aug 2019 12:14:25 -0600 Subject: [PATCH 19/32] PSR4-ify the Reports data store classes. --- .../src/API/Leaderboards.php | 13 +++-- .../src/API/OnboardingProfile.php | 4 +- .../API/Reports/Categories/DataStore.php} | 13 +++-- .../API/Reports/Coupons/DataStore.php} | 28 ++++----- .../API/Reports/Coupons/Stats/DataStore.php} | 15 ++--- .../API/Reports/Customers/DataStore.php} | 26 +++++---- .../Reports/Customers/Stats/DataStore.php} | 4 +- .../API/Reports/DataStore.php} | 58 ++++++++++--------- .../API/Reports/Downloads/DataStore.php} | 12 ++-- .../Reports/Downloads/Stats/DataStore.php} | 14 +++-- .../src/API/Reports/Import/Controller.php | 10 ++-- .../API/Reports/Orders/DataStore.php} | 4 +- .../API/Reports/Orders/Stats/DataStore.php} | 20 ++++--- .../API/Reports/Products/DataStore.php} | 12 ++-- .../API/Reports/Products/Stats/DataStore.php} | 19 +++--- .../API/Reports/Stock/Stats/DataStore.php} | 6 +- .../API/Reports/Taxes/DataStore.php} | 10 ++-- .../API/Reports/Taxes/Stats/DataStore.php} | 19 +++--- .../API/Reports/Variations/DataStore.php} | 10 ++-- .../src/API/WC_Admin_Api_Init.php | 34 +++++------ .../Notes/DataStore.php} | 8 +-- .../woocommerce-admin/src/WC_Admin_Order.php | 7 ++- .../src/WC_Admin_Order_Refund.php | 4 +- .../src/WC_Admin_Reports_Sync.php | 30 ++++++---- plugins/woocommerce-admin/tests/api-init.php | 3 +- .../woocommerce-admin/tests/api/orders.php | 4 +- .../tests/api/reports-customers.php | 8 ++- .../tests/api/reports-orders.php | 4 +- .../helpers/class-wc-helper-reports.php | 8 +-- .../class-wc-tests-reports-coupons-stats.php | 4 +- .../class-wc-tests-reports-coupons.php | 3 +- .../class-wc-tests-reports-orders-stats.php | 22 +++---- .../class-wc-tests-reports-products.php | 12 ++-- .../class-wc-tests-reports-revenue-stats.php | 4 +- .../class-wc-tests-reports-variations.php | 6 +- 35 files changed, 260 insertions(+), 198 deletions(-) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-categories-data-store.php => src/API/Reports/Categories/DataStore.php} (95%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-coupons-data-store.php => src/API/Reports/Coupons/DataStore.php} (92%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-coupons-stats-data-store.php => src/API/Reports/Coupons/Stats/DataStore.php} (89%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-customers-data-store.php => src/API/Reports/Customers/DataStore.php} (95%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-customers-stats-data-store.php => src/API/Reports/Customers/Stats/DataStore.php} (94%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-data-store.php => src/API/Reports/DataStore.php} (93%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-downloads-data-store.php => src/API/Reports/Downloads/DataStore.php} (96%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php => src/API/Reports/Downloads/Stats/DataStore.php} (88%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-orders-data-store.php => src/API/Reports/Orders/DataStore.php} (98%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php => src/API/Reports/Orders/Stats/DataStore.php} (94%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-products-data-store.php => src/API/Reports/Products/DataStore.php} (97%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-products-stats-data-store.php => src/API/Reports/Products/Stats/DataStore.php} (87%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-stock-stats-data-store.php => src/API/Reports/Stock/Stats/DataStore.php} (95%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-taxes-data-store.php => src/API/Reports/Taxes/DataStore.php} (96%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php => src/API/Reports/Taxes/Stats/DataStore.php} (89%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-reports-variations-data-store.php => src/API/Reports/Variations/DataStore.php} (96%) rename plugins/woocommerce-admin/{includes/data-stores/class-wc-admin-notes-data-store.php => src/Notes/DataStore.php} (97%) diff --git a/plugins/woocommerce-admin/src/API/Leaderboards.php b/plugins/woocommerce-admin/src/API/Leaderboards.php index 2d6839b52d2..f09a763a36e 100644 --- a/plugins/woocommerce-admin/src/API/Leaderboards.php +++ b/plugins/woocommerce-admin/src/API/Leaderboards.php @@ -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', diff --git a/plugins/woocommerce-admin/src/API/OnboardingProfile.php b/plugins/woocommerce-admin/src/API/OnboardingProfile.php index 268ed3bf103..73f23b6c194 100644 --- a/plugins/woocommerce-admin/src/API/OnboardingProfile.php +++ b/plugins/woocommerce-admin/src/API/OnboardingProfile.php @@ -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', ), ), diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-categories-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php similarity index 95% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-categories-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php index 4be8258d87c..0caa4256e07 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-categories-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php @@ -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 ); diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php similarity index 92% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php index 4165a982a71..bb8a808f784 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php @@ -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', diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-stats-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php similarity index 89% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-stats-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php index 9925ad7881f..1c70a1143b6 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-coupons-stats-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php @@ -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'] ); diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php similarity index 95% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php index 34edecac6f0..d1fc1483ec1 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php @@ -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; diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-stats-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php similarity index 94% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-stats-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php index 2feb0d98076..823ef296578 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-customers-stats-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php @@ -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. * diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php b/plugins/woocommerce-admin/src/API/Reports/DataStore.php similarity index 93% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/DataStore.php index f38036c261c..ad023aca970 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/DataStore.php @@ -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 ) ); diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php similarity index 96% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php index 3341b251841..140b644dda2 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php @@ -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 ); diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php similarity index 88% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php index 3c287272827..9ede3fac44c 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php @@ -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] ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php index 11d7604abd0..314d46596e6 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php @@ -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 ); diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php similarity index 98% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php index 7ca1b7c4e8d..ec13555783e 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php @@ -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. diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php similarity index 94% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php index 281e8600b20..fdd7d84936e 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-orders-stats-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php @@ -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; diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php similarity index 97% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php index 157a7695da4..72a98797a16 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php @@ -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, diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-stats-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php similarity index 87% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-stats-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php index 2057e85d89f..fc8f4bb3ace 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-products-stats-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php @@ -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'] ); diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-stock-stats-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php similarity index 95% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-stock-stats-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php index e8d82567e11..eb47d739ec4 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-stock-stats-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php @@ -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 ); } diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php similarity index 96% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php index 15d7c22f92a..a52fa81205c 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php @@ -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(), diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php similarity index 89% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php index 8a1abbb89e9..dafe5b9ada1 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-taxes-stats-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php @@ -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'] ); diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-variations-data-store.php b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php similarity index 96% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-variations-data-store.php rename to plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php index 2905ffa5f25..974f22628e0 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-variations-data-store.php +++ b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php @@ -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(), diff --git a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php index e022d2dd323..2bf66a770e9 100644 --- a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php +++ b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php @@ -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', ) ); } diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php b/plugins/woocommerce-admin/src/Notes/DataStore.php similarity index 97% rename from plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php rename to plugins/woocommerce-admin/src/Notes/DataStore.php index ad00b9b335d..f62a0a0c42e 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-notes-data-store.php +++ b/plugins/woocommerce-admin/src/Notes/DataStore.php @@ -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' ) ); } } diff --git a/plugins/woocommerce-admin/src/WC_Admin_Order.php b/plugins/woocommerce-admin/src/WC_Admin_Order.php index e1b3bc4eee9..2f839db616c 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Order.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Order.php @@ -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 ); } /** diff --git a/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php b/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php index 1c12478e835..174ef8f01c9 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php @@ -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 ); } /** diff --git a/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php b/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php index 286640e7eba..5b395a2fb88 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php @@ -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' ) ); diff --git a/plugins/woocommerce-admin/tests/api-init.php b/plugins/woocommerce-admin/tests/api-init.php index dd5eace6682..a325735ffa3 100644 --- a/plugins/woocommerce-admin/tests/api-init.php +++ b/plugins/woocommerce-admin/tests/api-init.php @@ -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. diff --git a/plugins/woocommerce-admin/tests/api/orders.php b/plugins/woocommerce-admin/tests/api/orders.php index f6ec715c3a1..2d01f05fe24 100644 --- a/plugins/woocommerce-admin/tests/api/orders.php +++ b/plugins/woocommerce-admin/tests/api/orders.php @@ -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() ) ); } } diff --git a/plugins/woocommerce-admin/tests/api/reports-customers.php b/plugins/woocommerce-admin/tests/api/reports-customers.php index fb8af68af0a..d167191f5a3 100644 --- a/plugins/woocommerce-admin/tests/api/reports-customers.php +++ b/plugins/woocommerce-admin/tests/api/reports-customers.php @@ -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 ) ); } } diff --git a/plugins/woocommerce-admin/tests/api/reports-orders.php b/plugins/woocommerce-admin/tests/api/reports-orders.php index c697b0593ee..56da4764897 100644 --- a/plugins/woocommerce-admin/tests/api/reports-orders.php +++ b/plugins/woocommerce-admin/tests/api/reports-orders.php @@ -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(); diff --git a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-reports.php b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-reports.php index 9bc4bcb43c7..f6faf8abc8c 100644 --- a/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-reports.php +++ b/plugins/woocommerce-admin/tests/framework/helpers/class-wc-helper-reports.php @@ -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. } } diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php index 2c6de71d4ae..5481659217a 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php @@ -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( diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php index 173e9b2b1cb..7a57114c6da 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php @@ -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( diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php index 65ebd3475fd..1f628eee019 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php @@ -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( diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php index d02e4e48dc5..fd1508fadc8 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php @@ -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( diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php index 7bcce7aa1f0..758f9bb0a51 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php @@ -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() ); diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php index fd44d4e957f..7ccdeb81d5e 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php @@ -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( From 3e9ef793a78aa2c523fe5ac87c47e3077fbaf37a Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 6 Aug 2019 11:39:28 -0600 Subject: [PATCH 20/32] PSR-4ify the reports data store interface class. --- .../src/API/Reports/Categories/DataStore.php | 5 ++++- .../woocommerce-admin/src/API/Reports/Coupons/DataStore.php | 5 ++++- .../src/API/Reports/Coupons/Stats/DataStore.php | 5 +++-- .../src/API/Reports/Customers/DataStore.php | 5 ++++- .../src/API/Reports/Customers/Stats/DataStore.php | 5 ++++- .../API/Reports/DataStoreInterface.php} | 4 +++- .../src/API/Reports/Downloads/DataStore.php | 5 ++++- .../src/API/Reports/Downloads/Stats/DataStore.php | 5 ++++- .../woocommerce-admin/src/API/Reports/Orders/DataStore.php | 5 ++++- .../src/API/Reports/Orders/Stats/DataStore.php | 5 ++++- .../woocommerce-admin/src/API/Reports/Products/DataStore.php | 5 ++++- .../src/API/Reports/Products/Stats/DataStore.php | 5 ++++- .../src/API/Reports/Stock/Stats/DataStore.php | 5 ++++- .../woocommerce-admin/src/API/Reports/Taxes/DataStore.php | 5 ++++- .../src/API/Reports/Taxes/Stats/DataStore.php | 5 ++++- .../src/API/Reports/Variations/DataStore.php | 5 ++++- 16 files changed, 62 insertions(+), 17 deletions(-) rename plugins/woocommerce-admin/{includes/interfaces/class-wc-admin-reports-data-store-interface.php => src/API/Reports/DataStoreInterface.php} (81%) diff --git a/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php index 0caa4256e07..cfac80183c6 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Categories; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Categories_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php index bb8a808f784..2cc4ca69582 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Coupons_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php index 1c70a1143b6..f2760b2f69a 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php @@ -8,12 +8,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; /** * WC_Reports_Coupons_Stats_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore implements \WC_Admin_Reports_Data_Store_Interface { - +class DataStore extends CouponsDataStore implements DataStoreInterface { /** * Mapping columns to data type to return correct response types. * diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php index d1fc1483ec1..a85c992a727 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Customers; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Customers_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php index 823ef296578..a36e7329ad1 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Customers\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Customers_Stats_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends CustomersDataStore implements DataStoreInterface { /** * Mapping columns to data type to return correct response types. * diff --git a/plugins/woocommerce-admin/includes/interfaces/class-wc-admin-reports-data-store-interface.php b/plugins/woocommerce-admin/src/API/Reports/DataStoreInterface.php similarity index 81% rename from plugins/woocommerce-admin/includes/interfaces/class-wc-admin-reports-data-store-interface.php rename to plugins/woocommerce-admin/src/API/Reports/DataStoreInterface.php index b202cacbb2f..cf72f61d7fb 100644 --- a/plugins/woocommerce-admin/includes/interfaces/class-wc-admin-reports-data-store-interface.php +++ b/plugins/woocommerce-admin/src/API/Reports/DataStoreInterface.php @@ -5,6 +5,8 @@ * @package WooCommerce Admin/Interface */ +namespace Automattic\WooCommerce\Admin\API\Reports; + if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -14,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) { * * @since 3.5.0 */ -interface WC_Admin_Reports_Data_Store_Interface { +interface DataStoreInterface { /** * Get the data based on args. diff --git a/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php index 140b644dda2..0cd17585268 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Downloads; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Downloads_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php index 9ede3fac44c..32280c5a082 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore as DownloadsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Downloads_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends DownloadsDataStore implements DataStoreInterface { /** * Mapping columns to data type to return correct response types. diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php index ec13555783e..6369a36be05 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Orders; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Orders_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php index fdd7d84936e..f60f549dd95 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Orders_Stats_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php index 72a98797a16..3c1242bbdf0 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Products; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Products_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php index fc8f4bb3ace..bfc46d4b5da 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Reports_Products_Stats_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ProductsDataStore implements DataStoreInterface { /** * Mapping columns to data type to return correct response types. diff --git a/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php index eb47d739ec4..b7448382add 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Stock\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Reports_Stock_Stats_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Get stock counts for the whole store. diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php index a52fa81205c..cd5f5244495 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Taxes; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Taxes_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php index dafe5b9ada1..ffdea58a302 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Reports_Taxes_Stats_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. diff --git a/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php index 974f22628e0..49b1188b992 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php @@ -9,10 +9,13 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Variations; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; + /** * WC_Admin_Reports_Products_Data_Store. */ -class DataStore extends \Automattic\WooCommerce\Admin\API\Reports\DataStore implements \WC_Admin_Reports_Data_Store_Interface { +class DataStore extends ReportsDataStore implements DataStoreInterface { /** * Table used to get the data. From 8f614623286dc98ca9e243aeebac70e7e4c1ab0b Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 6 Aug 2019 12:13:13 -0600 Subject: [PATCH 21/32] PSR-4ify the report stats segmenter classes. --- .../src/API/Reports/Coupons/Stats/DataStore.php | 2 +- .../API/Reports/Coupons/Stats/Segmenter.php} | 8 ++++++-- .../src/API/Reports/Orders/Stats/DataStore.php | 6 +++--- .../API/Reports/Orders/Stats/Segmenter.php} | 8 ++++++-- .../src/API/Reports/Products/Stats/DataStore.php | 2 +- .../API/Reports/Products/Stats/Segmenter.php} | 9 +++++++-- .../API/Reports/Segmenter.php} | 13 +++++++++---- .../src/API/Reports/Taxes/Stats/DataStore.php | 2 +- .../API/Reports/Taxes/Stats/Segmenter.php} | 6 +++++- 9 files changed, 39 insertions(+), 17 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-coupons-stats-segmenting.php => src/API/Reports/Coupons/Stats/Segmenter.php} (97%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-orders-stats-segmenting.php => src/API/Reports/Orders/Stats/Segmenter.php} (97%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-products-stats-segmenting.php => src/API/Reports/Products/Stats/Segmenter.php} (95%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-segmenting.php => src/API/Reports/Segmenter.php} (97%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-taxes-stats-segmenting.php => src/API/Reports/Taxes/Stats/Segmenter.php} (96%) diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php index f2760b2f69a..8d6b8e3417d 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php @@ -166,7 +166,7 @@ class DataStore extends CouponsDataStore implements DataStoreInterface { if ( null === $totals ) { return $data; } - $segmenter = new \WC_Admin_Reports_Coupons_Stats_Segmenting( $query_args, $this->report_columns ); + $segmenter = new Segmenter( $query_args, $this->report_columns ); $totals[0]['segments'] = $segmenter->get_totals_segments( $totals_query, $table_name ); $totals = (object) $this->cast_numbers( $totals[0] ); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-stats-segmenting.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php similarity index 97% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-stats-segmenting.php rename to plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php index 43c1f2e6ee2..1f126c08cd2 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-stats-segmenting.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php @@ -5,12 +5,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter; + /** * Date & time interval and numeric range handling class for Reporting API. */ -class WC_Admin_Reports_Coupons_Stats_Segmenting extends WC_Admin_Reports_Segmenting { +class Segmenter extends ReportsSegmenter { /** * Returns SELECT clause statements to be used for product-related product-level segmenting query (e.g. coupon discount amount for product X when segmenting by product id or category). @@ -271,7 +275,7 @@ class WC_Admin_Reports_Coupons_Stats_Segmenting extends WC_Admin_Reports_Segment $segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table ); } elseif ( 'variation' === $this->query_args['segmentby'] ) { if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) { - throw new WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); + throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); } $segmenting_selections = array( diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php index f60f549dd95..8baca25c617 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php @@ -275,10 +275,10 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { $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 ); + $segmenter = new Segmenter( $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 ); + $totals[0]['segments'] = $segmenter->get_totals_segments( $totals_query, $table_name ); $totals = (object) $this->cast_numbers( $totals[0] ); $db_intervals = $wpdb->get_col( @@ -355,7 +355,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { } else { $this->update_interval_boundary_dates( $query_args['after'], $query_args['before'], $query_args['interval'], $data->intervals ); } - $segmenting->add_intervals_segments( $data, $intervals_query, $table_name ); + $segmenter->add_intervals_segments( $data, $intervals_query, $table_name ); $this->create_interval_subtotals( $data->intervals ); wp_cache_set( $cache_key, $data, $this->cache_group ); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-stats-segmenting.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php similarity index 97% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-stats-segmenting.php rename to plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php index b349dfad337..b7a3b0602d9 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-stats-segmenting.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php @@ -5,12 +5,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter; + /** * Date & time interval and numeric range handling class for Reporting API. */ -class WC_Admin_Reports_Orders_Stats_Segmenting extends WC_Admin_Reports_Segmenting { +class Segmenter extends ReportsSegmenter { /** * Returns SELECT clause statements to be used for product-related product-level segmenting query (e.g. products sold, revenue from product X when segmenting by category). @@ -366,7 +370,7 @@ class WC_Admin_Reports_Orders_Stats_Segmenting extends WC_Admin_Reports_Segmenti $segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table ); } elseif ( 'variation' === $this->query_args['segmentby'] ) { if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) { - throw new WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); + throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); } $segmenting_selections = array( diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php index bfc46d4b5da..8749ae10658 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php @@ -169,7 +169,7 @@ class DataStore extends ProductsDataStore implements DataStoreInterface { 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 Segmenter( $query_args, $this->report_columns ); $totals[0]['segments'] = $segmenter->get_totals_segments( $totals_query, $table_name ); if ( null === $totals ) { diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-stats-segmenting.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php similarity index 95% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-products-stats-segmenting.php rename to plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php index e582d08dca2..ecb077e9310 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-stats-segmenting.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php @@ -5,12 +5,17 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter; + + /** * Date & time interval and numeric range handling class for Reporting API. */ -class WC_Admin_Reports_Products_Stats_Segmenting extends WC_Admin_Reports_Segmenting { +class Segmenter extends ReportsSegmenter { /** * Returns SELECT clause statements to be used for product-related product-level segmenting query (e.g. products sold, revenue from product X when segmenting by category). @@ -158,7 +163,7 @@ class WC_Admin_Reports_Products_Stats_Segmenting extends WC_Admin_Reports_Segmen $segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table ); } elseif ( 'variation' === $this->query_args['segmentby'] ) { if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) { - throw new WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); + throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); } $segmenting_selections = array( diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-segmenting.php b/plugins/woocommerce-admin/src/API/Reports/Segmenter.php similarity index 97% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-segmenting.php rename to plugins/woocommerce-admin/src/API/Reports/Segmenter.php index 4b761f2dde9..007c7687a2b 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-segmenting.php +++ b/plugins/woocommerce-admin/src/API/Reports/Segmenter.php @@ -5,12 +5,17 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\DataStore as TaxesStatsDataStore; + /** * Date & time interval and numeric range handling class for Reporting API. */ -class WC_Admin_Reports_Segmenting { +class Segmenter { /** * Array of all segment ids. @@ -375,7 +380,7 @@ class WC_Admin_Reports_Segmenting { if ( isset( $this->query_args['coupons'] ) ) { $args['include'] = $this->query_args['coupons']; } - $coupons = WC_Admin_Reports_Coupons_Data_Store::get_coupons( $args ); + $coupons = CouponsDataStore::get_coupons( $args ); $segments = wp_list_pluck( $coupons, 'ID' ); $segment_labels = wp_list_pluck( $coupons, 'post_title', 'ID' ); $segment_labels = array_map( 'wc_format_coupon_code', $segment_labels ); @@ -388,12 +393,12 @@ class WC_Admin_Reports_Segmenting { if ( isset( $this->query_args['taxes'] ) ) { $args['include'] = $this->query_args['taxes']; } - $taxes = WC_Admin_Reports_Taxes_Stats_Data_Store::get_taxes( $args ); + $taxes = TaxesStatsDataStore::get_taxes( $args ); foreach ( $taxes as $tax ) { $id = $tax['tax_rate_id']; $segments[] = $id; - $segment_labels[ $id ] = WC_Tax::get_rate_code( (object) $tax ); + $segment_labels[ $id ] = \WC_Tax::get_rate_code( (object) $tax ); } } else { // Catch all default. diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php index ffdea58a302..019beefe507 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php @@ -223,7 +223,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { if ( null === $totals ) { 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 Segmenter( $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 ); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-stats-segmenting.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Segmenter.php similarity index 96% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-stats-segmenting.php rename to plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Segmenter.php index 6f3bf61bada..7ad39fb3805 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-stats-segmenting.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Segmenter.php @@ -5,12 +5,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter; + /** * Date & time interval and numeric range handling class for Reporting API. */ -class WC_Admin_Reports_Taxes_Stats_Segmenting extends WC_Admin_Reports_Segmenting { +class Segmenter extends ReportsSegmenter { /** * Returns SELECT clause statements to be used for order-related order-level segmenting query (e.g. tax_rate_id). From 88f6fd9d06d27776d2eae070e7864f08893e2b08 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 6 Aug 2019 13:11:33 -0600 Subject: [PATCH 22/32] PSR-4ify report query classes. --- .../src/API/Reports/Categories/Controller.php | 2 +- .../API/Reports/Categories/Query.php} | 8 ++++++-- .../src/API/Reports/Coupons/Controller.php | 2 +- .../API/Reports/Coupons/Query.php} | 10 +++++++--- .../src/API/Reports/Coupons/Stats/Controller.php | 2 +- .../API/Reports/Coupons/Stats/Query.php} | 8 ++++++-- .../src/API/Reports/Customers/Controller.php | 2 +- .../API/Reports/Customers/Query.php} | 8 ++++++-- .../src/API/Reports/Customers/Stats/Controller.php | 2 +- .../API/Reports/Customers/Stats/Query.php} | 8 ++++++-- .../src/API/Reports/Downloads/Controller.php | 2 +- .../API/Reports/Downloads/Query.php} | 8 ++++++-- .../src/API/Reports/Downloads/Stats/Controller.php | 2 +- .../API/Reports/Downloads/Stats/Query.php} | 8 ++++++-- .../src/API/Reports/Orders/Controller.php | 2 +- .../API/Reports/Orders/Query.php} | 8 ++++++-- .../src/API/Reports/Orders/Stats/Controller.php | 2 +- .../API/Reports/Orders/Stats/Query.php} | 8 ++++++-- .../src/API/Reports/Products/Controller.php | 2 +- .../API/Reports/Products/Query.php} | 8 ++++++-- .../src/API/Reports/Products/Stats/Controller.php | 2 +- .../API/Reports/Products/Stats/Query.php} | 8 ++++++-- .../API/Reports/Query.php} | 6 ++++-- .../API/Reports/Revenue/Query.php} | 8 ++++++-- .../src/API/Reports/Revenue/Stats/Controller.php | 4 +++- .../src/API/Reports/Stock/Stats/Controller.php | 2 +- .../API/Reports/Stock/Stats/Query.php} | 8 ++++++-- .../src/API/Reports/Taxes/Controller.php | 2 +- .../API/Reports/Taxes/Query.php} | 8 ++++++-- .../src/API/Reports/Taxes/Stats/Controller.php | 2 +- .../API/Reports/Taxes/Stats/Query.php} | 8 ++++++-- .../src/API/Reports/Variations/Controller.php | 2 +- .../API/Reports/Variations/Query.php} | 8 ++++++-- .../reports/class-wc-tests-reports-coupons-stats.php | 3 ++- .../tests/reports/class-wc-tests-reports-coupons.php | 3 ++- .../reports/class-wc-tests-reports-orders-stats.php | 3 ++- .../tests/reports/class-wc-tests-reports-products.php | 7 ++++--- .../reports/class-wc-tests-reports-revenue-stats.php | 3 ++- .../reports/class-wc-tests-reports-variations.php | 3 ++- 39 files changed, 133 insertions(+), 59 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-categories-query.php => src/API/Reports/Categories/Query.php} (81%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-coupons-query.php => src/API/Reports/Coupons/Query.php} (78%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-coupons-stats-query.php => src/API/Reports/Coupons/Stats/Query.php} (80%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-customers-query.php => src/API/Reports/Customers/Query.php} (84%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-customers-stats-query.php => src/API/Reports/Customers/Stats/Query.php} (84%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-downloads-query.php => src/API/Reports/Downloads/Query.php} (81%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-downloads-stats-query.php => src/API/Reports/Downloads/Stats/Query.php} (74%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-orders-query.php => src/API/Reports/Orders/Query.php} (82%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-orders-stats-query.php => src/API/Reports/Orders/Stats/Query.php} (85%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-products-query.php => src/API/Reports/Products/Query.php} (82%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-products-stats-query.php => src/API/Reports/Products/Stats/Query.php} (81%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-query.php => src/API/Reports/Query.php} (55%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-revenue-query.php => src/API/Reports/Revenue/Query.php} (85%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-stock-stats-query.php => src/API/Reports/Stock/Stats/Query.php} (68%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-taxes-query.php => src/API/Reports/Taxes/Query.php} (81%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-taxes-stats-query.php => src/API/Reports/Taxes/Stats/Query.php} (82%) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-variations-query.php => src/API/Reports/Variations/Query.php} (82%) diff --git a/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php index ae6b2ae13b3..5070dda7bc7 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php @@ -64,7 +64,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $categories_query = new \WC_Admin_Reports_Categories_Query( $query_args ); + $categories_query = new Query( $query_args ); $report_data = $categories_query->get_data(); if ( is_wp_error( $report_data ) ) { diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-categories-query.php b/plugins/woocommerce-admin/src/API/Reports/Categories/Query.php similarity index 81% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-categories-query.php rename to plugins/woocommerce-admin/src/API/Reports/Categories/Query.php index 3a96fe7647f..2cb2067e672 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-categories-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/Query.php @@ -16,12 +16,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Categories; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Categories_Query */ -class WC_Admin_Reports_Categories_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { const REPORT_NAME = 'report-categories'; @@ -41,7 +45,7 @@ class WC_Admin_Reports_Categories_Query extends WC_Admin_Reports_Query { */ public function get_data() { $args = apply_filters( 'woocommerce_reports_categories_query_args', $this->get_query_vars() ); - $results = WC_Data_Store::load( self::REPORT_NAME )->get_data( $args ); + $results = \WC_Data_Store::load( self::REPORT_NAME )->get_data( $args ); return apply_filters( 'woocommerce_reports_categories_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Controller.php index bddd6ffcb41..6ac18561368 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Controller.php @@ -60,7 +60,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $coupons_query = new \WC_Admin_Reports_Coupons_Query( $query_args ); + $coupons_query = new Query( $query_args ); $report_data = $coupons_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-query.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Query.php similarity index 78% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-query.php rename to plugins/woocommerce-admin/src/API/Reports/Coupons/Query.php index 570c3a01013..fa07669e77e 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Query.php @@ -15,12 +15,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Coupons; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** - * WC_Admin_Reports_Products_Query + * WC_Admin_Reports_Coupons_Query */ -class WC_Admin_Reports_Coupons_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Products report. @@ -39,7 +43,7 @@ class WC_Admin_Reports_Coupons_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_coupons_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-coupons' ); + $data_store = \WC_Data_Store::load( 'report-coupons' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_coupons_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php index abc31a3f217..42ba964544d 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php @@ -63,7 +63,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $coupons_query = new \WC_Admin_Reports_Coupons_Stats_Query( $query_args ); + $coupons_query = new Query( $query_args ); try { $report_data = $coupons_query->get_data(); } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-stats-query.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Query.php similarity index 80% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-stats-query.php rename to plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Query.php index 4dd05a81ccd..722eb91ef5c 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-coupons-stats-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Query.php @@ -15,12 +15,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Products_Query */ -class WC_Admin_Reports_Coupons_Stats_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Products report. @@ -39,7 +43,7 @@ class WC_Admin_Reports_Coupons_Stats_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_coupons_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-coupons-stats' ); + $data_store = \WC_Data_Store::load( 'report-coupons-stats' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_coupons_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php index 91d054e955c..6e23f7eff00 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php @@ -89,7 +89,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $customers_query = new \WC_Admin_Reports_Customers_Query( $query_args ); + $customers_query = new Query( $query_args ); $report_data = $customers_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-customers-query.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Query.php similarity index 84% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-customers-query.php rename to plugins/woocommerce-admin/src/API/Reports/Customers/Query.php index 937a0bf7b42..cd394443216 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-customers-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Query.php @@ -16,12 +16,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Customers; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Customers_Query */ -class WC_Admin_Reports_Customers_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Customers report. @@ -46,7 +50,7 @@ class WC_Admin_Reports_Customers_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_customers_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-customers' ); + $data_store = \WC_Data_Store::load( 'report-customers' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_customers_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php index a845e9b9169..66cc8dc4ad8 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php @@ -81,7 +81,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $customers_query = new \WC_Admin_Reports_Customers_Stats_Query( $query_args ); + $customers_query = new Query( $query_args ); $report_data = $customers_query->get_data(); $out_data = array( 'totals' => $report_data, diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-customers-stats-query.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Query.php similarity index 84% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-customers-stats-query.php rename to plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Query.php index 70f4e3c7295..a04fdb4b1f3 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-customers-stats-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Query.php @@ -16,12 +16,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Customers\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Customers_Stats_Query */ -class WC_Admin_Reports_Customers_Stats_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Customers report. @@ -46,7 +50,7 @@ class WC_Admin_Reports_Customers_Stats_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_customers_stats_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-customers-stats' ); + $data_store = \WC_Data_Store::load( 'report-customers-stats' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_customers_stats_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Downloads/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Controller.php index 85990d4e538..05de92ba36f 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Downloads/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Controller.php @@ -47,7 +47,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { } } - $reports = new \WC_Admin_Reports_Downloads_Query( $args ); + $reports = new Query( $args ); $downloads_data = $reports->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-downloads-query.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Query.php similarity index 81% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-downloads-query.php rename to plugins/woocommerce-admin/src/API/Reports/Downloads/Query.php index aaeaa25c3c0..868be02a7d4 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-downloads-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Query.php @@ -15,12 +15,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Downloads; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Downloads_Query */ -class WC_Admin_Reports_Downloads_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for downloads report. @@ -39,7 +43,7 @@ class WC_Admin_Reports_Downloads_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_downloads_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-downloads' ); + $data_store = \WC_Data_Store::load( 'report-downloads' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_downloads_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Controller.php index 33ace0de433..beeb1c3cf35 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Controller.php @@ -69,7 +69,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $downloads_query = new \WC_Admin_Reports_Downloads_Stats_Query( $query_args ); + $downloads_query = new Query( $query_args ); $report_data = $downloads_query->get_data(); $out_data = array( diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-downloads-stats-query.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Query.php similarity index 74% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-downloads-stats-query.php rename to plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Query.php index 21ea14fc7c7..4a4b22c438a 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-downloads-stats-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/Query.php @@ -5,12 +5,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Downloads_Stats_Query */ -class WC_Admin_Reports_Downloads_Stats_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Orders report. @@ -29,7 +33,7 @@ class WC_Admin_Reports_Downloads_Stats_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_downloads_stats_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-downloads-stats' ); + $data_store = \WC_Data_Store::load( 'report-downloads-stats' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_downloads_stats_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Controller.php index f63ccb61b84..29c93f652d6 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Controller.php @@ -71,7 +71,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $orders_query = new \WC_Admin_Reports_Orders_Query( $query_args ); + $orders_query = new Query( $query_args ); $report_data = $orders_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-query.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Query.php similarity index 82% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-query.php rename to plugins/woocommerce-admin/src/API/Reports/Orders/Query.php index 55857312be9..be3a8387363 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Query.php @@ -19,12 +19,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Orders; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Orders_Query */ -class WC_Admin_Reports_Orders_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Get order data based on the current query vars. @@ -33,7 +37,7 @@ class WC_Admin_Reports_Orders_Query extends WC_Admin_Reports_Query { */ public function get_data() { $args = apply_filters( 'woocommerce_reports_orders_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-orders' ); + $data_store = \WC_Data_Store::load( 'report-orders' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_orders_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php index 60fd6dde22c..98984933125 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php @@ -72,7 +72,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $orders_query = new \WC_Admin_Reports_Orders_Stats_Query( $query_args ); + $orders_query = new Query( $query_args ); try { $report_data = $orders_query->get_data(); } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-stats-query.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Query.php similarity index 85% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-stats-query.php rename to plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Query.php index 829ba9b552d..c7c61be047f 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-orders-stats-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Query.php @@ -17,12 +17,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Orders_Stats_Query */ -class WC_Admin_Reports_Orders_Stats_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Orders report. @@ -53,7 +57,7 @@ class WC_Admin_Reports_Orders_Stats_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_orders_stats_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-orders-stats' ); + $data_store = \WC_Data_Store::load( 'report-orders-stats' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_orders_stats_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Products/Controller.php index 7a5a938971e..c6da2ec120b 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Controller.php @@ -62,7 +62,7 @@ class Controller extends \WC_REST_Reports_Controller { } } - $reports = new \WC_Admin_Reports_Products_Query( $args ); + $reports = new Query( $args ); $products_data = $reports->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-query.php b/plugins/woocommerce-admin/src/API/Reports/Products/Query.php similarity index 82% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-products-query.php rename to plugins/woocommerce-admin/src/API/Reports/Products/Query.php index 60d359b615a..414af725e7e 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Query.php @@ -16,12 +16,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Products; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Products_Query */ -class WC_Admin_Reports_Products_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Products report. @@ -40,7 +44,7 @@ class WC_Admin_Reports_Products_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_products_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-products' ); + $data_store = \WC_Data_Store::load( 'report-products' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_products_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php index a0a3e36bce9..50e708ccc11 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php @@ -77,7 +77,7 @@ class Controller extends \WC_REST_Reports_Controller { } } - $query = new \WC_Admin_Reports_Products_Stats_Query( $query_args ); + $query = new Query( $query_args ); try { $report_data = $query->get_data(); } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-stats-query.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Query.php similarity index 81% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-products-stats-query.php rename to plugins/woocommerce-admin/src/API/Reports/Products/Stats/Query.php index a1e89de2f5c..8cda3e9425f 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-products-stats-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Query.php @@ -16,12 +16,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Products_Query */ -class WC_Admin_Reports_Products_Stats_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Products report. @@ -40,7 +44,7 @@ class WC_Admin_Reports_Products_Stats_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_products_stats_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-products-stats' ); + $data_store = \WC_Data_Store::load( 'report-products-stats' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_products_stats_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-query.php b/plugins/woocommerce-admin/src/API/Reports/Query.php similarity index 55% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-query.php rename to plugins/woocommerce-admin/src/API/Reports/Query.php index 4fb0df6a3f1..d6440e8354e 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Query.php @@ -5,12 +5,14 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports; + defined( 'ABSPATH' ) || exit; /** * WC_Admin_Reports_Query */ -abstract class WC_Admin_Reports_Query extends WC_Object_Query { +abstract class Query extends \WC_Object_Query { /** * Get report data matching the current query vars. @@ -19,7 +21,7 @@ abstract class WC_Admin_Reports_Query extends WC_Object_Query { */ public function get_data() { /* translators: %s: Method name */ - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce-admin' ), __METHOD__ ), array( 'status' => 405 ) ); + return new \WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce-admin' ), __METHOD__ ), array( 'status' => 405 ) ); } } diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-revenue-query.php b/plugins/woocommerce-admin/src/API/Reports/Revenue/Query.php similarity index 85% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-revenue-query.php rename to plugins/woocommerce-admin/src/API/Reports/Revenue/Query.php index d88c1d3c91e..fc967357cae 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-revenue-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Revenue/Query.php @@ -14,12 +14,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Revenue; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Revenue_Query */ -class WC_Admin_Reports_Revenue_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Revenue report. @@ -57,7 +61,7 @@ class WC_Admin_Reports_Revenue_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_revenue_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-revenue-stats' ); + $data_store = \WC_Data_Store::load( 'report-revenue-stats' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_revenue_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php index d9ff6d55315..b6f6ecbdd81 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Revenue\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery; + /** * REST API Reports revenue stats controller class. * @@ -61,7 +63,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $reports_revenue = new \WC_Admin_Reports_Revenue_Query( $query_args ); + $reports_revenue = new RevenueQuery( $query_args ); try { $report_data = $reports_revenue->get_data(); } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { diff --git a/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Controller.php index 83e9df9b0b7..50ce02f501b 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Controller.php @@ -40,7 +40,7 @@ class Controller extends \WC_REST_Reports_Controller { * @return array|WP_Error */ public function get_items( $request ) { - $stock_query = new \WC_Admin_Reports_Stock_Stats_Query(); + $stock_query = new Query(); $report_data = $stock_query->get_data(); $out_data = array( 'totals' => $report_data, diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-stock-stats-query.php b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Query.php similarity index 68% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-stock-stats-query.php rename to plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Query.php index 297c19ede46..8dbca4b446f 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-stock-stats-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/Query.php @@ -8,12 +8,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Stock\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Stock_Stats_Query */ -class WC_Admin_Reports_Stock_Stats_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Get product data based on the current query vars. @@ -21,7 +25,7 @@ class WC_Admin_Reports_Stock_Stats_Query extends WC_Admin_Reports_Query { * @return array */ public function get_data() { - $data_store = WC_Data_Store::load( 'report-stock-stats' ); + $data_store = \WC_Data_Store::load( 'report-stock-stats' ); $results = $data_store->get_data(); return apply_filters( 'woocommerce_reports_stock_stats_query', $results ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Controller.php index 29d083a4e93..96a6fa12835 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Controller.php @@ -60,7 +60,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $taxes_query = new \WC_Admin_Reports_Taxes_Query( $query_args ); + $taxes_query = new Query( $query_args ); $report_data = $taxes_query->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-query.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Query.php similarity index 81% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-query.php rename to plugins/woocommerce-admin/src/API/Reports/Taxes/Query.php index 7a22a8413a9..2f8beef79e8 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Query.php @@ -15,12 +15,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Taxes; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Taxes_Query */ -class WC_Admin_Reports_Taxes_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Taxes report. @@ -39,7 +43,7 @@ class WC_Admin_Reports_Taxes_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_taxes_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-taxes' ); + $data_store = \WC_Data_Store::load( 'report-taxes' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_taxes_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Controller.php index 136bc159ee2..671e60581dd 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Controller.php @@ -92,7 +92,7 @@ class Controller extends \WC_REST_Reports_Controller { */ public function get_items( $request ) { $query_args = $this->prepare_reports_query( $request ); - $taxes_query = new \WC_Admin_Reports_Taxes_Stats_Query( $query_args ); + $taxes_query = new Query( $query_args ); $report_data = $taxes_query->get_data(); $out_data = array( diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-stats-query.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Query.php similarity index 82% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-stats-query.php rename to plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Query.php index 61a15ad139f..665b82a1213 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-taxes-stats-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Query.php @@ -16,12 +16,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Taxes_Query */ -class WC_Admin_Reports_Taxes_Stats_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Taxes report. @@ -40,7 +44,7 @@ class WC_Admin_Reports_Taxes_Stats_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_taxes_stats_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-taxes-stats' ); + $data_store = \WC_Data_Store::load( 'report-taxes-stats' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_taxes_stats_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Variations/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Variations/Controller.php index 98eae81d7af..2fd8398c337 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Variations/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Variations/Controller.php @@ -62,7 +62,7 @@ class Controller extends \WC_REST_Reports_Controller { } } - $reports = new \WC_Admin_Reports_Variations_Query( $args ); + $reports = new Query( $args ); $products_data = $reports->get_data(); $data = array(); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-variations-query.php b/plugins/woocommerce-admin/src/API/Reports/Variations/Query.php similarity index 82% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-variations-query.php rename to plugins/woocommerce-admin/src/API/Reports/Variations/Query.php index cc9729e1268..bf6dd6ff08d 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-variations-query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Variations/Query.php @@ -16,12 +16,16 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports\Variations; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; + /** * WC_Admin_Reports_Products_Query */ -class WC_Admin_Reports_Variations_Query extends WC_Admin_Reports_Query { +class Query extends ReportsQuery { /** * Valid fields for Products report. @@ -40,7 +44,7 @@ class WC_Admin_Reports_Variations_Query extends WC_Admin_Reports_Query { public function get_data() { $args = apply_filters( 'woocommerce_reports_variations_query_args', $this->get_query_vars() ); - $data_store = WC_Data_Store::load( 'report-variations' ); + $data_store = \WC_Data_Store::load( 'report-variations' ); $results = $data_store->get_data( $args ); return apply_filters( 'woocommerce_reports_variations_select_query', $results, $args ); } diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php index 5481659217a..646471ea71b 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons-stats.php @@ -6,6 +6,7 @@ */ use \Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\DataStore as CouponsStatsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\Query as CouponsStatsQuery; /** * Class WC_Tests_Reports_Coupons_Stats @@ -100,7 +101,7 @@ class WC_Tests_Reports_Coupons_Stats extends WC_Unit_Test_Case { $this->assertEquals( $expected_data, $data ); // Test retrieving the stats through the query class. - $query = new WC_Admin_Reports_Coupons_Stats_Query( $args ); + $query = new CouponsStatsQuery( $args ); $this->assertEquals( $expected_data, $query->get_data() ); } } diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php index 7a57114c6da..33081839025 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php @@ -7,6 +7,7 @@ use \Automattic\WooCommerce\Admin\WC_Admin_Report_CSV_Exporter; use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\Coupons\Query as CouponsQuery; /** * Class WC_Tests_Reports_Coupons @@ -95,7 +96,7 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case { $this->assertEquals( $expected_data, $data ); // Test retrieving the stats through the query class. - $query = new WC_Admin_Reports_Coupons_Query( $args ); + $query = new CouponsQuery( $args ); $this->assertEquals( $expected_data, $query->get_data() ); // Test order by orders_count DESC. diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php index 1f628eee019..834641e1c63 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php @@ -6,6 +6,7 @@ */ use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\Query as OrdersStatsQuery; /** * Class WC_Tests_Reports_Orders_Stats @@ -110,7 +111,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $this->assertEquals( $expected_stats, json_decode( wp_json_encode( $data_store->get_data( $args ) ), true ) ); // Test retrieving the stats through the query class. - $query = new WC_Admin_Reports_Orders_Stats_Query( $args ); + $query = new OrdersStatsQuery( $args ); $expected_stats = array( 'totals' => array( 'net_revenue' => 68, diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php index fd1508fadc8..ec02f0a3ac6 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-products.php @@ -7,6 +7,7 @@ */ use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\Products\Query as ProductsQuery; /** * Reports product stats tests class @@ -69,7 +70,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case { $this->assertEquals( $expected_data, $data ); // Test retrieving the stats through the query class. - $query = new WC_Admin_Reports_Products_Query( $args ); + $query = new ProductsQuery( $args ); $this->assertEquals( $expected_data, $query->get_data() ); } @@ -185,7 +186,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case { $this->assertEquals( $expected_data, $data ); // Test retrieving the stats through the query class. - $query = new WC_Admin_Reports_Products_Query( $args ); + $query = new ProductsQuery( $args ); $this->assertEquals( $expected_data, $query->get_data() ); } @@ -410,7 +411,7 @@ class WC_Tests_Reports_Products extends WC_Unit_Test_Case { $this->assertEquals( $expected_data, $data ); // Test retrieving the stats through the query class. - $query = new WC_Admin_Reports_Products_Query( $args ); + $query = new ProductsQuery( $args ); $this->assertEquals( $expected_data, $query->get_data() ); } } diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php index 758f9bb0a51..77186ebec61 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-revenue-stats.php @@ -7,6 +7,7 @@ */ use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery; /** * Class WC_Admin_Tests_Reports_Revenue_Stats @@ -146,7 +147,7 @@ class WC_Admin_Tests_Reports_Revenue_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $query = new WC_Admin_Reports_Revenue_Query( $args ); + $query = new RevenueQuery( $args ); $this->assertEquals( $expected_stats, json_decode( wp_json_encode( $query->get_data() ), true ) ); } } diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php index 7ccdeb81d5e..e42dcdaf8ba 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-variations.php @@ -7,6 +7,7 @@ */ use \Automattic\WooCommerce\Admin\API\Reports\Variations\DataStore as VariationsDataStore; +use \Automattic\WooCommerce\Admin\API\Reports\Variations\Query as VariationsQuery; /** * Reports order stats tests class. @@ -71,7 +72,7 @@ class WC_Tests_Reports_Variations extends WC_Unit_Test_Case { $this->assertEquals( $expected_data, $data ); // Test retrieving the stats through the query class. - $query = new WC_Admin_Reports_Variations_Query( $args ); + $query = new VariationsQuery( $args ); $this->assertEquals( $expected_data, $query->get_data() ); } From 57ece077a67df9f15c98e40ca74f0e5842f1afdf Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 6 Aug 2019 13:36:15 -0600 Subject: [PATCH 23/32] Fix daily cron notes task class. --- .../class-wc-admin-events.php => src/WC_Admin_Events.php} | 6 ++++++ plugins/woocommerce-admin/woocommerce-admin.php | 1 + 2 files changed, 7 insertions(+) rename plugins/woocommerce-admin/{includes/class-wc-admin-events.php => src/WC_Admin_Events.php} (81%) diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-events.php b/plugins/woocommerce-admin/src/WC_Admin_Events.php similarity index 81% rename from plugins/woocommerce-admin/includes/class-wc-admin-events.php rename to plugins/woocommerce-admin/src/WC_Admin_Events.php index 2934174053a..588d48fd651 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-events.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Events.php @@ -6,8 +6,14 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin; + defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Giving_Feedback_Notes; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Mobile_App; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_New_Sales_Record; + /** * WC_Admin_Events Class. */ diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 2e350b8fdaa..08d418a4605 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -24,6 +24,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes; +use Automattic\WooCommerce\Admin\WC_Admin_Events; use Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; use Automattic\WooCommerce\Admin\API\WC_Admin_Api_Init; From a61d292c6705581fd03504865a96d5c384562d6b Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 6 Aug 2019 14:17:37 -0600 Subject: [PATCH 24/32] PSR-4ify the report parameter exception class. --- .../src/API/Reports/Coupons/Stats/Controller.php | 4 +++- .../src/API/Reports/Coupons/Stats/Segmenter.php | 3 ++- .../src/API/Reports/Orders/Stats/Controller.php | 4 +++- .../src/API/Reports/Orders/Stats/Segmenter.php | 3 ++- .../API/Reports/ParameterException.php} | 4 +++- .../src/API/Reports/Products/Stats/Controller.php | 4 +++- .../src/API/Reports/Products/Stats/Segmenter.php | 4 ++-- .../src/API/Reports/Revenue/Stats/Controller.php | 3 ++- 8 files changed, 20 insertions(+), 9 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-parameter-exception.php => src/API/Reports/ParameterException.php} (70%) diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php index 42ba964544d..355b9bdea17 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Controller.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\ParameterException; + /** * REST API Reports coupons stats controller class. * @@ -66,7 +68,7 @@ class Controller extends \WC_REST_Reports_Controller { $coupons_query = new Query( $query_args ); try { $report_data = $coupons_query->get_data(); - } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + } catch ( ParameterException $e ) { return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php index 1f126c08cd2..227e098f08f 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php @@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats; defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter; +use \Automattic\WooCommerce\Admin\API\Reports\ParameterException; /** * Date & time interval and numeric range handling class for Reporting API. @@ -275,7 +276,7 @@ class Segmenter extends ReportsSegmenter { $segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table ); } elseif ( 'variation' === $this->query_args['segmentby'] ) { if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) { - throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); + throw new ParameterException( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); } $segmenting_selections = array( diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php index 98984933125..d81fad397a2 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Controller.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\ParameterException; + /** * REST API Reports orders stats controller class. * @@ -75,7 +77,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { $orders_query = new Query( $query_args ); try { $report_data = $orders_query->get_data(); - } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + } catch ( ParameterException $e ) { return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php index b7a3b0602d9..4c712d61c9c 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php @@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Orders\Stats; defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter; +use \Automattic\WooCommerce\Admin\API\Reports\ParameterException; /** * Date & time interval and numeric range handling class for Reporting API. @@ -370,7 +371,7 @@ class Segmenter extends ReportsSegmenter { $segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table ); } elseif ( 'variation' === $this->query_args['segmentby'] ) { if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) { - throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); + throw new ParameterException( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); } $segmenting_selections = array( diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-parameter-exception.php b/plugins/woocommerce-admin/src/API/Reports/ParameterException.php similarity index 70% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-parameter-exception.php rename to plugins/woocommerce-admin/src/API/Reports/ParameterException.php index 75231f7d595..246131a9144 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-parameter-exception.php +++ b/plugins/woocommerce-admin/src/API/Reports/ParameterException.php @@ -7,9 +7,11 @@ * @package WooCommerce Admin */ +namespace Automattic\WooCommerce\Admin\API\Reports; + defined( 'ABSPATH' ) || exit; /** * WC_Admin_Reports_Parameter_Exception class. */ -class WC_Admin_Reports_Parameter_Exception extends WC_Data_Exception {} +class ParameterException extends \WC_Data_Exception {} diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php index 50e708ccc11..e2d547e5f7a 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Controller.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\ParameterException; + /** * REST API Reports products stats controller class. * @@ -80,7 +82,7 @@ class Controller extends \WC_REST_Reports_Controller { $query = new Query( $query_args ); try { $report_data = $query->get_data(); - } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + } catch ( ParameterException $e ) { return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php index ecb077e9310..b2a4d44cdca 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php @@ -10,7 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Products\Stats; defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Segmenter as ReportsSegmenter; - +use \Automattic\WooCommerce\Admin\API\Reports\ParameterException; /** * Date & time interval and numeric range handling class for Reporting API. @@ -163,7 +163,7 @@ class Segmenter extends ReportsSegmenter { $segments = $this->get_product_related_segments( $type, $segmenting_selections, $segmenting_from, $segmenting_where, $segmenting_groupby, $segmenting_dimension_name, $table_name, $query_params, $unique_orders_table ); } elseif ( 'variation' === $this->query_args['segmentby'] ) { if ( ! isset( $this->query_args['product_includes'] ) || count( $this->query_args['product_includes'] ) !== 1 ) { - throw new \WC_Admin_Reports_Parameter_Exception( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); + throw new ParameterException( 'wc_admin_reports_invalid_segmenting_variation', __( 'product_includes parameter need to specify exactly one product when segmenting by variation.', 'woocommerce-admin' ) ); } $segmenting_selections = array( diff --git a/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php index b6f6ecbdd81..571185eb82a 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Revenue/Stats/Controller.php @@ -12,6 +12,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Revenue\Stats; defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery; +use \Automattic\WooCommerce\Admin\API\Reports\ParameterException; /** * REST API Reports revenue stats controller class. @@ -66,7 +67,7 @@ class Controller extends \WC_REST_Reports_Controller { $reports_revenue = new RevenueQuery( $query_args ); try { $report_data = $reports_revenue->get_data(); - } catch ( \WC_Admin_Reports_Parameter_Exception $e ) { + } catch ( ParameterException $e ) { return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } From 7dd4d2b791c06e1fb84e475a4051f33193f7c9e7 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 6 Aug 2019 14:41:01 -0600 Subject: [PATCH 25/32] PSR-4ify the reports time interval class. --- .../src/API/Reports/Categories/DataStore.php | 5 +- .../src/API/Reports/Coupons/DataStore.php | 15 +- .../API/Reports/Coupons/Stats/DataStore.php | 9 +- .../src/API/Reports/Customers/Controller.php | 16 +- .../src/API/Reports/Customers/DataStore.php | 13 +- .../Reports/Customers/Stats/Controller.php | 16 +- .../src/API/Reports/DataStore.php | 40 +-- .../src/API/Reports/Downloads/DataStore.php | 9 +- .../API/Reports/Downloads/Stats/DataStore.php | 7 +- .../API/Reports/Orders/Stats/DataStore.php | 9 +- .../src/API/Reports/Products/DataStore.php | 7 +- .../API/Reports/Products/Stats/DataStore.php | 9 +- .../src/API/Reports/Taxes/DataStore.php | 7 +- .../src/API/Reports/Taxes/Stats/DataStore.php | 9 +- .../API/Reports/TimeInterval.php} | 46 ++-- .../src/API/Reports/Variations/DataStore.php | 5 +- .../tests/api/reports-interval.php | 72 +++--- .../class-wc-tests-reports-coupons.php | 17 +- .../class-wc-tests-reports-orders-stats.php | 237 +++++++++--------- 19 files changed, 286 insertions(+), 262 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-reports-interval.php => src/API/Reports/TimeInterval.php} (93%) diff --git a/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php index cfac80183c6..4662f519a51 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Categories_Data_Store. @@ -236,8 +237,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'date', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'categories' => array(), 'extended_info' => false, diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php index 2cc4ca69582..302ba49a633 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Coupons_Data_Store. @@ -187,10 +188,10 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { $date_expires = ''; $date_expires_gmt = ''; } else { - $date_expires = $date_expires->format( \WC_Admin_Reports_Interval::$iso_datetime_format ); + $date_expires = $date_expires->format( TimeInterval::$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( TimeInterval::$iso_datetime_format ); } $date_created = $coupon->get_date_created(); @@ -198,10 +199,10 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { $date_created = ''; $date_created_gmt = ''; } else { - $date_created = $date_created->format( \WC_Admin_Reports_Interval::$iso_datetime_format ); + $date_created = $date_created->format( TimeInterval::$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( TimeInterval::$iso_datetime_format ); } $extended_info = array( @@ -234,8 +235,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'coupon_id', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'coupons' => array(), 'extended_info' => false, @@ -390,7 +391,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { '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( TimeInterval::$sql_datetime_format ), ), array( '%d', diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php index 8d6b8e3417d..a7b6d0856dd 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php @@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats; defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Reports_Coupons_Stats_Data_Store. @@ -104,8 +105,8 @@ class DataStore extends CouponsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'date', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'interval' => 'week', 'coupons' => array(), @@ -144,7 +145,7 @@ class DataStore extends CouponsDataStore implements DataStoreInterface { ); // 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 = TimeInterval::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; @@ -209,7 +210,7 @@ class DataStore extends CouponsDataStore implements DataStoreInterface { '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 ( TimeInterval::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'] ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php index 6e23f7eff00..681c8946f9a 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Controller.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Customers; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; + /** * REST API Reports customers controller class. * @@ -73,9 +75,9 @@ class Controller extends \WC_REST_Reports_Controller { $args['customers'] = $request['customers']; $between_params_numeric = array( 'orders_count', 'total_spend', 'avg_order_value' ); - $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); + $normalized_params_numeric = TimeInterval::normalize_between_params( $request, $between_params_numeric, false ); $between_params_date = array( 'last_active', 'registered' ); - $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); + $normalized_params_date = TimeInterval::normalize_between_params( $request, $between_params_date, true ); $args = array_merge( $args, $normalized_params_numeric, $normalized_params_date ); return $args; @@ -433,7 +435,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['last_active_between'] = array( 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_date_arg' ), ); $params['registered_before'] = array( 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce-admin' ), @@ -450,7 +452,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['registered_between'] = array( 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_date_arg' ), ); $params['orders_count_min'] = array( 'description' => __( 'Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce-admin' ), @@ -467,7 +469,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['orders_count_between'] = array( 'description' => __( 'Limit response to objects with an order count between two given integers.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ), ); $params['total_spend_min'] = array( 'description' => __( 'Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce-admin' ), @@ -482,7 +484,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['total_spend_between'] = array( 'description' => __( 'Limit response to objects with a total order spend between two given numbers.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ), ); $params['avg_order_value_min'] = array( 'description' => __( 'Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce-admin' ), @@ -497,7 +499,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['avg_order_value_between'] = array( 'description' => __( 'Limit response to objects with an average order spend between two given numbers.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ), ); $params['last_order_before'] = array( 'description' => __( 'Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce-admin' ), diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php index a85c992a727..385fe79cfda 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Customers_Data_Store. @@ -175,13 +176,13 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 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_str = $datetime->format( TimeInterval::$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_str = $datetime->format( TimeInterval::$sql_datetime_format ); $subclauses[] = "{$column_name} >= '$datetime_str'"; } @@ -352,8 +353,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { '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' => TimeInterval::default_before(), + 'order_after' => TimeInterval::default_after(), 'fields' => '*', ); $query_args = wp_parse_args( $query_args, $defaults ); @@ -524,7 +525,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { $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( TimeInterval::$sql_datetime_format ) : null; $format[] = '%d'; $format[] = '%s'; $format[] = '%s'; @@ -643,7 +644,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { '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( TimeInterval::$sql_datetime_format ), 'date_last_active' => $last_active ? date( 'Y-m-d H:i:s', $last_active ) : null, ); $format = array( diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php index 66cc8dc4ad8..8c57d582807 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/Controller.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Customers\Stats; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; + /** * REST API Reports customers stats controller class. * @@ -65,9 +67,9 @@ class Controller extends \WC_REST_Reports_Controller { $args['customers'] = $request['customers']; $between_params_numeric = array( 'orders_count', 'total_spend', 'avg_order_value' ); - $normalized_params_numeric = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_numeric, false ); + $normalized_params_numeric = TimeInterval::normalize_between_params( $request, $between_params_numeric, false ); $between_params_date = array( 'last_active', 'registered' ); - $normalized_params_date = \WC_Admin_Reports_Interval::normalize_between_params( $request, $between_params_date, true ); + $normalized_params_date = TimeInterval::normalize_between_params( $request, $between_params_date, true ); $args = array_merge( $args, $normalized_params_numeric, $normalized_params_date ); return $args; @@ -273,7 +275,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['last_active_between'] = array( 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_date_arg' ), ); $params['registered_before'] = array( 'description' => __( 'Limit response to objects registered before (or at) a given ISO8601 compliant datetime.', 'woocommerce-admin' ), @@ -290,7 +292,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['registered_between'] = array( 'description' => __( 'Limit response to objects last active between two given ISO8601 compliant datetime.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_date_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_date_arg' ), ); $params['orders_count_min'] = array( 'description' => __( 'Limit response to objects with an order count greater than or equal to given integer.', 'woocommerce-admin' ), @@ -307,7 +309,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['orders_count_between'] = array( 'description' => __( 'Limit response to objects with an order count between two given integers.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ), ); $params['total_spend_min'] = array( 'description' => __( 'Limit response to objects with a total order spend greater than or equal to given number.', 'woocommerce-admin' ), @@ -322,7 +324,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['total_spend_between'] = array( 'description' => __( 'Limit response to objects with a total order spend between two given numbers.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ), ); $params['avg_order_value_min'] = array( 'description' => __( 'Limit response to objects with an average order spend greater than or equal to given number.', 'woocommerce-admin' ), @@ -337,7 +339,7 @@ class Controller extends \WC_REST_Reports_Controller { $params['avg_order_value_between'] = array( 'description' => __( 'Limit response to objects with an average order spend between two given numbers.', 'woocommerce-admin' ), 'type' => 'array', - 'validate_callback' => array( 'WC_Admin_Reports_Interval', 'rest_validate_between_numeric_arg' ), + 'validate_callback' => array( '\Automattic\WooCommerce\Admin\API\Reports\TimeInterval', 'rest_validate_between_numeric_arg' ), ); $params['last_order_before'] = array( 'description' => __( 'Limit response to objects with last order before (or at) a given ISO8601 compliant datetime.', 'woocommerce-admin' ), diff --git a/plugins/woocommerce-admin/src/API/Reports/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/DataStore.php index ad023aca970..a489aaad4fa 100644 --- a/plugins/woocommerce-admin/src/API/Reports/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/DataStore.php @@ -11,6 +11,8 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; + /** * WC_Admin_Reports_Data_Store: Common parent for custom report data stores. */ @@ -144,8 +146,8 @@ class DataStore { // @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 = TimeInterval::iterate( $start_datetime, $time_interval ); + $time_id = TimeInterval::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' ); @@ -329,7 +331,7 @@ class DataStore { $start_iteration = 0; break; } - $new_start_date = \WC_Admin_Reports_Interval::iterate( $new_start_date, $query_args['interval'] ); + $new_start_date = TimeInterval::iterate( $new_start_date, $query_args['interval'] ); $start_iteration ++; } @@ -338,7 +340,7 @@ class DataStore { 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 = TimeInterval::iterate( $new_end_date, $query_args['interval'] ); $end_iteration ++; } if ( $new_end_date > $latest_end_date ) { @@ -360,7 +362,7 @@ class DataStore { $end_iteration = 0; break; } - $new_end_date = \WC_Admin_Reports_Interval::iterate( $new_end_date, $query_args['interval'], true ); + $new_end_date = TimeInterval::iterate( $new_end_date, $query_args['interval'], true ); $end_iteration ++; } @@ -369,7 +371,7 @@ class DataStore { 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 = TimeInterval::iterate( $new_start_date, $query_args['interval'], true ); $start_iteration ++; } if ( $new_start_date < $earliest_start_date ) { @@ -384,8 +386,8 @@ class DataStore { } $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( TimeInterval::$sql_datetime_format ); + $adj_before = $new_end_date->format( TimeInterval::$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'"; @@ -505,7 +507,7 @@ class DataStore { foreach ( $intervals as $key => $interval ) { $datetime = new \DateTime( $interval['datetime_anchor'], $local_tz ); - $prev_start = \WC_Admin_Reports_Interval::iterate( $datetime, $time_interval, true ); + $prev_start = TimeInterval::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 ); @@ -516,7 +518,7 @@ class DataStore { $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 = TimeInterval::iterate( $datetime, $time_interval ); $next_end_timestamp = (int) $next_end->format( 'U' ) - 1; $next_end->setTimestamp( $next_end_timestamp ); if ( $end_datetime ) { @@ -539,15 +541,15 @@ class DataStore { */ 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 = TimeInterval::convert_local_datetime_to_gmt( $interval['date_start'] ); + $end_gmt = TimeInterval::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( TimeInterval::$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( TimeInterval::$sql_datetime_format ), ); unset( $interval['interval'] ); @@ -575,9 +577,9 @@ class DataStore { 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( TimeInterval::$sql_datetime_format ); } else { - $datetime_str = $query_args['before']->format( \WC_Admin_Reports_Interval::$sql_datetime_format ); + $datetime_str = $query_args['before']->format( TimeInterval::$sql_datetime_format ); } $sql_query['where_time_clause'] .= " AND {$table_name}.date_created <= '$datetime_str'"; @@ -585,9 +587,9 @@ class DataStore { 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( TimeInterval::$sql_datetime_format ); } else { - $datetime_str = $query_args['after']->format( \WC_Admin_Reports_Interval::$sql_datetime_format ); + $datetime_str = $query_args['after']->format( TimeInterval::$sql_datetime_format ); } $sql_query['where_time_clause'] .= " AND {$table_name}.date_created >= '$datetime_str'"; } @@ -710,7 +712,7 @@ class DataStore { 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'] = TimeInterval::db_datetime_format( $interval, $table_name ); } $intervals_query = array_merge( $intervals_query, $this->get_limit_sql_params( $query_args ) ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php index 0cd17585268..53ca08c5c92 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Downloads_Data_Store. @@ -260,13 +261,13 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { ); if ( $query_args['before'] ) { - $datetime_str = $query_args['before']->format( \WC_Admin_Reports_Interval::$sql_datetime_format ); + $datetime_str = $query_args['before']->format( TimeInterval::$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( TimeInterval::$sql_datetime_format ); $sql_query['where_time_clause'] .= " AND {$table_name}.timestamp >= '$datetime_str'"; } @@ -317,8 +318,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'timestamp', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', ); $query_args = wp_parse_args( $query_args, $defaults ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php index 32280c5a082..d7c4641260d 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore as DownloadsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Downloads_Data_Store. @@ -62,8 +63,8 @@ class DataStore extends DownloadsDataStore implements DataStoreInterface { 'orderby' => 'date', 'fields' => '*', 'interval' => 'week', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), ); $query_args = wp_parse_args( $query_args, $defaults ); $this->normalize_timezones( $query_args, $defaults ); @@ -100,7 +101,7 @@ class DataStore extends DownloadsDataStore implements DataStoreInterface { $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 = TimeInterval::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(); diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php index 8baca25c617..bf270098dde 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Orders_Stats_Data_Store. @@ -207,8 +208,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'date', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'interval' => 'week', 'fields' => '*', 'segmentby' => '', @@ -297,7 +298,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { ); // 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 = TimeInterval::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 ) { @@ -348,7 +349,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { '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 ( TimeInterval::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'] ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php index 3c1242bbdf0..dd85acb09d5 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Products_Data_Store. @@ -260,8 +261,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'date', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'categories' => array(), 'product_includes' => array(), @@ -434,7 +435,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { '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( TimeInterval::$sql_datetime_format ), 'coupon_amount' => $coupon_amount, 'tax_amount' => $tax_amount, 'shipping_amount' => $shipping_amount, diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php index 8749ae10658..f98ed51f316 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Reports_Products_Stats_Data_Store. @@ -114,8 +115,8 @@ class DataStore extends ProductsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'date', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'categories' => array(), 'interval' => 'week', @@ -148,7 +149,7 @@ class DataStore extends ProductsDataStore implements DataStoreInterface { ); // 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 = TimeInterval::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(); @@ -214,7 +215,7 @@ class DataStore extends ProductsDataStore implements DataStoreInterface { '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 ( TimeInterval::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'] ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php index cd5f5244495..cd9173d4213 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Taxes_Data_Store. @@ -172,8 +173,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'tax_rate_id', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'taxes' => array(), ); @@ -330,7 +331,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { $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( TimeInterval::$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(), diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php index 019beefe507..4272bc873b0 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Reports_Taxes_Stats_Data_Store. @@ -156,8 +157,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'tax_rate_id', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'taxes' => array(), ); @@ -198,7 +199,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { ); // 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 = TimeInterval::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 ) { @@ -268,7 +269,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { '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 ( TimeInterval::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'] ); diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-interval.php b/plugins/woocommerce-admin/src/API/Reports/TimeInterval.php similarity index 93% rename from plugins/woocommerce-admin/includes/class-wc-admin-reports-interval.php rename to plugins/woocommerce-admin/src/API/Reports/TimeInterval.php index ff7bc7c1a52..345ba348bc8 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-interval.php +++ b/plugins/woocommerce-admin/src/API/Reports/TimeInterval.php @@ -5,12 +5,14 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin\API\Reports; + defined( 'ABSPATH' ) || exit; /** * Date & time interval and numeric range handling class for Reporting API. */ -class WC_Admin_Reports_Interval { +class TimeInterval { /** * Format string for ISO DateTime formatter. @@ -33,8 +35,8 @@ class WC_Admin_Reports_Interval { * @return DateTime */ public static function convert_local_datetime_to_gmt( $datetime_string ) { - $datetime = new DateTime( $datetime_string, new DateTimeZone( wc_timezone_string() ) ); - $datetime->setTimezone( new DateTimeZone( 'GMT' ) ); + $datetime = new \DateTime( $datetime_string, new \DateTimeZone( wc_timezone_string() ) ); + $datetime->setTimezone( new \DateTimeZone( 'GMT' ) ); return $datetime; } @@ -44,10 +46,10 @@ class WC_Admin_Reports_Interval { * @return DateTime */ public static function default_before() { - $datetime = new WC_DateTime(); + $datetime = new \WC_DateTime(); // Set local timezone or offset. if ( get_option( 'timezone_string' ) ) { - $datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) ); + $datetime->setTimezone( new \DateTimeZone( wc_timezone_string() ) ); } else { $datetime->set_utc_offset( wc_timezone_offset() ); } @@ -63,11 +65,11 @@ class WC_Admin_Reports_Interval { $now = time(); $week_back = $now - WEEK_IN_SECONDS; - $datetime = new WC_DateTime(); + $datetime = new \WC_DateTime(); $datetime->setTimestamp( $week_back ); // Set local timezone or offset. if ( get_option( 'timezone_string' ) ) { - $datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) ); + $datetime->setTimezone( new \DateTimeZone( wc_timezone_string() ) ); } else { $datetime->set_utc_offset( wc_timezone_offset() ); } @@ -147,7 +149,7 @@ class WC_Admin_Reports_Interval { * @return int */ public static function simple_week_number( $datetime, $first_day_of_week ) { - $beg_of_year_day = new DateTime( "{$datetime->format('Y')}-01-01" ); + $beg_of_year_day = new \DateTime( "{$datetime->format('Y')}-01-01" ); $adj_day_beg_of_year = ( (int) $beg_of_year_day->format( 'w' ) - $first_day_of_week + 7 ) % 7; $days_since_start_of_year = (int) $datetime->format( 'z' ) + 1; @@ -158,7 +160,7 @@ class WC_Admin_Reports_Interval { * Returns ISO 8601 week number for the DateTime, if week starts on Monday, * otherwise returns simple week number. * - * @see WC_Admin_Reports_Interval::simple_week_number() + * @see TimeInterval::simple_week_number() * * @param DateTime $datetime Local date for which the week number is to be calculated. * @param int $first_day_of_week 0 for Sunday to 6 for Saturday. @@ -288,9 +290,9 @@ class WC_Admin_Reports_Interval { $hours_offset_timestamp --; } - $hours_offset_time = new DateTime(); + $hours_offset_time = new \DateTime(); $hours_offset_time->setTimestamp( $hours_offset_timestamp ); - $hours_offset_time->setTimezone( new DateTimeZone( wc_timezone_string() ) ); + $hours_offset_time->setTimezone( new \DateTimeZone( wc_timezone_string() ) ); return $hours_offset_time; } @@ -312,9 +314,9 @@ class WC_Admin_Reports_Interval { $next_day_timestamp --; } - $next_day = new DateTime(); + $next_day = new \DateTime(); $next_day->setTimestamp( $next_day_timestamp ); - $next_day->setTimezone( new DateTimeZone( wc_timezone_string() ) ); + $next_day->setTimezone( new \DateTimeZone( wc_timezone_string() ) ); return $next_day; } @@ -357,7 +359,7 @@ class WC_Admin_Reports_Interval { $month = (int) $datetime->format( 'm' ); if ( $reversed ) { - $beg_of_month_datetime = new DateTime( "$year-$month-01 00:00:00", new DateTimeZone( wc_timezone_string() ) ); + $beg_of_month_datetime = new \DateTime( "$year-$month-01 00:00:00", new \DateTimeZone( wc_timezone_string() ) ); $timestamp = (int) $beg_of_month_datetime->format( 'U' ); $end_of_prev_month_timestamp = $timestamp - 1; $datetime->setTimestamp( $end_of_prev_month_timestamp ); @@ -368,7 +370,7 @@ class WC_Admin_Reports_Interval { $year ++; } $day = '01'; - $datetime = new DateTime( "$year-$month-$day 00:00:00", new DateTimeZone( wc_timezone_string() ) ); + $datetime = new \DateTime( "$year-$month-$day 00:00:00", new \DateTimeZone( wc_timezone_string() ) ); } return $datetime; @@ -424,7 +426,7 @@ class WC_Admin_Reports_Interval { } break; } - $datetime = new DateTime( "$year-$month-01 00:00:00", new DateTimeZone( wc_timezone_string() ) ); + $datetime = new \DateTime( "$year-$month-01 00:00:00", new \DateTimeZone( wc_timezone_string() ) ); if ( $reversed ) { $timestamp = (int) $datetime->format( 'U' ); $end_of_prev_month_timestamp = $timestamp - 1; @@ -448,13 +450,13 @@ class WC_Admin_Reports_Interval { $day = '01'; if ( $reversed ) { - $datetime = new DateTime( "$year-$month-$day 00:00:00", new DateTimeZone( wc_timezone_string() ) ); + $datetime = new \DateTime( "$year-$month-$day 00:00:00", new \DateTimeZone( wc_timezone_string() ) ); $timestamp = (int) $datetime->format( 'U' ); $end_of_prev_year_timestamp = $timestamp - 1; $datetime->setTimestamp( $end_of_prev_year_timestamp ); } else { $year += $year_increment; - $datetime = new DateTime( "$year-$month-$day 00:00:00", new DateTimeZone( wc_timezone_string() ) ); + $datetime = new \DateTime( "$year-$month-$day 00:00:00", new \DateTimeZone( wc_timezone_string() ) ); } return $datetime; @@ -591,7 +593,7 @@ class WC_Admin_Reports_Interval { */ public static function rest_validate_between_numeric_arg( $value, $request, $param ) { if ( ! wp_is_numeric_array( $value ) ) { - return new WP_Error( + return new \WP_Error( 'rest_invalid_param', /* translators: 1: parameter name */ sprintf( __( '%1$s is not a numerically indexed array.', 'woocommerce-admin' ), $param ) @@ -603,7 +605,7 @@ class WC_Admin_Reports_Interval { ! is_numeric( $value[0] ) || ! is_numeric( $value[1] ) ) { - return new WP_Error( + return new \WP_Error( 'rest_invalid_param', /* translators: %s: parameter name */ sprintf( __( '%s must contain 2 numbers.', 'woocommerce-admin' ), $param ) @@ -623,7 +625,7 @@ class WC_Admin_Reports_Interval { */ public static function rest_validate_between_date_arg( $value, $request, $param ) { if ( ! wp_is_numeric_array( $value ) ) { - return new WP_Error( + return new \WP_Error( 'rest_invalid_param', /* translators: 1: parameter name */ sprintf( __( '%1$s is not a numerically indexed array.', 'woocommerce-admin' ), $param ) @@ -635,7 +637,7 @@ class WC_Admin_Reports_Interval { ! rest_parse_date( $value[0] ) || ! rest_parse_date( $value[1] ) ) { - return new WP_Error( + return new \WP_Error( 'rest_invalid_param', /* translators: %s: parameter name */ sprintf( __( '%s must contain 2 valid dates.', 'woocommerce-admin' ), $param ) diff --git a/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php index 49b1188b992..d1fca8658a0 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php @@ -11,6 +11,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\DataStore as ReportsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\DataStoreInterface; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * WC_Admin_Reports_Products_Data_Store. @@ -231,8 +232,8 @@ class DataStore extends ReportsDataStore implements DataStoreInterface { 'page' => 1, 'order' => 'DESC', 'orderby' => 'date', - 'before' => \WC_Admin_Reports_Interval::default_before(), - 'after' => \WC_Admin_Reports_Interval::default_after(), + 'before' => TimeInterval::default_before(), + 'after' => TimeInterval::default_after(), 'fields' => '*', 'products' => array(), 'variations' => array(), diff --git a/plugins/woocommerce-admin/tests/api/reports-interval.php b/plugins/woocommerce-admin/tests/api/reports-interval.php index 9881ae69f8b..b6cc88afdd2 100644 --- a/plugins/woocommerce-admin/tests/api/reports-interval.php +++ b/plugins/woocommerce-admin/tests/api/reports-interval.php @@ -6,6 +6,8 @@ * @since x.x.0 */ +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; + /** * Class WC_Tests_Reports_Interval_Stats */ @@ -30,31 +32,31 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { */ public function test_quarter() { $datetime = new DateTime( '2017-12-31T00:00:00', self::$local_tz ); - $this->assertEquals( 4, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 4, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-01-01T00:00:00', self::$local_tz ); - $this->assertEquals( 1, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 1, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-03-31T23:59:59', self::$local_tz ); - $this->assertEquals( 1, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 1, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-04-01T00:00:00', self::$local_tz ); - $this->assertEquals( 2, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 2, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-06-30T23:59:59', self::$local_tz ); - $this->assertEquals( 2, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 2, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-07-01T00:00:00', self::$local_tz ); - $this->assertEquals( 3, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 3, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-09-30T23:59:59', self::$local_tz ); - $this->assertEquals( 3, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 3, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-10-01T00:00:00', self::$local_tz ); - $this->assertEquals( 4, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 4, TimeInterval::quarter( $datetime ) ); $datetime = new DateTime( '2018-12-31T23:59:59', self::$local_tz ); - $this->assertEquals( 4, WC_Admin_Reports_Interval::quarter( $datetime ) ); + $this->assertEquals( 4, TimeInterval::quarter( $datetime ) ); } /** @@ -337,7 +339,7 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $expected_week_no as $date => $week_numbers ) { for ( $first_day_of_week = 1; $first_day_of_week <= 7; $first_day_of_week++ ) { $datetime = new DateTime( $date, self::$local_tz ); - $this->assertEquals( $expected_week_no[ $date ][ $first_day_of_week ], WC_Admin_Reports_Interval::simple_week_number( $datetime, $first_day_of_week ), "First day of week: $first_day_of_week; Date: $date" ); + $this->assertEquals( $expected_week_no[ $date ][ $first_day_of_week ], TimeInterval::simple_week_number( $datetime, $first_day_of_week ), "First day of week: $first_day_of_week; Date: $date" ); } } @@ -381,7 +383,7 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { ); foreach ( $expected_week_no as $date => $week_numbers ) { $datetime = new DateTime( $date, self::$local_tz ); - $this->assertEquals( $expected_week_no[ $date ], WC_Admin_Reports_Interval::week_number( $datetime, 1 ), "ISO week number for date: $date" ); + $this->assertEquals( $expected_week_no[ $date ], TimeInterval::week_number( $datetime, 1 ), "ISO week number for date: $date" ); } } @@ -617,7 +619,7 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $setting['intervals'] as $interval => $exp_value ) { $start_datetime = new DateTime( $setting['start'], self::$local_tz ); $end_datetime = new DateTime( $setting['end'], self::$local_tz ); - $this->assertEquals( $exp_value, WC_Admin_Reports_Interval::intervals_between( $start_datetime, $end_datetime, $interval ), "First Day of Week: {$setting['week_start']}; Start: {$setting['start']}; End: {$setting['end']}; Interval: {$interval}" ); + $this->assertEquals( $exp_value, TimeInterval::intervals_between( $start_datetime, $end_datetime, $interval ), "First Day of Week: {$setting['week_start']}; Start: {$setting['start']}; End: {$setting['end']}; Interval: {$interval}" ); } } } @@ -639,8 +641,8 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $settings as $datetime_s => $setting ) { $datetime = new DateTime( $datetime_s, self::$local_tz ); foreach ( $setting as $reversed => $exp_value ) { - $result_dt = WC_Admin_Reports_Interval::next_hour_start( $datetime, $reversed ); - $this->assertEquals( $exp_value, $result_dt->format( WC_Admin_Reports_Interval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); + $result_dt = TimeInterval::next_hour_start( $datetime, $reversed ); + $this->assertEquals( $exp_value, $result_dt->format( TimeInterval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); } } } @@ -662,8 +664,8 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $settings as $datetime_s => $setting ) { $datetime = new DateTime( $datetime_s, self::$local_tz ); foreach ( $setting as $reversed => $exp_value ) { - $result_dt = WC_Admin_Reports_Interval::next_day_start( $datetime, $reversed ); - $this->assertEquals( $exp_value, $result_dt->format( WC_Admin_Reports_Interval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); + $result_dt = TimeInterval::next_day_start( $datetime, $reversed ); + $this->assertEquals( $exp_value, $result_dt->format( TimeInterval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); } } } @@ -710,8 +712,8 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $settings as $datetime_s => $setting ) { $datetime = new DateTime( $datetime_s, self::$local_tz ); foreach ( $setting as $reversed => $exp_value ) { - $result_dt = WC_Admin_Reports_Interval::next_week_start( $datetime, $reversed ); - $this->assertEquals( $exp_value, $result_dt->format( WC_Admin_Reports_Interval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); + $result_dt = TimeInterval::next_week_start( $datetime, $reversed ); + $this->assertEquals( $exp_value, $result_dt->format( TimeInterval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); } } } @@ -742,8 +744,8 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $settings as $datetime_s => $setting ) { $datetime = new DateTime( $datetime_s, self::$local_tz ); foreach ( $setting as $reversed => $exp_value ) { - $result_dt = WC_Admin_Reports_Interval::next_week_start( $datetime, $reversed ); - $this->assertEquals( $exp_value, $result_dt->format( WC_Admin_Reports_Interval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); + $result_dt = TimeInterval::next_week_start( $datetime, $reversed ); + $this->assertEquals( $exp_value, $result_dt->format( TimeInterval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); } } } @@ -766,8 +768,8 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $settings as $datetime_s => $setting ) { $datetime = new DateTime( $datetime_s, self::$local_tz ); foreach ( $setting as $reversed => $exp_value ) { - $result_dt = WC_Admin_Reports_Interval::next_month_start( $datetime, $reversed ); - $this->assertEquals( $exp_value, $result_dt->format( WC_Admin_Reports_Interval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); + $result_dt = TimeInterval::next_month_start( $datetime, $reversed ); + $this->assertEquals( $exp_value, $result_dt->format( TimeInterval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); } } } @@ -801,8 +803,8 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $settings as $datetime_s => $setting ) { $datetime = new DateTime( $datetime_s, self::$local_tz ); foreach ( $setting as $reversed => $exp_value ) { - $result_dt = WC_Admin_Reports_Interval::next_quarter_start( $datetime, $reversed ); - $this->assertEquals( $exp_value, $result_dt->format( WC_Admin_Reports_Interval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); + $result_dt = TimeInterval::next_quarter_start( $datetime, $reversed ); + $this->assertEquals( $exp_value, $result_dt->format( TimeInterval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); } } } @@ -828,8 +830,8 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $settings as $datetime_s => $setting ) { $datetime = new DateTime( $datetime_s, self::$local_tz ); foreach ( $setting as $reversed => $exp_value ) { - $result_dt = WC_Admin_Reports_Interval::next_year_start( $datetime, $reversed ); - $this->assertEquals( $exp_value, $result_dt->format( WC_Admin_Reports_Interval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); + $result_dt = TimeInterval::next_year_start( $datetime, $reversed ); + $this->assertEquals( $exp_value, $result_dt->format( TimeInterval::$iso_datetime_format ), __FUNCTION__ . ": DT: $datetime_s; R: $reversed" ); } } } @@ -846,7 +848,7 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { 'f_between' => array( 10, 12 ), // not in params, skipped. ); $params = array( 'a', 'b', 'c', 'd' ); - $result = WC_Admin_Reports_Interval::normalize_between_params( $request, $params, false ); + $result = TimeInterval::normalize_between_params( $request, $params, false ); $expected = array( 'b_min' => 1, 'b_max' => 5, @@ -869,7 +871,7 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { 'f_between' => array( 10, 12 ), // not in params, skipped. ); $params = array( 'a', 'b', 'c', 'd' ); - $result = WC_Admin_Reports_Interval::normalize_between_params( $request, $params, true ); + $result = TimeInterval::normalize_between_params( $request, $params, true ); $expected = array( 'b_after' => 1, 'b_before' => 5, @@ -885,17 +887,17 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { */ public function test_rest_validate_between_numeric_arg() { $this->assertWPError( - WC_Admin_Reports_Interval::rest_validate_between_numeric_arg( 'not array', null, 'param' ), + TimeInterval::rest_validate_between_numeric_arg( 'not array', null, 'param' ), 'param is not a numerically indexed array.' ); $this->assertWPError( - WC_Admin_Reports_Interval::rest_validate_between_numeric_arg( array( 1 ), null, 'param' ), + TimeInterval::rest_validate_between_numeric_arg( array( 1 ), null, 'param' ), 'param must contain 2 numbers.' ); $this->assertTrue( - WC_Admin_Reports_Interval::rest_validate_between_numeric_arg( array( 1, 2 ), null, 'param' ) + TimeInterval::rest_validate_between_numeric_arg( array( 1, 2 ), null, 'param' ) ); } @@ -904,22 +906,22 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { */ public function rest_validate_between_date_arg() { $this->assertWPError( - WC_Admin_Reports_Interval::rest_validate_between_date_arg( 'not array', null, 'param' ), + TimeInterval::rest_validate_between_date_arg( 'not array', null, 'param' ), 'param is not a numerically indexed array.' ); $this->assertWPError( - WC_Admin_Reports_Interval::rest_validate_between_date_arg( array( '2019-01-01T00:00:00' ), null, 'param' ), + TimeInterval::rest_validate_between_date_arg( array( '2019-01-01T00:00:00' ), null, 'param' ), 'param must contain 2 valid dates.' ); $this->assertWPError( - WC_Admin_Reports_Interval::rest_validate_between_date_arg( array( 'not a valid date' ), null, 'param' ), + TimeInterval::rest_validate_between_date_arg( array( 'not a valid date' ), null, 'param' ), 'param must contain 2 valid dates.' ); $this->assertTrue( - WC_Admin_Reports_Interval::rest_validate_between_date_arg( array( '2019-01-01T00:00:00', '2019-01-15T00:00:00' ), null, 'param' ) + TimeInterval::rest_validate_between_date_arg( array( '2019-01-01T00:00:00', '2019-01-15T00:00:00' ), null, 'param' ) ); } } diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php index 33081839025..974c1cd8c3a 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php @@ -8,6 +8,7 @@ use \Automattic\WooCommerce\Admin\WC_Admin_Report_CSV_Exporter; use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\Coupons\Query as CouponsQuery; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * Class WC_Tests_Reports_Coupons @@ -186,8 +187,8 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case { $c1_date_created_gmt = new DateTime( $c1_date_created ); $c1_date_created_gmt->setTimezone( $gmt_timezone ); - $c1_date_created = $c1_date_created->format( WC_Admin_Reports_Interval::$iso_datetime_format ); - $c1_date_created_gmt = $c1_date_created_gmt->format( WC_Admin_Reports_Interval::$iso_datetime_format ); + $c1_date_created = $c1_date_created->format( TimeInterval::$iso_datetime_format ); + $c1_date_created_gmt = $c1_date_created_gmt->format( TimeInterval::$iso_datetime_format ); } $c1_date_expires = $coupon_1->get_date_expires(); @@ -198,8 +199,8 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case { $c1_date_expires_gmt = new DateTime( $c1_date_expires ); $c1_date_expires_gmt->setTimezone( $gmt_timezone ); - $c1_date_expires = $c1_date_expires->format( WC_Admin_Reports_Interval::$iso_datetime_format ); - $c1_date_expires_gmt = $c1_date_expires_gmt->format( WC_Admin_Reports_Interval::$iso_datetime_format ); + $c1_date_expires = $c1_date_expires->format( TimeInterval::$iso_datetime_format ); + $c1_date_expires_gmt = $c1_date_expires_gmt->format( TimeInterval::$iso_datetime_format ); } $coupon_1_response = array( @@ -224,8 +225,8 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case { $c2_date_created_gmt = new DateTime( $c2_date_created ); $c2_date_created_gmt->setTimezone( $gmt_timezone ); - $c2_date_created = $c2_date_created->format( WC_Admin_Reports_Interval::$iso_datetime_format ); - $c2_date_created_gmt = $c2_date_created_gmt->format( WC_Admin_Reports_Interval::$iso_datetime_format ); + $c2_date_created = $c2_date_created->format( TimeInterval::$iso_datetime_format ); + $c2_date_created_gmt = $c2_date_created_gmt->format( TimeInterval::$iso_datetime_format ); } $c2_date_expires = $coupon_2->get_date_expires(); @@ -236,8 +237,8 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case { $c2_date_expires_gmt = new DateTime( $c2_date_expires ); $c2_date_expires_gmt->setTimezone( $gmt_timezone ); - $c2_date_expires = $c2_date_expires->format( WC_Admin_Reports_Interval::$iso_datetime_format ); - $c2_date_expires_gmt = $c2_date_expires_gmt->format( WC_Admin_Reports_Interval::$iso_datetime_format ); + $c2_date_expires = $c2_date_expires->format( TimeInterval::$iso_datetime_format ); + $c2_date_expires_gmt = $c2_date_expires_gmt->format( TimeInterval::$iso_datetime_format ); } $coupon_2_response = array( diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php index 834641e1c63..6e5e2514627 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php @@ -7,6 +7,7 @@ use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\Query as OrdersStatsQuery; +use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; /** * Class WC_Tests_Reports_Orders_Stats @@ -656,8 +657,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $current_hour_end->setTimestamp( $report_start_time + HOUR_IN_SECONDS - 1 ); $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', ); @@ -915,8 +916,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // 24 orders without coupons, 48 with coupons: 24 with $1 coupon and 24 with $2 coupon. // shipping is $10 per order. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', ); @@ -991,8 +992,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // * Order status filter // ** Status is, positive filter for 2 statuses, i.e. all orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1004,8 +1005,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Status is, positive filter for 1 status -> half orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1082,8 +1083,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Status is not, negative filter for 1 status -> half orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is_not' => array( $order_status_2, @@ -1160,8 +1161,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Status is not, negative filter for 2 statuses -> no orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is_not' => array( $order_status_1, @@ -1220,8 +1221,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Status is + Status is not, positive filter for 2 statuses, negative for 1 -> half of orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1303,8 +1304,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // * Product filter // ** Product includes, positive filter for 2 products, i.e. 2 orders out of 3. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_1->get_id(), @@ -1380,8 +1381,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Product includes, positive filter for 1 product, 1/3 of orders $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_3->get_id(), @@ -1455,8 +1456,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Product excludes, negative filter for 1 product, 2/3 of orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'product_excludes' => array( $product_1->get_id(), @@ -1531,8 +1532,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Product excludes, negative filter for 2 products, 1/3 of orders $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'product_excludes' => array( $product_1->get_id(), @@ -1606,8 +1607,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Product includes + product excludes, positive filter for 2 products, negative for 1 -> 1/3 of orders, only orders with product 2 and product 2 + product 4 $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_1->get_id(), @@ -1685,8 +1686,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // * Coupon filters // ** Coupon includes, positive filter for 2 coupons, i.e. 2/3 of orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_includes' => array( $coupon_1->get_id(), @@ -1764,8 +1765,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Coupon includes, positive filter for 1 coupon, 1/3 of orders $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_includes' => array( $coupon_1->get_id(), @@ -1842,8 +1843,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Coupon excludes, negative filter for 1 coupon, 2/3 of orders $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_excludes' => array( $coupon_1->get_id(), @@ -1920,8 +1921,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Coupon excludes, negative filter for 2 coupons, 1/3 of orders $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_excludes' => array( $coupon_1->get_id(), @@ -1999,8 +2000,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Coupon includes + coupon excludes, positive filter for 2 coupon, negative for 1, 1/3 orders $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_includes' => array( $coupon_1->get_id(), @@ -2082,8 +2083,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // * Customer filters // ** Customer new $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'customer' => 'new', ); @@ -2146,8 +2147,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ** Customer returning $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), // I don't think this makes sense.... date( 'Y-m-d H:i:s', $orders[0]->get_date_created()->getOffsetTimestamp() + 1 ), // Date after initial order to get a returning customer. - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), // I don't think this makes sense.... date( 'Y-m-d H:i:s', $orders[0]->get_date_created()->getOffsetTimestamp() + 1 ), // Date after initial order to get a returning customer. + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'customer' => 'returning', ); @@ -2193,8 +2194,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'intervals' => array( array( 'interval' => $current_hour_start->format( 'Y-m-d H' ), - 'date_start' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'date_start_gmt' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'date_start' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'date_start_gmt' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( @@ -2225,8 +2226,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Combinations: match all // status_is + product_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2302,8 +2303,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is + coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2383,8 +2384,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // product_includes + coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_1->get_id(), @@ -2460,8 +2461,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is + product_includes + coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2540,8 +2541,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is + status_is_not + product_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2624,8 +2625,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is + status_is_not + product_includes + product_excludes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2709,8 +2710,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is + status_is_not + product_includes + product_excludes + coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2796,8 +2797,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is + status_is_not + product_includes + product_excludes + coupon_includes + coupon_excludes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2888,8 +2889,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Combinations: match any // status_is + status_is_not, all orders. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2970,8 +2971,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR product_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3052,8 +3053,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3134,8 +3135,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR coupon_excludes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3216,8 +3217,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // product_includes OR coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'product_includes' => array( @@ -3298,8 +3299,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR product_includes OR coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3383,8 +3384,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR status_is_not OR product_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3471,8 +3472,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR status_is_not OR product_includes OR product_excludes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3559,8 +3560,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR status_is_not OR product_includes OR product_excludes OR coupon_includes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3650,8 +3651,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // status_is OR status_is_not OR product_includes OR product_excludes OR coupon_includes OR coupon_excludes. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -3970,8 +3971,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $i3_end->setTimestamp( $i3_end_timestamp ); $query_args = array( - 'after' => $two_hours_back->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $two_hours_back->format( TimeInterval::$sql_datetime_format ), + 'before' => $now->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'segmentby' => 'product', ); @@ -4521,8 +4522,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Test for current hour--only 1 hour visible. // DESC. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'desc', @@ -4587,8 +4588,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ASC -- only 1 interval, so should be the same. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'asc', @@ -4611,8 +4612,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $minus_5_hours->setTimestamp( $now_timestamp - $hour_offset * HOUR_IN_SECONDS ); $query_args = array( - 'after' => $minus_5_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_5_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'desc', @@ -4727,8 +4728,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ASC -- reverse the intervals array, but numbers stay the same. $query_args = array( - 'after' => $minus_5_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_5_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'asc', @@ -4754,8 +4755,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $minus_9_hours->setTimestamp( $now_timestamp - $hour_offset * HOUR_IN_SECONDS ); $query_args = array( - 'after' => $minus_9_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_9_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'desc', @@ -4867,8 +4868,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ASC -- same values, just reverse order of intervals. $query_args = array( - 'after' => $minus_9_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_9_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'asc', @@ -4903,8 +4904,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 1. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'desc', @@ -5018,8 +5019,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 2. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'desc', @@ -5072,8 +5073,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 1. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'asc', @@ -5109,8 +5110,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 2. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'date', 'order' => 'asc', @@ -5296,8 +5297,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Test 1: only one hour visible, so only 1 interval in the response, no real ordering. // DESC. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'desc', @@ -5363,8 +5364,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // ASC -- only 1 interval, so should be the same. $query_args = array( - 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'asc', @@ -5386,8 +5387,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $minus_5_hours->setTimestamp( $now_timestamp - $hour_offset * HOUR_IN_SECONDS ); $query_args = array( - 'after' => $minus_5_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_5_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'desc', @@ -5534,8 +5535,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { array_push( $expected_stats['intervals'], $to_be_last ); $query_args = array( - 'after' => $minus_5_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_5_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'asc', @@ -5555,8 +5556,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $minus_9_hours->setTimestamp( $now_timestamp - $hour_offset * HOUR_IN_SECONDS ); $query_args = array( - 'after' => $minus_9_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_9_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'desc', @@ -5700,8 +5701,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { array_push( $expected_stats['intervals'], $to_be_last ); $query_args = array( - 'after' => $minus_9_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_9_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'asc', @@ -5722,8 +5723,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 1. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'desc', @@ -5852,8 +5853,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 2. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'desc', @@ -5906,8 +5907,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 1. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'asc', @@ -5944,8 +5945,8 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { // Page 2. $query_args = array( - 'after' => $minus_10_hours->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $minus_10_hours->format( TimeInterval::$sql_datetime_format ), + 'before' => $current_hour_end->format( TimeInterval::$sql_datetime_format ), 'interval' => 'hour', 'orderby' => 'orders_count', 'order' => 'asc', From 13878db9ace1269877ce410ca53f1501192fc50b Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 12 Aug 2019 10:54:04 -0700 Subject: [PATCH 26/32] PSR-4ify the feature plugin and install classes. --- plugins/woocommerce-admin/src/API/Themes.php | 2 - .../Notes/WC_Admin_Notes_Historical_Data.php | 4 +- .../Notes/WC_Admin_Notes_Welcome_Message.php | 4 +- .../src/WC_Admin_Feature_Plugin.php | 317 ++++++++++++++++++ .../WC_Admin_Install.php} | 2 + plugins/woocommerce-admin/tests/bootstrap.php | 7 +- plugins/woocommerce-admin/uninstall.php | 2 + .../woocommerce-admin/woocommerce-admin.php | 310 +---------------- 8 files changed, 331 insertions(+), 317 deletions(-) create mode 100644 plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php rename plugins/woocommerce-admin/{includes/class-wc-admin-install.php => src/WC_Admin_Install.php} (99%) diff --git a/plugins/woocommerce-admin/src/API/Themes.php b/plugins/woocommerce-admin/src/API/Themes.php index 82163b211a6..dc069f72f86 100644 --- a/plugins/woocommerce-admin/src/API/Themes.php +++ b/plugins/woocommerce-admin/src/API/Themes.php @@ -81,8 +81,6 @@ class Themes extends \WC_REST_Data_Controller { include_once ABSPATH . 'wp-admin/includes/file.php'; include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - include_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-theme-upgrader.php'; - include_once WC_ADMIN_ABSPATH . 'includes/class-wc-admin-theme-upgrader-skin.php'; $_GET['package'] = true; $file_upload = new \File_Upload_Upgrader( 'pluginzip', 'package' ); diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php index 7e6a67ae447..afc3b3fc7c7 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\WC_Admin_Install; + /** * WC_Admin_Notes_Historical_Data. */ @@ -21,7 +23,7 @@ class WC_Admin_Notes_Historical_Data { * Creates a note for regenerating historical data. */ public static function add_note() { - $is_upgrading = get_option( \WC_Admin_Install::VERSION_OPTION ); + $is_upgrading = get_option( WC_Admin_Install::VERSION_OPTION ); if ( $is_upgrading ) { return; } diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php index 945cdcffde5..0e716a115df 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php @@ -11,6 +11,8 @@ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\WC_Admin_Install; + /** * WC_Admin_Notes_Welcome_Message. */ @@ -22,7 +24,7 @@ class WC_Admin_Notes_Welcome_Message { */ public static function add_welcome_note() { // Check if plugin is upgrading if yes then don't create this note. - $is_upgrading = get_option( \WC_Admin_Install::VERSION_OPTION ); + $is_upgrading = get_option( WC_Admin_Install::VERSION_OPTION ); if ( $is_upgrading ) { return; } diff --git a/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php b/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php new file mode 100644 index 00000000000..1e6c896620e --- /dev/null +++ b/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php @@ -0,0 +1,317 @@ +define_constants(); + register_activation_hook( WC_ADMIN_PLUGIN_FILE, array( $this, 'on_activation' ) ); + register_deactivation_hook( WC_ADMIN_PLUGIN_FILE, array( $this, 'on_deactivation' ) ); + add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) ); + add_filter( 'action_scheduler_store_class', array( $this, 'replace_actionscheduler_store_class' ) ); + } + + /** + * Install DB and create cron events when activated. + * + * @return void + */ + public function on_activation() { + WC_Admin_Install::create_tables(); + WC_Admin_Install::create_events(); + } + + /** + * Remove WooCommerce Admin scheduled actions on deactivate. + * + * @return void + */ + public function on_deactivation() { + // Check if we are deactivating due to dependencies not being satisfied. + // If WooCommerce is disabled we can't include files that depend upon it. + if ( ! $this->check_dependencies() ) { + return; + } + + $this->includes(); + WC_Admin_Reports_Sync::clear_queued_actions(); + WC_Admin_Notes::clear_queued_actions(); + wp_clear_scheduled_hook( 'wc_admin_daily' ); + } + + /** + * Setup plugin once all other plugins are loaded. + * + * @return void + */ + public function on_plugins_loaded() { + $this->load_plugin_textdomain(); + + if ( ! $this->check_dependencies() ) { + add_action( 'admin_init', array( $this, 'deactivate_self' ) ); + add_action( 'admin_notices', array( $this, 'render_dependencies_notice' ) ); + return; + } + + if ( ! $this->check_build() ) { + add_action( 'admin_notices', array( $this, 'render_build_notice' ) ); + } + + $this->includes(); + $this->hooks(); + } + + /** + * Define Constants. + */ + protected function define_constants() { + $this->define( 'WC_ADMIN_APP', 'wc-admin-app' ); + $this->define( 'WC_ADMIN_ABSPATH', dirname( __DIR__ ) . '/' ); + $this->define( 'WC_ADMIN_DIST_JS_FOLDER', 'dist/' ); + $this->define( 'WC_ADMIN_DIST_CSS_FOLDER', 'dist/' ); + $this->define( 'WC_ADMIN_FEATURES_PATH', WC_ADMIN_ABSPATH . 'includes/features/' ); + $this->define( 'WC_ADMIN_PLUGIN_FILE', WC_ADMIN_ABSPATH . 'woocommerce-admin.php' ); + // WARNING: Do not directly edit this version number constant. + // It is updated as part of the prebuild process from the package.json value. + $this->define( 'WC_ADMIN_VERSION_NUMBER', '0.16.0' ); + } + + /** + * Load Localisation files. + */ + protected function load_plugin_textdomain() { + load_plugin_textdomain( 'woocommerce-admin', false, basename( dirname( __DIR__ ) ) . '/languages' ); + } + + /** + * Include WC Admin classes. + */ + public function includes() { + // Initialize the WC API extensions. + WC_Admin_Reports_Sync::init(); + WC_Admin_Install::init(); + WC_Admin_Events::instance()->init(); + new WC_Admin_Api_Init(); + WC_Admin_Report_Exporter::init(); + + // CRUD classes. + WC_Admin_Notes::init(); + + // Admin note providers. + // @todo These should be bundled in the features/ folder, but loading them from there currently has a load order issue. + new WC_Admin_Notes_Woo_Subscriptions_Notes(); + new WC_Admin_Notes_Historical_Data(); + new WC_Admin_Notes_Order_Milestones(); + new WC_Admin_Notes_Welcome_Message(); + } + + /** + * Filter in our ActionScheduler Store class. + * + * @param string $store_class ActionScheduler Store class name. + * @return string ActionScheduler Store class name. + */ + public function replace_actionscheduler_store_class( $store_class ) { + // Don't override any other overrides. + if ( 'ActionScheduler_wpPostStore' !== $store_class ) { + return $store_class; + } + + return 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore'; + } + + /** + * Removes core hooks in favor of our local feature plugin handlers. + * + * @see WC_Admin_Library::__construct() + */ + protected function hooks() { + remove_action( 'init', array( 'WC_Admin_Library', 'load_features' ) ); + remove_action( 'admin_enqueue_scripts', array( 'WC_Admin_Library', 'register_scripts' ) ); + remove_action( 'admin_enqueue_scripts', array( 'WC_Admin_Library', 'load_scripts' ), 15 ); + remove_action( 'woocommerce_components_settings', array( 'WC_Admin_Library', 'add_component_settings' ) ); + remove_filter( 'admin_body_class', array( 'WC_Admin_Library', 'add_admin_body_classes' ) ); + remove_action( 'admin_menu', array( 'WC_Admin_Library', 'register_page_handler' ) ); + remove_filter( 'admin_title', array( 'WC_Admin_Library', 'update_admin_title' ) ); + + remove_action( 'rest_api_init', array( 'WC_Admin_Library', 'register_user_data' ) ); + remove_action( 'in_admin_header', array( 'WC_Admin_Library', 'embed_page_header' ) ); + remove_filter( 'woocommerce_settings_groups', array( 'WC_Admin_Library', 'add_settings_group' ) ); + remove_filter( 'woocommerce_settings-wc_admin', array( 'WC_Admin_Library', 'add_settings' ) ); + + remove_action( 'admin_head', array( 'WC_Admin_Library', 'update_link_structure' ), 20 ); + + new \WC_Admin_Loader(); + + add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ) ); + add_action( 'admin_menu', array( $this, 'register_devdocs_page' ) ); + + } + + /** + * Returns true if all dependencies for the wc-admin plugin are loaded. + * + * @return bool + */ + protected function check_dependencies() { + $woocommerce_minimum_met = class_exists( 'WooCommerce' ) && version_compare( WC_VERSION, '3.6', '>=' ); + if ( ! $woocommerce_minimum_met ) { + return false; + } + + $wordpress_version = get_bloginfo( 'version' ); + return version_compare( $wordpress_version, '5.2.0', '>=' ); + } + + /** + * Returns true if build file exists. + * + * @return bool + */ + protected function check_build() { + return file_exists( plugin_dir_path( __DIR__ ) . '/dist/app/index.js' ); + } + + /** + * Deactivates this plugin. + */ + public function deactivate_self() { + deactivate_plugins( plugin_basename( WC_ADMIN_PLUGIN_FILE ) ); + unset( $_GET['activate'] ); + } + + /** + * Notify users of the plugin requirements. + */ + public function render_dependencies_notice() { + // The notice varies by WordPress version. + $wordpress_version = get_bloginfo( 'version' ); + $has_valid_wp_version = version_compare( $wordpress_version, '5.2.0', '>=' ); + + if ( $has_valid_wp_version ) { + $message = sprintf( + /* translators: URL of WooCommerce plugin */ + __( 'The WooCommerce Admin feature plugin requires WooCommerce 3.6 or greater to be installed and active.', 'woocommerce-admin' ), + 'https://wordpress.org/plugins/woocommerce/' + ); + } else { + $message = sprintf( + /* translators: 1: URL of WordPress.org, 2: URL of WooCommerce plugin */ + __( 'The WooCommerce Admin feature plugin requires both WordPress 5.2 or greater and WooCommerce 3.6 or greater to be installed and active.', 'woocommerce-admin' ), + 'https://wordpress.org/', + 'https://wordpress.org/plugins/woocommerce/' + ); + } + printf( '

%s

', $message ); /* WPCS: xss ok. */ + } + + /** + * Notify users that the plugin needs to be built. + */ + public function render_build_notice() { + $message_one = __( 'You have installed a development version of WooCommerce Admin which requires files to be built. From the plugin directory, run npm install to install dependencies, npm run build to build the files.', 'woocommerce-admin' ); + $message_two = sprintf( + /* translators: 1: URL of GitHub Repository build page */ + __( 'Or you can download a pre-built version of the plugin by visiting the releases page in the repository.', 'woocommerce-admin' ), + 'https://github.com/woocommerce/woocommerce-admin/releases' + ); + printf( '

%s %s

', $message_one, $message_two ); /* WPCS: xss ok. */ + } + + /** + * Overwrites the allowed features array using a local `feature-config.php` file. + * + * @param array $features Array of feature slugs. + */ + public function replace_supported_features( $features ) { + $feature_config = apply_filters( 'wc_admin_get_feature_config', wc_admin_get_feature_config() ); + $features = array_keys( array_filter( $feature_config ) ); + return $features; + } + + /** + * Adds a menu item for the wc-admin devdocs. + */ + public function register_devdocs_page() { + if ( \WC_Admin_Loader::is_feature_enabled( 'devdocs' ) && defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { + wc_admin_register_page( + array( + 'title' => 'DevDocs', + 'parent' => 'woocommerce', + 'path' => '/devdocs', + ) + ); + } + } + + /** + * Define constant if not already set. + * + * @param string $name Constant name. + * @param string|bool $value Constant value. + */ + protected function define( $name, $value ) { + if ( ! defined( $name ) ) { + define( $name, $value ); + } + } + + /** + * Prevent cloning. + */ + private function __clone() {} + + /** + * Prevent unserializing. + */ + private function __wakeup() {} +} \ No newline at end of file diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-install.php b/plugins/woocommerce-admin/src/WC_Admin_Install.php similarity index 99% rename from plugins/woocommerce-admin/includes/class-wc-admin-install.php rename to plugins/woocommerce-admin/src/WC_Admin_Install.php index 57fb60b7481..367b25ba6bd 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-install.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Install.php @@ -5,6 +5,8 @@ * @package WooCommerce Admin/Classes */ +namespace Automattic\WooCommerce\Admin; + defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; diff --git a/plugins/woocommerce-admin/tests/bootstrap.php b/plugins/woocommerce-admin/tests/bootstrap.php index 1cad33e2fd8..c022e4cb44a 100755 --- a/plugins/woocommerce-admin/tests/bootstrap.php +++ b/plugins/woocommerce-admin/tests/bootstrap.php @@ -37,10 +37,8 @@ function wc_admin_install() { define( 'WC_REMOVE_ALL_DATA', true ); // Initialize the WC API extensions. - require_once dirname( dirname( __FILE__ ) ) . '/includes/class-wc-admin-install.php'; - - WC_Admin_Install::create_tables(); - WC_Admin_Install::create_events(); + \Automattic\WooCommerce\Admin\WC_Admin_Install::create_tables(); + \Automattic\WooCommerce\Admin\WC_Admin_Install::create_events(); // Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374. $GLOBALS['wp_roles'] = null; // WPCS: override ok. @@ -93,6 +91,7 @@ function _manually_load_plugin() { update_option( 'woocommerce_calc_taxes', 'yes' ); require_once wc_dir() . '/woocommerce.php'; + require dirname( __DIR__ ) . '/vendor/autoload.php'; wc_admin_install(); diff --git a/plugins/woocommerce-admin/uninstall.php b/plugins/woocommerce-admin/uninstall.php index 23410555484..8909c5074a5 100644 --- a/plugins/woocommerce-admin/uninstall.php +++ b/plugins/woocommerce-admin/uninstall.php @@ -7,6 +7,8 @@ defined( 'WP_UNINSTALL_PLUGIN' ) || exit; +use \Automattic\WooCommerce\Admin\WC_Admin_Install; + require_once dirname( __FILE__ ) . '/woocommerce-admin.php'; require_once dirname( __FILE__ ) . '/includes/class-wc-admin-install.php'; WC_Admin_Install::delete_table_data(); diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 08d418a4605..9caaee27164 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -19,15 +19,7 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; -use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; -use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones; -use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; -use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes; -use Automattic\WooCommerce\Admin\WC_Admin_Events; -use Automattic\WooCommerce\Admin\WC_Admin_Report_Exporter; -use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; -use Automattic\WooCommerce\Admin\API\WC_Admin_Api_Init; +use \Automattic\WooCommerce\Admin\WC_Admin_Feature_Plugin; /** * Autoload packages. @@ -74,304 +66,4 @@ if ( is_readable( $autoloader ) ) { return; } -/** - * Feature plugin main class. - * - * @internal This file will not be bundled with woo core, only the feature plugin. - * @internal Note this is not called WC_Admin due to a class already existing in core with that name. - */ -class WC_Admin_Feature_Plugin { - /** - * The single instance of the class. - * - * @var object - */ - protected static $instance = null; - - /** - * Constructor - * - * @return void - */ - protected function __construct() {} - - /** - * Get class instance. - * - * @return object Instance. - */ - final public static function instance() { - if ( null === static::$instance ) { - static::$instance = new static(); - } - return static::$instance; - } - - /** - * Init the feature plugin, only if we can detect both Gutenberg and WooCommerce. - */ - public function init() { - $this->define_constants(); - register_activation_hook( WC_ADMIN_PLUGIN_FILE, array( $this, 'on_activation' ) ); - register_deactivation_hook( WC_ADMIN_PLUGIN_FILE, array( $this, 'on_deactivation' ) ); - add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) ); - add_filter( 'action_scheduler_store_class', array( $this, 'replace_actionscheduler_store_class' ) ); - } - - /** - * Install DB and create cron events when activated. - * - * @return void - */ - public function on_activation() { - WC_Admin_Install::create_tables(); - WC_Admin_Install::create_events(); - } - - /** - * Remove WooCommerce Admin scheduled actions on deactivate. - * - * @return void - */ - public function on_deactivation() { - // Check if we are deactivating due to dependencies not being satisfied. - // If WooCommerce is disabled we can't include files that depend upon it. - if ( ! $this->check_dependencies() ) { - return; - } - - $this->includes(); - WC_Admin_Reports_Sync::clear_queued_actions(); - WC_Admin_Notes::clear_queued_actions(); - wp_clear_scheduled_hook( 'wc_admin_daily' ); - } - - /** - * Setup plugin once all other plugins are loaded. - * - * @return void - */ - public function on_plugins_loaded() { - $this->load_plugin_textdomain(); - - if ( ! $this->check_dependencies() ) { - add_action( 'admin_init', array( $this, 'deactivate_self' ) ); - add_action( 'admin_notices', array( $this, 'render_dependencies_notice' ) ); - return; - } - - if ( ! $this->check_build() ) { - add_action( 'admin_notices', array( $this, 'render_build_notice' ) ); - } - - $this->includes(); - $this->hooks(); - } - - /** - * Define Constants. - */ - protected function define_constants() { - $this->define( 'WC_ADMIN_APP', 'wc-admin-app' ); - $this->define( 'WC_ADMIN_ABSPATH', dirname( __FILE__ ) . '/' ); - $this->define( 'WC_ADMIN_DIST_JS_FOLDER', 'dist/' ); - $this->define( 'WC_ADMIN_DIST_CSS_FOLDER', 'dist/' ); - $this->define( 'WC_ADMIN_FEATURES_PATH', WC_ADMIN_ABSPATH . 'includes/features/' ); - $this->define( 'WC_ADMIN_PLUGIN_FILE', __FILE__ ); - // WARNING: Do not directly edit this version number constant. - // It is updated as part of the prebuild process from the package.json value. - $this->define( 'WC_ADMIN_VERSION_NUMBER', '0.16.0' ); - } - - /** - * Load Localisation files. - */ - protected function load_plugin_textdomain() { - load_plugin_textdomain( 'woocommerce-admin', false, basename( dirname( __FILE__ ) ) . '/languages' ); - } - - /** - * Include WC Admin classes. - */ - public function includes() { - // Initialize the WC API extensions. - WC_Admin_Reports_Sync::init(); - WC_Admin_Install::init(); - WC_Admin_Events::instance()->init(); - new WC_Admin_Api_Init(); - WC_Admin_Report_Exporter::init(); - - // CRUD classes. - WC_Admin_Notes::init(); - - // Admin note providers. - // @todo These should be bundled in the features/ folder, but loading them from there currently has a load order issue. - new WC_Admin_Notes_Woo_Subscriptions_Notes(); - new WC_Admin_Notes_Historical_Data(); - new WC_Admin_Notes_Order_Milestones(); - new WC_Admin_Notes_Welcome_Message(); - } - - /** - * Filter in our ActionScheduler Store class. - * - * @param string $store_class ActionScheduler Store class name. - * @return string ActionScheduler Store class name. - */ - public function replace_actionscheduler_store_class( $store_class ) { - // Don't override any other overrides. - if ( 'ActionScheduler_wpPostStore' !== $store_class ) { - return $store_class; - } - - return 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore'; - } - - /** - * Removes core hooks in favor of our local feature plugin handlers. - * - * @see WC_Admin_Library::__construct() - */ - protected function hooks() { - remove_action( 'init', array( 'WC_Admin_Library', 'load_features' ) ); - remove_action( 'admin_enqueue_scripts', array( 'WC_Admin_Library', 'register_scripts' ) ); - remove_action( 'admin_enqueue_scripts', array( 'WC_Admin_Library', 'load_scripts' ), 15 ); - remove_action( 'woocommerce_components_settings', array( 'WC_Admin_Library', 'add_component_settings' ) ); - remove_filter( 'admin_body_class', array( 'WC_Admin_Library', 'add_admin_body_classes' ) ); - remove_action( 'admin_menu', array( 'WC_Admin_Library', 'register_page_handler' ) ); - remove_filter( 'admin_title', array( 'WC_Admin_Library', 'update_admin_title' ) ); - - remove_action( 'rest_api_init', array( 'WC_Admin_Library', 'register_user_data' ) ); - remove_action( 'in_admin_header', array( 'WC_Admin_Library', 'embed_page_header' ) ); - remove_filter( 'woocommerce_settings_groups', array( 'WC_Admin_Library', 'add_settings_group' ) ); - remove_filter( 'woocommerce_settings-wc_admin', array( 'WC_Admin_Library', 'add_settings' ) ); - - remove_action( 'admin_head', array( 'WC_Admin_Library', 'update_link_structure' ), 20 ); - - new WC_Admin_Loader(); - - add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ) ); - add_action( 'admin_menu', array( $this, 'register_devdocs_page' ) ); - - } - - /** - * Returns true if all dependencies for the wc-admin plugin are loaded. - * - * @return bool - */ - protected function check_dependencies() { - $woocommerce_minimum_met = class_exists( 'WooCommerce' ) && version_compare( WC_VERSION, '3.6', '>=' ); - if ( ! $woocommerce_minimum_met ) { - return false; - } - - $wordpress_version = get_bloginfo( 'version' ); - return version_compare( $wordpress_version, '5.2.0', '>=' ); - } - - /** - * Returns true if build file exists. - * - * @return bool - */ - protected function check_build() { - return file_exists( plugin_dir_path( __FILE__ ) . '/dist/app/index.js' ); - } - - /** - * Deactivates this plugin. - */ - public function deactivate_self() { - deactivate_plugins( plugin_basename( WC_ADMIN_PLUGIN_FILE ) ); - unset( $_GET['activate'] ); - } - - /** - * Notify users of the plugin requirements. - */ - public function render_dependencies_notice() { - // The notice varies by WordPress version. - $wordpress_version = get_bloginfo( 'version' ); - $has_valid_wp_version = version_compare( $wordpress_version, '5.2.0', '>=' ); - - if ( $has_valid_wp_version ) { - $message = sprintf( - /* translators: URL of WooCommerce plugin */ - __( 'The WooCommerce Admin feature plugin requires WooCommerce 3.6 or greater to be installed and active.', 'woocommerce-admin' ), - 'https://wordpress.org/plugins/woocommerce/' - ); - } else { - $message = sprintf( - /* translators: 1: URL of WordPress.org, 2: URL of WooCommerce plugin */ - __( 'The WooCommerce Admin feature plugin requires both WordPress 5.2 or greater and WooCommerce 3.6 or greater to be installed and active.', 'woocommerce-admin' ), - 'https://wordpress.org/', - 'https://wordpress.org/plugins/woocommerce/' - ); - } - printf( '

%s

', $message ); /* WPCS: xss ok. */ - } - - /** - * Notify users that the plugin needs to be built. - */ - public function render_build_notice() { - $message_one = __( 'You have installed a development version of WooCommerce Admin which requires files to be built. From the plugin directory, run npm install to install dependencies, npm run build to build the files.', 'woocommerce-admin' ); - $message_two = sprintf( - /* translators: 1: URL of GitHub Repository build page */ - __( 'Or you can download a pre-built version of the plugin by visiting the releases page in the repository.', 'woocommerce-admin' ), - 'https://github.com/woocommerce/woocommerce-admin/releases' - ); - printf( '

%s %s

', $message_one, $message_two ); /* WPCS: xss ok. */ - } - - /** - * Overwrites the allowed features array using a local `feature-config.php` file. - * - * @param array $features Array of feature slugs. - */ - public function replace_supported_features( $features ) { - $feature_config = apply_filters( 'wc_admin_get_feature_config', wc_admin_get_feature_config() ); - $features = array_keys( array_filter( $feature_config ) ); - return $features; - } - - /** - * Adds a menu item for the wc-admin devdocs. - */ - public function register_devdocs_page() { - if ( WC_Admin_Loader::is_feature_enabled( 'devdocs' ) && defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { - wc_admin_register_page( - array( - 'title' => 'DevDocs', - 'parent' => 'woocommerce', - 'path' => '/devdocs', - ) - ); - } - } - - /** - * Define constant if not already set. - * - * @param string $name Constant name. - * @param string|bool $value Constant value. - */ - protected function define( $name, $value ) { - if ( ! defined( $name ) ) { - define( $name, $value ); - } - } - - /** - * Prevent cloning. - */ - private function __clone() {} - - /** - * Prevent unserializing. - */ - private function __wakeup() {} -} - WC_Admin_Feature_Plugin::instance()->init(); From c73325c3123be98da11dd858637ebabaa5be643f Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 12 Aug 2019 11:11:28 -0700 Subject: [PATCH 27/32] PSR-4ify the loader class. --- .../includes/core-functions.php | 2 + .../src/API/WC_Admin_Api_Init.php | 4 +- .../src/Features/WC_Admin_Onboarding.php | 4 +- .../src/WC_Admin_Feature_Plugin.php | 4 +- .../WC_Admin_Loader.php} | 40 ++++++++++--------- 5 files changed, 31 insertions(+), 23 deletions(-) rename plugins/woocommerce-admin/{includes/class-wc-admin-loader.php => src/WC_Admin_Loader.php} (93%) diff --git a/plugins/woocommerce-admin/includes/core-functions.php b/plugins/woocommerce-admin/includes/core-functions.php index 930221dd9e9..4bd9ba2a05f 100644 --- a/plugins/woocommerce-admin/includes/core-functions.php +++ b/plugins/woocommerce-admin/includes/core-functions.php @@ -9,6 +9,8 @@ defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\WC_Admin_Loader; + /** * Format a number using the decimal and thousands separator settings in WooCommerce. * diff --git a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php index 2bf66a770e9..d18f2627b22 100644 --- a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php +++ b/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php @@ -9,6 +9,8 @@ namespace Automattic\WooCommerce\Admin\API; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\WC_Admin_Loader; + /** * WC_Admin_Api_Init class. */ @@ -72,7 +74,7 @@ class WC_Admin_Api_Init { 'Automattic\WooCommerce\Admin\API\Themes', ); - if ( \WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { + if ( WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { $controllers = array_merge( $controllers, array( diff --git a/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php b/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php index 662aff86b5f..555706c67c6 100644 --- a/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php @@ -8,6 +8,8 @@ namespace Automattic\WooCommerce\Admin\Features; +use \Automattic\WooCommerce\Admin\WC_Admin_Loader; + /** * Contains backend logic for the onboarding profile and checklist feature. */ @@ -363,7 +365,7 @@ class WC_Admin_Onboarding { */ public static function reset_onboarding() { if ( - ! \WC_Admin_Loader::is_admin_page() || + ! WC_Admin_Loader::is_admin_page() || ! isset( $_GET['reset_onboarding'] ) || // WPCS: CSRF ok. 1 !== absint( $_GET['reset_onboarding'] ) // WPCS: CSRF ok. ) { diff --git a/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php b/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php index 1e6c896620e..5ce821022fb 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php @@ -190,7 +190,7 @@ class WC_Admin_Feature_Plugin { remove_action( 'admin_head', array( 'WC_Admin_Library', 'update_link_structure' ), 20 ); - new \WC_Admin_Loader(); + new WC_Admin_Loader(); add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ) ); add_action( 'admin_menu', array( $this, 'register_devdocs_page' ) ); @@ -282,7 +282,7 @@ class WC_Admin_Feature_Plugin { * Adds a menu item for the wc-admin devdocs. */ public function register_devdocs_page() { - if ( \WC_Admin_Loader::is_feature_enabled( 'devdocs' ) && defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { + if ( WC_Admin_Loader::is_feature_enabled( 'devdocs' ) && defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { wc_admin_register_page( array( 'title' => 'DevDocs', diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php b/plugins/woocommerce-admin/src/WC_Admin_Loader.php similarity index 93% rename from plugins/woocommerce-admin/includes/class-wc-admin-loader.php rename to plugins/woocommerce-admin/src/WC_Admin_Loader.php index 90814cb2757..1ec63b8f7ec 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-loader.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Loader.php @@ -6,6 +6,8 @@ * @package Woocommerce Admin */ +namespace Automattic\WooCommerce\Admin; + /** * WC_Admin_Loader Class. */ @@ -44,23 +46,23 @@ class WC_Admin_Loader { * Hooks added here should be removed in `wc_admin_initialize` via the feature plugin. */ public function __construct() { - add_action( 'init', array( 'WC_Admin_Loader', 'load_features' ) ); - add_action( 'admin_enqueue_scripts', array( 'WC_Admin_Loader', 'register_scripts' ) ); - add_action( 'admin_enqueue_scripts', array( 'WC_Admin_Loader', 'load_scripts' ), 15 ); - add_action( 'woocommerce_components_settings', array( 'WC_Admin_Loader', 'add_component_settings' ) ); - add_filter( 'admin_body_class', array( 'WC_Admin_Loader', 'add_admin_body_classes' ) ); - add_action( 'admin_menu', array( 'WC_Admin_Loader', 'register_page_handler' ) ); - add_filter( 'admin_title', array( 'WC_Admin_Loader', 'update_admin_title' ) ); - add_action( 'rest_api_init', array( 'WC_Admin_Loader', 'register_user_data' ) ); - add_action( 'in_admin_header', array( 'WC_Admin_Loader', 'embed_page_header' ) ); - add_filter( 'woocommerce_settings_groups', array( 'WC_Admin_Loader', 'add_settings_group' ) ); - add_filter( 'woocommerce_settings-wc_admin', array( 'WC_Admin_Loader', 'add_settings' ) ); - add_action( 'admin_head', array( 'WC_Admin_Loader', 'remove_notices' ) ); - add_action( 'admin_notices', array( 'WC_Admin_Loader', 'inject_before_notices' ) ); - add_action( 'admin_notices', array( 'WC_Admin_Loader', 'inject_after_notices' ), PHP_INT_MAX ); + add_action( 'init', array( __CLASS__, 'load_features' ) ); + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'register_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_scripts' ), 15 ); + add_action( 'woocommerce_components_settings', array( __CLASS__, 'add_component_settings' ) ); + add_filter( 'admin_body_class', array( __CLASS__, 'add_admin_body_classes' ) ); + add_action( 'admin_menu', array( __CLASS__, 'register_page_handler' ) ); + add_filter( 'admin_title', array( __CLASS__, 'update_admin_title' ) ); + add_action( 'rest_api_init', array( __CLASS__, 'register_user_data' ) ); + add_action( 'in_admin_header', array( __CLASS__, 'embed_page_header' ) ); + add_filter( 'woocommerce_settings_groups', array( __CLASS__, 'add_settings_group' ) ); + add_filter( 'woocommerce_settings-wc_admin', array( __CLASS__, 'add_settings' ) ); + add_action( 'admin_head', array( __CLASS__, 'remove_notices' ) ); + add_action( 'admin_notices', array( __CLASS__, 'inject_before_notices' ) ); + add_action( 'admin_notices', array( __CLASS__, 'inject_after_notices' ), PHP_INT_MAX ); // priority is 20 to run after https://github.com/woocommerce/woocommerce/blob/a55ae325306fc2179149ba9b97e66f32f84fdd9c/includes/admin/class-wc-admin-menus.php#L165. - add_action( 'admin_head', array( 'WC_Admin_Loader', 'remove_app_entry_page_menu_item' ), 20 ); + add_action( 'admin_head', array( __CLASS__, 'remove_app_entry_page_menu_item' ), 20 ); /* * Remove the emoji script as it always defaults to replacing emojis with Twemoji images. @@ -538,7 +540,7 @@ class WC_Admin_Loader { $settings['notifyLowStockAmount'] = get_option( 'woocommerce_notify_low_stock_amount' ); // @todo On merge, once plugin images are added to core WooCommerce, `wcAdminAssetUrl` can be retired, // and `wcAssetUrl` can be used in its place throughout the codebase. - $settings['wcAdminAssetUrl'] = plugins_url( 'images/', plugin_dir_path( dirname( __FILE__ ) ) . 'woocommerce-admin.php' ); + $settings['wcAdminAssetUrl'] = plugins_url( 'images/', plugin_dir_path( dirname( __DIR__ ) ) . 'woocommerce-admin.php' ); if ( ! empty( $preload_data_endpoints ) ) { foreach ( $preload_data_endpoints as $key => $endpoint ) { @@ -633,7 +635,7 @@ class WC_Admin_Loader { * @return array */ public static function get_custom_settings( $settings ) { - $wc_rest_settings_options_controller = new WC_REST_Setting_Options_Controller(); + $wc_rest_settings_options_controller = new \WC_REST_Setting_Options_Controller(); $wc_admin_group_settings = $wc_rest_settings_options_controller->get_group_settings( 'wc_admin' ); $settings['wcAdminSettings'] = array(); @@ -681,8 +683,8 @@ class WC_Admin_Loader { 'user', 'woocommerce_meta', array( - 'get_callback' => array( 'WC_Admin_Loader', 'get_user_data_values' ), - 'update_callback' => array( 'WC_Admin_Loader', 'update_user_data_values' ), + 'get_callback' => array( __CLASS__, 'get_user_data_values' ), + 'update_callback' => array( __CLASS__, 'update_user_data_values' ), 'schema' => null, ) ); From d4d0a3148632052facea442c69b319dc35579862 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 12 Aug 2019 11:22:32 -0700 Subject: [PATCH 28/32] Flatten includes/ directory. --- plugins/woocommerce-admin/composer.json | 2 +- .../includes/{page-controller => }/connect-existing-pages.php | 0 .../{page-controller => }/page-controller-functions.php | 0 plugins/woocommerce-admin/src/WC_Admin_Loader.php | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename plugins/woocommerce-admin/includes/{page-controller => }/connect-existing-pages.php (100%) rename plugins/woocommerce-admin/includes/{page-controller => }/page-controller-functions.php (100%) diff --git a/plugins/woocommerce-admin/composer.json b/plugins/woocommerce-admin/composer.json index 2e531d72cd1..e6ba4804ec9 100644 --- a/plugins/woocommerce-admin/composer.json +++ b/plugins/woocommerce-admin/composer.json @@ -38,7 +38,7 @@ "files": [ "includes/core-functions.php", "includes/feature-config.php", - "includes/page-controller/page-controller-functions.php" + "includes/page-controller-functions.php" ], "psr-4": { "Automattic\\WooCommerce\\Admin\\": "src/" diff --git a/plugins/woocommerce-admin/includes/page-controller/connect-existing-pages.php b/plugins/woocommerce-admin/includes/connect-existing-pages.php similarity index 100% rename from plugins/woocommerce-admin/includes/page-controller/connect-existing-pages.php rename to plugins/woocommerce-admin/includes/connect-existing-pages.php diff --git a/plugins/woocommerce-admin/includes/page-controller/page-controller-functions.php b/plugins/woocommerce-admin/includes/page-controller-functions.php similarity index 100% rename from plugins/woocommerce-admin/includes/page-controller/page-controller-functions.php rename to plugins/woocommerce-admin/includes/page-controller-functions.php diff --git a/plugins/woocommerce-admin/src/WC_Admin_Loader.php b/plugins/woocommerce-admin/src/WC_Admin_Loader.php index 1ec63b8f7ec..bb1fbdb6cfb 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Loader.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Loader.php @@ -158,7 +158,7 @@ class WC_Admin_Loader { ); // Connect existing WooCommerce pages. - require_once WC_ADMIN_ABSPATH . 'includes/page-controller/connect-existing-pages.php'; + require_once WC_ADMIN_ABSPATH . 'includes/connect-existing-pages.php'; } /** From 4356eef13d579cb87d927d98b58aba71b13fefe5 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 12 Aug 2019 11:50:22 -0700 Subject: [PATCH 29/32] Remove defunct filename prefix from feature classes. --- plugins/woocommerce-admin/src/API/OnboardingProfile.php | 6 +++--- .../{WC_Admin_Activity_Panels.php => ActivityPanels.php} | 2 +- .../src/Features/{WC_Admin_Analytics.php => Analytics.php} | 2 +- ...Admin_Analytics_Dashboard.php => AnalyticsDashboard.php} | 2 +- .../Features/{WC_Admin_Onboarding.php => Onboarding.php} | 4 ++-- .../{WC_Admin_Onboarding_Tasks.php => OnboardingTasks.php} | 2 +- plugins/woocommerce-admin/src/WC_Admin_Loader.php | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) rename plugins/woocommerce-admin/src/Features/{WC_Admin_Activity_Panels.php => ActivityPanels.php} (98%) rename plugins/woocommerce-admin/src/Features/{WC_Admin_Analytics.php => Analytics.php} (99%) rename plugins/woocommerce-admin/src/Features/{WC_Admin_Analytics_Dashboard.php => AnalyticsDashboard.php} (98%) rename plugins/woocommerce-admin/src/Features/{WC_Admin_Onboarding.php => Onboarding.php} (99%) rename plugins/woocommerce-admin/src/Features/{WC_Admin_Onboarding_Tasks.php => OnboardingTasks.php} (98%) diff --git a/plugins/woocommerce-admin/src/API/OnboardingProfile.php b/plugins/woocommerce-admin/src/API/OnboardingProfile.php index 73f23b6c194..b64f68e5884 100644 --- a/plugins/woocommerce-admin/src/API/OnboardingProfile.php +++ b/plugins/woocommerce-admin/src/API/OnboardingProfile.php @@ -11,7 +11,7 @@ namespace Automattic\WooCommerce\Admin\API; defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\Features\WC_Admin_Onboarding; +use Automattic\WooCommerce\Admin\Features\Onboarding; /** * Onboarding Profile controller. @@ -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( 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( Onboarding::get_allowed_product_types() ), 'type' => 'string', ), ), diff --git a/plugins/woocommerce-admin/src/Features/WC_Admin_Activity_Panels.php b/plugins/woocommerce-admin/src/Features/ActivityPanels.php similarity index 98% rename from plugins/woocommerce-admin/src/Features/WC_Admin_Activity_Panels.php rename to plugins/woocommerce-admin/src/Features/ActivityPanels.php index 33142fbb23e..ce521c17068 100644 --- a/plugins/woocommerce-admin/src/Features/WC_Admin_Activity_Panels.php +++ b/plugins/woocommerce-admin/src/Features/ActivityPanels.php @@ -14,7 +14,7 @@ use Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Settings_Notes; /** * Contains backend logic for the activity panel feature. */ -class WC_Admin_Activity_Panels { +class ActivityPanels { /** * Class instance. * diff --git a/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics.php b/plugins/woocommerce-admin/src/Features/Analytics.php similarity index 99% rename from plugins/woocommerce-admin/src/Features/WC_Admin_Analytics.php rename to plugins/woocommerce-admin/src/Features/Analytics.php index 7b8cebc41a7..12e71830bae 100644 --- a/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics.php +++ b/plugins/woocommerce-admin/src/Features/Analytics.php @@ -11,7 +11,7 @@ namespace Automattic\WooCommerce\Admin\Features; /** * Contains backend logic for the Analytics feature. */ -class WC_Admin_Analytics { +class Analytics { /** * Class instance. * diff --git a/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics_Dashboard.php b/plugins/woocommerce-admin/src/Features/AnalyticsDashboard.php similarity index 98% rename from plugins/woocommerce-admin/src/Features/WC_Admin_Analytics_Dashboard.php rename to plugins/woocommerce-admin/src/Features/AnalyticsDashboard.php index 1ac55134353..98a7b9c3e6c 100644 --- a/plugins/woocommerce-admin/src/Features/WC_Admin_Analytics_Dashboard.php +++ b/plugins/woocommerce-admin/src/Features/AnalyticsDashboard.php @@ -11,7 +11,7 @@ namespace Automattic\WooCommerce\Admin\Features; /** * Contains backend logic for the dashboard feature. */ -class WC_Admin_Analytics_Dashboard { +class AnalyticsDashboard { /** * Menu slug. */ diff --git a/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php b/plugins/woocommerce-admin/src/Features/Onboarding.php similarity index 99% rename from plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php rename to plugins/woocommerce-admin/src/Features/Onboarding.php index 555706c67c6..948aa6c8be9 100644 --- a/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/Onboarding.php @@ -13,7 +13,7 @@ use \Automattic\WooCommerce\Admin\WC_Admin_Loader; /** * Contains backend logic for the onboarding profile and checklist feature. */ -class WC_Admin_Onboarding { +class Onboarding { /** * Class instance. * @@ -54,7 +54,7 @@ class WC_Admin_Onboarding { } // Include WC Admin Onboarding classes. - WC_Admin_Onboarding_Tasks::get_instance(); + OnboardingTasks::get_instance(); add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after WC_Admin_Loader. add_action( 'woocommerce_theme_installed', array( $this, 'delete_themes_transient' ) ); diff --git a/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding_Tasks.php b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php similarity index 98% rename from plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding_Tasks.php rename to plugins/woocommerce-admin/src/Features/OnboardingTasks.php index e6f5d3438c9..1a523aa9a29 100644 --- a/plugins/woocommerce-admin/src/Features/WC_Admin_Onboarding_Tasks.php +++ b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php @@ -11,7 +11,7 @@ namespace Automattic\WooCommerce\Admin\Features; /** * Contains the logic for completing onboarding tasks. */ -class WC_Admin_Onboarding_Tasks { +class OnboardingTasks { /** * Class instance. * diff --git a/plugins/woocommerce-admin/src/WC_Admin_Loader.php b/plugins/woocommerce-admin/src/WC_Admin_Loader.php index bb1fbdb6cfb..27f338d4931 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Loader.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Loader.php @@ -131,8 +131,8 @@ class WC_Admin_Loader { public static function load_features() { $features = self::get_features(); foreach ( $features as $feature ) { - $feature = strtolower( str_replace( '-', '_', $feature ) ); - $feature = 'Automattic\WooCommerce\Admin\Features\WC_Admin_' . ucwords( $feature, '_' ); + $feature = str_replace( '-', '', ucwords( strtolower( $feature ), '-' ) ); + $feature = 'Automattic\\WooCommerce\\Admin\\Features\\' . $feature; if ( class_exists( $feature ) ) { new $feature; From 9bc54b33446b051e18968029886156f4039a70ff Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 12 Aug 2019 12:34:08 -0700 Subject: [PATCH 30/32] Remove defunct filename prefix from API init class. --- .../src/API/{WC_Admin_Api_Init.php => Init.php} | 2 +- plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) rename plugins/woocommerce-admin/src/API/{WC_Admin_Api_Init.php => Init.php} (99%) diff --git a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php b/plugins/woocommerce-admin/src/API/Init.php similarity index 99% rename from plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php rename to plugins/woocommerce-admin/src/API/Init.php index d18f2627b22..480f83327a6 100644 --- a/plugins/woocommerce-admin/src/API/WC_Admin_Api_Init.php +++ b/plugins/woocommerce-admin/src/API/Init.php @@ -14,7 +14,7 @@ use \Automattic\WooCommerce\Admin\WC_Admin_Loader; /** * WC_Admin_Api_Init class. */ -class WC_Admin_Api_Init { +class Init { /** * Boostrap REST API. diff --git a/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php b/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php index 5ce821022fb..7e39370a121 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php +++ b/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php @@ -13,8 +13,7 @@ use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; -use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes; -use \Automattic\WooCommerce\Admin\API\WC_Admin_Api_Init; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes;; /** * Feature plugin main class. @@ -140,7 +139,7 @@ class WC_Admin_Feature_Plugin { WC_Admin_Reports_Sync::init(); WC_Admin_Install::init(); WC_Admin_Events::instance()->init(); - new WC_Admin_Api_Init(); + new \Automattic\WooCommerce\Admin\API\Init(); WC_Admin_Report_Exporter::init(); // CRUD classes. From 953427bea52f44d3e28f26a3f8dc632264597d33 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 12 Aug 2019 14:52:09 -0700 Subject: [PATCH 31/32] Remove defunct filename prefix from remaining files. Excluding the note classes for third party compatibility. --- .../woocommerce-admin-add-report-example.php | 2 +- .../woocommerce-admin-dashboard-section.php | 2 +- .../woocommerce-admin-table-column.php | 2 +- .../woocommerce-admin/docs/feature-flags.md | 4 +- .../woocommerce-admin/docs/page-controller.md | 4 +- .../includes/core-functions.php | 4 +- .../includes/page-controller-functions.php | 28 +++++----- .../woocommerce-admin/src/API/Customers.php | 2 +- plugins/woocommerce-admin/src/API/Init.php | 6 +-- .../src/API/ProductVariations.php | 12 ++--- .../src/API/Reports/Categories/Controller.php | 2 +- .../src/API/Reports/Categories/DataStore.php | 4 +- .../src/API/Reports/Categories/Query.php | 4 +- .../src/API/Reports/Coupons/DataStore.php | 4 +- .../src/API/Reports/Coupons/Query.php | 4 +- .../API/Reports/Coupons/Stats/DataStore.php | 4 +- .../src/API/Reports/Coupons/Stats/Query.php | 4 +- .../API/Reports/Coupons/Stats/Segmenter.php | 2 +- .../src/API/Reports/Customers/DataStore.php | 4 +- .../src/API/Reports/Customers/Query.php | 4 +- .../API/Reports/Customers/Stats/DataStore.php | 4 +- .../src/API/Reports/Customers/Stats/Query.php | 4 +- .../src/API/Reports/DataStore.php | 4 +- .../src/API/Reports/Downloads/DataStore.php | 4 +- .../src/API/Reports/Downloads/Query.php | 4 +- .../API/Reports/Downloads/Stats/DataStore.php | 4 +- .../src/API/Reports/Downloads/Stats/Query.php | 2 +- .../src/API/Reports/Export/Controller.php | 10 ++-- .../src/API/Reports/Import/Controller.php | 12 ++--- .../src/API/Reports/Orders/DataStore.php | 4 +- .../src/API/Reports/Orders/Query.php | 4 +- .../API/Reports/Orders/Stats/DataStore.php | 4 +- .../src/API/Reports/Orders/Stats/Query.php | 4 +- .../API/Reports/Orders/Stats/Segmenter.php | 2 +- .../src/API/Reports/ParameterException.php | 2 +- .../PerformanceIndicators/Controller.php | 2 +- .../src/API/Reports/Products/DataStore.php | 4 +- .../src/API/Reports/Products/Query.php | 4 +- .../API/Reports/Products/Stats/DataStore.php | 4 +- .../src/API/Reports/Products/Stats/Query.php | 4 +- .../API/Reports/Products/Stats/Segmenter.php | 2 +- .../src/API/Reports/Query.php | 2 +- .../src/API/Reports/Revenue/Query.php | 4 +- .../src/API/Reports/Segmenter.php | 2 +- .../src/API/Reports/Stock/Stats/DataStore.php | 4 +- .../src/API/Reports/Stock/Stats/Query.php | 4 +- .../src/API/Reports/Taxes/DataStore.php | 4 +- .../src/API/Reports/Taxes/Query.php | 4 +- .../src/API/Reports/Taxes/Stats/DataStore.php | 4 +- .../src/API/Reports/Taxes/Stats/Query.php | 4 +- .../src/API/Reports/Taxes/Stats/Segmenter.php | 2 +- .../src/API/Reports/Variations/DataStore.php | 4 +- .../src/API/Reports/Variations/Query.php | 4 +- plugins/woocommerce-admin/src/API/Themes.php | 6 +-- .../src/{WC_Admin_Events.php => Events.php} | 2 +- ...n_Feature_Plugin.php => FeaturePlugin.php} | 24 ++++----- .../src/Features/ActivityPanels.php | 4 +- .../src/Features/Analytics.php | 2 +- .../src/Features/AnalyticsDashboard.php | 2 +- .../src/Features/Onboarding.php | 8 +-- .../src/Features/OnboardingTasks.php | 4 +- .../src/{WC_Admin_Install.php => Install.php} | 4 +- .../src/{WC_Admin_Loader.php => Loader.php} | 10 ++-- .../src/Notes/WC_Admin_Notes.php | 2 +- .../Notes/WC_Admin_Notes_Historical_Data.php | 4 +- .../Notes/WC_Admin_Notes_Welcome_Message.php | 4 +- .../Order.php} | 14 ++--- .../OrderRefund.php} | 14 ++--- .../OrderTraits.php} | 6 +-- .../ThemeUpgrader.php} | 6 +-- .../ThemeUpgraderSkin.php} | 6 +-- .../WPPostStore.php} | 4 +- ...Page_Controller.php => PageController.php} | 8 +-- ...CSV_Exporter.php => ReportCSVExporter.php} | 4 +- ...Report_Exporter.php => ReportExporter.php} | 12 ++--- ...Admin_Reports_Sync.php => ReportsSync.php} | 10 ++-- plugins/woocommerce-admin/tests/api-init.php | 10 ++-- .../tests/api/reports-import.php | 4 +- .../woocommerce-admin/tests/batch-queue.php | 52 +++++++++---------- plugins/woocommerce-admin/tests/bootstrap.php | 4 +- .../tests/queue-priority.php | 14 ++--- .../class-wc-tests-reports-coupons.php | 4 +- .../class-wc-tests-reports-orders-stats.php | 8 +-- plugins/woocommerce-admin/uninstall.php | 6 +-- .../woocommerce-admin/woocommerce-admin.php | 4 +- 85 files changed, 249 insertions(+), 249 deletions(-) rename plugins/woocommerce-admin/src/{WC_Admin_Events.php => Events.php} (98%) rename plugins/woocommerce-admin/src/{WC_Admin_Feature_Plugin.php => FeaturePlugin.php} (94%) rename plugins/woocommerce-admin/src/{WC_Admin_Install.php => Install.php} (99%) rename plugins/woocommerce-admin/src/{WC_Admin_Loader.php => Loader.php} (98%) rename plugins/woocommerce-admin/src/{WC_Admin_Order.php => Overrides/Order.php} (85%) rename plugins/woocommerce-admin/src/{WC_Admin_Order_Refund.php => Overrides/OrderRefund.php} (77%) rename plugins/woocommerce-admin/src/{WC_Admin_Order_Trait.php => Overrides/OrderTraits.php} (96%) rename plugins/woocommerce-admin/src/{WC_Admin_Theme_Upgrader.php => Overrides/ThemeUpgrader.php} (93%) rename plugins/woocommerce-admin/src/{WC_Admin_Theme_Upgrader_Skin.php => Overrides/ThemeUpgraderSkin.php} (77%) rename plugins/woocommerce-admin/src/{WC_Admin_ActionScheduler_WPPostStore.php => Overrides/WPPostStore.php} (92%) rename plugins/woocommerce-admin/src/{WC_Admin_Page_Controller.php => PageController.php} (99%) rename plugins/woocommerce-admin/src/{WC_Admin_Report_CSV_Exporter.php => ReportCSVExporter.php} (98%) rename plugins/woocommerce-admin/src/{WC_Admin_Report_Exporter.php => ReportExporter.php} (92%) rename plugins/woocommerce-admin/src/{WC_Admin_Reports_Sync.php => ReportsSync.php} (99%) diff --git a/plugins/woocommerce-admin/docs/examples/extensions/add-report/woocommerce-admin-add-report-example.php b/plugins/woocommerce-admin/docs/examples/extensions/add-report/woocommerce-admin-add-report-example.php index cd04a4e6e32..d010165de17 100644 --- a/plugins/woocommerce-admin/docs/examples/extensions/add-report/woocommerce-admin-add-report-example.php +++ b/plugins/woocommerce-admin/docs/examples/extensions/add-report/woocommerce-admin-add-report-example.php @@ -10,7 +10,7 @@ */ function add_report_register_script() { - if ( ! class_exists( 'WC_Admin_Loader' ) || ! WC_Admin_Loader::is_admin_page() ) { + if ( ! class_exists( 'Automattic\WooCommerce\Admin\Loader' ) || ! \Automattic\WooCommerce\Admin\Loader::is_admin_page() ) { return; } diff --git a/plugins/woocommerce-admin/docs/examples/extensions/dashboard-section/woocommerce-admin-dashboard-section.php b/plugins/woocommerce-admin/docs/examples/extensions/dashboard-section/woocommerce-admin-dashboard-section.php index 8a30c43ad46..ad639b4a15a 100644 --- a/plugins/woocommerce-admin/docs/examples/extensions/dashboard-section/woocommerce-admin-dashboard-section.php +++ b/plugins/woocommerce-admin/docs/examples/extensions/dashboard-section/woocommerce-admin-dashboard-section.php @@ -10,7 +10,7 @@ */ function dashboard_section_register_script() { - if ( ! class_exists( 'WC_Admin_Loader' ) || ! WC_Admin_Loader::is_admin_page() ) { + if ( ! class_exists( 'Automattic\WooCommerce\Admin\Loader' ) || ! \Automattic\WooCommerce\Admin\Loader::is_admin_page() ) { return; } diff --git a/plugins/woocommerce-admin/docs/examples/extensions/table-column/woocommerce-admin-table-column.php b/plugins/woocommerce-admin/docs/examples/extensions/table-column/woocommerce-admin-table-column.php index a77417451c2..b79a135e319 100644 --- a/plugins/woocommerce-admin/docs/examples/extensions/table-column/woocommerce-admin-table-column.php +++ b/plugins/woocommerce-admin/docs/examples/extensions/table-column/woocommerce-admin-table-column.php @@ -10,7 +10,7 @@ */ function table_column_register_script() { - if ( ! class_exists( 'WC_Admin_Loader' ) || ! WC_Admin_Loader::is_admin_page() ) { + if ( ! class_exists( 'Automattic\WooCommerce\Admin\Loader' ) || ! \Automattic\WooCommerce\Admin\Loader::is_admin_page() ) { return; } diff --git a/plugins/woocommerce-admin/docs/feature-flags.md b/plugins/woocommerce-admin/docs/feature-flags.md index 4b3b828d3c0..5996178efca 100644 --- a/plugins/woocommerce-admin/docs/feature-flags.md +++ b/plugins/woocommerce-admin/docs/feature-flags.md @@ -38,10 +38,10 @@ We also expose CSS classes on the `body` tag, so that you can target specific fe Feature flags are also available via PHP. To ensure these are consistent with the built client assets, `includes/feature-flags.php` is generated by the plugin build process or `npm start`. Do not edit `includes/feature-flags.php` directly. -To check if a feature is enabled, you can use the `WC_Admin_Loader::is_feature_enabled()`: +To check if a feature is enabled, you can use the `Automattic\WooCommerce\Admin\Loader::is_feature_enabled()`: ``` -if ( WC_Admin_Loader::is_feature_enabled( 'activity-panels' ) ) { +if ( \Automattic\WooCommerce\Admin\Loader::is_feature_enabled( 'activity-panels' ) ) { add_action( 'admin_header', 'wc_admin_activity_panel' ); } ``` diff --git a/plugins/woocommerce-admin/docs/page-controller.md b/plugins/woocommerce-admin/docs/page-controller.md index 4614e2ba828..2d41e227aeb 100644 --- a/plugins/woocommerce-admin/docs/page-controller.md +++ b/plugins/woocommerce-admin/docs/page-controller.md @@ -13,7 +13,7 @@ Connecting pages uses five parameters to `wc_admin_connect_page()`: * `id` - Identifies the page with the controller. Required. * `parent` - Denotes the page as a child of `parent`. Used for breadcrumbs. Optional. -* `screen_id` - Corresponds to [`WC_Admin_Page_Controller::get_current_screen_id()`](../includes/page-controller/class-wc-admin-page-controller.php#L219) to determine the current page. Required. +* `screen_id` - Corresponds to [`PageController::get_current_screen_id()`](../includes/page-controller/class-wc-admin-page-controller.php#L219) to determine the current page. Required. * `title` - Page title. Used to build breadcrumbs. String or array of breadcrumb pieces. Required. * `path` - Page path (relative). Used for linking breadcrumb pieces when this page is a `parent`. Optional. @@ -132,6 +132,6 @@ add_filter( 'woocommerce_admin_report_menu_items', 'add_report_menu_item' ); ### Further Reading -* Check out the [`WC_Admin_Page_Controller`](../includes/page-controller/class-wc-admin-page-controller.php) class. +* Check out the [`PageController`](../includes/page-controller/class-wc-admin-page-controller.php) class. * See how we're [connecting existing WooCommerce pages](../includes/page-controller/connect-existing-pages.php). * See how we're [registering Analytics Reports](../includes/features/analytics/class-wc-admin-analytics.php#L75). diff --git a/plugins/woocommerce-admin/includes/core-functions.php b/plugins/woocommerce-admin/includes/core-functions.php index 4bd9ba2a05f..72edb9d508f 100644 --- a/plugins/woocommerce-admin/includes/core-functions.php +++ b/plugins/woocommerce-admin/includes/core-functions.php @@ -9,7 +9,7 @@ defined( 'ABSPATH' ) || exit; -use \Automattic\WooCommerce\Admin\WC_Admin_Loader; +use \Automattic\WooCommerce\Admin\Loader; /** * Format a number using the decimal and thousands separator settings in WooCommerce. @@ -18,7 +18,7 @@ use \Automattic\WooCommerce\Admin\WC_Admin_Loader; * @return string */ function wc_admin_number_format( $number ) { - $currency_settings = WC_Admin_Loader::get_currency_settings(); + $currency_settings = Loader::get_currency_settings(); return number_format( $number, 0, diff --git a/plugins/woocommerce-admin/includes/page-controller-functions.php b/plugins/woocommerce-admin/includes/page-controller-functions.php index af227e5baf7..8d6d68bdb96 100644 --- a/plugins/woocommerce-admin/includes/page-controller-functions.php +++ b/plugins/woocommerce-admin/includes/page-controller-functions.php @@ -1,63 +1,63 @@ connect_page( $options ); } /** * Register JS-powered WooCommerce Admin Page. - * Passthrough to WC_Admin_Page_Controller::register_page(). + * Passthrough to PageController::register_page(). * - * @param array $options Options for WC_Admin_Page_Controller::register_page(). + * @param array $options Options for PageController::register_page(). */ function wc_admin_register_page( $options ) { - $controller = WC_Admin_Page_Controller::get_instance(); + $controller = PageController::get_instance(); $controller->register_page( $options ); } /** * Is this page connected to WooCommerce Admin? - * Passthrough to WC_Admin_Page_Controller::is_connected_page(). + * Passthrough to PageController::is_connected_page(). * * @return boolean True if the page is connected to WooCommerce Admin. */ function wc_admin_is_connected_page() { - $controller = WC_Admin_Page_Controller::get_instance(); + $controller = PageController::get_instance(); return $controller->is_connected_page(); } /** * Is this a WooCommerce Admin Page? - * Passthrough to WC_Admin_Page_Controller::is_registered_page(). + * Passthrough to PageController::is_registered_page(). * * @return boolean True if the page is a WooCommerce Admin page. */ function wc_admin_is_registered_page() { - $controller = WC_Admin_Page_Controller::get_instance(); + $controller = PageController::get_instance(); return $controller->is_registered_page(); } /** * Get breadcrumbs for WooCommerce Admin Page navigation. - * Passthrough to WC_Admin_Page_Controller::get_breadcrumbs(). + * Passthrough to PageController::get_breadcrumbs(). * * @return array Navigation pieces (breadcrumbs). */ function wc_admin_get_breadcrumbs() { - $controller = WC_Admin_Page_Controller::get_instance(); + $controller = PageController::get_instance(); return $controller->get_breadcrumbs(); } diff --git a/plugins/woocommerce-admin/src/API/Customers.php b/plugins/woocommerce-admin/src/API/Customers.php index 1899e40e2b3..563cda4a4f8 100644 --- a/plugins/woocommerce-admin/src/API/Customers.php +++ b/plugins/woocommerce-admin/src/API/Customers.php @@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || exit; * Customers controller. * * @package WooCommerce Admin/API - * @extends WC_Admin_REST_Reports_Customers_Controller + * @extends \Automattic\WooCommerce\Admin\API\Reports\Customers\Controller */ class Customers extends \Automattic\WooCommerce\Admin\API\Reports\Customers\Controller { diff --git a/plugins/woocommerce-admin/src/API/Init.php b/plugins/woocommerce-admin/src/API/Init.php index 480f83327a6..862084277c7 100644 --- a/plugins/woocommerce-admin/src/API/Init.php +++ b/plugins/woocommerce-admin/src/API/Init.php @@ -9,10 +9,10 @@ namespace Automattic\WooCommerce\Admin\API; defined( 'ABSPATH' ) || exit; -use \Automattic\WooCommerce\Admin\WC_Admin_Loader; +use \Automattic\WooCommerce\Admin\Loader; /** - * WC_Admin_Api_Init class. + * Init class. */ class Init { @@ -74,7 +74,7 @@ class Init { 'Automattic\WooCommerce\Admin\API\Themes', ); - if ( WC_Admin_Loader::is_feature_enabled( 'onboarding' ) ) { + if ( Loader::is_feature_enabled( 'onboarding' ) ) { $controllers = array_merge( $controllers, array( diff --git a/plugins/woocommerce-admin/src/API/ProductVariations.php b/plugins/woocommerce-admin/src/API/ProductVariations.php index 0ec84ae0709..965be5f6088 100644 --- a/plugins/woocommerce-admin/src/API/ProductVariations.php +++ b/plugins/woocommerce-admin/src/API/ProductVariations.php @@ -64,13 +64,13 @@ class ProductVariations extends \WC_REST_Product_Variations_Controller { * @return WP_Error|WP_REST_Response */ public function get_items( $request ) { - add_filter( 'posts_where', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_filter' ), 10, 2 ); - add_filter( 'posts_join', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_join' ), 10, 2 ); - add_filter( 'posts_groupby', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_group_by' ), 10, 2 ); + add_filter( 'posts_where', array( 'Automattic\WooCommerce\Admin\API\Products', 'add_wp_query_filter' ), 10, 2 ); + add_filter( 'posts_join', array( 'Automattic\WooCommerce\Admin\API\Products', 'add_wp_query_join' ), 10, 2 ); + add_filter( 'posts_groupby', array( 'Automattic\WooCommerce\Admin\API\Products', 'add_wp_query_group_by' ), 10, 2 ); $response = parent::get_items( $request ); - remove_filter( 'posts_where', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_filter' ), 10 ); - remove_filter( 'posts_join', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_join' ), 10 ); - remove_filter( 'posts_groupby', array( 'WC_Admin_REST_Products_Controller', 'add_wp_query_group_by' ), 10 ); + remove_filter( 'posts_where', array( 'Automattic\WooCommerce\Admin\API\Products', 'add_wp_query_filter' ), 10 ); + remove_filter( 'posts_join', array( 'Automattic\WooCommerce\Admin\API\Products', 'add_wp_query_join' ), 10 ); + remove_filter( 'posts_groupby', array( 'Automattic\WooCommerce\Admin\API\Products', 'add_wp_query_group_by' ), 10 ); return $response; } diff --git a/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php index 5070dda7bc7..847c2f0c134 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/Controller.php @@ -139,7 +139,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { /** * Prepare links for the request. * - * @param WC_Admin_Reports_Query $object Object data. + * @param \Automattic\WooCommerce\Admin\API\Reports\Query $object Object data. * @return array */ protected function prepare_links( $object ) { diff --git a/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php index 4662f519a51..bc17c97690e 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Categories/DataStore.php @@ -1,6 +1,6 @@ 'desc', * 'orderby' => 'items_sold', * ); - * $report = new WC_Admin_Reports_Categories_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Categories_Query + * API\Reports\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php index 302ba49a633..4c5d1266bac 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/DataStore.php @@ -1,6 +1,6 @@ 2, * 'coupons' => array(5, 120), * ); - * $report = new WC_Admin_Reports_Coupons_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Coupons\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Coupons_Query + * API\Reports\Coupons\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php index a7b6d0856dd..8f441acac23 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/DataStore.php @@ -1,6 +1,6 @@ 2, * 'coupons' => array(5, 120), * ); - * $report = new WC_Admin_Reports_Coupons_Stats_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Products_Query + * API\Reports\Coupons\Stats\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php index 227e098f08f..b8ad220fcdd 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Coupons/Stats/Segmenter.php @@ -249,7 +249,7 @@ class Segmenter extends ReportsSegmenter { * @param string $table_name Name of main SQL table for the data store (used as basis for JOINS). * * @return array - * @throws WC_Admin_Reports_Parameter_Exception In case of segmenting by variations, when no parent product is specified. + * @throws \Automattic\WooCommerce\Admin\API\Reports\ParameterException In case of segmenting by variations, when no parent product is specified. */ protected function get_segments( $type, $query_params, $table_name ) { global $wpdb; diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php index 385fe79cfda..b4e6e85cf62 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/DataStore.php @@ -1,6 +1,6 @@ 100, * 'country' => 'GB', * ); - * $report = new WC_Admin_Reports_Customers_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Customers\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Customers_Query + * API\Reports\Customers\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php index a36e7329ad1..2457b4cb3ab 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Customers/Stats/DataStore.php @@ -1,6 +1,6 @@ 100, * 'country' => 'GB', * ); - * $report = new WC_Admin_Reports_Customers_Stats_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Customers_Stats_Query + * API\Reports\Customers\Stats\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/DataStore.php index a489aaad4fa..46da2696846 100644 --- a/plugins/woocommerce-admin/src/API/Reports/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/DataStore.php @@ -1,6 +1,6 @@ 2, * 'products' => array(1,2,3) * ); - * $report = new WC_Admin_Reports_Downloads_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Downloads\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Downloads_Query + * API\Reports\Downloads\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php index d7c4641260d..c1e7a1dcb15 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Downloads/Stats/DataStore.php @@ -1,6 +1,6 @@ prepare_response_for_collection( $response ); @@ -196,7 +196,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { public function export_status( $request ) { $report_type = $request['type']; $export_id = $request['export_id']; - $percentage = WC_Admin_Report_Exporter::get_export_percentage_complete( $report_type, $export_id ); + $percentage = ReportExporter::get_export_percentage_complete( $report_type, $export_id ); if ( false === $percentage ) { return new \WP_Error( @@ -213,7 +213,7 @@ class Controller extends \Automattic\WooCommerce\Admin\API\Reports\Controller { // @todo - add thing in the links below instead? if ( 100 === $percentage ) { $query_args = array( - 'action' => WC_Admin_Report_Exporter::DOWNLOAD_EXPORT_ACTION, + 'action' => ReportExporter::DOWNLOAD_EXPORT_ACTION, 'filename' => "wc-{$report_type}-report-export-{$export_id}", ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php b/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php index 314d46596e6..5172a19a1ae 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/Import/Controller.php @@ -11,7 +11,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports\Import; defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; +use Automattic\WooCommerce\Admin\ReportsSync; /** * Reports Imports controller. @@ -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 = ReportsSync::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(); + ReportsSync::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 = ReportsSync::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' => ReportsSync::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 = ReportsSync::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 ); diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php index 6369a36be05..339b624dcbe 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/DataStore.php @@ -1,6 +1,6 @@ array('failed'), * 'new_customers' => false, * ); - * $report = new WC_Admin_Reports_Orders_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Orders\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -26,7 +26,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Orders_Query + * API\Reports\Orders\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php index bf270098dde..a42af30eb95 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/DataStore.php @@ -1,6 +1,6 @@ array(138), * 'status_in' => array('completed'), * ); - * $report = new WC_Admin_Reports_Orders_Stats_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -24,7 +24,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Orders_Stats_Query + * API\Reports\Orders\Stats\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php index 4c712d61c9c..34c87f00202 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Orders/Stats/Segmenter.php @@ -342,7 +342,7 @@ class Segmenter extends ReportsSegmenter { * @param string $table_name Name of main SQL table for the data store (used as basis for JOINS). * * @return array - * @throws WC_Admin_Reports_Parameter_Exception In case of segmenting by variations, when no parent product is specified. + * @throws \Automattic\WooCommerce\Admin\API\Reports\ParameterException In case of segmenting by variations, when no parent product is specified. */ protected function get_segments( $type, $query_params, $table_name ) { global $wpdb; diff --git a/plugins/woocommerce-admin/src/API/Reports/ParameterException.php b/plugins/woocommerce-admin/src/API/Reports/ParameterException.php index 246131a9144..749ff3a6428 100644 --- a/plugins/woocommerce-admin/src/API/Reports/ParameterException.php +++ b/plugins/woocommerce-admin/src/API/Reports/ParameterException.php @@ -12,6 +12,6 @@ namespace Automattic\WooCommerce\Admin\API\Reports; defined( 'ABSPATH' ) || exit; /** - * WC_Admin_Reports_Parameter_Exception class. + * API\Reports\ParameterException class. */ class ParameterException extends \WC_Data_Exception {} diff --git a/plugins/woocommerce-admin/src/API/Reports/PerformanceIndicators/Controller.php b/plugins/woocommerce-admin/src/API/Reports/PerformanceIndicators/Controller.php index 025955e1139..0cbe9ea81e2 100644 --- a/plugins/woocommerce-admin/src/API/Reports/PerformanceIndicators/Controller.php +++ b/plugins/woocommerce-admin/src/API/Reports/PerformanceIndicators/Controller.php @@ -373,7 +373,7 @@ class Controller extends \WC_REST_Reports_Controller { /** * Prepare links for the request. * - * @param WC_Admin_Reports_Query $object Object data. + * @param \Automattic\WooCommerce\Admin\API\Reports\Query $object Object data. * @return array */ protected function prepare_links( $object ) { diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php index dd85acb09d5..e69c28fafb7 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/DataStore.php @@ -1,6 +1,6 @@ array(15, 18), * 'products' => array(1,2,3) * ); - * $report = new WC_Admin_Reports_Products_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Products\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Products_Query + * API\Reports\Products\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php index f98ed51f316..fe4339c207b 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/DataStore.php @@ -1,6 +1,6 @@ array(15, 18), * 'product_ids' => array(1,2,3) * ); - * $report = new WC_Admin_Reports_Products_Stats_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Products\Stats\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Products_Query + * API\Reports\Products\Stats\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php index b2a4d44cdca..70f5d92ca80 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Products/Stats/Segmenter.php @@ -137,7 +137,7 @@ class Segmenter extends ReportsSegmenter { * @param string $table_name Name of main SQL table for the data store (used as basis for JOINS). * * @return array - * @throws WC_Admin_Reports_Parameter_Exception In case of segmenting by variations, when no parent product is specified. + * @throws \Automattic\WooCommerce\Admin\API\Reports\ParameterException In case of segmenting by variations, when no parent product is specified. */ protected function get_segments( $type, $query_params, $table_name ) { global $wpdb; diff --git a/plugins/woocommerce-admin/src/API/Reports/Query.php b/plugins/woocommerce-admin/src/API/Reports/Query.php index d6440e8354e..d0237ea32f5 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Query.php @@ -10,7 +10,7 @@ namespace Automattic\WooCommerce\Admin\API\Reports; defined( 'ABSPATH' ) || exit; /** - * WC_Admin_Reports_Query + * Admin\API\Reports\Query */ abstract class Query extends \WC_Object_Query { diff --git a/plugins/woocommerce-admin/src/API/Reports/Revenue/Query.php b/plugins/woocommerce-admin/src/API/Reports/Revenue/Query.php index fc967357cae..45371cdf28f 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Revenue/Query.php +++ b/plugins/woocommerce-admin/src/API/Reports/Revenue/Query.php @@ -8,7 +8,7 @@ * 'after' => '2018-07-05 00:00:00', * 'interval' => 'week', * ); - * $report = new WC_Admin_Reports_Revenue_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Revenue\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -21,7 +21,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Revenue_Query + * API\Reports\Revenue\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Segmenter.php index 007c7687a2b..18a5f612888 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Segmenter.php @@ -46,7 +46,7 @@ class Segmenter { protected $report_columns = array(); /** - * WC_Admin_Reports_Segmenting constructor. + * Constructor. * * @param array $query_args Query arguments supplied by the user for data store. * @param array $report_columns Report columns lookup from data store. diff --git a/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php index b7448382add..34368dc70cc 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Stock/Stats/DataStore.php @@ -1,6 +1,6 @@ get_data(); * * @package WooCommerce Admin/Classes @@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Stock_Stats_Query + * API\Reports\Stock\Stats\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php index cd9173d4213..6eb361c44c1 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/DataStore.php @@ -1,6 +1,6 @@ 2, * 'taxes' => array(1,2,3) * ); - * $report = new WC_Admin_Reports_Taxes_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Taxes\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -22,7 +22,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Taxes_Query + * API\Reports\Taxes\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php index 4272bc873b0..ec2dac18a78 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/DataStore.php @@ -1,6 +1,6 @@ array(15, 18), * 'product_ids' => array(1,2,3) * ); - * $report = new WC_Admin_Reports_Taxes_Stats_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Taxes_Query + * API\Reports\Taxes\Stats\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Segmenter.php b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Segmenter.php index 7ad39fb3805..dd68c16d0eb 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Segmenter.php +++ b/plugins/woocommerce-admin/src/API/Reports/Taxes/Stats/Segmenter.php @@ -128,7 +128,7 @@ class Segmenter extends ReportsSegmenter { * @param string $table_name Name of main SQL table for the data store (used as basis for JOINS). * * @return array - * @throws WC_Admin_Reports_Parameter_Exception In case of segmenting by variations, when no parent product is specified. + * @throws \Automattic\WooCommerce\Admin\API\Reports\ParameterException In case of segmenting by variations, when no parent product is specified. */ protected function get_segments( $type, $query_params, $table_name ) { if ( ! isset( $this->query_args['segmentby'] ) || '' === $this->query_args['segmentby'] ) { diff --git a/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php index d1fca8658a0..8605510845e 100644 --- a/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php +++ b/plugins/woocommerce-admin/src/API/Reports/Variations/DataStore.php @@ -1,6 +1,6 @@ array(15, 18), * 'products' => array(1,2,3) * ); - * $report = new WC_Admin_Reports_Products_Query( $args ); + * $report = new \Automattic\WooCommerce\Admin\API\Reports\Variations\Query( $args ); * $mydata = $report->get_data(); * * @package WooCommerce Admin/Classes @@ -23,7 +23,7 @@ defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Query as ReportsQuery; /** - * WC_Admin_Reports_Products_Query + * API\Reports\Variations\Query */ class Query extends ReportsQuery { diff --git a/plugins/woocommerce-admin/src/API/Themes.php b/plugins/woocommerce-admin/src/API/Themes.php index dc069f72f86..c9070624587 100644 --- a/plugins/woocommerce-admin/src/API/Themes.php +++ b/plugins/woocommerce-admin/src/API/Themes.php @@ -11,8 +11,8 @@ namespace Automattic\WooCommerce\Admin\API; defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader; -use Automattic\WooCommerce\Admin\WC_Admin_Theme_Upgrader_Skin; +use Automattic\WooCommerce\Admin\Overrides\ThemeUpgrader; +use Automattic\WooCommerce\Admin\Overrides\ThemeUpgraderSkin; /** * Themes controller. @@ -84,7 +84,7 @@ class Themes extends \WC_REST_Data_Controller { $_GET['package'] = true; $file_upload = new \File_Upload_Upgrader( 'pluginzip', 'package' ); - $upgrader = new \WC_Admin_Theme_Upgrader( new \WC_Admin_Theme_Upgrader_Skin() ); + $upgrader = new ThemeUpgrader( new ThemeUpgraderSkin() ); $install = $upgrader->install( $file_upload->package ); if ( $install || is_wp_error( $install ) ) { diff --git a/plugins/woocommerce-admin/src/WC_Admin_Events.php b/plugins/woocommerce-admin/src/Events.php similarity index 98% rename from plugins/woocommerce-admin/src/WC_Admin_Events.php rename to plugins/woocommerce-admin/src/Events.php index 588d48fd651..2114cea02b6 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Events.php +++ b/plugins/woocommerce-admin/src/Events.php @@ -17,7 +17,7 @@ use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_New_Sales_Record; /** * WC_Admin_Events Class. */ -class WC_Admin_Events { +class Events { /** * The single instance of the class. * diff --git a/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php b/plugins/woocommerce-admin/src/FeaturePlugin.php similarity index 94% rename from plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php rename to plugins/woocommerce-admin/src/FeaturePlugin.php index 7e39370a121..040486d20a6 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Feature_Plugin.php +++ b/plugins/woocommerce-admin/src/FeaturePlugin.php @@ -21,7 +21,7 @@ use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Woo_Subscriptions_Notes;; * @internal This file will not be bundled with woo core, only the feature plugin. * @internal Note this is not called WC_Admin due to a class already existing in core with that name. */ -class WC_Admin_Feature_Plugin { +class FeaturePlugin { /** * The single instance of the class. * @@ -65,8 +65,8 @@ class WC_Admin_Feature_Plugin { * @return void */ public function on_activation() { - WC_Admin_Install::create_tables(); - WC_Admin_Install::create_events(); + Install::create_tables(); + Install::create_events(); } /** @@ -82,7 +82,7 @@ class WC_Admin_Feature_Plugin { } $this->includes(); - WC_Admin_Reports_Sync::clear_queued_actions(); + ReportsSync::clear_queued_actions(); WC_Admin_Notes::clear_queued_actions(); wp_clear_scheduled_hook( 'wc_admin_daily' ); } @@ -136,11 +136,11 @@ class WC_Admin_Feature_Plugin { */ public function includes() { // Initialize the WC API extensions. - WC_Admin_Reports_Sync::init(); - WC_Admin_Install::init(); - WC_Admin_Events::instance()->init(); - new \Automattic\WooCommerce\Admin\API\Init(); - WC_Admin_Report_Exporter::init(); + ReportsSync::init(); + Install::init(); + Events::instance()->init(); + new API\Init(); + ReportExporter::init(); // CRUD classes. WC_Admin_Notes::init(); @@ -165,7 +165,7 @@ class WC_Admin_Feature_Plugin { return $store_class; } - return 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore'; + return 'Automattic\WooCommerce\Admin\Overrides\WPPostStore'; } /** @@ -189,7 +189,7 @@ class WC_Admin_Feature_Plugin { remove_action( 'admin_head', array( 'WC_Admin_Library', 'update_link_structure' ), 20 ); - new WC_Admin_Loader(); + new Loader(); add_filter( 'woocommerce_admin_features', array( $this, 'replace_supported_features' ) ); add_action( 'admin_menu', array( $this, 'register_devdocs_page' ) ); @@ -281,7 +281,7 @@ class WC_Admin_Feature_Plugin { * Adds a menu item for the wc-admin devdocs. */ public function register_devdocs_page() { - if ( WC_Admin_Loader::is_feature_enabled( 'devdocs' ) && defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { + if ( Loader::is_feature_enabled( 'devdocs' ) && defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { wc_admin_register_page( array( 'title' => 'DevDocs', diff --git a/plugins/woocommerce-admin/src/Features/ActivityPanels.php b/plugins/woocommerce-admin/src/Features/ActivityPanels.php index ce521c17068..2e4ddaad8fc 100644 --- a/plugins/woocommerce-admin/src/Features/ActivityPanels.php +++ b/plugins/woocommerce-admin/src/Features/ActivityPanels.php @@ -18,7 +18,7 @@ class ActivityPanels { /** * Class instance. * - * @var WC_Admin_Activity_Panels instance + * @var ActivityPanels instance */ protected static $instance = null; @@ -37,7 +37,7 @@ class ActivityPanels { */ public function __construct() { add_filter( 'wc_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) ); - add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after WC_Admin_Loader. + add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after Automattic\WooCommerce\Admin\Loader. add_action( 'woocommerce_updated', array( $this, 'woocommerce_updated_note' ) ); } diff --git a/plugins/woocommerce-admin/src/Features/Analytics.php b/plugins/woocommerce-admin/src/Features/Analytics.php index 12e71830bae..6646aa57f2b 100644 --- a/plugins/woocommerce-admin/src/Features/Analytics.php +++ b/plugins/woocommerce-admin/src/Features/Analytics.php @@ -15,7 +15,7 @@ class Analytics { /** * Class instance. * - * @var WC_Admin_Analytics instance + * @var Analytics instance */ protected static $instance = null; diff --git a/plugins/woocommerce-admin/src/Features/AnalyticsDashboard.php b/plugins/woocommerce-admin/src/Features/AnalyticsDashboard.php index 98a7b9c3e6c..ce9f4c64eca 100644 --- a/plugins/woocommerce-admin/src/Features/AnalyticsDashboard.php +++ b/plugins/woocommerce-admin/src/Features/AnalyticsDashboard.php @@ -20,7 +20,7 @@ class AnalyticsDashboard { /** * Class instance. * - * @var WC_Admin_Analytics_Dashboard instance + * @var AnalyticsDashboard instance */ protected static $instance = null; diff --git a/plugins/woocommerce-admin/src/Features/Onboarding.php b/plugins/woocommerce-admin/src/Features/Onboarding.php index 948aa6c8be9..dfddbfc372e 100644 --- a/plugins/woocommerce-admin/src/Features/Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/Onboarding.php @@ -8,7 +8,7 @@ namespace Automattic\WooCommerce\Admin\Features; -use \Automattic\WooCommerce\Admin\WC_Admin_Loader; +use \Automattic\WooCommerce\Admin\Loader; /** * Contains backend logic for the onboarding profile and checklist feature. @@ -17,7 +17,7 @@ class Onboarding { /** * Class instance. * - * @var WC_Admin_Onboarding instance + * @var Onboarding instance */ protected static $instance = null; @@ -56,7 +56,7 @@ class Onboarding { // Include WC Admin Onboarding classes. OnboardingTasks::get_instance(); - add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after WC_Admin_Loader. + add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 20 ); // Run after Automattic\WooCommerce\Admin\Loader. add_action( 'woocommerce_theme_installed', array( $this, 'delete_themes_transient' ) ); add_action( 'after_switch_theme', array( $this, 'delete_themes_transient' ) ); add_action( 'current_screen', array( $this, 'update_help_tab' ), 60 ); @@ -365,7 +365,7 @@ class Onboarding { */ public static function reset_onboarding() { if ( - ! WC_Admin_Loader::is_admin_page() || + ! Loader::is_admin_page() || ! isset( $_GET['reset_onboarding'] ) || // WPCS: CSRF ok. 1 !== absint( $_GET['reset_onboarding'] ) // WPCS: CSRF ok. ) { diff --git a/plugins/woocommerce-admin/src/Features/OnboardingTasks.php b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php index 1a523aa9a29..eb84a88c02a 100644 --- a/plugins/woocommerce-admin/src/Features/OnboardingTasks.php +++ b/plugins/woocommerce-admin/src/Features/OnboardingTasks.php @@ -15,7 +15,7 @@ class OnboardingTasks { /** * Class instance. * - * @var WC_Admin_Onboarding_Tasks instance + * @var OnboardingTasks instance */ protected static $instance = null; @@ -47,7 +47,7 @@ class OnboardingTasks { * Constructor */ public function __construct() { - add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 30 ); // Run after WC_Admin_Onboarding. + add_action( 'woocommerce_components_settings', array( $this, 'component_settings' ), 30 ); // Run after Onboarding. add_action( 'admin_init', array( $this, 'set_active_task' ), 20 ); add_action( 'admin_init', array( $this, 'check_active_task_completion' ), 1 ); } diff --git a/plugins/woocommerce-admin/src/WC_Admin_Install.php b/plugins/woocommerce-admin/src/Install.php similarity index 99% rename from plugins/woocommerce-admin/src/WC_Admin_Install.php rename to plugins/woocommerce-admin/src/Install.php index 367b25ba6bd..804c1222f29 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Install.php +++ b/plugins/woocommerce-admin/src/Install.php @@ -13,9 +13,9 @@ use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; /** - * WC_Admin_Install Class. + * Install Class. */ -class WC_Admin_Install { +class Install { /** * Plugin version option name. */ diff --git a/plugins/woocommerce-admin/src/WC_Admin_Loader.php b/plugins/woocommerce-admin/src/Loader.php similarity index 98% rename from plugins/woocommerce-admin/src/WC_Admin_Loader.php rename to plugins/woocommerce-admin/src/Loader.php index 27f338d4931..12e1e6e5ed3 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Loader.php +++ b/plugins/woocommerce-admin/src/Loader.php @@ -9,9 +9,9 @@ namespace Automattic\WooCommerce\Admin; /** - * WC_Admin_Loader Class. + * Loader Class. */ -class WC_Admin_Loader { +class Loader { /** * App entry point. */ @@ -20,7 +20,7 @@ class WC_Admin_Loader { /** * Class instance. * - * @var WC_Admin_Loader instance + * @var Loader instance */ protected static $instance = null; @@ -691,7 +691,7 @@ class WC_Admin_Loader { } /** - * For all the registered user data fields ( WC_Admin_Loader::get_user_data_fields ), fetch the data + * For all the registered user data fields ( Loader::get_user_data_fields ), fetch the data * for returning via the REST API. * * @param WP_User $user Current user. @@ -705,7 +705,7 @@ class WC_Admin_Loader { } /** - * For all the registered user data fields ( WC_Admin_Loader::get_user_data_fields ), update the data + * For all the registered user data fields ( Loader::get_user_data_fields ), update the data * for the REST API. * * @param array $values The new values for the meta. diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php index 741864e8269..36ec632f6b7 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes.php @@ -174,7 +174,7 @@ class WC_Admin_Notes { public static function clear_queued_actions() { $store = \ActionScheduler::store(); - if ( is_a( $store, 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore' ) ) { + if ( is_a( $store, 'Automattic\WooCommerce\Admin\Overrides\WPPostStore' ) ) { // If we're using our data store, call our bespoke deletion method. $action_types = array( self::UNSNOOZE_HOOK ); $store->clear_pending_wcadmin_actions( $action_types ); diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php index afc3b3fc7c7..0bb6c70c9e8 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php @@ -11,7 +11,7 @@ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; -use \Automattic\WooCommerce\Admin\WC_Admin_Install; +use \Automattic\WooCommerce\Admin\Install; /** * WC_Admin_Notes_Historical_Data. @@ -23,7 +23,7 @@ class WC_Admin_Notes_Historical_Data { * Creates a note for regenerating historical data. */ public static function add_note() { - $is_upgrading = get_option( WC_Admin_Install::VERSION_OPTION ); + $is_upgrading = get_option( Install::VERSION_OPTION ); if ( $is_upgrading ) { return; } diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php index 0e716a115df..3f048c21f36 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Welcome_Message.php @@ -11,7 +11,7 @@ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; -use \Automattic\WooCommerce\Admin\WC_Admin_Install; +use \Automattic\WooCommerce\Admin\Install; /** * WC_Admin_Notes_Welcome_Message. @@ -24,7 +24,7 @@ class WC_Admin_Notes_Welcome_Message { */ public static function add_welcome_note() { // Check if plugin is upgrading if yes then don't create this note. - $is_upgrading = get_option( WC_Admin_Install::VERSION_OPTION ); + $is_upgrading = get_option( Install::VERSION_OPTION ); if ( $is_upgrading ) { return; } diff --git a/plugins/woocommerce-admin/src/WC_Admin_Order.php b/plugins/woocommerce-admin/src/Overrides/Order.php similarity index 85% rename from plugins/woocommerce-admin/src/WC_Admin_Order.php rename to plugins/woocommerce-admin/src/Overrides/Order.php index 2f839db616c..c597f3a30e3 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Order.php +++ b/plugins/woocommerce-admin/src/Overrides/Order.php @@ -7,7 +7,7 @@ * @package WooCommerce Admin/Classes */ -namespace Automattic\WooCommerce\Admin; +namespace Automattic\WooCommerce\Admin\Overrides; defined( 'ABSPATH' ) || exit; @@ -15,13 +15,13 @@ use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDa use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore; /** - * WC_Admin_Order class. + * WC_Order subclass. */ -class WC_Admin_Order extends \WC_Order { +class Order extends \WC_Order { /** * Order traits. */ - use \Automattic\WooCommerce\Admin\WC_Admin_Order_Trait; + use OrderTraits; /** * Holds refund amounts and quantities for the order. @@ -31,14 +31,14 @@ class WC_Admin_Order extends \WC_Order { protected $refunded_line_items; /** - * Add filter(s) required to hook WC_Admin_Order class to substitute WC_Order. + * Add filter(s) required to hook this class to substitute WC_Order. */ public static function add_filters() { add_filter( 'woocommerce_order_class', array( __CLASS__, 'order_class_name' ), 10, 3 ); } /** - * Filter function to swap class WC_Order for WC_Admin_Order in cases when it's suitable. + * Filter function to swap class WC_Order for this one in cases when it's suitable. * * @param string $classname Name of the class to be created. * @param string $order_type Type of order object to be created. @@ -49,7 +49,7 @@ class WC_Admin_Order extends \WC_Order { public static function order_class_name( $classname, $order_type, $order_id ) { // @todo - Only substitute class when necessary (during sync). if ( 'WC_Order' === $classname ) { - return '\Automattic\WooCommerce\Admin\WC_Admin_Order'; + return '\Automattic\WooCommerce\Admin\Overrides\Order'; } else { return $classname; } diff --git a/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php b/plugins/woocommerce-admin/src/Overrides/OrderRefund.php similarity index 77% rename from plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php rename to plugins/woocommerce-admin/src/Overrides/OrderRefund.php index 174ef8f01c9..13ef80ba728 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Order_Refund.php +++ b/plugins/woocommerce-admin/src/Overrides/OrderRefund.php @@ -7,30 +7,30 @@ * @package WooCommerce Admin/Classes */ -namespace Automattic\WooCommerce\Admin; +namespace Automattic\WooCommerce\Admin\Overrides; defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore as CustomersDataStore; /** - * WC_Admin_Order_Refund class. + * WC_Order_Refund subclass. */ -class WC_Admin_Order_Refund extends \WC_Order_Refund { +class OrderRefund extends \WC_Order_Refund { /** * Order traits. */ - use \Automattic\WooCommerce\Admin\WC_Admin_Order_Trait; + use OrderTraits; /** - * Add filter(s) required to hook WC_Admin_Order_Refund class to substitute WC_Order_Refund. + * Add filter(s) required to hook this class to substitute WC_Order_Refund. */ public static function add_filters() { add_filter( 'woocommerce_order_class', array( __CLASS__, 'order_class_name' ), 10, 3 ); } /** - * Filter function to swap class WC_Order_Refund for WC_Admin_Order_Refund in cases when it's suitable. + * Filter function to swap class WC_Order_Refund for this one in cases when it's suitable. * * @param string $classname Name of the class to be created. * @param string $order_type Type of order object to be created. @@ -41,7 +41,7 @@ class WC_Admin_Order_Refund extends \WC_Order_Refund { public static function order_class_name( $classname, $order_type, $order_id ) { // @todo - Only substitute class when necessary (during sync). if ( 'WC_Order_Refund' === $classname ) { - return '\Automattic\WooCommerce\Admin\WC_Admin_Order_Refund'; + return '\Automattic\WooCommerce\Admin\Overrides\OrderRefund'; } else { return $classname; } diff --git a/plugins/woocommerce-admin/src/WC_Admin_Order_Trait.php b/plugins/woocommerce-admin/src/Overrides/OrderTraits.php similarity index 96% rename from plugins/woocommerce-admin/src/WC_Admin_Order_Trait.php rename to plugins/woocommerce-admin/src/Overrides/OrderTraits.php index 759e2a612cc..477cff9c4ed 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Order_Trait.php +++ b/plugins/woocommerce-admin/src/Overrides/OrderTraits.php @@ -7,14 +7,14 @@ * @package WooCommerce Admin/Classes */ -namespace Automattic\WooCommerce\Admin; +namespace Automattic\WooCommerce\Admin\Overrides; defined( 'ABSPATH' ) || exit; /** - * WC_Admin_Order_Trait class. + * OrderTraits class. */ -trait WC_Admin_Order_Trait { +trait OrderTraits { /** * Calculate shipping amount for line item/product as a total shipping amount ratio based on quantity. * diff --git a/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader.php b/plugins/woocommerce-admin/src/Overrides/ThemeUpgrader.php similarity index 93% rename from plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader.php rename to plugins/woocommerce-admin/src/Overrides/ThemeUpgrader.php index ea67c9067a2..a0b8aed4798 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader.php +++ b/plugins/woocommerce-admin/src/Overrides/ThemeUpgrader.php @@ -5,14 +5,14 @@ * @package WooCommerce Admin/Classes */ -namespace Automattic\WooCommerce\Admin; +namespace Automattic\WooCommerce\Admin\Overrides; defined( 'ABSPATH' ) || exit; /** - * WC_Admin_Theme_Upgrader Class. + * Admin\Overrides\ThemeUpgrader Class. */ -class WC_Admin_Theme_Upgrader extends \Theme_Upgrader { +class ThemeUpgrader extends \Theme_Upgrader { /** * Install a theme package. * diff --git a/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader_Skin.php b/plugins/woocommerce-admin/src/Overrides/ThemeUpgraderSkin.php similarity index 77% rename from plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader_Skin.php rename to plugins/woocommerce-admin/src/Overrides/ThemeUpgraderSkin.php index 9de76267de4..df2518c7e4e 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Theme_Upgrader_Skin.php +++ b/plugins/woocommerce-admin/src/Overrides/ThemeUpgraderSkin.php @@ -5,14 +5,14 @@ * @package WooCommerce Admin/Classes */ -namespace Automattic\WooCommerce\Admin; +namespace Automattic\WooCommerce\Admin\Overrides; defined( 'ABSPATH' ) || exit; /** - * WC_Admin_Theme_Upgrader_Skin Class. + * Admin\Overrides\ThemeUpgraderSkin Class. */ -class WC_Admin_Theme_Upgrader_Skin extends \Theme_Upgrader_Skin { +class ThemeUpgraderSkin extends \Theme_Upgrader_Skin { /** * Hide the skin header display. */ diff --git a/plugins/woocommerce-admin/src/WC_Admin_ActionScheduler_WPPostStore.php b/plugins/woocommerce-admin/src/Overrides/WPPostStore.php similarity index 92% rename from plugins/woocommerce-admin/src/WC_Admin_ActionScheduler_WPPostStore.php rename to plugins/woocommerce-admin/src/Overrides/WPPostStore.php index f2348e9b956..4d2c1812e8c 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_ActionScheduler_WPPostStore.php +++ b/plugins/woocommerce-admin/src/Overrides/WPPostStore.php @@ -5,12 +5,12 @@ * @package WooCommerce Admin/Classes */ -namespace Automattic\WooCommerce\Admin; +namespace Automattic\WooCommerce\Admin\Overrides; /** * Class WC Admin Action Scheduler Store. */ -class WC_Admin_ActionScheduler_WPPostStore extends \ActionScheduler_wpPostStore { +class WPPostStore extends \ActionScheduler_wpPostStore { /** * Action scheduler job priority (lower numbers are claimed first). */ diff --git a/plugins/woocommerce-admin/src/WC_Admin_Page_Controller.php b/plugins/woocommerce-admin/src/PageController.php similarity index 99% rename from plugins/woocommerce-admin/src/WC_Admin_Page_Controller.php rename to plugins/woocommerce-admin/src/PageController.php index 856bc838b11..1618096baab 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Page_Controller.php +++ b/plugins/woocommerce-admin/src/PageController.php @@ -1,6 +1,6 @@ prepare_data_to_export(); $total_rows = $exporter->get_total_rows(); @@ -95,7 +95,7 @@ class WC_Admin_Report_Exporter { $report_batch_args = array( $export_id, $report_type, $report_args ); if ( 0 < $num_batches ) { - WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, self::REPORT_EXPORT_ACTION, $report_batch_args ); + ReportsSync::queue_batches( 1, $num_batches, self::REPORT_EXPORT_ACTION, $report_batch_args ); } return $total_rows; @@ -113,7 +113,7 @@ class WC_Admin_Report_Exporter { public static function report_export_action( $page_number, $export_id, $report_type, $report_args ) { $report_args['page'] = $page_number; - $exporter = new WC_Admin_Report_CSV_Exporter( $report_type, $report_args ); + $exporter = new ReportCSVExporter( $report_type, $report_args ); $exporter->set_filename( "wc-{$report_type}-report-export-{$export_id}" ); $exporter->generate_file(); @@ -177,7 +177,7 @@ class WC_Admin_Report_Exporter { self::DOWNLOAD_EXPORT_ACTION === wp_unslash( $_GET['action'] ) && // WPCS: input var ok, sanitization ok. current_user_can( 'view_woocommerce_reports' ) ) { - $exporter = new WC_Admin_Report_CSV_Exporter(); + $exporter = new ReportCSVExporter(); $exporter->set_filename( wp_unslash( $_GET['filename'] ) ); // WPCS: input var ok, sanitization ok. $exporter->export(); } diff --git a/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php b/plugins/woocommerce-admin/src/ReportsSync.php similarity index 99% rename from plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php rename to plugins/woocommerce-admin/src/ReportsSync.php index 5b395a2fb88..3564bf2505a 100644 --- a/plugins/woocommerce-admin/src/WC_Admin_Reports_Sync.php +++ b/plugins/woocommerce-admin/src/ReportsSync.php @@ -16,9 +16,9 @@ use \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsData use \Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore as TaxesDataStore; /** - * WC_Admin_Reports_Sync Class. + * ReportsSync Class. */ -class WC_Admin_Reports_Sync { +class ReportsSync { /** * Action hook for reducing a range of batches down to single actions. */ @@ -215,7 +215,7 @@ class WC_Admin_Reports_Sync { public static function clear_queued_actions() { $store = \ActionScheduler::store(); - if ( is_a( $store, 'Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_WPPostStore' ) ) { + if ( is_a( $store, 'Automattic\WooCommerce\Admin\Overrides\WPPostStore' ) ) { // If we're using our data store, call our bespoke deletion method. $action_types = array( self::QUEUE_BATCH_ACTION, @@ -312,8 +312,8 @@ class WC_Admin_Reports_Sync { */ public static function orders_lookup_update_init() { // Activate WC_Order extension. - WC_Admin_Order::add_filters(); - WC_Admin_Order_Refund::add_filters(); + \Automattic\WooCommerce\Admin\Overrides\Order::add_filters(); + \Automattic\WooCommerce\Admin\Overrides\OrderRefund::add_filters(); // Order and refund data must be run on these hooks to ensure meta data is set. add_action( 'save_post', array( __CLASS__, 'schedule_single_order_import' ) ); diff --git a/plugins/woocommerce-admin/tests/api-init.php b/plugins/woocommerce-admin/tests/api-init.php index a325735ffa3..e27ec7294f2 100644 --- a/plugins/woocommerce-admin/tests/api-init.php +++ b/plugins/woocommerce-admin/tests/api-init.php @@ -6,7 +6,7 @@ * @since 3.5.0 */ -use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; +use Automattic\WooCommerce\Admin\ReportsSync; use \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore as OrdersStatsDataStore; /** @@ -19,7 +19,7 @@ class WC_Tests_API_Init extends WC_REST_Unit_Test_Case { public function setUp() { parent::setUp(); $this->queue = new WC_Admin_Test_Action_Queue(); - WC_Admin_Reports_Sync::set_queue( $this->queue ); + ReportsSync::set_queue( $this->queue ); } /** @@ -27,7 +27,7 @@ class WC_Tests_API_Init extends WC_REST_Unit_Test_Case { */ public function tearDown() { parent::tearDown(); - WC_Admin_Reports_Sync::set_queue( null ); + ReportsSync::set_queue( null ); $this->queue->actions = array(); } @@ -75,13 +75,13 @@ class WC_Tests_API_Init extends WC_REST_Unit_Test_Case { add_filter( 'query', array( $this, 'filter_order_query' ) ); // Initiate sync. - WC_Admin_Reports_Sync::orders_lookup_import_order( $order->get_id() ); + ReportsSync::orders_lookup_import_order( $order->get_id() ); // Verify that a retry job was scheduled. $this->assertCount( 1, $this->queue->actions ); $this->assertArraySubset( array( - 'hook' => WC_Admin_Reports_Sync::SINGLE_ORDER_IMPORT_ACTION, + 'hook' => ReportsSync::SINGLE_ORDER_IMPORT_ACTION, 'args' => array( $order->get_id() ), ), $this->queue->actions[0] diff --git a/plugins/woocommerce-admin/tests/api/reports-import.php b/plugins/woocommerce-admin/tests/api/reports-import.php index 3b717bcf4d7..fc40da4d1f6 100644 --- a/plugins/woocommerce-admin/tests/api/reports-import.php +++ b/plugins/woocommerce-admin/tests/api/reports-import.php @@ -5,7 +5,7 @@ * @package WooCommerce\Tests\API */ -use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; +use Automattic\WooCommerce\Admin\ReportsSync; /** * Reports Import REST API Test Class @@ -293,7 +293,7 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case { */ public function test_import_status() { // Delete any pending actions that weren't fully run. - WC_Admin_Reports_Sync::clear_queued_actions(); + ReportsSync::clear_queued_actions(); wp_set_current_user( $this->user ); diff --git a/plugins/woocommerce-admin/tests/batch-queue.php b/plugins/woocommerce-admin/tests/batch-queue.php index 925c7702b09..446960649a1 100644 --- a/plugins/woocommerce-admin/tests/batch-queue.php +++ b/plugins/woocommerce-admin/tests/batch-queue.php @@ -6,7 +6,7 @@ * @since 3.5.0 */ -use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; +use Automattic\WooCommerce\Admin\ReportsSync; /** * Reports Generation Batch Queue Test Class @@ -45,11 +45,11 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { */ public function filter_batch_size( $batch_size, $action ) { switch ( $action ) { - case WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION: + case ReportsSync::QUEUE_BATCH_ACTION: return $this->queue_batch_size; - case WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION: + case ReportsSync::CUSTOMERS_IMPORT_BATCH_ACTION: return $this->customers_batch_size; - case WC_Admin_Reports_Sync::ORDERS_BATCH_ACTION: + case ReportsSync::ORDERS_BATCH_ACTION: return $this->orders_batch_size; default: return 1; @@ -62,7 +62,7 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { public function setUp() { parent::setUp(); $this->queue = new WC_Admin_Test_Action_Queue(); - WC_Admin_Reports_Sync::set_queue( $this->queue ); + ReportsSync::set_queue( $this->queue ); add_filter( 'wc_admin_report_regenerate_batch_size', array( $this, 'filter_batch_size' ), 10, 2 ); } @@ -71,7 +71,7 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { */ public function tearDown() { parent::tearDown(); - WC_Admin_Reports_Sync::set_queue( null ); + ReportsSync::set_queue( null ); $this->queue->actions = array(); remove_filter( 'wc_admin_report_regenerate_batch_size', array( $this, 'filter_batch_size' ), 10, 2 ); } @@ -85,20 +85,20 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { $chunk_size = (int) ceil( $num_batches / $this->queue_batch_size ); $num_chunks = (int) ceil( $num_batches / $chunk_size ); - WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ); + ReportsSync::queue_batches( 1, $num_batches, ReportsSync::CUSTOMERS_IMPORT_BATCH_ACTION ); $this->assertCount( $num_chunks, $this->queue->actions ); $this->assertArraySubset( array( - 'hook' => WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION, - 'args' => array( 1, $chunk_size, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ), + 'hook' => ReportsSync::QUEUE_BATCH_ACTION, + 'args' => array( 1, $chunk_size, ReportsSync::CUSTOMERS_IMPORT_BATCH_ACTION ), ), $this->queue->actions[0] ); $this->assertArraySubset( array( - 'hook' => WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION, - 'args' => array( 247, 247, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ), + 'hook' => ReportsSync::QUEUE_BATCH_ACTION, + 'args' => array( 247, 247, ReportsSync::CUSTOMERS_IMPORT_BATCH_ACTION ), ), $this->queue->actions[ $num_chunks - 1 ] ); @@ -111,19 +111,19 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { $num_customers = 45; // 45 / 5 = 9 batches (which is less than the batch queue size) $num_batches = ceil( $num_customers / $this->customers_batch_size ); - WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ); + ReportsSync::queue_batches( 1, $num_batches, ReportsSync::CUSTOMERS_IMPORT_BATCH_ACTION ); $this->assertCount( 9, $this->queue->actions ); $this->assertArraySubset( array( - 'hook' => WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION, + 'hook' => ReportsSync::CUSTOMERS_IMPORT_BATCH_ACTION, 'args' => array( 1 ), ), $this->queue->actions[0] ); $this->assertArraySubset( array( - 'hook' => WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION, + 'hook' => ReportsSync::CUSTOMERS_IMPORT_BATCH_ACTION, 'args' => array( 9 ), ), $this->queue->actions[8] @@ -135,15 +135,15 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { */ public function test_queue_dependent_action() { // reset back to using a real queue. - WC_Admin_Reports_Sync::set_queue( null ); + ReportsSync::set_queue( null ); // insert a blocking job. - WC_Admin_Reports_Sync::queue()->schedule_single( time(), 'blocking_job', array( 'stuff' ), WC_Admin_Reports_Sync::QUEUE_GROUP ); + ReportsSync::queue()->schedule_single( time(), 'blocking_job', array( 'stuff' ), ReportsSync::QUEUE_GROUP ); // queue an action that depends on blocking job. - WC_Admin_Reports_Sync::queue_dependent_action( 'dependent_action', array(), 'blocking_job' ); + ReportsSync::queue_dependent_action( 'dependent_action', array(), 'blocking_job' ); // verify that the action was properly blocked. $this->assertEmpty( - WC_Admin_Reports_Sync::queue()->search( + ReportsSync::queue()->search( array( 'hook' => 'dependent_action', ) @@ -152,20 +152,20 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { // verify that a follow up action was queued. $this->assertCount( 1, - WC_Admin_Reports_Sync::queue()->search( + ReportsSync::queue()->search( array( - 'hook' => WC_Admin_Reports_Sync::QUEUE_DEPEDENT_ACTION, + 'hook' => ReportsSync::QUEUE_DEPEDENT_ACTION, 'args' => array( 'dependent_action', array(), 'blocking_job' ), ) ) ); // queue an action that isn't blocked. - WC_Admin_Reports_Sync::queue_dependent_action( 'another_dependent_action', array(), 'nonexistant_blocking_job' ); + ReportsSync::queue_dependent_action( 'another_dependent_action', array(), 'nonexistant_blocking_job' ); // verify that the dependent action was queued. $this->assertCount( 1, - WC_Admin_Reports_Sync::queue()->search( + ReportsSync::queue()->search( array( 'hook' => 'another_dependent_action', ) @@ -173,16 +173,16 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case { ); // verify that no follow up action was queued. $this->assertEmpty( - WC_Admin_Reports_Sync::queue()->search( + ReportsSync::queue()->search( array( - 'hook' => WC_Admin_Reports_Sync::QUEUE_DEPEDENT_ACTION, + 'hook' => ReportsSync::QUEUE_DEPEDENT_ACTION, 'args' => array( 'another_dependent_action', array(), 'nonexistant_blocking_job' ), ) ) ); // clean up. - WC_Admin_Reports_Sync::queue()->cancel_all( 'another_dependent_action' ); - WC_Admin_Reports_Sync::queue()->cancel_all( WC_Admin_Reports_Sync::QUEUE_DEPEDENT_ACTION ); + ReportsSync::queue()->cancel_all( 'another_dependent_action' ); + ReportsSync::queue()->cancel_all( ReportsSync::QUEUE_DEPEDENT_ACTION ); } } diff --git a/plugins/woocommerce-admin/tests/bootstrap.php b/plugins/woocommerce-admin/tests/bootstrap.php index c022e4cb44a..5624bbb8910 100755 --- a/plugins/woocommerce-admin/tests/bootstrap.php +++ b/plugins/woocommerce-admin/tests/bootstrap.php @@ -37,8 +37,8 @@ function wc_admin_install() { define( 'WC_REMOVE_ALL_DATA', true ); // Initialize the WC API extensions. - \Automattic\WooCommerce\Admin\WC_Admin_Install::create_tables(); - \Automattic\WooCommerce\Admin\WC_Admin_Install::create_events(); + \Automattic\WooCommerce\Admin\Install::create_tables(); + \Automattic\WooCommerce\Admin\Install::create_events(); // Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374. $GLOBALS['wp_roles'] = null; // WPCS: override ok. diff --git a/plugins/woocommerce-admin/tests/queue-priority.php b/plugins/woocommerce-admin/tests/queue-priority.php index 4821d6b0255..c482d64c22d 100644 --- a/plugins/woocommerce-admin/tests/queue-priority.php +++ b/plugins/woocommerce-admin/tests/queue-priority.php @@ -6,8 +6,8 @@ * @since 3.5.0 */ -use Automattic\WooCommerce\Admin\WC_Admin_Reports_Sync; -use Automattic\WooCommerce\Admin\WC_Admin_ActionScheduler_wpPostStore; +use Automattic\WooCommerce\Admin\ReportsSync; +use Automattic\WooCommerce\Admin\Overrides\WPPostStore; /** * Reports Generation Batch Queue Prioritizaion Test Class @@ -40,13 +40,13 @@ class WC_Tests_Reports_Queue_Prioritization extends WC_REST_Unit_Test_Case { * Test that we're setting a priority on our actions. */ public function test_queue_action_sets_priority() { - WC_Admin_Reports_Sync::queue()->schedule_single( time(), WC_Admin_Reports_Sync::SINGLE_ORDER_IMPORT_ACTION ); + ReportsSync::queue()->schedule_single( time(), ReportsSync::SINGLE_ORDER_IMPORT_ACTION ); - $actions = WC_Admin_Reports_Sync::queue()->search( + $actions = ReportsSync::queue()->search( array( 'status' => 'pending', 'claimed' => false, - 'hook' => WC_Admin_Reports_Sync::SINGLE_ORDER_IMPORT_ACTION, + 'hook' => ReportsSync::SINGLE_ORDER_IMPORT_ACTION, ) ); @@ -56,9 +56,9 @@ class WC_Tests_Reports_Queue_Prioritization extends WC_REST_Unit_Test_Case { $action_id = $action_ids[0]; $action = get_post( $action_id ); - $this->assertEquals( WC_Admin_ActionScheduler_wpPostStore::JOB_PRIORITY, $action->menu_order ); + $this->assertEquals( WPPostStore::JOB_PRIORITY, $action->menu_order ); - WC_Admin_Reports_Sync::queue()->cancel_all( WC_Admin_Reports_Sync::SINGLE_ORDER_IMPORT_ACTION ); + ReportsSync::queue()->cancel_all( ReportsSync::SINGLE_ORDER_IMPORT_ACTION ); } } diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php index 974c1cd8c3a..cd8d342c81a 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-coupons.php @@ -5,7 +5,7 @@ * @package WooCommerce\Tests\Coupons */ -use \Automattic\WooCommerce\Admin\WC_Admin_Report_CSV_Exporter; +use \Automattic\WooCommerce\Admin\ReportCSVExporter; use \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore as CouponsDataStore; use \Automattic\WooCommerce\Admin\API\Reports\Coupons\Query as CouponsQuery; use \Automattic\WooCommerce\Admin\API\Reports\TimeInterval; @@ -321,7 +321,7 @@ class WC_Tests_Reports_Coupons extends WC_Unit_Test_Case { do_action( 'rest_api_init' ); // Run the export and compare values. - $export = new WC_Admin_Report_CSV_Exporter( 'coupons', $args ); + $export = new ReportCSVExporter( 'coupons', $args ); $export->generate_file(); $actual_csv = $export->get_file(); diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php index 6e5e2514627..ac0bd9dec49 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php @@ -3748,10 +3748,10 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { /** * Test if lookup tables are cleaned after delete an order. * - * @covers WC_Admin_Reports_Orders_Stats_Data_Store::delete_order - * @covers WC_Admin_Reports_Products_Data_Store::sync_on_order_delete - * @covers WC_Admin_Reports_Coupons_Data_Store::sync_on_order_delete - * @covers WC_Admin_Reports_Taxes_Data_Store::sync_on_order_delete + * @covers \Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore::delete_order + * @covers \Automattic\WooCommerce\Admin\API\Reports\Products\DataStore::sync_on_order_delete + * @covers \Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore::sync_on_order_delete + * @covers \Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore::sync_on_order_delete */ public function test_order_deletion() { global $wpdb; diff --git a/plugins/woocommerce-admin/uninstall.php b/plugins/woocommerce-admin/uninstall.php index 8909c5074a5..8cc33f23a64 100644 --- a/plugins/woocommerce-admin/uninstall.php +++ b/plugins/woocommerce-admin/uninstall.php @@ -7,8 +7,8 @@ defined( 'WP_UNINSTALL_PLUGIN' ) || exit; -use \Automattic\WooCommerce\Admin\WC_Admin_Install; +use \Automattic\WooCommerce\Admin\Install; require_once dirname( __FILE__ ) . '/woocommerce-admin.php'; -require_once dirname( __FILE__ ) . '/includes/class-wc-admin-install.php'; -WC_Admin_Install::delete_table_data(); + +Install::delete_table_data(); diff --git a/plugins/woocommerce-admin/woocommerce-admin.php b/plugins/woocommerce-admin/woocommerce-admin.php index 9caaee27164..c0cacbeceb8 100755 --- a/plugins/woocommerce-admin/woocommerce-admin.php +++ b/plugins/woocommerce-admin/woocommerce-admin.php @@ -19,7 +19,7 @@ defined( 'ABSPATH' ) || exit; -use \Automattic\WooCommerce\Admin\WC_Admin_Feature_Plugin; +use \Automattic\WooCommerce\Admin\FeaturePlugin; /** * Autoload packages. @@ -66,4 +66,4 @@ if ( is_readable( $autoloader ) ) { return; } -WC_Admin_Feature_Plugin::instance()->init(); +FeaturePlugin::instance()->init(); From 37e849221bf3701519932988213ee737028ee283 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 12 Aug 2019 15:10:23 -0700 Subject: [PATCH 32/32] Fix namespace on helper class usage. --- .../src/API/OnboardingPlugins.php | 14 +++++++------- .../src/API/OnboardingProfile.php | 2 +- .../woocommerce-admin/src/Features/Onboarding.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/woocommerce-admin/src/API/OnboardingPlugins.php b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php index e999d9d232d..af0d28fecac 100644 --- a/plugins/woocommerce-admin/src/API/OnboardingPlugins.php +++ b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php @@ -277,7 +277,7 @@ class OnboardingPlugins extends \WC_REST_Data_Controller { $redirect_uri = wc_admin_url( '&task=connect&wccom-connected=1' ); - $request = WC_Helper_API::post( + $request = \WC_Helper_API::post( 'oauth/request_token', array( 'body' => array( @@ -306,7 +306,7 @@ class OnboardingPlugins extends \WC_REST_Data_Controller { 'secret' => rawurlencode( $secret ), 'wccom-from' => 'onboarding', ), - WC_Helper_API::url( 'oauth/authorize' ) + \WC_Helper_API::url( 'oauth/authorize' ) ); // Redirect to local calypso instead of production. @@ -341,7 +341,7 @@ class OnboardingPlugins extends \WC_REST_Data_Controller { } // Obtain an access token. - $request = WC_Helper_API::post( + $request = \WC_Helper_API::post( 'oauth/access_token', array( 'body' => array( @@ -361,7 +361,7 @@ class OnboardingPlugins extends \WC_REST_Data_Controller { return new WP_Error( 'woocommerce_rest_helper_connect', __( 'There was an error connecting to WooCommerce.com. Please try again.', 'woocommerce-admin' ), 500 ); } - WC_Helper_Options::update( + \WC_Helper_Options::update( 'auth', array( 'access_token' => $access_token['access_token'], @@ -372,13 +372,13 @@ class OnboardingPlugins extends \WC_REST_Data_Controller { ) ); - if ( ! WC_Helper::_flush_authentication_cache() ) { - WC_Helper_Options::update( 'auth', array() ); + if ( ! \WC_Helper::_flush_authentication_cache() ) { + \WC_Helper_Options::update( 'auth', array() ); return new WP_Error( 'woocommerce_rest_helper_connect', __( 'There was an error connecting to WooCommerce.com. Please try again.', 'woocommerce-admin' ), 500 ); } delete_transient( '_woocommerce_helper_subscriptions' ); - WC_Helper_Updater::flush_updates_cache(); + \WC_Helper_Updater::flush_updates_cache(); do_action( 'woocommerce_helper_connected' ); diff --git a/plugins/woocommerce-admin/src/API/OnboardingProfile.php b/plugins/woocommerce-admin/src/API/OnboardingProfile.php index b64f68e5884..9977e4d45c9 100644 --- a/plugins/woocommerce-admin/src/API/OnboardingProfile.php +++ b/plugins/woocommerce-admin/src/API/OnboardingProfile.php @@ -110,7 +110,7 @@ class OnboardingProfile extends \WC_REST_Data_Controller { $items[ $key ] = isset( $onboarding_data[ $key ] ) ? $onboarding_data[ $key ] : null; } - $wccom_auth = WC_Helper_Options::get( 'auth' ); + $wccom_auth = \WC_Helper_Options::get( 'auth' ); $items['wccom_connected'] = empty( $wccom_auth['access_token'] ) ? false : true; $item = $this->prepare_item_for_response( $items, $request ); diff --git a/plugins/woocommerce-admin/src/Features/Onboarding.php b/plugins/woocommerce-admin/src/Features/Onboarding.php index dfddbfc372e..e1c5b5c53f5 100644 --- a/plugins/woocommerce-admin/src/Features/Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/Onboarding.php @@ -301,7 +301,7 @@ class Onboarding { $profile = get_option( 'wc_onboarding_profile', array() ); include_once WC_ABSPATH . 'includes/admin/helper/class-wc-helper-options.php'; - $wccom_auth = WC_Helper_Options::get( 'auth' ); + $wccom_auth = \WC_Helper_Options::get( 'auth' ); $profile['wccom_connected'] = empty( $wccom_auth['access_token'] ) ? false : true; $settings['onboarding'] = array(