Do not attempt to re-save hooks after delivery when not already persisted (#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
This commit is contained in:
Jorge A. Torres 2024-06-14 19:12:04 +01:00 committed by GitHub
parent a5893ac066
commit 24391fba0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Do not create empty webhooks after failure to deliver deleted webhook.

View File

@ -533,7 +533,10 @@ class WC_Webhook extends WC_Legacy_Webhook {
// 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();
}
@ -557,7 +560,9 @@ class WC_Webhook extends WC_Legacy_Webhook {
$this->set_failure_count( ++$failures );
}
$this->save();
if ( 0 !== $this->get_id() ) {
$this->save();
}
}
/**

View File

@ -75,6 +75,11 @@ add_action( 'woocommerce_webhook_process_delivery', 'wc_webhook_process_delivery
*/
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 );