Skip to content

Commit c5f806e

Browse files
authored
Merge pull request #296 from wp-cli/copilot/add-clear-core-updater-lock
2 parents 5097d80 + d1f2758 commit c5f806e

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

features/core-update.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,21 @@ Feature: Update WordPress core
419419
"""
420420
</div>
421421
"""
422+
423+
Scenario: Show helpful tip when update is locked
424+
Given a WP install
425+
426+
When I run `wp option update core_updater.lock 100000000000000`
427+
And I try `wp core update --version=trunk`
428+
Then STDERR should contain:
429+
"""
430+
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.
431+
"""
432+
And the return code should be 1
433+
434+
# Clean up the lock
435+
When I run `wp option delete core_updater.lock`
436+
Then STDOUT should contain:
437+
"""
438+
Success:
439+
"""

src/Core_Command.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,12 @@ static function () {
12431243
if ( is_wp_error( $result ) ) {
12441244
$message = WP_CLI::error_to_string( $result );
12451245
if ( 'up_to_date' !== $result->get_error_code() ) {
1246-
WP_CLI::error( $message );
1246+
// Check if the error is related to the core_updater.lock
1247+
if ( self::is_lock_error( $result ) ) {
1248+
WP_CLI::error( rtrim( $message, '.' ) . '. You may need to run `wp option delete core_updater.lock` after verifying another update isn\'t actually running.' );
1249+
} else {
1250+
WP_CLI::error( $message );
1251+
}
12471252
} else {
12481253
WP_CLI::success( $message );
12491254
}
@@ -1672,4 +1677,21 @@ function () use ( $new_zip_file ) {
16721677
WP_CLI::error( 'ZipArchive failed to open ZIP file.' );
16731678
}
16741679
}
1680+
1681+
/**
1682+
* Checks if a WP_Error is related to the core_updater.lock.
1683+
*
1684+
* @param \WP_Error $error The error object to check.
1685+
* @return bool True if the error is related to the lock, false otherwise.
1686+
*/
1687+
private static function is_lock_error( $error ) {
1688+
// Check for the 'locked' error code used by WordPress Core
1689+
if ( 'locked' === $error->get_error_code() ) {
1690+
return true;
1691+
}
1692+
1693+
// Also check if the error message contains the lock text as a fallback
1694+
$message = WP_CLI::error_to_string( $error );
1695+
return false !== stripos( $message, 'another update is currently in progress' );
1696+
}
16751697
}

0 commit comments

Comments
 (0)