WordPress.org

Make WordPress Core

Changeset 25823


Ignore:
Timestamp:
10/17/13 00:54:15 (4 years ago)
Author:
nacin
Message:

Make WP_Automatic_Upgrader a proper object that gets instantiated. Renames nearly all of its methods.

Also renames wp_auto_updates_maybe_update() to wp_maybe_auto_update().

see #22704.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r25822 r25823  
    15521552 
    15531553/** 
    1554  * WordPress Automatic Upgrader helper class 
     1554 * WordPress automatic background upgrader. 
    15551555 * 
    15561556 * @since 3.7.0 
     
    15581558class WP_Automatic_Upgrader { 
    15591559 
    1560     static $upgrade_results = array(); 
    1561  
    1562     static function upgrader_disabled() { 
    1563         // That's a no if you don't want files changes 
     1560    protected $update_results = array(); 
     1561 
     1562    function is_disabled() { 
     1563        // Background updates are disabled if you don't want file changes. 
    15641564        if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) 
    15651565            return true; 
    15661566 
    1567         // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters 
    1568         if ( defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED ) 
    1569             return true; 
    1570  
    15711567        if ( defined( 'WP_INSTALLING' ) ) 
    15721568            return true; 
    15731569 
    1574         return apply_filters( 'auto_upgrader_disabled', false ); 
     1570        // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters. 
     1571        $disabled = defined( 'AUTOMATIC_UPDATES_DISABLED' ) && AUTOMATIC_UPDATES_DISABLED; 
     1572 
     1573        return apply_filters( 'auto_upgrader_disabled', $disabled ); 
    15751574    } 
    15761575 
     
    15781577     * Check for GIT/SVN checkouts. 
    15791578     */ 
    1580     static function is_vcs_checkout( $context ) { 
     1579    function is_vcs_checkout( $context ) { 
    15811580        $context_dirs = array( untrailingslashit( $context ) ); 
    15821581        if ( $context !== ABSPATH ) 
     
    16081607     * Tests to see if we can and should upgrade a specific item. 
    16091608     */ 
    1610     static function should_auto_update( $type, $item, $context ) { 
     1609    function should_upgrade( $type, $item, $context ) { 
     1610        if ( $this->is_disabled() ) 
     1611            return false; 
    16111612 
    16121613        // Checks to see if WP_Filesystem is set up to allow unattended upgrades. 
     
    16151616            return false; 
    16161617 
    1617         if ( self::upgrader_disabled() ) 
    1618             return false; 
    1619  
    1620         if ( self::is_vcs_checkout( $context ) ) 
     1618        if ( $this->is_vcs_checkout( $context ) ) 
    16211619            return false; 
    16221620 
     
    16581656    } 
    16591657 
    1660     static function upgrade( $type, $item ) { 
     1658    function upgrade( $type, $item ) { 
    16611659 
    16621660        $skin = new Automatic_Upgrader_Skin(); 
     
    16841682 
    16851683        // Determine whether we can and should perform this upgrade. 
    1686         if ( ! self::should_auto_update( $type, $item, $context ) ) 
     1684        if ( ! $this->should_upgrade( $type, $item, $context ) ) 
    16871685            return false; 
    16881686 
     
    17251723        } 
    17261724 
    1727         self::$upgrade_results[ $type ][] = (object) array( 
     1725        $this->update_results[ $type ][] = (object) array( 
    17281726            'item'     => $item, 
    17291727            'result'   => $upgrade_result, 
     
    17381736     * Kicks off a upgrade request for each item in the upgrade "queue" 
    17391737     */ 
    1740     static function perform_auto_updates() { 
    1741  
     1738    function run() { 
    17421739        $lock_name = 'auto_upgrader.lock'; 
    17431740        if ( get_site_option( $lock_name ) ) { 
     
    17631760        if ( $plugin_updates && !empty( $plugin_updates->response ) ) { 
    17641761            foreach ( array_keys( $plugin_updates->response ) as $plugin ) { 
    1765                 self::upgrade( 'plugin', $plugin ); 
     1762                $this->upgrade( 'plugin', $plugin ); 
    17661763            } 
    17671764            // Force refresh of plugin update information 
     
    17741771        if ( $theme_updates && !empty( $theme_updates->response ) ) { 
    17751772            foreach ( array_keys( $theme_updates->response ) as $theme ) { 
    1776                 self::upgrade( 'theme', $theme ); 
     1773                $this->upgrade( 'theme', $theme ); 
    17771774            } 
    17781775            // Force refresh of theme update information 
     
    17841781        $extra_update_stats = array(); 
    17851782        $core_update = find_core_auto_update(); 
     1783 
    17861784        if ( $core_update ) { 
    17871785            $start_time = time(); 
    1788             $core_update_result = self::upgrade( 'core', $core_update ); 
     1786 
     1787            $core_update_result = $this->upgrade( 'core', $core_update ); 
    17891788            delete_site_transient( 'update_core' ); 
     1789 
    17901790            $extra_update_stats['success'] = is_wp_error( $core_update_result ) ? $core_update_result->get_error_code() : true; 
    17911791            $extra_update_stats['error_data'] = is_wp_error( $core_update_result ) ? $core_update_result->get_error_data() : ''; 
     1792 
    17921793            if ( is_wp_error( $core_update_result ) && 'rollback_was_required' == $core_update_result->get_error_code() ) { 
    17931794                $rollback_data = $core_update_result->get_error_data(); 
     
    17971798                $extra_update_stats['rollback_data'] = is_wp_error( $rollback_data['rollback'] ) ? $rollback_data['rollback']->get_error_data() : ''; 
    17981799            } 
     1800 
    17991801            $extra_update_stats['fs_method'] = $GLOBALS['wp_filesystem']->method; 
    18001802            $extra_update_stats['fs_method_forced'] = defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ); 
     
    18121814        if ( $language_updates ) { 
    18131815            foreach ( $language_updates as $update ) { 
    1814                 self::upgrade( 'language', $update ); 
     1816                $this->upgrade( 'language', $update ); 
    18151817            } 
     1818 
    18161819            // Clear existing caches 
    18171820            wp_clean_plugins_cache(); 
     
    18241827        } 
    18251828 
    1826         /** 
    1827          * Filter whether to email an update summary to the site administrator. 
    1828          * 
    1829          * @since 3.7.0 
    1830          * 
    1831          * @param bool                         Whether or not email should be sent to administrator. Default true. 
    1832          * @param bool|array $core_update      An array of core update data, false otherwise. 
    1833          * @param object     $theme_updates    Object containing theme update properties. 
    1834          * @param object     $plugin_updates   Object containing plugin update properties. 
    1835          * @param array      $language_updates Array containing the Language updates available. 
    1836          * @param array      $upgrade_results  Array of the upgrade results keyed by upgrade type, and plugin/theme slug. 
    1837          */ 
    1838         if ( apply_filters( 'enable_auto_upgrade_email', true, $core_update, $theme_updates, $plugin_updates, $language_updates, self::$upgrade_results ) ) 
    1839             self::send_email(); 
     1829        $this->send_debug_email(); 
    18401830 
    18411831        // Clear the lock 
     
    18441834    } 
    18451835 
    1846     static function send_email() { 
    1847  
    1848         if ( empty( self::$upgrade_results ) ) 
     1836    function send_debug_email() { 
     1837 
     1838        if ( empty( $this->update_results ) ) 
    18491839            return; 
    18501840 
    18511841        $upgrade_count = 0; 
    1852         foreach ( self::$upgrade_results as $type => $upgrades ) 
     1842        foreach ( $this->update_results as $type => $upgrades ) 
    18531843            $upgrade_count += count( $upgrades ); 
    18541844 
     
    18591849 
    18601850        // Core 
    1861         if ( isset( self::$upgrade_results['core'] ) ) { 
    1862             $result = self::$upgrade_results['core'][0]; 
     1851        if ( isset( $this->update_results['core'] ) ) { 
     1852            $result = $this->update_results['core'][0]; 
    18631853            if ( $result->result && ! is_wp_error( $result->result ) ) { 
    18641854                $body[] = sprintf( 'SUCCESS: WordPress was successfully updated to %s', $result->name ); 
     
    18721862        // Plugins, Themes, Languages 
    18731863        foreach ( array( 'plugin', 'theme', 'language' ) as $type ) { 
    1874             if ( ! isset( self::$upgrade_results[ $type ] ) ) 
     1864            if ( ! isset( $this->update_results[ $type ] ) ) 
    18751865                continue; 
    1876             $success_items = wp_list_filter( self::$upgrade_results[ $type ], array( 'result' => true ) ); 
     1866            $success_items = wp_list_filter( $this->update_results[ $type ], array( 'result' => true ) ); 
    18771867            if ( $success_items ) { 
    18781868                $body[] = "The following {$type}s were successfully updated:"; 
     
    18801870                    $body[] = ' * SUCCESS: ' . $name; 
    18811871            } 
    1882             if ( $success_items != self::$upgrade_results[ $type ] ) { 
     1872            if ( $success_items != $this->update_results[ $type ] ) { 
    18831873                // Failed updates 
    18841874                $body[] = "The following {$type}s failed to update:"; 
    1885                 foreach ( self::$upgrade_results[ $type ] as $item ) { 
     1875                foreach ( $this->update_results[ $type ] as $item ) { 
    18861876                    if ( ! $item->result || is_wp_error( $item->result ) ) { 
    18871877                        $body[] = ' * FAILED: ' . $item->name; 
     
    19141904 
    19151905        foreach ( array( 'core', 'plugin', 'theme', 'language' ) as $type ) { 
    1916             if ( ! isset( self::$upgrade_results[ $type ] ) ) 
     1906            if ( ! isset( $this->update_results[ $type ] ) ) 
    19171907                continue; 
    1918             foreach ( self::$upgrade_results[ $type ] as $upgrade ) { 
     1908            foreach ( $this->update_results[ $type ] as $upgrade ) { 
    19191909                $body[] = $upgrade->name; 
    19201910                $body[] = str_repeat( '-', strlen( $upgrade->name ) ); 
  • trunk/src/wp-admin/includes/update.php

    r25810 r25823  
    7878 
    7979    $auto_update = false; 
     80    $upgrader = new WP_Automatic_Upgrader; 
    8081    foreach ( $updates->updates as $update ) { 
    8182        if ( 'autoupdate' != $update->response ) 
    8283            continue; 
    8384 
    84         if ( ! WP_Automatic_Upgrader::should_auto_update( 'core', $update, ABSPATH ) ) 
     85        if ( ! $upgrader->should_upgrade( 'core', $update, ABSPATH ) ) 
    8586            continue; 
    8687 
  • trunk/src/wp-admin/update-core.php

    r25820 r25823  
    149149        if ( wp_http_supports( 'ssl' ) ) { 
    150150            require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
     151            $upgrader = new WP_Automatic_Upgrader; 
    151152            $future_minor_update = (object) array( 
    152153                'current'       => $wp_version . '.1-update-core.php', 
     
    155156                'mysql_version' => $required_mysql_version, 
    156157            ); 
    157             $should_auto_update = WP_Automatic_Upgrader::should_auto_update( 'core', $future_minor_update, ABSPATH ); 
     158            $should_auto_update = $upgrader->should_upgrade( 'core', $future_minor_update, ABSPATH ); 
    158159            if ( $should_auto_update ) 
    159160                echo ' ' . __( 'Future security updates will be applied automatically.' ); 
     
    172173    if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) { 
    173174        require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
    174         if ( wp_http_supports( 'ssl' ) && WP_Automatic_Upgrader::should_auto_update( 'core', $updates[0], ABSPATH ) ) 
     175        $upgrader = new WP_Automatic_Upgrader; 
     176        if ( wp_http_supports( 'ssl' ) && $upgrader->should_upgrade( 'core', $updates[0], ABSPATH ) ) 
    175177            echo '<div class="updated inline"><p><strong>BETA TESTERS:</strong> This site is set up to install updates of future beta versions automatically.</p></div>'; 
    176178    } 
  • trunk/src/wp-includes/update.php

    r25810 r25823  
    407407 
    408408/** 
    409  * Cron entry which runs the WordPress Automatic Updates 
     409 * Performs WordPress automatic background updates. 
    410410 * 
    411411 * @since 3.7.0 
    412412 */ 
    413 function wp_auto_updates_maybe_update() { 
     413function wp_maybe_auto_update() { 
    414414    include_once ABSPATH . '/wp-admin/includes/admin.php'; 
    415415    include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php'; 
    416416 
    417     if ( WP_Automatic_Upgrader::upgrader_disabled() ) 
     417    $upgrader = new WP_Automatic_Upgrader; 
     418    if ( $upgrader->is_disabled() ) 
    418419        return; 
    419420 
    420     WP_Automatic_Upgrader::perform_auto_updates(); 
     421    $upgrader->run(); 
    421422} 
    422423 
     
    566567        wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); 
    567568 
    568     if ( !wp_next_scheduled( 'wp_auto_updates_maybe_update' ) && ! defined( 'WP_INSTALLING' ) ) 
    569         wp_schedule_event( time(), 'twicedaily', 'wp_auto_updates_maybe_update' ); 
    570  
     569    if ( !wp_next_scheduled( 'wp_maybe_auto_update' ) && ! defined( 'WP_INSTALLING' ) ) 
     570        wp_schedule_event( time(), 'twicedaily', 'wp_maybe_auto_update' ); 
    571571} 
    572572 
     
    592592add_action( 'upgrader_process_complete', 'wp_update_themes' ); 
    593593 
    594 // Automatic Updates - Cron callback 
    595 add_action( 'wp_auto_updates_maybe_update', 'wp_auto_updates_maybe_update' ); 
     594add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); 
    596595 
    597596add_action('init', 'wp_schedule_update_checks'); 
Note: See TracChangeset for help on using the changeset viewer.