Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions features/core-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
24 changes: 23 additions & 1 deletion src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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' );
}
}
Loading