Skip to content

Commit

Permalink
Log deprecation warnings for Query class (woocommerce#50969)
Browse files Browse the repository at this point in the history
Log deprecation warnings for analytic reports `Automattic\WooCommerce\Admin\API\Reports\Query` class usage.

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
tomalec and github-actions authored Aug 27, 2024
1 parent bd9716a commit deb76cb
Show file tree
Hide file tree
Showing 31 changed files with 123 additions and 57 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/50969-dev-deprecate-query
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: tweak

Log deprecation warnings for `Query` class usage.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Controller extends GenericController implements ExportableInterface {
protected $rest_base = 'reports/categories';

/**
* Get data from `'categories'` Query.
* Get data from `'categories'` GenericQuery.
*
* @override GenericController::get_datastore_data()
*
Expand Down
10 changes: 7 additions & 3 deletions plugins/woocommerce/src/Admin/API/Reports/Categories/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* API\Reports\Categories\Query
*
* @deprecated 9.3.0 Categories\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Categories\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*/
class Query extends ReportsQuery {

Expand All @@ -32,22 +32,26 @@ class Query extends ReportsQuery {
/**
* Valid fields for Categories report.
*
* @deprecated 9.3.0 Categories\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Categories\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
protected function get_default_query_vars() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

return array();
}

/**
* Get categories data based on the current query vars.
*
* @deprecated 9.3.0 Categories\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Categories\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
public function get_data() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

$args = apply_filters( 'woocommerce_analytics_categories_query_args', $this->get_query_vars() );
$results = \WC_Data_Store::load( self::REPORT_NAME )->get_data( $args );
return apply_filters( 'woocommerce_analytics_categories_select_query', $results, $args );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Controller extends GenericController implements ExportableInterface {
protected $rest_base = 'reports/coupons';

/**
* Get data from `'coupons'` Query.
* Get data from `'coupons'` GenericQuery.
*
* @override GenericController::get_datastore_data()
*
Expand Down
10 changes: 7 additions & 3 deletions plugins/woocommerce/src/Admin/API/Reports/Coupons/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,33 @@
/**
* API\Reports\Coupons\Query
*
* @deprecated 9.3.0 Coupons\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Coupons\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*/
class Query extends ReportsQuery {

/**
* Valid fields for Products report.
*
* @deprecated 9.3.0 Coupons\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Coupons\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
protected function get_default_query_vars() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

return array();
}

/**
* Get product data based on the current query vars.
*
* @deprecated 9.3.0 Coupons\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Coupons\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
public function get_data() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

$args = apply_filters( 'woocommerce_analytics_coupons_query_args', $this->get_query_vars() );

$data_store = \WC_Data_Store::load( 'report-coupons' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function prepare_reports_query( $request ) {
}

/**
* Get data from `'coupons-stats'` Query.
* Get data from `'coupons-stats'` GenericQuery.
*
* @override GenericController::get_datastore_data()
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,33 @@
/**
* API\Reports\Coupons\Stats\Query
*
* @deprecated 9.3.0 Coupons\Stats\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Coupons\Stats\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*/
class Query extends ReportsQuery {

/**
* Valid fields for Products report.
*
* @deprecated 9.3.0 Coupons\Stats\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Coupons\Stats\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
protected function get_default_query_vars() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

return array();
}

/**
* Get product data based on the current query vars.
*
* @deprecated 9.3.0 Coupons\Stats\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Coupons\Stats\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
public function get_data() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

$args = apply_filters( 'woocommerce_analytics_coupons_stats_query_args', $this->get_query_vars() );

$data_store = \WC_Data_Store::load( 'report-coupons-stats' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Controller extends GenericController implements ExportableInterface {
protected $rest_base = 'reports/customers';

/**
* Get data from Query.
* Get data from Customers\Query.
*
* @override GenericController::get_datastore_data()
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@
/**
* API\Reports\Customers\Stats\Query
*
* @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use Reports\Customers\Query with a custom name, GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use `Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or use `DataStore` directly.
*/
class Query extends ReportsQuery {

/**
* Valid fields for Customers report.
*
* @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use Reports\Customers\Query with a custom name, GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use `Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
protected function get_default_query_vars() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

return array(
'per_page' => get_option( 'posts_per_page' ), // not sure if this should be the default.
'page' => 1,
Expand All @@ -47,11 +49,13 @@ protected function get_default_query_vars() {
/**
* Get product data based on the current query vars.
*
* @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use Reports\Customers\Query with a custom name, GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Customers\Stats\Query class is deprecated, please use `Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
public function get_data() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'x.x.x', '`Reports\Customers\Query` with a custom name, `GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

$args = apply_filters( 'woocommerce_analytics_customers_stats_query_args', $this->get_query_vars() );

$data_store = \WC_Data_Store::load( 'report-customers-stats' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Controller extends GenericController implements ExportableInterface {
protected $rest_base = 'reports/downloads';

/**
* Get data from `'downloads'` Query.
* Get data from `'downloads'` GenericQuery.
*
* @override GenericController::get_datastore_data()
*
Expand Down
10 changes: 7 additions & 3 deletions plugins/woocommerce/src/Admin/API/Reports/Downloads/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,33 @@
/**
* API\Reports\Downloads\Query
*
* @deprecated 9.3.0 Downloads\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Downloads\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*/
class Query extends ReportsQuery {

/**
* Valid fields for downloads report.
*
* @deprecated 9.3.0 Downloads\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Downloads\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
protected function get_default_query_vars() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

return array();
}

/**
* Get downloads data based on the current query vars.
*
* @deprecated 9.3.0 Downloads\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Downloads\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
public function get_data() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

$args = apply_filters( 'woocommerce_analytics_downloads_query_args', $this->get_query_vars() );

$data_store = \WC_Data_Store::load( 'report-downloads' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function prepare_reports_query( $request ) {
}

/**
* Get data from `'downloads-stats'` Query.
* Get data from `'downloads-stats'` GenericQuery.
*
* @override GenericController::get_datastore_data()
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@
/**
* API\Reports\Downloads\Stats\Query
*
* @deprecated 9.3.0 Downloads\Stats\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Downloads\Stats\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*/
class Query extends ReportsQuery {

/**
* Valid fields for Orders report.
*
* @deprecated 9.3.0 Downloads\Stats\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Downloads\Stats\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
protected function get_default_query_vars() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

return array();
}

/**
* Get revenue data based on the current query vars.
*
* @deprecated 9.3.0 Downloads\Stats\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Downloads\Stats\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
public function get_data() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

$args = apply_filters( 'woocommerce_analytics_downloads_stats_query_args', $this->get_query_vars() );

$data_store = \WC_Data_Store::load( 'report-downloads-stats' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function get_collection_params() {
/**
* Get the report data.
*
* Prepares query params, fetches the report data from the Query object,
* Prepares query params, fetches the report data from the data store,
* prepares it for the response, and packs it into the convention-conforming response object.
*
* @throws \WP_Error When the queried data is invalid.
Expand Down Expand Up @@ -237,7 +237,7 @@ public function prepare_item_for_response( $report_item, $request ) {
}

/**
* Maps query arguments from the REST request, to be fed to Query.
* Maps query arguments from the REST request, to be used to query the datastore.
*
* `WP_REST_Request` does not expose a method to return all params covering defaults,
* as it does for `$request['param']` accessor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function get_item_schema() {
/**
* Get the report data.
*
* Prepares query params, fetches the report data from the Query object,
* Prepares query params, fetches the report data from the data store,
* prepares it for the response, and packs it into the convention-conforming response object.
*
* @override GenericController::get_items()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Controller extends GenericController implements ExportableInterface {
protected $rest_base = 'reports/orders';

/**
* Get data from Query.
* Get data from Orders\Query.
*
* @override GenericController::get_datastore_data()
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Controller extends GenericStatsController {
protected $rest_base = 'reports/orders/stats';

/**
* Get data from Query.
* Get data from Orders\Stats\Query.
*
* @override GenericController::get_datastore_data()
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public function prepare_item_for_response( $stat_data, $request ) {
/**
* Prepare links for the request.
*
* @param \Automattic\WooCommerce\Admin\API\Reports\Query $object Object data.
* @param object $object data.
* @return array
*/
protected function prepare_links( $object ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Controller extends GenericController implements ExportableInterface {
);

/**
* Get data from `'products'` Query.
* Get data from `'products'` GenericQuery.
*
* @override GenericController::get_datastore_data()
*
Expand Down
10 changes: 7 additions & 3 deletions plugins/woocommerce/src/Admin/API/Reports/Products/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,33 @@
/**
* API\Reports\Products\Query
*
* @deprecated 9.3.0 Products\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Products\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*/
class Query extends ReportsQuery {

/**
* Valid fields for Products report.
*
* @deprecated 9.3.0 Products\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Products\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
protected function get_default_query_vars() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

return array();
}

/**
* Get product data based on the current query vars.
*
* @deprecated 9.3.0 Products\Query class is deprecated, please use GenericQuery or \WC_Object_Query instead.
* @deprecated 9.3.0 Products\Query class is deprecated. Please use `GenericQuery`, \WC_Object_Query`, or use `DataStore` directly.
*
* @return array
*/
public function get_data() {
wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.3.0', '`GenericQuery`, `\WC_Object_Query`, or direct `DataStore` use' );

$args = apply_filters( 'woocommerce_analytics_products_query_args', $this->get_query_vars() );

$data_store = \WC_Data_Store::load( 'report-products' );
Expand Down
Loading

0 comments on commit deb76cb

Please sign in to comment.