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
26 changes: 13 additions & 13 deletions features/core-download.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Feature: Download WordPress
When I run `wp core download`
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
Then the wp-settings.php file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.tar.gz file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.zip file should exist

When I run `mkdir inner`
And I run `cd inner && wp core download`
Expand All @@ -40,7 +40,7 @@ Feature: Download WordPress
Then the wp-settings.php file should exist
And STDOUT should contain:
"""
Using cached file '{SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.tar.gz'...
Using cached file '{SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.zip'...
"""

Scenario: Localized install
Expand All @@ -49,7 +49,7 @@ Feature: Download WordPress
When I run `wp core download --version=4.4.2 --locale=de_DE`
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
Then the wp-settings.php file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.zip file should exist

Scenario: Error when requested locale is not available for the latest version
Given an empty directory
Expand Down Expand Up @@ -150,7 +150,7 @@ Feature: Download WordPress
When I run `wp core download --version=4.4.1`
Then STDOUT should contain:
"""
md5 hash verified: 1907d1dbdac7a009d89224a516496b8d
md5 hash verified: 0c87de03eb3d76467cd0d3ab7268f1fd
Success: WordPress downloaded.
"""

Expand Down Expand Up @@ -328,7 +328,7 @@ Feature: Download WordPress
And STDOUT should contain:
"""
Downloading WordPress 4.6-RC2 (en_US)...
md5 hash verified: 90c93a15092b2d5d4c960ec1fc183e07
md5 hash verified: dbf4a8fe1c54d1e3e28532402da9a743
Success: WordPress downloaded.
"""

Expand All @@ -344,8 +344,8 @@ Feature: Download WordPress

When I run `wp core version`
Then save STDOUT as {VERSION}
And the {SUITE_CACHE_DIR}/core/wordpress-latest-en_US.tar.gz file should not exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.tar.gz file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-latest-en_US.zip file should not exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-en_US.zip file should exist

Scenario: Fail if path can't be created
Given an empty directory
Expand Down Expand Up @@ -503,14 +503,14 @@ Feature: Download WordPress

When I run `wp core download --version=4.5 --locale=de_DE`
Then the wp-content directory should exist
And the wordpress-4.5-de_DE.tar.gz file should not exist
And the wordpress-4.5-de_DE.zip file should not exist

Scenario: Core download with extract parameter should unzip the download file
Given an empty directory

When I run `wp core download --version=4.5 --locale=de_DE --extract`
Then the wp-content directory should exist
And the wordpress-4.5-de_DE.tar.gz file should not exist
And the wordpress-4.5-de_DE.zip file should not exist

Scenario: Core download with extract parameter should unzip the download file (already cached)
Given an empty directory
Expand All @@ -519,23 +519,23 @@ Feature: Download WordPress
And I run `rm -rf *`
And I run `wp core download --version=4.5 --locale=de_DE --extract`
Then the wp-content directory should exist
And the wordpress-4.5-de_DE.tar.gz file should not exist
And the wordpress-4.5-de_DE.zip file should not exist

Scenario: Core download with no-extract should not unzip the download file
Given an empty directory

When I run `wp core download --version=4.5 --locale=de_DE --no-extract`
Then the wp-content directory should not exist
And the wordpress-4.5-de_DE.tar.gz file should exist
And the wordpress-4.5-de_DE.zip file should exist

Scenario: Core download with no-extract should not unzip the download file (already cached)
Given an empty directory

When I run `wp core download --version=4.5 --locale=de_DE --no-extract`
And I run `rm -rf wordpress-4.5-de_DE.tar.gz`
And I run `rm -rf wordpress-4.5-de_DE.zip`
And I run `wp core download --version=4.5 --locale=de_DE --no-extract`
Then the wp-content directory should not exist
And the wordpress-4.5-de_DE.tar.gz file should exist
And the wordpress-4.5-de_DE.zip file should exist

Scenario: Error when using both --skip-content and --no-extract
Given an empty directory
Expand Down
2 changes: 1 addition & 1 deletion features/core-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Feature: Install WordPress core
5.6
"""
And the wp-settings.php file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.zip file should exist

When I run `wp config create --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASSWORD} --dbhost={DB_HOST} --locale=de_DE --skip-check`
Then STDOUT should be:
Expand Down
6 changes: 3 additions & 3 deletions features/core-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Feature: Update WordPress core
"""
And the {SUITE_CACHE_DIR}/core directory should contain:
"""
wordpress-6.5.2-en_US.tar.gz
wordpress-6.5.2-en_US.zip
wordpress-6.5.5-partial-1-en_US.zip
"""

