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 17 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
11 changes: 11 additions & 0 deletions src/DB/Table/MerchantIssueTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
$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' ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 We can add :void as a return type in the signature to be consistent with the other functions. delete_stalealso missed it, but was not introduced in this PR tho

$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