Skip to content

Commit 61e8fcb

Browse files
authored
Merge pull request #204 from xyulex/master
2 parents db6b0ec + bd41427 commit 61e8fcb

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

features/core-download.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,15 @@ Feature: Download WordPress
372372
"""
373373
And the wp-includes directory should exist
374374
And the wp-content directory should not exist
375+
376+
Scenario: Core download with extract parameter should unzip the download file
377+
Given an empty directory
378+
379+
When I run `wp core download --extract`
380+
Then the wp-content directory should exist
381+
382+
Scenario: Core download with no-extract should not unzip the download file
383+
Given an empty directory
384+
385+
When I run `wp core download --no-extract`
386+
Then the wp-content directory should not exist

src/Core_Command.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ public function check_update( $_, $assoc_args ) {
120120
* [--insecure]
121121
* : Retry download without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.
122122
*
123+
* [--extract]
124+
* : Whether to extract the downloaded file. Defaults to true.
125+
*
123126
* ## EXAMPLES
124127
*
125128
* $ wp core download --locale=nl_NL
@@ -130,7 +133,6 @@ public function check_update( $_, $assoc_args ) {
130133
* @when before_wp_load
131134
*/
132135
public function download( $args, $assoc_args ) {
133-
134136
$download_dir = ! empty( $assoc_args['path'] )
135137
? ( rtrim( $assoc_args['path'], '/\\' ) . '/' )
136138
: ABSPATH;
@@ -239,14 +241,19 @@ public function download( $args, $assoc_args ) {
239241
}
240242

241243
$bad_cache = false;
244+
$extract = (bool) Utils\get_flag_value( $assoc_args, 'extract', true );
245+
242246
if ( $cache_file ) {
243247
WP_CLI::log( "Using cached file '{$cache_file}'..." );
244248
$skip_content_cache_file = $skip_content ? self::strip_content_dir( $cache_file ) : null;
245-
try {
246-
Extractor::extract( $skip_content_cache_file ?: $cache_file, $download_dir );
247-
} catch ( Exception $exception ) {
248-
WP_CLI::warning( 'Extraction failed, downloading a new copy...' );
249-
$bad_cache = true;
249+
if ( $extract ) {
250+
try {
251+
Extractor::extract( $skip_content_cache_file ?: $cache_file, $download_dir );
252+
253+
} catch ( Exception $exception ) {
254+
WP_CLI::warning( 'Extraction failed, downloading a new copy...' );
255+
$bad_cache = true;
256+
}
250257
}
251258
}
252259

@@ -296,11 +303,12 @@ function () use ( $temp ) {
296303
}
297304

298305
$skip_content_temp = $skip_content ? self::strip_content_dir( $temp ) : null;
299-
300-
try {
301-
Extractor::extract( $skip_content_temp ?: $temp, $download_dir );
302-
} catch ( Exception $exception ) {
303-
WP_CLI::error( "Couldn't extract WordPress archive. {$exception->getMessage()}" );
306+
if ( $extract ) {
307+
try {
308+
Extractor::extract( $skip_content_temp ?: $temp, $download_dir );
309+
} catch ( Exception $exception ) {
310+
WP_CLI::error( "Couldn't extract WordPress archive. {$exception->getMessage()}" );
311+
}
304312
}
305313

306314
// Do not use the cache for nightly builds or for downloaded URLs

0 commit comments

Comments
 (0)