rename DS get_* to add_* where function does not return values (https://github.com/woocommerce/woocommerce-admin/pull/3275)
* rename DS get_* to add_* where function does not return values * phpcs fixes on coupons, products data stores
This commit is contained in:
parent
1e792b7e86
commit
2b8b1e4c1c
|
@ -85,11 +85,11 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
$order_product_lookup_table = self::get_db_table_name();
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
|
||||
// join wp_order_product_lookup_table with relationships and taxonomies
|
||||
// @todo How to handle custom product tables?
|
||||
|
@ -102,9 +102,9 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
|
||||
// Limit is left out here so that the grouping in code by PHP can be applied correctly.
|
||||
// This also needs to be put after the term_taxonomy JOIN so that we can match the correct term name.
|
||||
$this->get_order_by_params( $query_args, 'outer', 'default_results.category_id' );
|
||||
$this->add_order_by_params( $query_args, 'outer', 'default_results.category_id' );
|
||||
} else {
|
||||
$this->get_order_by_params( $query_args, 'inner', "{$wpdb->wc_category_lookup}.category_tree_id" );
|
||||
$this->add_order_by_params( $query_args, 'inner', "{$wpdb->wc_category_lookup}.category_tree_id" );
|
||||
}
|
||||
|
||||
// @todo Only products in the category C or orders with products from category C (and, possibly others?).
|
||||
|
@ -124,7 +124,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
* @param string $from_arg Target of the JOIN sql param.
|
||||
* @param string $id_cell ID cell identifier, like `table_name.id_column_name`.
|
||||
*/
|
||||
protected function get_order_by_params( $query_args, $from_arg, $id_cell ) {
|
||||
protected function add_order_by_params( $query_args, $from_arg, $id_cell ) {
|
||||
global $wpdb;
|
||||
$lookup_table = self::get_db_table_name();
|
||||
$order_by_clause = $this->add_order_by_clause( $query_args, $this );
|
||||
|
@ -243,7 +243,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
|
||||
$this->subquery->add_sql_clause( 'select', $this->selected_columns( $query_args ) );
|
||||
$included_categories = $this->get_included_categories_array( $query_args );
|
||||
$this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
|
||||
if ( count( $included_categories ) > 0 ) {
|
||||
$fields = $this->get_fields( $query_args );
|
||||
|
|
|
@ -90,20 +90,20 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
$order_coupon_lookup_table = self::get_db_table_name();
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_coupon_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_coupon_lookup_table );
|
||||
$this->get_limit_sql_params( $query_args );
|
||||
|
||||
$included_coupons = $this->get_included_coupons( $query_args, 'coupons' );
|
||||
if ( $included_coupons ) {
|
||||
$this->subquery->add_sql_clause( 'where', "AND {$order_coupon_lookup_table}.coupon_id IN ({$included_coupons})" );
|
||||
|
||||
$this->get_order_by_params( $query_args, 'outer', 'default_results.coupon_id' );
|
||||
$this->add_order_by_params( $query_args, 'outer', 'default_results.coupon_id' );
|
||||
} else {
|
||||
$this->get_order_by_params( $query_args, 'inner', "{$order_coupon_lookup_table}.coupon_id" );
|
||||
$this->add_order_by_params( $query_args, 'inner', "{$order_coupon_lookup_table}.coupon_id" );
|
||||
}
|
||||
|
||||
$this->add_order_status_clause( $query_args, $order_coupon_lookup_table, $this->subquery );
|
||||
|
@ -116,7 +116,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
* @param string $from_arg Target of the JOIN sql param.
|
||||
* @param string $id_cell ID cell identifier, like `table_name.id_column_name`.
|
||||
*/
|
||||
protected function get_order_by_params( $query_args, $from_arg, $id_cell ) {
|
||||
protected function add_order_by_params( $query_args, $from_arg, $id_cell ) {
|
||||
global $wpdb;
|
||||
$lookup_table = self::get_db_table_name();
|
||||
$order_by_clause = $this->add_order_by_clause( $query_args, $this );
|
||||
|
@ -249,7 +249,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
$included_coupons = $this->get_included_coupons_array( $query_args );
|
||||
$limit_params = $this->get_limit_params( $query_args );
|
||||
$this->subquery->add_sql_clause( 'select', $selections );
|
||||
$this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
|
||||
if ( count( $included_coupons ) > 0 ) {
|
||||
$total_results = count( $included_coupons );
|
||||
|
@ -275,12 +275,13 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
|
||||
$this->subquery->clear_sql_clause( array( 'select', 'order_by' ) );
|
||||
$this->subquery->add_sql_clause( 'select', 'coupon_id' );
|
||||
$coupon_subquery = "SELECT COUNT(*) FROM (
|
||||
{$this->subquery->get_query_statement()}
|
||||
) AS tt";
|
||||
|
||||
$db_records_count = (int) $wpdb->get_var(
|
||||
"SELECT COUNT(*) FROM (
|
||||
{$this->subquery->get_query_statement()}
|
||||
) AS tt"
|
||||
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
|
||||
$coupon_subquery // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
);
|
||||
|
||||
$total_results = $db_records_count;
|
||||
$total_pages = (int) ceil( $db_records_count / $limit_params['per_page'] );
|
||||
|
@ -290,10 +291,9 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
}
|
||||
|
||||
$coupon_data = $wpdb->get_results(
|
||||
$coupons_query,
|
||||
$coupons_query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
ARRAY_A
|
||||
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
|
||||
|
||||
);
|
||||
if ( null === $coupon_data ) {
|
||||
return $data;
|
||||
}
|
||||
|
@ -336,7 +336,13 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
}
|
||||
|
||||
$table_name = self::get_db_table_name();
|
||||
$existing_items = $wpdb->get_col( $wpdb->prepare( "SELECT coupon_id FROM {$table_name} WHERE order_id = %d", $order_id ) );
|
||||
$existing_items = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
"SELECT coupon_id FROM {$table_name} WHERE order_id = %d",
|
||||
$order_id
|
||||
)
|
||||
);
|
||||
$existing_items = array_flip( $existing_items );
|
||||
$coupon_items = $order->get_items( 'coupon' );
|
||||
$coupon_items_count = count( $coupon_items );
|
||||
|
@ -386,6 +392,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
array_unshift( $existing_items, $order_id );
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
"DELETE FROM {$table_name} WHERE order_id = %d AND coupon_id in ({$format})",
|
||||
$existing_items
|
||||
)
|
||||
|
@ -452,7 +459,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
$query .= " AND ID IN ({$included_coupons})";
|
||||
}
|
||||
|
||||
return $wpdb->get_results( $query ); // WPCS: cache ok, DB call ok, unprepared SQL ok.
|
||||
return $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,8 +91,8 @@ class DataStore extends CouponsDataStore implements DataStoreInterface {
|
|||
$clauses['where'] .= " AND ( {$order_status_filter} )";
|
||||
}
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_coupon_lookup_table );
|
||||
$this->get_intervals_sql_params( $query_args, $order_coupon_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_coupon_lookup_table );
|
||||
$this->add_intervals_sql_params( $query_args, $order_coupon_lookup_table );
|
||||
$clauses['where_time'] = $this->get_sql_clause( 'where_time' );
|
||||
|
||||
$this->interval_query->add_sql_clause( 'limit', $this->get_sql_clause( 'limit' ) );
|
||||
|
|
|
@ -121,7 +121,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
* @param array $query_args Parameters supplied by the user.
|
||||
* @param string $table_name Name of the db table relevant for the date constraint.
|
||||
*/
|
||||
protected function get_time_period_sql_params( $query_args, $table_name ) {
|
||||
protected function add_time_period_sql_params( $query_args, $table_name ) {
|
||||
global $wpdb;
|
||||
|
||||
$this->clear_sql_clause( array( 'where', 'where_time', 'having' ) );
|
||||
|
@ -188,14 +188,14 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
$customer_lookup_table = self::get_db_table_name();
|
||||
$order_stats_table_name = $wpdb->prefix . 'wc_order_stats';
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $customer_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $customer_lookup_table );
|
||||
$this->get_limit_sql_params( $query_args );
|
||||
$this->get_order_by_sql_params( $query_args );
|
||||
$this->add_order_by_sql_params( $query_args );
|
||||
$this->subquery->add_sql_clause( 'left_join', "LEFT JOIN {$order_stats_table_name} ON {$customer_lookup_table}.customer_id = {$order_stats_table_name}.customer_id" );
|
||||
|
||||
$match_operator = $this->get_match_operator( $query_args );
|
||||
|
@ -352,7 +352,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
);
|
||||
|
||||
$selections = $this->selected_columns( $query_args );
|
||||
$sql_query_params = $this->get_sql_query_params( $query_args );
|
||||
$sql_query_params = $this->add_sql_query_params( $query_args );
|
||||
|
||||
$db_records_count = (int) $wpdb->get_var(
|
||||
"SELECT COUNT(*) FROM (
|
||||
|
|
|
@ -94,7 +94,7 @@ class DataStore extends CustomersDataStore implements DataStoreInterface {
|
|||
);
|
||||
|
||||
$selections = $this->selected_columns( $query_args );
|
||||
$sql_query_params = $this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
// Clear SQL clauses set for parent class queries that are different here.
|
||||
$this->subquery->clear_sql_clause( 'select' );
|
||||
$this->subquery->add_sql_clause( 'select', 'SUM( gross_total ) AS total_spend,' );
|
||||
|
|
|
@ -649,7 +649,7 @@ class DataStore extends SqlQuery {
|
|||
* @param array $query_args Parameters supplied by the user.
|
||||
* @param string $table_name Name of the db table relevant for the date constraint.
|
||||
*/
|
||||
protected function get_time_period_sql_params( $query_args, $table_name ) {
|
||||
protected function add_time_period_sql_params( $query_args, $table_name ) {
|
||||
$this->clear_sql_clause( array( 'from', 'where_time', 'where' ) );
|
||||
if ( isset( $this->subquery ) ) {
|
||||
$this->subquery->clear_sql_clause( 'where_time' );
|
||||
|
@ -777,7 +777,7 @@ class DataStore extends SqlQuery {
|
|||
*
|
||||
* @param array $query_args Parameters supplied by the user.
|
||||
*/
|
||||
protected function get_order_by_sql_params( $query_args ) {
|
||||
protected function add_order_by_sql_params( $query_args ) {
|
||||
if ( isset( $query_args['orderby'] ) ) {
|
||||
$order_by_clause = $this->normalize_order_by( $query_args['orderby'] );
|
||||
} else {
|
||||
|
@ -795,10 +795,10 @@ class DataStore extends SqlQuery {
|
|||
* @param array $query_args Parameters supplied by the user.
|
||||
* @param string $table_name Name of the db table relevant for the date constraint.
|
||||
*/
|
||||
protected function get_intervals_sql_params( $query_args, $table_name ) {
|
||||
protected function add_intervals_sql_params( $query_args, $table_name ) {
|
||||
$this->clear_sql_clause( array( 'from', 'where_time', 'where' ) );
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $table_name );
|
||||
$this->add_time_period_sql_params( $query_args, $table_name );
|
||||
|
||||
if ( isset( $query_args['interval'] ) && '' !== $query_args['interval'] ) {
|
||||
$interval = $query_args['interval'];
|
||||
|
|
|
@ -77,7 +77,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
|
||||
$lookup_table = self::get_db_table_name();
|
||||
|
@ -86,7 +86,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
$where_filters = array();
|
||||
$join = "JOIN {$permission_table} as product_permissions ON {$lookup_table}.permission_id = product_permissions.permission_id";
|
||||
|
||||
$where_time = $this->get_time_period_sql_params( $query_args, $lookup_table );
|
||||
$where_time = $this->add_time_period_sql_params( $query_args, $lookup_table );
|
||||
if ( $where_time ) {
|
||||
if ( isset( $this->subquery ) ) {
|
||||
$this->subquery->add_sql_clause( 'where_time', $where_time );
|
||||
|
@ -180,7 +180,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
} else {
|
||||
$this->interval_query->add_sql_clause( 'join', $join );
|
||||
}
|
||||
$this->get_order_by( $query_args );
|
||||
$this->add_order_by( $query_args );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,7 +236,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
* @param string $table_name Name of the db table relevant for the date constraint.
|
||||
* @return string
|
||||
*/
|
||||
protected function get_time_period_sql_params( $query_args, $table_name ) {
|
||||
protected function add_time_period_sql_params( $query_args, $table_name ) {
|
||||
$where_time = '';
|
||||
if ( $query_args['before'] ) {
|
||||
$datetime_str = $query_args['before']->format( TimeInterval::$sql_datetime_format );
|
||||
|
@ -257,7 +257,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Parameters supplied by the user.
|
||||
*/
|
||||
protected function get_order_by( $query_args ) {
|
||||
protected function add_order_by( $query_args ) {
|
||||
global $wpdb;
|
||||
$this->clear_sql_clause( 'order_by' );
|
||||
$order_by = '';
|
||||
|
@ -315,7 +315,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
);
|
||||
|
||||
$selections = $this->selected_columns( $query_args );
|
||||
$sql_query_params = $this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
|
||||
$db_records_count = (int) $wpdb->get_var(
|
||||
"SELECT COUNT(*) FROM (
|
||||
|
|
|
@ -86,9 +86,9 @@ class DataStore extends DownloadsDataStore implements DataStoreInterface {
|
|||
if ( false === $data ) {
|
||||
$this->initialize_queries();
|
||||
$selections = $this->selected_columns( $query_args );
|
||||
$this->get_sql_query_params( $query_args );
|
||||
$this->get_time_period_sql_params( $query_args, $table_name );
|
||||
$this->get_intervals_sql_params( $query_args, $table_name );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
$this->add_time_period_sql_params( $query_args, $table_name );
|
||||
$this->add_intervals_sql_params( $query_args, $table_name );
|
||||
|
||||
$this->interval_query->add_sql_clause( 'select', $this->get_sql_clause( 'select' ) . ' AS time_interval' );
|
||||
$this->interval_query->str_replace_clause( 'select', 'date_created', 'timestamp' );
|
||||
|
|
|
@ -82,7 +82,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
$order_stats_lookup_table = self::get_db_table_name();
|
||||
$order_coupon_lookup_table = $wpdb->prefix . 'wc_order_coupon_lookup';
|
||||
|
@ -91,9 +91,9 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
$operator = $this->get_match_operator( $query_args );
|
||||
$where_subquery = array();
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_stats_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_stats_lookup_table );
|
||||
$this->get_limit_sql_params( $query_args );
|
||||
$this->get_order_by_sql_params( $query_args );
|
||||
$this->add_order_by_sql_params( $query_args );
|
||||
|
||||
$status_subquery = $this->get_status_subquery( $query_args );
|
||||
if ( $status_subquery ) {
|
||||
|
@ -221,7 +221,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
|
||||
$selections = $this->selected_columns( $query_args );
|
||||
$params = $this->get_limit_params( $query_args );
|
||||
$this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
$db_records_count = (int) $wpdb->get_var(
|
||||
"SELECT COUNT(*) FROM (
|
||||
{$this->subquery->get_query_statement()}
|
||||
|
|
|
@ -257,9 +257,9 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
);
|
||||
|
||||
$selections = $this->selected_columns( $query_args );
|
||||
$this->get_time_period_sql_params( $query_args, $table_name );
|
||||
$this->get_intervals_sql_params( $query_args, $table_name );
|
||||
$this->get_order_by_sql_params( $query_args );
|
||||
$this->add_time_period_sql_params( $query_args, $table_name );
|
||||
$this->add_intervals_sql_params( $query_args, $table_name );
|
||||
$this->add_order_by_sql_params( $query_args );
|
||||
$where_time = $this->get_sql_clause( 'where_time' );
|
||||
$params = $this->get_limit_sql_params( $query_args );
|
||||
$coupon_join = "LEFT JOIN (
|
||||
|
|
|
@ -112,7 +112,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
* @param string $arg_name Target of the JOIN sql param.
|
||||
* @param string $id_cell ID cell identifier, like `table_name.id_column_name`.
|
||||
*/
|
||||
protected function get_from_sql_params( $query_args, $arg_name, $id_cell ) {
|
||||
protected function add_from_sql_params( $query_args, $arg_name, $id_cell ) {
|
||||
global $wpdb;
|
||||
|
||||
$type = 'join';
|
||||
|
@ -146,20 +146,20 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
$order_product_lookup_table = self::get_db_table_name();
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->get_limit_sql_params( $query_args );
|
||||
$this->get_order_by_sql_params( $query_args );
|
||||
$this->add_order_by_sql_params( $query_args );
|
||||
|
||||
$included_products = $this->get_included_products( $query_args );
|
||||
if ( $included_products ) {
|
||||
$this->get_from_sql_params( $query_args, 'outer', 'default_results.product_id' );
|
||||
$this->add_from_sql_params( $query_args, 'outer', 'default_results.product_id' );
|
||||
$this->subquery->add_sql_clause( 'where', "AND {$order_product_lookup_table}.product_id IN ({$included_products})" );
|
||||
} else {
|
||||
$this->get_from_sql_params( $query_args, 'inner', "{$order_product_lookup_table}.product_id" );
|
||||
$this->add_from_sql_params( $query_args, 'inner', "{$order_product_lookup_table}.product_id" );
|
||||
}
|
||||
|
||||
$included_variations = $this->get_included_variations( $query_args );
|
||||
|
@ -302,7 +302,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
$selections = $this->selected_columns( $query_args );
|
||||
$included_products = $this->get_included_products_array( $query_args );
|
||||
$params = $this->get_limit_params( $query_args );
|
||||
$this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
|
||||
if ( count( $included_products ) > 0 ) {
|
||||
$total_results = count( $included_products );
|
||||
|
@ -330,11 +330,12 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
|
||||
$products_query = $this->get_query_statement();
|
||||
} else {
|
||||
$db_records_count = (int) $wpdb->get_var(
|
||||
"SELECT COUNT(*) FROM (
|
||||
$count_query = "SELECT COUNT(*) FROM (
|
||||
{$this->subquery->get_query_statement()}
|
||||
) AS tt"
|
||||
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
|
||||
) AS tt";
|
||||
$db_records_count = (int) $wpdb->get_var(
|
||||
$count_query // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
);
|
||||
|
||||
$total_results = $db_records_count;
|
||||
$total_pages = (int) ceil( $db_records_count / $params['per_page'] );
|
||||
|
@ -351,9 +352,9 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
}
|
||||
|
||||
$product_data = $wpdb->get_results(
|
||||
$products_query,
|
||||
$products_query, // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
ARRAY_A
|
||||
); // WPCS: cache ok, DB call ok, unprepared SQL ok.
|
||||
);
|
||||
|
||||
if ( null === $product_data ) {
|
||||
return $data;
|
||||
|
@ -391,7 +392,13 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
}
|
||||
|
||||
$table_name = self::get_db_table_name();
|
||||
$existing_items = $wpdb->get_col( $wpdb->prepare( "SELECT order_item_id FROM {$table_name} WHERE order_id = %d", $order_id ) );
|
||||
$existing_items = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
"SELECT order_item_id FROM {$table_name} WHERE order_id = %d",
|
||||
$order_id
|
||||
)
|
||||
);
|
||||
$existing_items = array_flip( $existing_items );
|
||||
$order_items = $order->get_items();
|
||||
$num_updated = 0;
|
||||
|
@ -480,6 +487,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
array_unshift( $existing_items, $order_id );
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
"DELETE FROM {$table_name} WHERE order_id = %d AND order_item_id in ({$format})",
|
||||
$existing_items
|
||||
)
|
||||
|
|
|
@ -84,11 +84,11 @@ class DataStore extends ProductsDataStore implements DataStoreInterface {
|
|||
$products_where_clause .= " AND ( {$order_status_filter} )";
|
||||
}
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->total_query->add_sql_clause( 'where', $products_where_clause );
|
||||
$this->total_query->add_sql_clause( 'join', $products_from_clause );
|
||||
|
||||
$this->get_intervals_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->add_intervals_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->interval_query->add_sql_clause( 'where', $products_where_clause );
|
||||
$this->interval_query->add_sql_clause( 'join', $products_from_clause );
|
||||
$this->interval_query->add_sql_clause( 'select', $this->get_sql_clause( 'select' ) . ' AS time_interval' );
|
||||
|
|
|
@ -91,7 +91,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
* @param array $query_args Query arguments supplied by the user.
|
||||
* @param string $order_status_filter Order status subquery.
|
||||
*/
|
||||
protected function get_from_sql_params( $query_args, $order_status_filter ) {
|
||||
protected function add_from_sql_params( $query_args, $order_status_filter ) {
|
||||
global $wpdb;
|
||||
$table_name = self::get_db_table_name();
|
||||
|
||||
|
@ -111,16 +111,16 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
|
||||
$order_tax_lookup_table = self::get_db_table_name();
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_tax_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_tax_lookup_table );
|
||||
$this->get_limit_sql_params( $query_args );
|
||||
$this->get_order_by_sql_params( $query_args );
|
||||
$this->add_order_by_sql_params( $query_args );
|
||||
$order_status_filter = $this->get_status_subquery( $query_args );
|
||||
$this->get_from_sql_params( $query_args, $order_status_filter );
|
||||
$this->add_from_sql_params( $query_args, $order_status_filter );
|
||||
|
||||
if ( isset( $query_args['taxes'] ) && ! empty( $query_args['taxes'] ) ) {
|
||||
$allowed_taxes = self::get_filtered_ids( $query_args, 'taxes' );
|
||||
|
@ -174,7 +174,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
'page_no' => 0,
|
||||
);
|
||||
|
||||
$this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
$params = $this->get_limit_params( $query_args );
|
||||
|
||||
if ( isset( $query_args['taxes'] ) && ! empty( $query_args['taxes'] ) ) {
|
||||
|
|
|
@ -86,10 +86,10 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
$taxes_where_clause .= " AND ( {$order_status_filter} )";
|
||||
}
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_tax_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_tax_lookup_table );
|
||||
$this->total_query->add_sql_clause( 'where', $taxes_where_clause );
|
||||
|
||||
$this->get_intervals_sql_params( $query_args, $order_tax_lookup_table );
|
||||
$this->add_intervals_sql_params( $query_args, $order_tax_lookup_table );
|
||||
$this->interval_query->add_sql_clause( 'where', $taxes_where_clause );
|
||||
$this->interval_query->add_sql_clause( 'select', $this->get_sql_clause( 'select' ) . ' AS time_interval' );
|
||||
$this->interval_query->add_sql_clause( 'where_time', $this->get_sql_clause( 'where_time' ) );
|
||||
|
|
|
@ -96,7 +96,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
* @param array $query_args Parameters supplied by the user.
|
||||
* @param string $arg_name Target of the JOIN sql param.
|
||||
*/
|
||||
protected function get_from_sql_params( $query_args, $arg_name ) {
|
||||
protected function add_from_sql_params( $query_args, $arg_name ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( 'sku' !== $query_args['orderby'] ) {
|
||||
|
@ -118,18 +118,18 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
*
|
||||
* @param array $query_args Query arguments supplied by the user.
|
||||
*/
|
||||
protected function get_sql_query_params( $query_args ) {
|
||||
protected function add_sql_query_params( $query_args ) {
|
||||
global $wpdb;
|
||||
$order_product_lookup_table = self::get_db_table_name();
|
||||
|
||||
$this->get_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->add_time_period_sql_params( $query_args, $order_product_lookup_table );
|
||||
$this->get_limit_sql_params( $query_args );
|
||||
$this->get_order_by_sql_params( $query_args );
|
||||
$this->add_order_by_sql_params( $query_args );
|
||||
|
||||
if ( count( $query_args['variations'] ) > 0 ) {
|
||||
$this->get_from_sql_params( $query_args, 'outer' );
|
||||
$this->add_from_sql_params( $query_args, 'outer' );
|
||||
} else {
|
||||
$this->get_from_sql_params( $query_args, 'inner' );
|
||||
$this->add_from_sql_params( $query_args, 'inner' );
|
||||
}
|
||||
|
||||
$included_products = $this->get_included_products( $query_args );
|
||||
|
@ -270,7 +270,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
|||
|
||||
$included_products = $this->get_included_products_array( $query_args );
|
||||
|
||||
$this->get_sql_query_params( $query_args );
|
||||
$this->add_sql_query_params( $query_args );
|
||||
$params = $this->get_limit_params( $query_args );
|
||||
if ( count( $included_products ) > 0 && count( $query_args['variations'] ) > 0 ) {
|
||||
$this->subquery->add_sql_clause( 'select', $this->selected_columns( $query_args ) );
|
||||
|
|
Loading…
Reference in New Issue