Make WordPress Core

Changeset 25863


Ignore:
Timestamp:
10/22/2013 09:48:36 AM (11 years ago)
Author:
nacin
Message:

Updates: Saner stats and rollback handling. WP.org now collects basic stats on non-auto updates as they have been hugely informative.

props dd32 for initial patch.
fixes #25657.

File:
1 edited

Legend:

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

    r25861 r25863  
    13171317        global $wp_filesystem, $wp_version;
    13181318
     1319        $start_time = time();
     1320
    13191321        $defaults = array(
    13201322            'pre_check_md5'    => true,
     
    14031405                $rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) );
    14041406
    1405                 $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], array( 'rollback' => $rollback_result, 'update' => $result ) );
     1407                $original_result = $result;
     1408                $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 'update' => $original_result, 'rollback' => $rollback_result ) );
    14061409            }
    14071410        }
    14081411
    14091412        do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ) );
     1413
     1414        // Clear the current updates
     1415        delete_site_transient( 'update_core' );
     1416
     1417        if ( ! $parsed_args['do_rollback'] ) {
     1418            $stats = array(
     1419                'update_type'      => $current->response,
     1420                'success'          => true,
     1421                'fs_method'        => $wp_filesystem->method,
     1422                'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ),
     1423                'time_taken'       => time() - $start_time,
     1424                'attempted'        => $current->version,
     1425            );
     1426
     1427            if ( is_wp_error( $result ) ) {
     1428                $stats['success'] = false;
     1429                // Did a rollback occur?
     1430                if ( ! empty( $try_rollback ) ) {
     1431                    $stats['error_code'] = $original_result->get_error_code();
     1432                    $stats['error_data'] = $original_result->get_error_data();
     1433                    // Was the rollback successful? If not, collect its error too.
     1434                    $stats['rollback'] = ! is_wp_error( $rollback_result );
     1435                    if ( is_wp_error( $rollback_result ) ) {
     1436                        $stats['rollback_code'] = $rollback_result->get_error_code();
     1437                        $stats['rollback_data'] = $rollback_result->get_error_data();
     1438                    }
     1439                } else {
     1440                    $stats['error_code'] = $result->get_error_code();
     1441                    $stats['error_data'] = $result->get_error_data();
     1442                }
     1443            }
     1444
     1445            wp_version_check( $stats );
     1446        }
    14101447
    14111448        return $result;
     
    19071944        // Next, Process any core update
    19081945        wp_version_check(); // Check for Core updates
    1909         $extra_update_stats = array();
    19101946        $core_update = find_core_auto_update();
    19111947
    1912         if ( $core_update ) {
    1913             $start_time = time();
    1914 
    1915             $core_update_result = $this->update( 'core', $core_update );
    1916             delete_site_transient( 'update_core' );
    1917 
    1918             $extra_update_stats['success'] = is_wp_error( $core_update_result ) ? $core_update_result->get_error_code() : true;
    1919             $extra_update_stats['error_data'] = is_wp_error( $core_update_result ) ? $core_update_result->get_error_data() : '';
    1920 
    1921             if ( is_wp_error( $core_update_result ) && 'rollback_was_required' == $core_update_result->get_error_code() ) {
    1922                 $rollback_data = $core_update_result->get_error_data();
    1923                 $extra_update_stats['success'] = is_wp_error( $rollback_data['update'] ) ? $rollback_data['update']->get_error_code() : $rollback_data['update'];
    1924                 $extra_update_stats['error_data'] = is_wp_error( $rollback_data['update'] ) ? $rollback_data['update']->get_error_data() : '';
    1925                 $extra_update_stats['rollback'] = is_wp_error( $rollback_data['rollback'] ) ? $rollback_data['rollback']->get_error_code() : true; // If it's not a WP_Error, the rollback was successful.
    1926                 $extra_update_stats['rollback_data'] = is_wp_error( $rollback_data['rollback'] ) ? $rollback_data['rollback']->get_error_data() : '';
    1927             }
    1928 
    1929             $extra_update_stats['fs_method'] = $GLOBALS['wp_filesystem']->method;
    1930             $extra_update_stats['fs_method_forced'] = defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' );
    1931             $extra_update_stats['time_taken'] = ( time() - $start_time );
    1932             $extra_update_stats['attempted'] = $core_update->version;
    1933         }
    1934 
    1935         // Cleanup, and check for any pending translations
    1936         wp_version_check( $extra_update_stats );  // check for Core updates
     1948        if ( $core_update )
     1949            $this->update( 'core', $core_update );
     1950
     1951        // Clean up, and check for any pending translations
     1952        // (Core_Upgrader checks for core updates)
    19371953        wp_update_themes();  // Check for Theme updates
    19381954        wp_update_plugins(); // Check for Plugin updates
     
    20002016        if ( $error_code === 'disk_full' || false !== strpos( $error_code, '__copy_dir' ) ) {
    20012017            $critical = true;
    2002         } elseif ( $error_code === 'rollback_was_required' ) {
    2003             $error_data = $result->get_error_data();
    2004             if ( is_wp_error( $error_data['rollback'] ) )
    2005                 $critical = true;
     2018        } elseif ( $error_code === 'rollback_was_required' && is_wp_error( $result->get_error_data()->rollback ) ) {
     2019            // A rollback is only critical if it failed too.
     2020            $critical = true;
     2021            $rollback_result = $result->get_error_data()->rollback;
    20062022        } elseif ( false !== strpos( $error_code, 'do_rollback' ) ) {
    20072023            $critical = true;
     
    20092025
    20102026        if ( $critical ) {
    2011             update_site_option( 'auto_core_update_failed', array(
     2027            $critical_data = array(
    20122028                'attempted'  => $core_update->current,
    20132029                'current'    => $wp_version,
     
    20162032                'timestamp'  => time(),
    20172033                'critical'   => true,
    2018             ) );
     2034            );
     2035            if ( isset( $rollback_result ) ) {
     2036                $critical_data['rollback_code'] = $rollback_result->get_error_code();
     2037                $critical_data['rollback_data'] = $rollback_result->get_error_data();
     2038            }
     2039            update_site_option( 'auto_core_update_failed', $critical_data );
    20192040            $this->send_email( 'critical', $core_update, $result );
    20202041            return;
     
    21642185            $body .= __( 'We have some data that describes the error your site encountered.' );
    21652186            $body .= ' ' . __( 'Your hosting company, support forum volunteers, or a friendly developer may be able to use this information to help you:' );
    2166             $body .= "\n\n" . sprintf( __( "Error code: %s" ), $result->get_error_code() );
    2167             if ( $result->get_error_message() )
    2168                 $body .= "\n" . $result->get_error_message();
    2169             if ( $result->get_error_data() )
    2170                 $body .= "\n" . implode( ', ', (array) $result->get_error_data() );
     2187
     2188            // If we had a rollback and we're still critical, then the rollback failed too.
     2189            // Loop through all errors (the main WP_Error, the update result, the rollback result) for code, data, etc.
     2190            if ( 'rollback_was_required' == $result->get_error_code() )
     2191                $errors = array( $result, $result->get_error_data()->update, $result->get_error_data()->rollback );
     2192            else
     2193                $errors = array( $result );
     2194
     2195            foreach ( $errors as $error ) {
     2196                if ( ! is_wp_error( $error ) )
     2197                    continue;
     2198                $error_code = $error->get_error_code();
     2199                $body .= "\n\n" . sprintf( __( "Error code: %s" ), $error_code );
     2200                if ( 'rollback_was_required' == $error_code )
     2201                    continue;
     2202                if ( $error->get_error_message() )
     2203                    $body .= "\n" . $error->get_error_message();
     2204                $error_data = $error->get_error_data();
     2205                if ( $error_data )
     2206                    $body .= "\n" . implode( ', ', (array) $error_data );
     2207            }
    21712208            $body .= "\n";
    21722209        }
     
    22792316                    $body[] = "  " . html_entity_decode( str_replace( '…', '...', $message ) );
    22802317                if ( is_wp_error( $update->result ) ) {
    2281                     $body[] = '  Error: [' . $update->result->get_error_code() . '] ' . $update->result->get_error_message();
    2282                     if ( $update->result->get_error_data() )
    2283                         $body[] = '         ' . implode( ', ', (array) $update->result->get_error_data() );
     2318                    $results = array( 'update' => $update->result );
     2319                    // If we rolled back, we want to know an error that occurred then too.
     2320                    if ( 'rollback_was_required' === $update->result->get_error_code() )
     2321                        $results = (array) $update->result->get_error_data();
     2322                    foreach ( $results as $result_type => $result ) {
     2323                        if ( ! is_wp_error( $result ) )
     2324                            continue;
     2325                        $body[] = '  ' . ( 'rollback' === $result_type ? 'Rollback ' : '' ) . 'Error: [' . $result->get_error_code() . '] ' . $result->get_error_message();
     2326                        if ( $result->get_error_data() )
     2327                            $body[] = '         ' . implode( ', ', (array) $result->get_error_data() );
     2328                    }
    22842329                }
    22852330                $body[] = '';
Note: See TracChangeset for help on using the changeset viewer.