From 0b9f198994afc52967cba7c967f0f18347e6fc61 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Thu, 10 Oct 2013 01:32:09 +0000 Subject: [PATCH] In the event that an Automatic Upgrade fails, send a failure status on the next API request to indicate that it failed, and if the rollback was successful. See #22704 Built from https://develop.svn.wordpress.org/trunk@25750 git-svn-id: http://core.svn.wordpress.org/trunk@25663 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 20 +++++++++++++++----- wp-includes/update.php | 12 ++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index df81f8ccd0..041fc3a56d 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -1299,13 +1299,13 @@ class Core_Upgrader extends WP_Upgrader { $result = update_core( $working_dir, $wp_dir ); // In the event of an error, rollback to the previous version - if ( is_wp_error( $result ) && $parsed_args['attempt_rollback'] && $current->packages->rollback ) { + if ( is_wp_error( $result ) && $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) { apply_filters( 'update_feedback', $result ); apply_filters( 'update_feedback', $this->strings['start_rollback'] ); - $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) ); + $rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) ); - $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'] ); + $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], array( 'rollback' => $rollback_result, 'update' => $result ) ); } do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ), $result ); return $result; @@ -1726,14 +1726,24 @@ class WP_Automatic_Upgrader { // Next, Process any core upgrade wp_version_check(); // Check for Core updates + $extra_update_stats = array(); $core_update = find_core_auto_update(); if ( $core_update ) { - self::upgrade( 'core', $core_update ); + $start_time = time(); + $core_update_result = self::upgrade( 'core', $core_update ); delete_site_transient( 'update_core' ); + $extra_update_stats['success'] = is_wp_error( $core_update_result ) ? $core_update_result->get_error_code() : true; + if ( is_wp_error( $core_update_result ) && 'rollback_was_required' == $core_update_result->get_error_code() ) { + $rollback_data = $core_update_result->get_error_data(); + $extra_update_stats['success'] = is_wp_error( $rollback_data['update'] ) ? $rollback_data['update']->get_error_code() : $rollback_data['update']; + $extra_update_stats['rollback'] = is_wp_error( $rollback_data['rollback'] ) ? $rollback_data['rollback']->get_error_code() : $rollback_data['rollback']; + } + $extra_update_stats['fs_method'] = $GLOBALS['wp_filesystem']->method; + $extra_update_stats['time_taken'] = ( time() - $start_time ); } // Cleanup, and check for any pending translations - wp_version_check(); // check for Core updates + wp_version_check( $extra_update_stats ); // check for Core updates wp_update_themes(); // Check for Theme updates wp_update_plugins(); // Check for Plugin updates diff --git a/wp-includes/update.php b/wp-includes/update.php index 842b7f3719..65489deb4f 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -17,9 +17,10 @@ * @since 2.3.0 * @uses $wp_version Used to check against the newest WordPress version. * + * @param array $extra_stats Extra statistics to report to the WordPress.org API. * @return mixed Returns null if update is unsupported. Returns false if check is too soon. */ -function wp_version_check() { +function wp_version_check( $extra_stats = array() ) { if ( defined('WP_INSTALLING') ) return; @@ -39,7 +40,7 @@ function wp_version_check() { // Wait 60 seconds between multiple version check requests $timeout = 60; $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); - if ( $time_not_changed ) + if ( $time_not_changed && empty( $extra_args ) ) return false; $locale = get_locale(); @@ -82,9 +83,12 @@ function wp_version_check() { 'local_package' => isset( $wp_local_package ) ? $wp_local_package : '', 'blogs' => $num_blogs, 'users' => $user_count, - 'multisite_enabled' => $multisite_enabled + 'multisite_enabled' => $multisite_enabled, ); + if ( $extra_stats ) + $query = array_merge( $query, $extra_stats ); + $url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' ); if ( wp_http_supports( array( 'ssl' ) ) ) $url = set_url_scheme( $url, 'https' ); @@ -542,7 +546,7 @@ if ( ( ! is_main_site() && ! is_network_admin() ) || ( defined( 'DOING_AJAX' ) & add_action( 'admin_init', '_maybe_update_core' ); add_action( 'wp_version_check', 'wp_version_check' ); -add_action( 'upgrader_process_complete', 'wp_version_check' ); +add_action( 'upgrader_process_complete', 'wp_version_check', 10, 0 ); add_action( 'load-plugins.php', 'wp_update_plugins' ); add_action( 'load-update.php', 'wp_update_plugins' );