Skip to content

Commit 9850529

Browse files
CopilotswissspidyCopilot
authored
Honor --locale in wp core update and allow locale-change without --force (#310)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent 1a36683 commit 9850529

File tree

2 files changed

+91
-3
lines changed

2 files changed

+91
-3
lines changed

features/core-update.feature

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,71 @@ Feature: Update WordPress core
420420
</div>
421421
"""
422422

423+
Scenario: Update WordPress locale without --force when version is the same
424+
Given a WP install
425+
And an empty cache
426+
427+
# Using `try` in case there are checksum warnings.
428+
When I try `wp core download --version=6.5 --locale=de_DE --force`
429+
Then STDOUT should contain:
430+
"""
431+
Success: WordPress downloaded.
432+
"""
433+
434+
When I run `wp core version --extra`
435+
Then STDOUT should contain:
436+
"""
437+
Package language: de_DE
438+
"""
439+
440+
When I run `wp core version`
441+
Then save STDOUT as {CURRENT_VERSION}
442+
443+
# Updating to the same version with a different locale should work without --force.
444+
When I run `wp core update --version={CURRENT_VERSION} --locale=en_US`
445+
Then STDOUT should contain:
446+
"""
447+
Updating to version {CURRENT_VERSION} (en_US)...
448+
"""
449+
And STDOUT should contain:
450+
"""
451+
Success: WordPress updated successfully.
452+
"""
453+
454+
When I run `wp core version --extra`
455+
Then STDOUT should contain:
456+
"""
457+
Package language: en_US
458+
"""
459+
460+
Scenario: Update WordPress locale when using --minor
461+
Given a WP install
462+
And an empty cache
463+
464+
# Using `try` in case there are checksum warnings.
465+
When I try `wp core download --version=6.5 --locale=de_DE --force`
466+
Then STDOUT should contain:
467+
"""
468+
Success: WordPress downloaded.
469+
"""
470+
471+
When I run `wp core version --extra`
472+
Then STDOUT should contain:
473+
"""
474+
Package language: de_DE
475+
"""
476+
477+
When I run `wp core update --minor --locale=en_US`
478+
Then STDOUT should contain:
479+
"""
480+
Success: WordPress updated successfully.
481+
"""
482+
483+
When I run `wp core version --extra`
484+
Then STDOUT should contain:
485+
"""
486+
Package language: en_US
487+
"""
423488
@require-php-7.0 @require-wp-6.1
424489
Scenario: Attempting to downgrade without --force shows helpful message
425490
Given a WP install

src/Core_Command.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ public function update( $args, $assoc_args ) {
11781178
wp_version_check();
11791179

11801180
/**
1181-
* @var object{updates: array<object{version: string, locale: string}>} $from_api
1181+
* @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
11821182
*/
11831183
$from_api = get_site_transient( 'update_core' );
11841184

@@ -1198,9 +1198,31 @@ public function update( $args, $assoc_args ) {
11981198
} elseif ( ! empty( $from_api->updates ) ) {
11991199
list( $update ) = $from_api->updates;
12001200
}
1201+
1202+
// Override the locale in the transient-based update if --locale is explicitly specified.
1203+
if ( ! empty( $update ) ) {
1204+
$locale_arg = Utils\get_flag_value( $assoc_args, 'locale' );
1205+
if ( $locale_arg ) {
1206+
$new_package = $this->get_download_url( $update->version, $locale_arg );
1207+
$update = (object) [
1208+
'response' => $update->response ?? 'upgrade',
1209+
'current' => $update->version,
1210+
'download' => $new_package,
1211+
'packages' => (object) [
1212+
'partial' => null,
1213+
'new_bundled' => $update->packages->new_bundled ?? null,
1214+
'no_content' => null,
1215+
'full' => $new_package,
1216+
],
1217+
'version' => $update->version,
1218+
'locale' => $locale_arg,
1219+
];
1220+
}
1221+
}
12011222
} elseif ( Utils\wp_version_compare( $assoc_args['version'], '<' )
12021223
|| 'nightly' === $assoc_args['version']
1203-
|| Utils\get_flag_value( $assoc_args, 'force' ) ) {
1224+
|| Utils\get_flag_value( $assoc_args, 'force' )
1225+
|| ! empty( $assoc_args['locale'] ) ) {
12041226

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

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

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

0 commit comments

Comments
 (0)