From 9e0ffbc901f90d0011e65852ef60de0c3360661b Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 10 Feb 2016 05:15:02 -0800 Subject: [PATCH 1/4] Failing test case for #2468 --- features/core-update.feature | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/features/core-update.feature b/features/core-update.feature index ef52aa8ea2..53db29ba2c 100644 --- a/features/core-update.feature +++ b/features/core-update.feature @@ -193,3 +193,19 @@ Feature: Update WordPress core Then STDOUT should not be empty When I run `wp post create --post_title='Test post' --porcelain` Then STDOUT should be a number + + @less-than-php-7 + Scenario: Minor update on an unlocalized WordPress release + Given a WP install + + When I run `wp core download --version=4.0 --locale=es_ES --force` + Then STDOUT should contain: + """ + Success: WordPress downloaded. + """ + + When I run `wp core update --minor` + Then STDOUT should contain: + """ + Success: WordPress updated successfully + """ From ef24a31153aff410e552fd62e0e91e9c3ab40638 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 10 Feb 2016 05:58:38 -0800 Subject: [PATCH 2/4] Use WP.org's download offer for minor updates Sometimes localized versions of WordPress don't have a minor release build, and we need to use the en_US partial instead. Also, when performing `wp core check-update`, don't list release files that don't exist. --- features/core-check-update.feature | 19 ++++++++++++++++ features/core-update.feature | 8 ++++++- php/commands/core.php | 36 ++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/features/core-check-update.feature b/features/core-check-update.feature index 10a6508845..5fb91fe9ef 100644 --- a/features/core-check-update.feature +++ b/features/core-check-update.feature @@ -40,3 +40,22 @@ Feature: Check for more recent versions """ 1 """ + + @less-than-php-7 + Scenario: No minor updates for an unlocalized WordPress release + Given a WP install + + When I run `wp core download --version=4.0 --locale=es_ES --force` + Then STDOUT should contain: + """ + Success: WordPress downloaded. + """ + + When I run `wp core check-update --minor` + Then STDOUT should be a table containing rows: + | version | update_type | package_url | + | 4.0.1 | minor | https://es.wordpress.org/wordpress-4.0.1-es_ES.zip | + And STDERR should contain: + """ + Warning: No release found for 4.0.10 (es_ES) + """ diff --git a/features/core-update.feature b/features/core-update.feature index 53db29ba2c..93eec5bf93 100644 --- a/features/core-update.feature +++ b/features/core-update.feature @@ -197,6 +197,7 @@ Feature: Update WordPress core @less-than-php-7 Scenario: Minor update on an unlocalized WordPress release Given a WP install + And an empty cache When I run `wp core download --version=4.0 --locale=es_ES --force` Then STDOUT should contain: @@ -207,5 +208,10 @@ Feature: Update WordPress core When I run `wp core update --minor` Then STDOUT should contain: """ - Success: WordPress updated successfully + Updating to version 4.0.10 (en_US)... + Descargando paquete de instalación desde https://downloads.wordpress.org/release/wordpress-4.0.10-partial-0.zip + """ + And STDOUT should contain: + """ + Success: WordPress updated successfully. """ diff --git a/php/commands/core.php b/php/commands/core.php index 4ec4592de4..1424d2c3aa 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -976,16 +976,6 @@ function update( $args, $assoc_args ) { $update = $from_api = null; $upgrader = 'WP_CLI\\CoreUpgrader'; - if ( empty( $args[0] ) && empty( $assoc_args['version'] ) && \WP_CLI\Utils\get_flag_value( $assoc_args, 'minor' ) ) { - $updates = $this->get_updates( array( 'minor' => true ) ); - if ( ! empty( $updates ) ) { - $assoc_args['version'] = $updates[0]['version']; - } else { - WP_CLI::success( 'WordPress is at the latest minor release.' ); - return; - } - } - if ( ! empty( $args[0] ) ) { $upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader'; @@ -1010,8 +1000,23 @@ function update( $args, $assoc_args ) { wp_version_check(); $from_api = get_site_transient( 'update_core' ); - if ( ! empty( $from_api->updates ) ) { - list( $update ) = $from_api->updates; + if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'minor' ) ) { + foreach( $from_api->updates as $offer ) { + $sem_ver = Utils\get_named_sem_ver( $offer->version, $wp_version ); + if ( ! $sem_ver || 'patch' !== $sem_ver ) { + continue; + } + $update = $offer; + break; + } + if ( empty( $update ) ) { + WP_CLI::success( 'WordPress is at the latest minor release.' ); + return; + } + } else { + if ( ! empty( $from_api->updates ) ) { + list( $update ) = $from_api->updates; + } } } else if ( \WP_CLI\Utils\wp_version_compare( $assoc_args['version'], '<' ) @@ -1224,6 +1229,13 @@ private function get_updates( $assoc_args ) { continue; } + $download_url = $this->get_download_url( $release_version, $locale ); + $response = Utils\http_request( 'HEAD', $download_url ); + if ( 20 != substr( $response->status_code, 0, 2 ) ) { + WP_CLI::warning( "No release found for {$release_version} ({$locale})" ); + continue; + } + $updates[ $update_type ] = array( 'version' => $release_version, 'update_type' => $update_type, From a8ec806d42a0006d0264e26acf3c2767c9e6dc51 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 10 Feb 2016 06:13:40 -0800 Subject: [PATCH 3/4] Better idea: use core's versions API to check for updates We should've done this in the very beginning. Now lists the partial package for update when it's available --- features/core-check-update.feature | 18 +++++------- php/commands/core.php | 44 ++++++------------------------ 2 files changed, 16 insertions(+), 46 deletions(-) diff --git a/features/core-check-update.feature b/features/core-check-update.feature index 5fb91fe9ef..600beba472 100644 --- a/features/core-check-update.feature +++ b/features/core-check-update.feature @@ -9,9 +9,9 @@ Feature: Check for more recent versions When I run `wp core check-update` Then STDOUT should be a table containing rows: - | version | update_type | package_url | - | 4.4.2 | major | https://wordpress.org/wordpress-4.4.2.zip | - | 3.8.13 | minor | https://wordpress.org/wordpress-3.8.13.zip | + | version | update_type | package_url | + | 4.4.2 | major | https://downloads.wordpress.org/release/wordpress-4.4.2.zip | + | 3.8.13 | minor | https://downloads.wordpress.org/release/wordpress-3.8.13-partial-0.zip | When I run `wp core check-update --format=count` Then STDOUT should be: @@ -21,8 +21,8 @@ Feature: Check for more recent versions When I run `wp core check-update --major` Then STDOUT should be a table containing rows: - | version | update_type | package_url | - | 4.4.2 | major | https://wordpress.org/wordpress-4.4.2.zip | + | version | update_type | package_url | + | 4.4.2 | major | https://downloads.wordpress.org/release/wordpress-4.4.2.zip | When I run `wp core check-update --major --format=count` Then STDOUT should be: @@ -33,7 +33,7 @@ Feature: Check for more recent versions When I run `wp core check-update --minor` Then STDOUT should be a table containing rows: | version | update_type | package_url | - | 3.8.13 | minor | https://wordpress.org/wordpress-3.8.13.zip | + | 3.8.13 | minor | https://downloads.wordpress.org/release/wordpress-3.8.13-partial-0.zip | When I run `wp core check-update --minor --format=count` Then STDOUT should be: @@ -54,8 +54,4 @@ Feature: Check for more recent versions When I run `wp core check-update --minor` Then STDOUT should be a table containing rows: | version | update_type | package_url | - | 4.0.1 | minor | https://es.wordpress.org/wordpress-4.0.1-es_ES.zip | - And STDERR should contain: - """ - Warning: No release found for 4.0.10 (es_ES) - """ + | 4.0.10 | minor | https://downloads.wordpress.org/release/wordpress-4.0.10-partial-0.zip | diff --git a/php/commands/core.php b/php/commands/core.php index 1424d2c3aa..6fc55c18e4 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -1180,40 +1180,21 @@ private function get_download_url($version, $locale = 'en_US', $file_type = 'zip * Returns update information */ private function get_updates( $assoc_args ) { - global $wp_version; - $versions_path = ABSPATH . 'wp-includes/version.php'; - include $versions_path; - - $url = 'https://api.wordpress.org/core/stable-check/1.0/'; - - $options = array( - 'timeout' => 30 - ); - $headers = array( - 'Accept' => 'application/json' - ); - $response = Utils\http_request( 'GET', $url, $headers, $options ); - - if ( ! $response->success || 200 !== $response->status_code ) { - WP_CLI::error( "Failed to get latest version list." ); + wp_version_check(); + $from_api = get_site_transient( 'update_core' ); + if ( ! $from_api ) { + return array(); } - $release_data = json_decode( $response->body ); - $release_versions = array_keys( (array) $release_data ); - usort( $release_versions, function( $a, $b ){ - return 1 === version_compare( $a, $b ); - }); - - $locale = get_locale(); $compare_version = str_replace( '-src', '', $GLOBALS['wp_version'] ); $updates = array( 'major' => false, 'minor' => false, ); - foreach ( $release_versions as $release_version ) { + foreach ( $from_api->updates as $offer ) { - $update_type = Utils\get_named_sem_ver( $release_version, $compare_version ); + $update_type = Utils\get_named_sem_ver( $offer->version, $compare_version ); if ( ! $update_type ) { continue; } @@ -1225,21 +1206,14 @@ private function get_updates( $assoc_args ) { $update_type = 'minor'; } - if ( ! empty( $updates[ $update_type ] ) && ! Comparator::greaterThan( $release_version, $updates[ $update_type ]['version'] ) ) { - continue; - } - - $download_url = $this->get_download_url( $release_version, $locale ); - $response = Utils\http_request( 'HEAD', $download_url ); - if ( 20 != substr( $response->status_code, 0, 2 ) ) { - WP_CLI::warning( "No release found for {$release_version} ({$locale})" ); + if ( ! empty( $updates[ $update_type ] ) && ! Comparator::greaterThan( $offer->version, $updates[ $update_type ]['version'] ) ) { continue; } $updates[ $update_type ] = array( - 'version' => $release_version, + 'version' => $offer->version, 'update_type' => $update_type, - 'package_url' => $this->get_download_url( $release_version, $locale ) + 'package_url' => ! empty( $offer->packages->partial ) ? $offer->packages->partial : $offer->packages->full, ); } From b442a98ae7f9f7dadf3e2b549a5136bb721571fe Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Tue, 16 Feb 2016 04:40:44 -0800 Subject: [PATCH 4/4] Require WP 4.0 or greater for this step --- features/core-update.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/core-update.feature b/features/core-update.feature index 93eec5bf93..2cb55be5f7 100644 --- a/features/core-update.feature +++ b/features/core-update.feature @@ -194,7 +194,7 @@ Feature: Update WordPress core When I run `wp post create --post_title='Test post' --porcelain` Then STDOUT should be a number - @less-than-php-7 + @less-than-php-7 @require-wp-4.0 Scenario: Minor update on an unlocalized WordPress release Given a WP install And an empty cache