Skip to content

Commit b76b935

Browse files
Copilotschlessera
andauthored
Use Utils\make_temp_file() only on translation cache hits (#190)
Co-authored-by: schlessera <83631+schlessera@users.noreply.github.com>
1 parent d8ec417 commit b76b935

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎features/language-core.feature‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,36 @@ Feature: Manage core translation files for a WordPress install
220220
"""
221221
And the return code should be 0
222222

223+
@require-wp-4.0
224+
Scenario: Use cached language file when available
225+
Given a WP install
226+
And an empty cache
227+
228+
When I run `wp language core install en_GB`
229+
Then STDOUT should contain:
230+
"""
231+
Success: Installed 1 of 1 languages.
232+
"""
233+
And STDERR should be empty
234+
235+
When I run `wp language core uninstall en_GB`
236+
Then STDOUT should be:
237+
"""
238+
Success: Language uninstalled.
239+
"""
240+
And STDERR should be empty
241+
242+
When I run `wp language core install en_GB`
243+
Then STDOUT should contain:
244+
"""
245+
Using cached file
246+
"""
247+
And STDOUT should contain:
248+
"""
249+
Success: Installed 1 of 1 languages.
250+
"""
251+
And STDERR should be empty
252+
223253
@require-wp-6.0 @require-php-7.2
224254
Scenario Outline: Core translation update in newer versions
225255
Given an empty directory

‎src/WP_CLI/LanguagePackUpgrader.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ public function download_package( $package, $check_signatures = false, $hook_ext
9999
$language = $language_update->language;
100100
$ext = pathinfo( $package, PATHINFO_EXTENSION );
101101

102-
$temp = \WP_CLI\Utils\get_temp_dir() . uniqid( 'wp_' ) . '.' . $ext;
103-
104102
$cache = WP_CLI::get_cache();
105103
$cache_key = "translation/{$type}-{$slug}-{$version}-{$language}-{$updated}.{$ext}";
106104

@@ -110,6 +108,7 @@ public function download_package( $package, $check_signatures = false, $hook_ext
110108
$cache_file = $cache->has( $cache_key );
111109

112110
if ( $cache_file ) {
111+
$temp = \WP_CLI\Utils\make_temp_file( 'wp_', '.' . $ext );
113112
WP_CLI::log( "Using cached file '$cache_file'..." );
114113
copy( $cache_file, $temp );
115114
return $temp;

0 commit comments

Comments
 (0)