Skip to content

Commit

Permalink
Add delete specific product issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemd24 committed Mar 4, 2024
1 parent 737351e commit c75eb4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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 @@ public function delete_stale( DateTime $created_before ) {
$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' ) {
$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
}

/**
* Get the columns for the table.
*
Expand Down
5 changes: 4 additions & 1 deletion src/MerchantCenter/MerchantStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,14 @@ protected function calculate_total_synced_product_statistics( array $statistics
* @since x.x.x
*
* @param string $error_message The error message.
*
* @throws NotFoundExceptionInterface If the class is not found in the container.
* @throws ContainerExceptionInterface If the container throws an exception.
*/
public function handle_failed_mc_statuses_fetching( string $error_message = '' ): void {
$this->delete_product_statuses_count_intermediate_data();
// Let's remove any issue created during the failed fetch.
$this->delete_stale_issues( '=' );
$this->container->get( MerchantIssueTable::class )->delete_specific_product_issues( array_keys( $this->product_data_lookup ) );

$mc_statuses = [
'timestamp' => $this->cache_created_time->getTimestamp(),
Expand Down

0 comments on commit c75eb4d

Please sign in to comment.