WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/15/2013 11:02:28 PM (6 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/update.php

    r25783 r25801  
    9292
    9393/**
    94  * Gets and caches the checksums for the given versions of WordPress
     94 * Gets and caches the checksums for the given version of WordPress.
    9595 *
    9696 * @since 3.7.0
    9797 *
    98  * @param $version string|array A single version, or an array of versions to fetch
    99  *
    100  * @return bool|array False on failure, otherwise the array of checksums, keyed by version
    101  */
    102 function get_core_checksums( $version ) {
    103     if ( ! is_array( $version ) )
    104         $version = array( $version );
    105 
     98 * @param string $version Version string to query.
     99 * @param string $locale  Locale to query.
     100 * @return bool|array False on failure. An array of checksums on success.
     101 */
     102function get_core_checksums( $version, $locale ) {
    106103    $return = array();
    107104
    108     // Check to see if we have cached copies available, if we do, no need to request them
    109     foreach ( $version as $i => $v ) {
    110         if ( $checksums = get_site_transient( "core_checksums_$v" ) ) {
    111             unset( $version[ $i ] );
    112             $return[ $v ] = $checksums;
    113         }
    114     }
    115 
    116     // We had cached copies for all of the versions!
    117     if ( empty( $version ) )
    118         return $return;
    119 
    120     $url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( array( 'version' => $version ), null, '&' );
     105    $url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
    121106
    122107    if ( wp_http_supports( array( 'ssl' ) ) )
     
    138123        return false;
    139124
    140     // Cache the checksums for later
    141     foreach ( $version as $v ) {
    142         if ( ! isset( $body['checksums'][ $v ] ) )
    143             $body['checksums'][ $v ] = false;
    144         set_site_transient( "core_checksums_$v", $body['checksums'][ $v ], HOUR_IN_SECONDS );
    145         $return[ $v ] = $body['checksums'][ $v ];
    146     }
    147 
    148     // If the API didn't return anything for a version, explicitly set it's return value to false
    149     foreach ( $return as $v => $r ) {
    150         if ( empty( $r ) )
    151             $return[ $v ] = false;
    152     }
    153 
    154     return $return;
     125    return $body['checksums'];
    155126}
    156127
Note: See TracChangeset for help on using the changeset viewer.