Ticket #18201: 18201.6.diff
| File 18201.6.diff, 6.1 KB (added by , 13 years ago) |
|---|
-
wp-admin/includes/update.php
87 87 return $auto_update; 88 88 } 89 89 90 /** 91 * Gets and caches the checksums for the given versions of WordPress 92 * 93 * @since 3.7.0 94 * 95 * @param $version string|array A single version, or an array of versions to fetch 96 * 97 * @return bool|array False on failure, otherwise the array of checksums, keyed by version 98 */ 99 100 101 function get_core_checksums( $version ) { 102 if ( ! is_array( $version ) ) 103 $version = array( $version ); 104 105 $return = array(); 106 107 // Check to see if we have cached copies available, if we do, no need to request them 108 foreach ( $version as $i => $v ) { 109 if ( $checksums = get_site_transient( "core_checksums_$v" ) ) { 110 unset( $version[ $i ] ); 111 $return[ $v ] = $checksums; 112 } 113 } 114 115 // We had cached copies for all of the versions! 116 if ( empty( $version ) ) 117 return $return; 118 119 $url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( array( 'version' => $version ), null, '&' ); 120 121 if ( wp_http_supports( array( 'ssl' ) ) ) 122 $url = set_url_scheme( $url, 'https' ); 123 124 $options = array( 125 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), 126 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) 127 ); 128 129 $response = wp_remote_get( $url, $options ); 130 131 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) 132 return false; 133 134 $body = trim( wp_remote_retrieve_body( $response ) ); 135 $body = json_decode( $body, true ); 136 137 if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) 138 return false; 139 140 // Cache the checksums for later 141 foreach ( $version as $v ) { 142 set_site_transient( "core_checksums_$v", $body['checksums'][ $v ], HOUR_IN_SECONDS ); 143 $return[ $v ] = $body['checksums'][ $v ]; 144 } 145 146 // If the API didn't return anything for a version, explicitly set it's return value to false 147 foreach ( $return as $v => $r ) { 148 if ( empty( $r ) ) 149 $return[ $v ] = false; 150 } 151 152 return $return; 153 } 154 90 155 function dismiss_core_update( $update ) { 91 156 $dismissed = get_site_option( 'dismissed_update_core' ); 92 157 $dismissed[ $update->current . '|' . $update->locale ] = true; -
wp-admin/includes/class-wp-upgrader.php
1111 1111 1112 1112 $wp_dir = trailingslashit($wp_filesystem->abspath()); 1113 1113 1114 // Pre-cache the checksums for the versions we care about 1115 get_core_checksums( array( $wp_version, $current->version ) ); 1116 1117 $no_partial = false; 1118 if ( ! $this->check_files() ) 1119 $no_partial = true; 1120 1114 1121 // If partial update is returned from the API, use that, unless we're doing a reinstall. 1115 1122 // If we cross the new_bundled version number, then use the new_bundled zip. 1116 1123 // Don't though if the constant is set to skip bundled items. 1117 1124 // If the API returns a no_content zip, go with it. Finally, default to the full zip. 1118 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )1125 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && ! $no_partial ) 1119 1126 $to_download = 'partial'; 1120 1127 elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) 1121 1128 && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) … … 1205 1212 return false; 1206 1213 } 1207 1214 1215 function check_files() { 1216 global $wp_version; 1217 1218 $checksums = get_core_checksums( $wp_version ); 1219 1220 if ( empty( $checksums[ $wp_version ] ) || ! is_array( $checksums[ $wp_version ] ) ) 1221 return false; 1222 1223 foreach ( $checksums[ $wp_version ] as $file => $checksum ) { 1224 if ( md5_file( ABSPATH . $file ) !== $checksum ) 1225 return false; 1226 } 1227 1228 return true; 1229 } 1208 1230 } 1209 1231 1210 1232 /** -
wp-admin/includes/update-core.php
690 690 691 691 apply_filters('update_feedback', __('Installing the latest version…')); 692 692 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 ( ! empty( $checksums[ $wp_version ] && is_array( $checksums[ $wp_version ] ) ) { 697 foreach( $checksums[ $wp_version ] as $file => $checksum ) { 698 if ( md5_file( $to . $file ) === $checksum ) 699 $skip[] = $file; 700 } 701 } 702 693 703 // Create maintenance file to signal that we are upgrading 694 704 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; 695 705 $maintenance_file = $to . '.maintenance'; … … 697 707 $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE); 698 708 699 709 // 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 ( ! empty( $checksums[ $wp_version ] && is_array( $checksums[ $wp_version ] ) ) { 716 foreach( $checksums[ $wp_version ] 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 } 701 736 702 737 // Custom Content Directory needs updating now. 703 738 // Copy Languages