Expand All @@ -246,8 +246,8 @@ Feature: Update WordPress core
"""
And the {SUITE_CACHE_DIR}/core directory should contain:
"""
wordpress-6.4.1-en_US.tar.gz
wordpress-6.5.2-en_US.tar.gz
wordpress-6.4.1-en_US.zip
wordpress-6.5.2-en_US.zip
wordpress-6.5.5-no-content-en_US.zip
wordpress-6.5.5-partial-1-en_US.zip
"""
Expand Down
40 changes: 7 additions & 33 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,7 @@ public function download( $args, $assoc_args ) {
$version = 'nightly';
}

// Nightly builds and skip content are only available in .zip format.
$extension = ( ( 'nightly' === $version ) || $skip_content )
? 'zip'
: 'tar.gz';

$download_url = $this->get_download_url( $version, $locale, $extension );
$download_url = $this->get_download_url( $version, $locale );
} else {
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );
try {
Expand All @@ -256,9 +251,6 @@ public function download( $args, $assoc_args ) {
}
$version = $offer['current'];
$download_url = $offer['download'];
if ( ! $skip_content ) {
$download_url = str_replace( '.zip', '.tar.gz', $download_url );
}
}

if ( 'nightly' === $version && 'en_US' !== $locale ) {
Expand All @@ -277,18 +269,7 @@ public function download( $args, $assoc_args ) {
WP_CLI::log( "Downloading WordPress {$version} ({$locale})..." );
}

$path_parts = pathinfo( $download_url );
$extension = 'tar.gz';
if ( isset( $path_parts['extension'] ) && 'zip' === $path_parts['extension'] ) {
$extension = 'zip';
if ( $extract && ! class_exists( 'ZipArchive' ) ) {
WP_CLI::error( 'Extracting a zip file requires ZipArchive.' );
}
}

if ( $skip_content && 'zip' !== $extension ) {
WP_CLI::error( 'Skip content is only available for ZIP files.' );
}
$extension = 'zip';

Comment thread
swissspidy marked this conversation as resolved.
$cache = WP_CLI::get_cache();
if ( $from_url ) {
Expand Down Expand Up @@ -316,8 +297,6 @@ public function download( $args, $assoc_args ) {
}

if ( ! $cache_file || $bad_cache ) {
// We need to use a temporary file because piping from cURL to tar is flaky
// on MinGW (and probably in other environments too).
$temp = Utils\get_temp_dir() . uniqid( 'wp_' ) . ".{$extension}";
register_shutdown_function(
function () use ( $temp ) {
Expand Down Expand Up @@ -1652,21 +1631,16 @@ public function update_db( $args, $assoc_args ) {
}

/**
* Gets download url based on version, locale and desired file type.
* Gets download url based on version and locale.
*
* @param $version
* @param string $locale
* @param string $file_type
* @return string
*/
private function get_download_url( $version, $locale = 'en_US', $file_type = 'zip' ) {
private function get_download_url( $version, $locale = 'en_US' ) {

if ( 'nightly' === $version ) {
if ( 'zip' === $file_type ) {
return 'https://wordpress.org/nightly-builds/wordpress-latest.zip';
} else {
WP_CLI::error( 'Nightly builds are only available in .zip format.' );
}
return 'https://wordpress.org/nightly-builds/wordpress-latest.zip';
}

$locale_subdomain = 'en_US' === $locale ? '' : substr( $locale, 0, 2 ) . '.';
Expand All @@ -1676,7 +1650,7 @@ private function get_download_url( $version, $locale = 'en_US', $file_type = 'zi
$version = substr( $version, 0, -2 );
}

return "https://{$locale_subdomain}wordpress.org/wordpress-{$version}{$locale_suffix}.{$file_type}";
return "https://{$locale_subdomain}wordpress.org/wordpress-{$version}{$locale_suffix}.zip";
}

/**
Expand Down Expand Up @@ -1722,7 +1696,7 @@ private function find_latest_offer_for_locale( $locale, $insecure ) {
) {
return [
'current' => $translation['version'],
'download' => $this->get_download_url( $translation['version'], $locale, 'zip' ),
'download' => $this->get_download_url( $translation['version'], $locale ),
];
}
}
Expand Down