Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor product issues #2277

Merged
merged 20 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/API/Google/MerchantReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function get_product_view_report( $next_page_token = null ): array {
}

$product_view_data['statuses'][ $wc_product_id ] = [
'mc_id' => $product_view->getId(),
'product_id' => $wc_product_id,
'status' => $mc_product_status,
'expiration_date' => $this->convert_shopping_content_date( $product_view->getExpirationDate() ),
Expand Down
13 changes: 12 additions & 1 deletion src/DB/Table/MerchantIssueTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,22 @@
*
* @param DateTime $created_before Delete all records created before this.
*/
public function delete_stale( DateTime $created_before ) {
public function delete_stale( DateTime $created_before ): void {

Check warning on line 59 in src/DB/Table/MerchantIssueTable.php

View check run for this annotation

Codecov / codecov/patch

src/DB/Table/MerchantIssueTable.php#L59

Added line #L59 was not covered by tests
$query = "DELETE FROM `{$this->get_sql_safe_name()}` WHERE `created_at` < '%s'";
$this->wpdb->query( $this->wpdb->prepare( $query, $created_before->format( 'Y-m-d H:i:s' ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL
}

/**
* Delete product issues for specific products and source.
*
* @param array $products_ids Array of product IDs to delete issues for.
* @param string $source The source of the issues. Default is 'mc'.
*/
public function delete_specific_product_issues( array $products_ids, string $source = 'mc' ): void {
$placeholder = '(' . implode( ',', array_fill( 0, count( $products_ids ), '%d' ) ) . ')';
$this->wpdb->query( $this->wpdb->prepare( "DELETE FROM `{$this->get_sql_safe_name()}` WHERE `product_id` IN {$placeholder} AND `source` = %s", array_merge( $products_ids, [ $source ] ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL

Check warning on line 72 in src/DB/Table/MerchantIssueTable.php

View check run for this annotation

Codecov / codecov/patch

src/DB/Table/MerchantIssueTable.php#L70-L72

Added lines #L70 - L72 were not covered by tests
}

/**
* Get the columns for the table.
*
Expand Down
3 changes: 1 addition & 2 deletions src/Jobs/UpdateMerchantProductStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public function process_items( array $items ) {

// Clear the cache if we're starting from the beginning.
if ( ! $next_page_token ) {
$this->merchant_statuses->clear_cache();
$this->merchant_statuses->delete_product_statuses_count_intermediate_data();
$this->merchant_statuses->clear_product_statuses_cache_and_issues();
}

$results = $this->merchant_report->get_product_view_report( $next_page_token );
Expand Down
Loading
Loading