Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions features/core-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,32 @@ Feature: Update WordPress core
"""
Success:
"""

Scenario: Show helpful tip when update is locked
Given a WP install

# Create a lock option to simulate another update in progress
When I run `wp option add core_updater.lock 1`
Then STDOUT should contain:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swissspidy This looks like testing of wp-cli/entity-command

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean we should remove the assertion here?

Copy link
Contributor

@wojsmol wojsmol Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO yes, tests fot then wp-cli/entity-commad are in the command repo.

"""
Success:
"""

# Try to update and expect the lock error with helpful tip
When I try `wp core update --version=latest`
Then STDERR should contain:
"""
wp option delete core_updater.lock
"""
And STDERR should contain:
"""
another update
"""
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:
"""
33 changes: 32 additions & 1 deletion src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
*/
class Core_Command extends WP_CLI_Command {

/**
* Tip message for resolving the core_updater.lock issue.
*/
const CORE_UPDATER_LOCK_TIP = 'You may need to run `wp option delete core_updater.lock` after verifying another update isn\'t actually running.';

/**
* Checks for WordPress updates via Version Check API.
*
Expand Down Expand Up @@ -1234,7 +1239,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, '.' ) . '. ' . self::CORE_UPDATER_LOCK_TIP );
} else {
WP_CLI::error( $message );
}
} else {
WP_CLI::success( $message );
}
Expand Down Expand Up @@ -1663,4 +1673,25 @@ 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 ) {
if ( ! is_wp_error( $error ) ) {
return false;
}

// 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' );
}
}