Make WordPress Core

Ticket #18201: 18201.4.diff

File 18201.4.diff, 4.8 KB (added by pento, 10 years ago)
  • wp-admin/includes/update.php

     
    5757        return $result;
    5858}
    5959
     60function get_core_checksums( $version ) {
     61        if ( $checksums = get_site_transient( "core_checksums_$version" ) )
     62                return $checksums;
     63
     64        $url = 'http://api.wordpress.org/core/checksum/1.0/?' . http_build_query( array( 'version' => $version ), null, '&' );
     65
     66        if ( wp_http_supports( array( 'ssl' ) ) )
     67                $url = set_url_scheme( $url, 'https' );
     68
     69        $options = array(
     70                'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
     71                'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' )
     72        );
     73
     74        $response = wp_remote_get( $url, $options );
     75
     76        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     77                return false;
     78
     79        $body = trim( wp_remote_retrieve_body( $response ) );
     80        $body = json_decode( $body, true );
     81
     82        if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
     83                return false;
     84
     85        set_site_transient( "core_checksums_$version", $body['checksums'], HOUR_IN_SECONDS );
     86
     87        return $body['checksums'];
     88}
     89
    6090function dismiss_core_update( $update ) {
    6191        $dismissed = get_site_option( 'dismissed_update_core' );
    6292        $dismissed[ $update->current . '|' . $update->locale ] = true;
  • wp-admin/includes/class-wp-upgrader.php

     
    10981098
    10991099                $wp_dir = trailingslashit($wp_filesystem->abspath());
    11001100
     1101                $no_partial = false;
     1102                if ( ! $this->check_files() )
     1103                        $no_partial = true;
     1104
    11011105                // If partial update is returned from the API, use that, unless we're doing a reinstall.
    11021106                // If we cross the new_bundled version number, then use the new_bundled zip.
    11031107                // Don't though if the constant is set to skip bundled items.
    11041108                // If the API returns a no_content zip, go with it. Finally, default to the full zip.
    1105                 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
     1109                if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && ! $no_partial )
    11061110                        $to_download = 'partial';
    11071111                elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
    11081112                        && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
     
    11371141                return $result;
    11381142        }
    11391143
     1144        function check_files() {
     1145                global $wp_version;
     1146
     1147                $checksums = get_core_checksums( $wp_version );
     1148
     1149                if ( empty( $checksums ) )
     1150                        return false;
     1151
     1152                foreach ( $checksums as $file => $checksum ) {
     1153                        if ( md5_file( ABSPATH . $file ) !== $checksum )
     1154                                return false;
     1155                }
     1156
     1157                return true;
     1158        }
    11401159}
    11411160
    11421161/**
  • wp-admin/includes/update-core.php

     
    690690
    691691        apply_filters('update_feedback', __('Installing the latest version&#8230;'));
    692692
     693        // Check to see which files don't really need updating
     694        $skip = array( 'wp-content' );
     695        $checksums = get_core_checksums( $wp_version );
     696        if ( is_array( $checksums ) ) {
     697                foreach( $checksums as $file => $checksum ) {
     698                        if ( md5_file( $to . $file ) === $checksum )
     699                                $skip[] = $file;
     700                }
     701        }
     702
    693703        // Create maintenance file to signal that we are upgrading
    694704        $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    695705        $maintenance_file = $to . '.maintenance';
     
    697707        $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
    698708
    699709        // Copy new versions of WP files into place.
    700         $result = _copy_dir($from . $distro, $to, array('wp-content') );
     710        $result = _copy_dir($from . $distro, $to, $skip );
     711
     712        // Check to make sure everything copied correctly
     713        $skip = array( 'wp-content' );
     714        $failed = array();
     715        if ( is_array( $checksums ) ) {
     716                foreach( $checksums as $file => $checksum ) {
     717                        if ( md5_file( $to . $file ) === $checksum )
     718                                $skip[] = $file;
     719                        else
     720                                $failed[] = $file;
     721                }
     722        }
     723
     724        // Some files didn't copy properly
     725        if ( ! empty( $failed ) ) {
     726                $total_size = 0;
     727                foreach ( $failed as $file => $checksum )
     728                        $total_size += filesize( $from . $file );
     729
     730                // If we don't have enough free space, it isn't worth trying again
     731                if ( $total_size >= disk_free_space( $to ) )
     732                        $result = new WP_Error( 'disk_full', __( "There isn't enough free disk space to complete the upgrade." ), $to );
     733                else
     734                        $result = _copy_dir( $from . $distro, $to, $skip );
     735        }
    701736
    702737        // Custom Content Directory needs updating now.
    703738        // Copy Languages