Skip to content
25 changes: 25 additions & 0 deletions features/core-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,28 @@ 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:
"""
Success:
"""

# Try to update and expect the lock error with helpful tip
When I try `wp core update --version=latest`
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:
"""
28 changes: 27 additions & 1 deletion src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,12 @@
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 );
}
Expand Down Expand Up @@ -1663,4 +1668,25 @@
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 ) ) {

Check failure on line 1679 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

is_wp_error(WP_Error) will always evaluate to true.

Check failure on line 1679 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

is_wp_error(WP_Error) will always evaluate to true.
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' );
}
}
Loading