Skip to content
Merged
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
65 changes: 65 additions & 0 deletions features/core-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,71 @@ Feature: Update WordPress core
</div>
"""

Scenario: Update WordPress locale without --force when version is the same
Given a WP install
And an empty cache

# Using `try` in case there are checksum warnings.
When I try `wp core download --version=6.5 --locale=de_DE --force`
Then STDOUT should contain:
"""
Success: WordPress downloaded.
"""

When I run `wp core version --extra`
Then STDOUT should contain:
"""
Package language: de_DE
"""

When I run `wp core version`
Then save STDOUT as {CURRENT_VERSION}

# Updating to the same version with a different locale should work without --force.
When I run `wp core update --version={CURRENT_VERSION} --locale=en_US`
Then STDOUT should contain:
"""
Updating to version {CURRENT_VERSION} (en_US)...
"""
And STDOUT should contain:
"""
Success: WordPress updated successfully.
"""

When I run `wp core version --extra`
Then STDOUT should contain:
"""
Package language: en_US
"""

Scenario: Update WordPress locale when using --minor
Given a WP install
And an empty cache

# Using `try` in case there are checksum warnings.
When I try `wp core download --version=6.5 --locale=de_DE --force`
Then STDOUT should contain:
"""
Success: WordPress downloaded.
"""

When I run `wp core version --extra`
Then STDOUT should contain:
"""
Package language: de_DE
"""

When I run `wp core update --minor --locale=en_US`
Then STDOUT should contain:
"""
Success: WordPress updated successfully.
"""

When I run `wp core version --extra`
Then STDOUT should contain:
"""
Package language: en_US
"""
@require-php-7.0 @require-wp-6.1
Scenario: Attempting to downgrade without --force shows helpful message
Given a WP install
Expand Down
29 changes: 26 additions & 3 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ public function update( $args, $assoc_args ) {
wp_version_check();

/**
* @var object{updates: array<object{version: string, locale: string}>} $from_api
* @var object{updates: array<object{response: string, version: string, locale: string, download: string, packages: object{partial: string|null, new_bundled: string|null, no_content: string|null, full: string}}>} $from_api
*/
$from_api = get_site_transient( 'update_core' );

Expand All @@ -1198,9 +1198,31 @@ public function update( $args, $assoc_args ) {
} elseif ( ! empty( $from_api->updates ) ) {
list( $update ) = $from_api->updates;
}

// Override the locale in the transient-based update if --locale is explicitly specified.
if ( ! empty( $update ) ) {
$locale_arg = Utils\get_flag_value( $assoc_args, 'locale' );
if ( $locale_arg ) {
$new_package = $this->get_download_url( $update->version, $locale_arg );
$update = (object) [
'response' => $update->response ?? 'upgrade',
'current' => $update->version,
'download' => $new_package,
'packages' => (object) [
'partial' => null,
'new_bundled' => $update->packages->new_bundled ?? null,
'no_content' => null,
'full' => $new_package,
],
'version' => $update->version,
'locale' => $locale_arg,
];
}
}
} elseif ( Utils\wp_version_compare( $assoc_args['version'], '<' )
|| 'nightly' === $assoc_args['version']
|| Utils\get_flag_value( $assoc_args, 'force' ) ) {
|| Utils\get_flag_value( $assoc_args, 'force' )
|| ! empty( $assoc_args['locale'] ) ) {

// Specific version is given
$version = $assoc_args['version'];
Expand Down Expand Up @@ -1230,7 +1252,8 @@ public function update( $args, $assoc_args ) {

if ( ! empty( $update )
&& ( $update->version !== $wp_version
|| Utils\get_flag_value( $assoc_args, 'force' ) ) ) {
|| Utils\get_flag_value( $assoc_args, 'force' )
|| ( $update->locale ?: 'en_US' ) !== ( self::get_wp_details()['wp_local_package'] ?: 'en_US' ) ) ) {

require_once ABSPATH . 'wp-admin/includes/upgrade.php';

Expand Down