Skip to content

Commit

Permalink
Do not attempt to re-save hooks after delivery when not already persi…
Browse files Browse the repository at this point in the history
…sted (woocommerce#48480)

* Do not re-save hooks not in the DB after delivery

* Add changelog

* Do not try to deliver (async) webhooks that have been deleted
  • Loading branch information
jorgeatorres authored Jun 14, 2024
1 parent a5893ac commit 24391fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/fix-32346
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Do not create empty webhooks after failure to deliver deleted webhook.
9 changes: 7 additions & 2 deletions plugins/woocommerce/includes/class-wc-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@ public function log_delivery( $delivery_id, $request, $response, $duration ) {
// Check for a success, which is a 2xx, 301 or 302 Response Code.
if ( intval( $response_code ) >= 200 && intval( $response_code ) < 303 ) {
$this->set_failure_count( 0 );
$this->save();

if ( 0 !== $this->get_id() ) {
$this->save();
}
} else {
$this->failed_delivery();
}
Expand All @@ -557,7 +560,9 @@ private function failed_delivery() {
$this->set_failure_count( ++$failures );
}

$this->save();
if ( 0 !== $this->get_id() ) {
$this->save();
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions plugins/woocommerce/includes/wc-webhook-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ function wc_webhook_process_delivery( $webhook, $arg ) {
*/
function wc_deliver_webhook_async( $webhook_id, $arg ) {
$webhook = new WC_Webhook( $webhook_id );

if ( 0 === $webhook->get_id() ) {
return;
}

$webhook->deliver( $arg );
}
add_action( 'woocommerce_deliver_webhook_async', 'wc_deliver_webhook_async', 10, 2 );
Expand Down

0 comments on commit 24391fb

Please sign in to comment.