Skip to content

Commit 1d966ff

Browse files
authored
Merge pull request #300 from wp-cli/copilot/fix-wordpress-downgrade-message
Fix misleading "Success: WordPress is up to date" message when downgrade blocked
2 parents 31b0176 + ead1307 commit 1d966ff

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

features/core-update.feature

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Feature: Update WordPress core
167167
When I run `wp core update`
168168
Then STDOUT should contain:
169169
"""
170-
WordPress is up to date
170+
WordPress is up to date at version
171171
"""
172172
And STDOUT should not contain:
173173
"""
@@ -420,6 +420,42 @@ Feature: Update WordPress core
420420
</div>
421421
"""
422422

423+
@require-php-7.0 @require-wp-6.1
424+
Scenario: Attempting to downgrade without --force shows helpful message
425+
Given a WP install
426+
427+
When I run `wp core version`
428+
Then save STDOUT as {WP_CURRENT_VERSION}
429+
430+
When I try `wp core update --version=6.0`
431+
Then STDOUT should contain:
432+
"""
433+
WordPress is up to date at version
434+
"""
435+
And STDOUT should contain:
436+
"""
437+
is older than the current version
438+
"""
439+
And STDOUT should contain:
440+
"""
441+
Use --force to update anyway
442+
"""
443+
And STDOUT should not contain:
444+
"""
445+
Success:
446+
"""
447+
And the return code should be 0
448+
449+
When I run `wp core update --version=6.0 --force`
450+
Then STDOUT should contain:
451+
"""
452+
Updating to version 6.0
453+
"""
454+
And STDOUT should contain:
455+
"""
456+
Success: WordPress updated successfully.
457+
"""
458+
423459
Scenario: Show helpful tip when update is locked
424460
Given a WP install
425461

@@ -436,4 +472,4 @@ Feature: Update WordPress core
436472
Then STDOUT should contain:
437473
"""
438474
Success:
439-
"""
475+
"""

src/Core_Command.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,14 @@ static function () {
12981298

12991299
WP_CLI::success( 'WordPress updated successfully.' );
13001300
}
1301+
// Check if user attempted to downgrade without --force
1302+
} elseif ( ! empty( Utils\get_flag_value( $assoc_args, 'version' ) ) && version_compare( Utils\get_flag_value( $assoc_args, 'version' ), $wp_version, '<' ) ) {
1303+
// Requested version is older than current (downgrade attempt)
1304+
WP_CLI::log( "WordPress is up to date at version {$wp_version}." );
1305+
WP_CLI::log( 'The version you requested (' . Utils\get_flag_value( $assoc_args, 'version' ) . ") is older than the current version ({$wp_version})." );
1306+
WP_CLI::log( 'Use --force to update anyway (e.g., to downgrade to version ' . Utils\get_flag_value( $assoc_args, 'version' ) . ').' );
13011307
} else {
1302-
WP_CLI::success( 'WordPress is up to date.' );
1308+
WP_CLI::success( "WordPress is up to date at version {$wp_version}." );
13031309
}
13041310
}
13051311

0 commit comments

Comments
 (0)