WordPress.org

Make WordPress Core

Changeset 25649


Ignore:
Timestamp:
09/30/13 00:20:35 (4 years ago)
Author:
dd32
Message:

Automatic Updates: Add a rollback functionality upon installation failure, the rollback package will be available for partial-updates for automatic updates and be similar to our existing partial builds (but in reverse).
A further iteration of this is to also detect whitescreens (fatals) after a auto update, and trigger the rollback for that too.
See #22704

Location:
trunk/src
Files:
4 edited

Legend:

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

    r25648 r25649  
    12251225        $this->strings['copy_failed'] = __('Could not copy files.'); 
    12261226        $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' ); 
     1227        $this->strings['start_rollback'] = __( 'Attempting to rollback to previous version.' ); 
     1228        $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version' ); 
    12271229    } 
    12281230 
     
    12311233 
    12321234        $defaults = array( 
    1233             'pre_check_md5' => true, 
     1235            'pre_check_md5'    => true, 
     1236            'attempt_rollback' => false, 
     1237            'do_rollback'      => false, 
    12341238        ); 
    12351239        $parsed_args = wp_parse_args( $args, $defaults ); 
     
    12521256 
    12531257        $no_partial = false; 
    1254         if ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) 
     1258        if ( $parsed_args['do_rollback'] ) 
     1259            $no_partial = true; 
     1260        elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) 
    12551261            $no_partial = true; 
    12561262 
     
    12591265        // Don't though if the constant is set to skip bundled items. 
    12601266        // If the API returns a no_content zip, go with it. Finally, default to the full zip. 
    1261         if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && ! $no_partial ) 
     1267        if ( $parsed_args['do_rollback'] && $current->packages->rollback ) 
     1268            $to_download = 'rollback'; 
     1269        elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && ! $no_partial ) 
    12621270            $to_download = 'partial'; 
    12631271        elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) 
     
    12841292        $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); 
    12851293 
    1286         require(ABSPATH . 'wp-admin/includes/update-core.php'); 
     1294        require_once( ABSPATH . 'wp-admin/includes/update-core.php' ); 
    12871295 
    12881296        if ( ! function_exists( 'update_core' ) ) 
    12891297            return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] ); 
    12901298 
    1291         $result = update_core( $working_dir, $wp_dir ); 
     1299        $result = update_core( $working_dir, $wp_dir, $parsed_args['do_rollback'] ); 
     1300 
     1301        // In the event of an error, rollback to the previous version 
     1302        if ( is_wp_error( $result ) && $parsed_args['attempt_rollback'] && $current->packages->rollback ) { 
     1303            apply_filters( 'update_feedback', $result ); 
     1304            apply_filters( 'update_feedback', $this->strings['start_rollback'] ); 
     1305 
     1306            $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) ); 
     1307 
     1308            $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'] ); 
     1309        } 
    12921310        do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ), $result ); 
    12931311        return $result; 
     
    16311649            'clear_update_cache' => false, 
    16321650            'pre_check_md5'      => false, /* always use partial builds if possible for core updates */ 
     1651            'attempt_rollback'   => true, /* only available for core updates */ 
    16331652        ) ); 
    16341653 
  • trunk/src/wp-admin/includes/update-core.php

    r25648 r25649  
    666666 
    667667    $wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE ); 
    668     require_once( WP_CONTENT_DIR . '/upgrade/version-current.php' ); 
     668    require( WP_CONTENT_DIR . '/upgrade/version-current.php' ); 
    669669    $wp_filesystem->delete( $versions_file ); 
    670670 
  • trunk/src/wp-admin/includes/update.php

    r25566 r25649  
    137137    // Cache the checksums for later 
    138138    foreach ( $version as $v ) { 
     139        if ( ! isset( $body['checksums'][ $v ] ) ) 
     140            $body['checksums'][ $v ] = false; 
    139141        set_site_transient( "core_checksums_$v", $body['checksums'][ $v ], HOUR_IN_SECONDS ); 
    140142        $return[ $v ] = $body['checksums'][ $v ]; 
  • trunk/src/wp-includes/update.php

    r25634 r25649  
    106106            if ( 'packages' == $offer_key ) 
    107107                $offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ), 
    108                     array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial' ), '' ) ); 
     108                    array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) ); 
    109109            elseif ( 'download' == $offer_key ) 
    110110                $offer['download'] = esc_url( $value ); 
Note: See TracChangeset for help on using the changeset viewer.