From 867f084ca00b616130f619e4edf6a58d1704e88f Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 15 Oct 2013 23:02:28 +0000 Subject: [PATCH] Significantly simplify get_core_checksums(), as the caching and chunking was causing too much grief. Make sure we only do our pre-flight is_writable check when the file exists. see #18201. see #22704. git-svn-id: https://develop.svn.wordpress.org/trunk@25801 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-upgrader.php | 11 ++---- src/wp-admin/includes/update-core.php | 16 +++++--- src/wp-admin/includes/update.php | 43 ++++----------------- src/wp-includes/version.php | 2 +- 4 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/wp-admin/includes/class-wp-upgrader.php b/src/wp-admin/includes/class-wp-upgrader.php index 61ac90bcd6..459a30749c 100644 --- a/src/wp-admin/includes/class-wp-upgrader.php +++ b/src/wp-admin/includes/class-wp-upgrader.php @@ -1251,9 +1251,6 @@ class Core_Upgrader extends WP_Upgrader { $wp_dir = trailingslashit($wp_filesystem->abspath()); - // Pre-cache the checksums for the versions we care about - get_core_checksums( array( $wp_version, $current->version ) ); - $partial = true; if ( $parsed_args['do_rollback'] ) $partial = false; @@ -1384,14 +1381,14 @@ class Core_Upgrader extends WP_Upgrader { } function check_files() { - global $wp_version; + global $wp_version, $wp_local_package; - $checksums = get_core_checksums( $wp_version ); + $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); - if ( empty( $checksums[ $wp_version ] ) || ! is_array( $checksums[ $wp_version ] ) ) + if ( ! is_array( $checksums ) ) return false; - foreach ( $checksums[ $wp_version ] as $file => $checksum ) { + foreach ( $checksums as $file => $checksum ) { // Skip files which get updated if ( 'wp-content' == substr( $file, 0, 10 ) ) continue; diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php index a74abd20bb..5f3eaaf572 100644 --- a/src/wp-admin/includes/update-core.php +++ b/src/wp-admin/includes/update-core.php @@ -696,12 +696,16 @@ function update_core($from, $to) { // Check to see which files don't really need updating - only available for 3.7 and higher if ( function_exists( 'get_core_checksums' ) ) { - $checksums = get_core_checksums( $wp_version ); - if ( ! empty( $checksums[ $wp_version ] ) && is_array( $checksums[ $wp_version ] ) ) { - foreach( $checksums[ $wp_version ] as $file => $checksum ) { + $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); + if ( is_array( current( $checksums ) ) ) // Compat code for 3.7-beta2 + $checksums = current( $checksums ); + if ( is_array( $checksums ) ) { + foreach( $checksums as $file => $checksum ) { if ( 'wp-content' == substr( $file, 0, 10 ) ) continue; - if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) === $checksum ) + if ( ! file_exists( ABSPATH . $file ) ) + continue; + if ( md5_file( ABSPATH . $file ) === $checksum ) $skip[] = $file; else $check_is_writable[ $file ] = ABSPATH . $file; @@ -745,8 +749,8 @@ function update_core($from, $to) { // Check to make sure everything copied correctly, ignoring the contents of wp-content $skip = array( 'wp-content' ); $failed = array(); - if ( ! empty( $checksums[ $wp_version ] ) && is_array( $checksums[ $wp_version ] ) ) { - foreach ( $checksums[ $wp_version ] as $file => $checksum ) { + if ( is_array( $checksums ) ) { + foreach ( $checksums as $file => $checksum ) { if ( 0 === strpos( $file, 'wp-content' ) ) continue; diff --git a/src/wp-admin/includes/update.php b/src/wp-admin/includes/update.php index a71778d4e1..d63757caf9 100644 --- a/src/wp-admin/includes/update.php +++ b/src/wp-admin/includes/update.php @@ -91,33 +91,18 @@ function find_core_auto_update() { } /** - * Gets and caches the checksums for the given versions of WordPress + * Gets and caches the checksums for the given version of WordPress. * * @since 3.7.0 * - * @param $version string|array A single version, or an array of versions to fetch - * - * @return bool|array False on failure, otherwise the array of checksums, keyed by version + * @param string $version Version string to query. + * @param string $locale Locale to query. + * @return bool|array False on failure. An array of checksums on success. */ -function get_core_checksums( $version ) { - if ( ! is_array( $version ) ) - $version = array( $version ); - +function get_core_checksums( $version, $locale ) { $return = array(); - // Check to see if we have cached copies available, if we do, no need to request them - foreach ( $version as $i => $v ) { - if ( $checksums = get_site_transient( "core_checksums_$v" ) ) { - unset( $version[ $i ] ); - $return[ $v ] = $checksums; - } - } - - // We had cached copies for all of the versions! - if ( empty( $version ) ) - return $return; - - $url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( array( 'version' => $version ), null, '&' ); + $url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' ); if ( wp_http_supports( array( 'ssl' ) ) ) $url = set_url_scheme( $url, 'https' ); @@ -137,21 +122,7 @@ function get_core_checksums( $version ) { if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) return false; - // Cache the checksums for later - foreach ( $version as $v ) { - if ( ! isset( $body['checksums'][ $v ] ) ) - $body['checksums'][ $v ] = false; - set_site_transient( "core_checksums_$v", $body['checksums'][ $v ], HOUR_IN_SECONDS ); - $return[ $v ] = $body['checksums'][ $v ]; - } - - // If the API didn't return anything for a version, explicitly set it's return value to false - foreach ( $return as $v => $r ) { - if ( empty( $r ) ) - $return[ $v ] = false; - } - - return $return; + return $body['checksums']; } function dismiss_core_update( $update ) { diff --git a/src/wp-includes/version.php b/src/wp-includes/version.php index 5d1e384062..05b2c789c6 100644 --- a/src/wp-includes/version.php +++ b/src/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '3.7-beta2-25800-src'; +$wp_version = '3.7-beta2-25801-src'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.