prefix . 'aipt_job_products'; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name from $wpdb->prefix; values prepared; plugin-owned table. $updated = $wpdb->query( $wpdb->prepare( "UPDATE {$table} SET retry_attempts = retry_attempts + 1 WHERE job_id = %d AND product_id = %d", (int) $job_id, (int) $product_id ) ); if ( false === $updated ) { Logger::error( 'automation', 'Retry count could not be stored', array( 'job_id' => (int) $job_id, 'product_id' => (int) $product_id, 'error' => (string) $wpdb->last_error ) ); return 1; } if ( 0 === (int) $updated ) { return 1; } $count = $wpdb->get_var( $wpdb->prepare( "SELECT retry_attempts FROM {$table} WHERE job_id = %d AND product_id = %d", (int) $job_id, (int) $product_id ) ); // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching return max( 1, (int) $count ); } /** * Forget this job/product pair's attempt count: a terminal failure (or a * later success) both start the next run clean. * * Writes only a row that holds a count, so the common success path costs * one indexed lookup and no row write. * * @param int $job_id * @param int $product_id * @return void */ public function clear( $job_id, $product_id ) { global $wpdb; $table = $wpdb->prefix . 'aipt_job_products'; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name from $wpdb->prefix; values prepared; plugin-owned table. $cleared = $wpdb->query( $wpdb->prepare( "UPDATE {$table} SET retry_attempts = 0 WHERE job_id = %d AND product_id = %d AND retry_attempts <> 0", (int) $job_id, (int) $product_id ) ); // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching if ( false === $cleared ) { Logger::error( 'automation', 'Retry count could not be cleared', array( 'job_id' => (int) $job_id, 'product_id' => (int) $product_id, 'error' => (string) $wpdb->last_error ) ); } } }