WordPress.org

Make WordPress Core

Ticket #22704: 22704.6.diff

File 22704.6.diff, 2.8 KB (added by dd32, 5 years ago)
  • src/wp-admin/includes/class-wp-upgrader.php

     
    12981298
    12991299                $result = update_core( $working_dir, $wp_dir );
    13001300
     1301                $try_rollback = false;
     1302                if ( is_wp_error( $result ) )
     1303                        $try_rollback = true;
     1304                elseif ( ! $this->test_if_site_is_ok() )
     1305                        $try_rollback = true;
     1306
    13011307                // In the event of an error, rollback to the previous version
    1302                 if ( is_wp_error( $result ) && $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) {
     1308                if ( $try_rollback && $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) {
    13031309                        apply_filters( 'update_feedback', $result );
    13041310                        apply_filters( 'update_feedback', $this->strings['start_rollback'] );
    13051311
     
    13661372                return false;
    13671373        }
    13681374
     1375        function test_if_site_is_ok() {
     1376                // Is the Admin ajax handler returning what we expect of it?
     1377                $http_result = wp_remote_post( admin_url( 'admin-ajax.php?action=test-upgrade-OK' ), array( 'timeout' => 10 ) );
     1378                $admin_ok = ! is_wp_error( $http_result ) && ( 'OK' === wp_remote_retrieve_body( $http_result ) );
     1379
     1380                if ( ! $admin_ok )
     1381                        return false;
     1382
     1383                // Is the front-end returning what we'd expect of it? (Note, this is a filter on template_redirect + wp_footer below)
     1384                // This WILL break with caching plugins, a POST should make it past most caching plugins, but I suspect not all of them
     1385                $http_result = wp_remote_post( site_url( '?test-upgrade-OK=1' ), array( 'timeout' => 10 ) );
     1386                $front_ok = ! is_wp_error( $http_result ) && ( 'OK' === wp_remote_retrieve_body( $http_result ) );
     1387
     1388                if ( ! $front_ok )
     1389                        return false;
     1390
     1391                return true;
     1392        }
     1393
    13691394        function check_files() {
    13701395                global $wp_version;
    13711396
  • src/wp-includes/update.php

     
    521521        wp_update_themes();
    522522}
    523523
     524function site_is_OK_callback() {
     525        die( 'OK' );
     526}
     527
     528
    524529/**
    525530 * Schedule core, theme, and plugin update checks.
    526531 *
     
    562567add_action( 'wp_update_themes', 'wp_update_themes' );
    563568add_action( 'upgrader_process_complete', 'wp_update_themes' );
    564569
     570add_action('init', 'wp_schedule_update_checks');
     571
    565572// Automatic Updates - Cron callback
    566573add_action( 'wp_auto_updates_maybe_update', 'wp_auto_updates_maybe_update' );
    567574
    568 add_action('init', 'wp_schedule_update_checks');
     575// Automatic Updates - Site is OK callbacks
     576if ( isset( $_GET['test-upgrade-OK'] ) )
     577        add_action( 'template_redirect', 'site_is_OK_callback' );
     578
     579add_action( 'wp_ajax_test-upgrade-OK', 'site_is_OK_callback' );
     580add_action( 'wp_ajax_nopriv_test-upgrade-OK', 'site_is_OK_callback' );