diff --git a/features/core-update.feature b/features/core-update.feature index a52bcd3b..6e1fb8ab 100644 --- a/features/core-update.feature +++ b/features/core-update.feature @@ -384,3 +384,21 @@ Feature: Update WordPress core """ Success: """ + + Scenario: Show helpful tip when update is locked + Given a WP install + + When I run `wp option update core_updater.lock 100000000000000` + And I try `wp core update --version=trunk` + Then STDERR should contain: + """ + Another update is currently in progress. You may need to run `wp option delete core_updater.lock` after verifying another update isn't actually running. + """ + And the return code should be 1 + + # Clean up the lock + When I run `wp option delete core_updater.lock` + Then STDOUT should contain: + """ + Success: + """ diff --git a/src/Core_Command.php b/src/Core_Command.php index b9bbb2b4..71724aba 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -1234,7 +1234,12 @@ public function update( $args, $assoc_args ) { if ( is_wp_error( $result ) ) { $message = WP_CLI::error_to_string( $result ); if ( 'up_to_date' !== $result->get_error_code() ) { - WP_CLI::error( $message ); + // Check if the error is related to the core_updater.lock + if ( self::is_lock_error( $result ) ) { + WP_CLI::error( rtrim( $message, '.' ) . '. You may need to run `wp option delete core_updater.lock` after verifying another update isn\'t actually running.' ); + } else { + WP_CLI::error( $message ); + } } else { WP_CLI::success( $message ); } @@ -1663,4 +1668,21 @@ function () use ( $new_zip_file ) { WP_CLI::error( 'ZipArchive failed to open ZIP file.' ); } } + + /** + * Checks if a WP_Error is related to the core_updater.lock. + * + * @param \WP_Error $error The error object to check. + * @return bool True if the error is related to the lock, false otherwise. + */ + private static function is_lock_error( $error ) { + // Check for the 'locked' error code used by WordPress Core + if ( 'locked' === $error->get_error_code() ) { + return true; + } + + // Also check if the error message contains the lock text as a fallback + $message = WP_CLI::error_to_string( $error ); + return false !== stripos( $message, 'another update is currently in progress' ); + } }