From ba43dce533c50013ddddb8386baf63ba1eb8ffc6 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Wed, 8 Nov 2023 15:12:55 +0000 Subject: [PATCH] Fix warning when order edit lock is released mid page load (#41278) --- plugins/woocommerce/changelog/fix-39824 | 4 ++++ plugins/woocommerce/src/Internal/Admin/Orders/Edit.php | 4 ++++ plugins/woocommerce/src/Internal/Admin/Orders/EditLock.php | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-39824 diff --git a/plugins/woocommerce/changelog/fix-39824 b/plugins/woocommerce/changelog/fix-39824 new file mode 100644 index 00000000000..20dbd08049a --- /dev/null +++ b/plugins/woocommerce/changelog/fix-39824 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Prevent PHP warning when order lock is released during page load. diff --git a/plugins/woocommerce/src/Internal/Admin/Orders/Edit.php b/plugins/woocommerce/src/Internal/Admin/Orders/Edit.php index 7e8abd903ff..f624207262d 100644 --- a/plugins/woocommerce/src/Internal/Admin/Orders/Edit.php +++ b/plugins/woocommerce/src/Internal/Admin/Orders/Edit.php @@ -237,6 +237,10 @@ class Edit { // Order updated message. $this->message = 1; + // Claim lock. + $edit_lock = wc_get_container()->get( EditLock::class ); + $edit_lock->lock( $this->order ); + $this->redirect_order( $this->order ); } diff --git a/plugins/woocommerce/src/Internal/Admin/Orders/EditLock.php b/plugins/woocommerce/src/Internal/Admin/Orders/EditLock.php index 00d0a8d1436..2b9534b862e 100644 --- a/plugins/woocommerce/src/Internal/Admin/Orders/EditLock.php +++ b/plugins/woocommerce/src/Internal/Admin/Orders/EditLock.php @@ -166,9 +166,9 @@ class EditLock { * @return void */ public function render_dialog( $order ) { - $locked = $this->is_locked_by_another_user( $order ); $lock = $this->get_lock( $order ); - $user = get_user_by( 'id', $lock['user_id'] ); + $user = $lock ? get_user_by( 'id', $lock['user_id'] ) : false; + $locked = $user && ( get_current_user_id() !== $user->ID ); $edit_url = wc_get_container()->get( \Automattic\WooCommerce\Internal\Admin\Orders\PageController::class )->get_edit_url( $order->get_id() );