Make WordPress Core

Ticket #18201: 18201.7.diff

File 18201.7.diff, 10.2 KB (added by dd32, 11 years ago)
  • wp-admin/includes/class-wp-upgrader.php

     
    10421042
    10431043                $wp_dir = trailingslashit($wp_filesystem->abspath());
    10441044
     1045                // Pre-cache the checksums for the versions we care about
     1046                get_core_checksums( array( $wp_version, $current->current ) ); /* TODO for 3.7, change this to $current->version */
     1047
     1048                $no_partial = false;
     1049                apply_filters('update_feedback', __( 'Verifying existing files…' ) );
     1050                if ( ! $this->check_files() )
     1051                        $no_partial = true;
     1052
    10451053                // If partial update is returned from the API, use that, unless we're doing a reinstall.
    10461054                // If we cross the new_bundled version number, then use the new_bundled zip.
    10471055                // Don't though if the constant is set to skip bundled items.
    10481056                // If the API returns a no_content zip, go with it. Finally, default to the full zip.
    1049                 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
     1057                if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && ! $no_partial )
    10501058                        $to_download = 'partial';
    10511059                elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
    10521060                        && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
     
    10651073                        return $working_dir;
    10661074
    10671075                // Copy update-core.php from the new version into place.
     1076                /* // TESTING use existing upgrade-core file
    10681077                if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
    10691078                        $wp_filesystem->delete($working_dir, true);
    10701079                        return new WP_Error('copy_failed', $this->strings['copy_failed']);
    10711080                }
    10721081                $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
    1073 
     1082*/
    10741083                require(ABSPATH . 'wp-admin/includes/update-core.php');
    10751084
    10761085                if ( ! function_exists( 'update_core' ) )
     
    10811090                return $result;
    10821091        }
    10831092
     1093        function check_files() {
     1094                global $wp_version;
     1095
     1096                $checksums = get_core_checksums( $wp_version );
     1097var_dump([ __METHOD__, $wp_version ]);
     1098                if ( empty( $checksums[ $wp_version ] ) || ! is_array( $checksums[ $wp_version ] ) )
     1099                        return false;
     1100
     1101                foreach ( $checksums[ $wp_version ] as $file => $checksum ) {
     1102                        if ( md5_file( ABSPATH . $file ) !== $checksum )
     1103                                return false;
     1104                }
     1105
     1106                return true;
     1107        }
    10841108}
    10851109
    10861110/**
  • wp-admin/includes/update-core.php

     
    683683
    684684        apply_filters('update_feedback', __('Installing the latest version&#8230;'));
    685685
     686        // Check to see which files don't really need updating
     687        $skip = array( 'wp-content' );
     688        $checksums = get_core_checksums( $wp_version ); /* TODO This function won't exist when upgrading from pre-3.7, which will cause a fatal (This file is included from the new package, and runs with the old versions code) */
     689        if ( ! empty( $checksums[ $wp_version ] ) && is_array( $checksums[ $wp_version ] ) ) {
     690                apply_filters('update_feedback', __( 'Determining which files need copying&#8230;' ) ); /* TODO language */
     691                foreach( $checksums[ $wp_version ] as $file => $checksum ) {
     692                        if ( md5_file( ABSPATH . $file ) === $checksum )
     693                                $skip[] = $file;
     694                }
     695        }
     696
     697        apply_filters('update_feedback', __( 'Enabling Maintainence Mode&#8230;' ) ); /* TODO language */
     698
    686699        // Create maintenance file to signal that we are upgrading
    687700        $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    688701        $maintenance_file = $to . '.maintenance';
    689702        $wp_filesystem->delete($maintenance_file);
    690703        $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
    691704
     705        apply_filters('update_feedback', __( 'Copying the required files&#8230;' ) ); /* TODO language */
    692706        // Copy new versions of WP files into place.
    693         $result = _copy_dir($from . $distro, $to, array('wp-content') );
     707        $result = _copy_dir($from . $distro, $to, $skip );
    694708
     709        // Check to make sure everything copied correctly
     710        $skip = array( 'wp-content' );
     711        $failed = array();
     712        if ( ! empty( $checksums[ $wp_version ] ) && is_array( $checksums[ $wp_version ] ) ) {
     713                foreach( $checksums[ $wp_version ] as $file => $checksum ) {
     714                        if ( md5_file( ABSPATH . $file ) === $checksum )
     715                                $skip[] = $file;
     716                        else
     717                                $failed[] = $file;
     718                }
     719        }
     720
     721        // Some files didn't copy properly
     722        if ( ! empty( $failed ) ) {
     723                $total_size = 0;
     724                foreach ( $failed as $file )
     725                        $total_size += filesize( $from . '/' . $distro . '/' . $file ); /* TODO This won't work with FTP The $from contains a dynamic name so WP_CONTENT_DIR can't be used directly */
     726
     727                // If we don't have enough free space, it isn't worth trying again
     728                if ( $total_size >= disk_free_space( ABSPATH ) )
     729                        $result = new WP_Error( 'disk_full', __( "There isn't enough free disk space to complete the upgrade." ), $to );
     730                else
     731                        $result = _copy_dir( $from . $distro, $to, $skip );
     732        }
     733
    695734        // Custom Content Directory needs updating now.
    696735        // Copy Languages
    697736        if ( !is_wp_error($result) && $wp_filesystem->is_dir($from . $distro . 'wp-content/languages') ) {
     
    788827        else
    789828                delete_option('update_core');
    790829
     830        apply_filters('update_feedback', __( 'Disabling Maintainence mode&#8230;' ) ); /* TODO language */
    791831        // Remove maintenance file, we're done.
    792832        $wp_filesystem->delete($maintenance_file);
    793833
    794834        // If we made it this far:
    795         do_action( '_core_updated_successfully', $wp_version );
     835        //do_action( '_core_updated_successfully', $wp_version );
    796836
    797837        return $wp_version;
    798838}
     
    801841 * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
    802842 * Assumes that WP_Filesystem() has already been called and setup.
    803843 *
    804  * This is a temporary function for the 3.1 -> 3.2 upgrade only and will be removed in 3.3
    805  *
    806844 * @ignore
    807845 * @since 3.2.0
     846 * @since 3.7.0 Updated not to use a regular expression for the skip list
    808847 * @see copy_dir()
    809848 *
    810849 * @param string $from source directory
     
    820859        $from = trailingslashit($from);
    821860        $to = trailingslashit($to);
    822861
    823         $skip_regex = '';
    824         foreach ( (array)$skip_list as $key => $skip_file )
    825                 $skip_regex .= preg_quote($skip_file, '!') . '|';
     862        /* The regex form doesn't like long $skip_list's, nor does it deal well with */
     863        $skip_string = implode( ',', $skip_list ) . ',update-core.php'; /* TODO remove hard-coded file */
    826864
    827         if ( !empty($skip_regex) )
    828                 $skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
    829 
    830865        foreach ( (array) $dirlist as $filename => $fileinfo ) {
    831                 if ( !empty($skip_regex) )
    832                         if ( preg_match($skip_regex, $from . $filename) )
    833                                 continue;
     866        //      if ( $skip_list && false !== stripos( $skip_string, $filename ) ) /* TODO This skip functionality doesn't work either. all sub directories fail to copy, ie. wp-includes IS in 'wp-includes/some/file.php,wp-content/whatever' */
     867        //              continue;
    834868
    835869                if ( 'f' == $fileinfo['type'] ) {
    836870                        if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
     
    883917        show_message( '<span class="hide-if-no-js">' . sprintf( __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ), $new_version, 'about.php?updated' ) . '</span>' );
    884918        show_message( '<span class="hide-if-js">' . sprintf( __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ), $new_version, 'about.php?updated' ) . '</span>' );
    885919        echo '</div>';
     920        return;
     921
    886922        ?>
    887923<script type="text/javascript">
    888924window.location = 'about.php?updated';
     
    893929        include(ABSPATH . 'wp-admin/admin-footer.php');
    894930        exit();
    895931}
    896 add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );
     932// add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' ); /* TESTING I want to see the upgrade result! */
  • wp-admin/includes/update.php

     
    5656        return $result;
    5757}
    5858
     59/**
     60 * Gets and caches the checksums for the given versions of WordPress
     61 *
     62 * @since 3.7.0
     63 *
     64 * @param $version string|array A single version, or an array of versions to fetch
     65 *
     66 * @return bool|array False on failure, otherwise the array of checksums, keyed by version
     67 */
     68
     69
     70function get_core_checksums( $version ) {
     71        if ( ! is_array( $version ) )
     72                $version = array( $version );
     73var_dump( $version );
     74        $return = array();
     75
     76        // Check to see if we have cached copies available, if we do, no need to request them
     77        foreach ( $version as $i => $v ) {
     78                if ( $checksums = get_site_transient( "core_checksums_$v" ) ) {
     79                        unset( $version[ $i ] );
     80                        $return[ $v ] = $checksums;
     81                }
     82        }
     83
     84        // We had cached copies for all of the versions!
     85        if ( empty( $version ) )
     86                return $return;
     87
     88        $url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( array( 'version' => $version ), null, '&' );
     89
     90        if ( wp_http_supports( array( 'ssl' ) ) )
     91                $url = set_url_scheme( $url, 'https' );
     92
     93        $options = array(
     94                'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
     95        );
     96
     97        $response = wp_remote_get( $url, $options );
     98
     99        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
     100                return false;
     101
     102        $body = trim( wp_remote_retrieve_body( $response ) );
     103        $body = json_decode( $body, true );
     104
     105        if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
     106                return false;
     107
     108        // Cache the checksums for later
     109        foreach ( $version as $v ) {
     110                set_site_transient( "core_checksums_$v", $body['checksums'][ $v ], HOUR_IN_SECONDS );
     111                $return[ $v ] = $body['checksums'][ $v ];
     112        }
     113
     114        // If the API didn't return anything for a version, explicitly set it's return value to false
     115        foreach ( $return as $v => $r ) {
     116                if ( empty( $r ) )
     117                        $return[ $v ] = false;
     118        }
     119
     120        return $return;
     121}
     122
    59123function dismiss_core_update( $update ) {
    60124        $dismissed = get_site_option( 'dismissed_update_core' );
    61125        $dismissed[ $update->current.'|'.$update->locale ] = true;