WordPress.org

Plugin Directory

Changeset 629846


Ignore:
Timestamp:
11/25/12 23:06:32 (17 months ago)
Author:
pento
Message:

Added retry limits on updates

Location:
automatic-updater/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • automatic-updater/trunk/admin.php

    r628514 r629846  
    9292?> 
    9393    <br> 
     94    <h3><?php esc_html_e( 'Retries', 'automatic-updater' ); ?></h3> 
     95    <p><?php esc_html_e( 'To avoid updating when something is broken, Automatic Updater can limit the number of times it will attempt to update WordPress Core, a plugin or a theme. If, for example, a plugin update reaches this limit, Automatic Updater will stop trying to update it until you manually install the update, or a new version is released.', 'automatic-updater' ); ?></p> 
     96    <p><label for="retries-limit"><?php esc_html_e( 'Retries Limit', 'automatic-updater' ); ?>:</label> <input type="number" step="1" name="retries-limit" id="retries-limit" class="small-text" value="<?php echo esc_attr( $options['retries-limit'] ); ?>"></p> 
     97 
     98    <br> 
    9499    <h3><?php esc_html_e( 'SVN Support', 'automatic-updater' ); ?></h3> 
    95100    <p><?php echo wp_kses( __( "It looks like you're running an SVN version of WordPress, that's cool! Automatic Updater can run <tt>svn up</tt> once an hour, to keep you up-to-date. For safety, enabling this option will disable the normal WordPress core updates.", 'automatic-updater' ), array( 'tt' => array() ) ); ?></p> 
     
    140145    } 
    141146 
    142     $top_options = array( 'override-email' ); 
     147    $top_options = array( 'override-email', 'retries-limit' ); 
    143148    foreach ( $top_options as $option ) 
    144149        $options[$option] = $_REQUEST[$option]; 
  • automatic-updater/trunk/automatic-updater.php

    r628760 r629846  
    5858                                'themes' => false, 
    5959                            ), 
     60                    'retries-limit' => 3, 
     61                    'tries' => array( 
     62                                'core' => array( 
     63                                            'version' => 0, 
     64                                            'tries' => 0, 
     65                                ), 
     66                                'plugins' => array(), 
     67                                'themes' => array(), 
     68                            ), 
    6069                    'svn' => false, 
    6170                    'debug' => false, 
     
    94103    if ( ! array_key_exists( 'disable-email', $options ) ) { 
    95104        $options['disable-email'] = false; 
     105        update_option( 'automatic-updater', $options ); 
     106    } 
     107 
     108    // Ability to limit retries added in version 0.8 
     109    if ( ! array_key_exists( 'retries-limit', $options ) ) { 
     110        $options['retries-limit'] = 3; 
     111        $option['tries'] = array( 
     112                                'core' => array( 
     113                                            'version' => 0, 
     114                                            'tries' => 0, 
     115                                ), 
     116                                'plugins' => array(), 
     117                                'themes' => array(), 
     118                            ); 
    96119        update_option( 'automatic-updater', $options ); 
    97120    } 
     
    143166        return; 
    144167 
    145     $options = get_option( 'automatic-updater', array() ); 
     168    $options = get_option( 'automatic-updater' ); 
    146169    if ( $options['svn'] ) 
    147170        return; 
     
    166189        return; 
    167190 
     191    // Check that we haven't failed to upgrade to the updated version in the past 
     192    if ( version_compare( $update->current, $options['retries']['core']['version'], '>=' ) && $options['retries']['core']['tries'] >= $option['retries-limit'] ) 
     193        return; 
     194 
    168195    $old_version = $GLOBALS['wp_version']; 
    169196 
     
    178205 
    179206        $options['next-development-update'] = strtotime( '+24 hours' ); 
    180         update_option( 'automatic-updater', $options ); 
    181207    } 
    182208 
     
    184210 
    185211    do_action( 'auto_updater_before_update', 'core' ); 
     212 
     213    $upgrade_failed = false; 
    186214 
    187215    $skin = new Auto_Updater_Skin(); 
     
    192220 
    193221    if ( is_wp_error( $result ) ) { 
     222        if ( $options['tries']['core']['version'] != $update->current ) 
     223            $options['tries']['core']['version'] = $update->current; 
     224 
     225        $options['tries']['core']['tries']++; 
     226 
     227        $upgrade_failed = true; 
     228 
    194229        $message = esc_html__( "While trying to upgrade WordPress, we ran into the following error:", 'automatic-updater' ); 
    195230        $message .= '<br><br>' . $result->get_error_message() . '<br><br>'; 
    196         $message .= esc_html__( "We're sorry it didn't work out. Please try upgrading manually, instead.", 'automatic-updater' ); 
     231        $message .= sprintf( esc_html__( 'We\'re sorry it didn\'t work out. Please try upgrading manually, instead. This is attempt %1$d of %2$d.', 'automatic-updater' ), 
     232                        $options['tries']['core']['tries'], 
     233                        $option['retries-limit'] ); 
    197234    } 
    198235    else if( 'development' == $update->response ) { 
    199236        $message = esc_html__( "We've successfully upgraded WordPress to the latest nightly build!", 'automatic-updater' ); 
    200237        $message .= '<br><br>' . esc_html__( 'Have fun!', 'automatic-updater' ); 
     238 
     239        $options['tries']['core']['version'] = 0; 
     240        $options['tries']['core']['tries'] = 0; 
    201241    } 
    202242    else { 
    203243        $message = sprintf( esc_html__( 'We\'ve successfully upgraded WordPress from version %1$s to version %2$s!', 'automatic-updater' ), $old_version, $update->current ); 
    204244        $message .= '<br><br>' . esc_html__( 'Have fun!', 'automatic-updater' ); 
     245 
     246        $options['tries']['core']['version'] = 0; 
     247        $options['tries']['core']['tries'] = 0; 
    205248    } 
    206249 
     
    209252    $debug = join( '<br>', $skin->messages ); 
    210253 
    211     auto_updater_notification( $message, $debug ); 
     254    update_option( 'automatic-updater', $options ); 
     255 
     256    auto_updater_notification( $message, $debug, $upgrade_failed ); 
    212257 
    213258    wp_version_check(); 
     
    226271    include_once( dirname( __FILE__ ) . '/updater-skin.php' ); 
    227272 
     273    $options = get_option( 'automatic-updater' ); 
     274 
    228275    $plugins = apply_filters( 'auto_updater_plugin_updates', get_plugin_updates() ); 
    229276 
    230     // Remove any plugins from the list that may've already been updated 
    231277    foreach ( $plugins as $id => $plugin ) { 
     278        // Remove any plugins from the list that may've already been updated 
    232279        if ( version_compare( $plugin->Version, $plugin->update->new_version, '>=' ) ) 
    233280            unset( $plugins[$id] ); 
     281 
     282        // Remove any plugins that have failed to upgrade 
     283        if ( ! empty( $options['retries']['plugins'][$id] ) ) { 
     284            // If there's a new version of a failed plugin, we should give it another go. 
     285            if ( $options['retries']['plugins'][$id]['version'] != $plugin->update->new_version ) 
     286                unset( $options['retries']['plugins'][$id] ); 
     287            // If the plugin has already had it's chance, move on. 
     288            else if ($options['retries']['plugins'][$id]['tries'] > $options['retries-limit'] ) 
     289                unset( $plugins[$id] ); 
     290        } 
    234291    } 
    235292 
     
    250307    $message .= '<br><br>'; 
    251308 
     309    $upgrade_failed = false; 
     310 
    252311    foreach ( $plugins as $id => $plugin ) { 
    253312        if ( is_wp_error( $result[$id] ) ) { 
    254             /* translators: First argument is the plugin url, second argument is the Plugin name, third argument is the error encountered while upgrading */ 
    255             $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this plugin: %3$s', 'automatic-updater' ), 
     313            if ( empty( $options['retries']['plugins'][$id] ) ) 
     314                $options['retries']['plugins'][$id] = array( 
     315                                                        'tries' => 1, 
     316                                                        'version' => $plugin->update->new_version, 
     317                                                    ); 
     318            else 
     319                $options['retries']['plugins'][$id]['tries']++; 
     320 
     321            $upgrade_failed = true; 
     322 
     323            /* translators: First argument is the plugin url, second argument is the Plugin name, third argument is the error encountered while upgrading. The fourth and fifth arguments refer to how many retries we've had at installing this plugin. */ 
     324            $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this plugin: %3$s (Attempt %4$d of %5$d)', 'automatic-updater' ), 
    256325                                        $plugin->update->url, 
    257326                                        $plugin->Name, 
    258                                         $result[$id]->get_error_message() ), array( 'a' => array( 'href' => array() ) ) ); 
     327                                        $result[$id]->get_error_message(), 
     328                                        $options['retries']['plugins'][$id]['tries'], 
     329                                        $options['retries-limit'] ),  
     330                                array( 'a' => array( 'href' => array() ) ) ); 
    259331        } 
    260332        else { 
     
    265337                                        $plugin->Version, 
    266338                                        $plugin->update->new_version ), array( 'a' => array( 'href' => array() ) ) ); 
     339 
     340            if ( ! empty( $options['retries']['plugins'][$id] ) ) 
     341                unset( $options['retries']['plugins'][$id] ); 
    267342        } 
    268343 
     
    273348 
    274349    $debug = join( '<br>', $skin->messages ); 
    275  
    276     auto_updater_notification( $message, $debug ); 
     350     
     351    update_option( 'automatic-updater', $options ); 
     352 
     353    auto_updater_notification( $message, $debug, $upgrade_failed ); 
    277354 
    278355    wp_update_plugins(); 
     
    290367    include_once( dirname( __FILE__ ) . '/updater-skin.php' ); 
    291368 
     369    $options = get_option( 'automatic-updater' ); 
     370 
    292371    $themes = apply_filters( 'auto_updater_theme_updates', get_theme_updates() ); 
    293372 
    294     // Remove any themes from the list that may've already been updated 
    295373    foreach ( $themes as $id => $theme ) { 
     374        // Remove any themes from the list that may've already been updated 
    296375        if ( version_compare( $theme->Version, $theme->update['new_version'], '>=' ) ) 
    297376            unset( $themes[$id] ); 
     377 
     378        // Remove any themes that have failed to upgrade 
     379        if ( ! empty( $options['retries']['themes'][$id] ) ) { 
     380            // If there's a new version of a failed theme, we should give it another go. 
     381            if ( $options['retries']['themes'][$id]['version'] != $theme->update['new_version'] ) 
     382                unset( $options['retries']['themes'][$id] ); 
     383            // If the themes has already had it's chance, move on. 
     384            else if ($options['retries']['themes'][$id]['tries'] > $options['retries-limit'] ) 
     385                unset( $themes[$id] ); 
     386        } 
    298387    } 
    299388 
     
    314403    $message .= '<br><br>'; 
    315404 
     405    $upgrade_failed = false; 
     406 
    316407    foreach ( $themes as $id => $theme ) { 
    317408        if ( is_wp_error( $result[$id] ) ) { 
    318             /* translators: First argument is the theme URL, second argument is the Theme name, third argument is the error encountered while upgrading */ 
    319             $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this theme: %3$s', 'automatic-updater' ), 
     409            if ( empty( $options['retries']['themes'][$id] ) ) 
     410                $options['retries']['themes'][$id] = array( 
     411                                                        'tries' => 1, 
     412                                                        'version' => $themes->update['new_version'], 
     413                                                    ); 
     414            else 
     415                $options['retries']['themes'][$id]['tries']++; 
     416 
     417            $upgrade_failed = true; 
     418 
     419            /* translators: First argument is the theme URL, second argument is the Theme name, third argument is the error encountered while upgrading. The fourth and fifth arguments refer to how many retries we've had at installing this theme. */ 
     420            $message .= wp_kses( sprintf( __( '<a href="%1$s">%2$s</a>: We encounted an error upgrading this theme: %3$s (Attempt %4$d of %5$d)', 'automatic-updater' ), 
    320421                                        $theme->update['url'], 
    321422                                        $theme->name, 
    322                                         $result[$id]->get_error_message() ), array( 'a' => array( 'href' => array() ) ) ); 
     423                                        $result[$id]->get_error_message(), 
     424                                        $options['retries']['plugins'][$id]['tries'], 
     425                                        $options['retries-limit'] ), 
     426                                array( 'a' => array( 'href' => array() ) ) ); 
    323427        } 
    324428        else { 
     
    329433                                        $theme->version, 
    330434                                        $theme->update['new_version'] ), array( 'a' => array( 'href' => array() ) ) ); 
     435 
     436            if ( ! empty( $options['retries']['themes'][$id] ) ) 
     437                unset( $options['retries']['themes'][$id] ); 
    331438        } 
    332439 
     
    338445    $debug = join( '<br>', $skin->messages ); 
    339446 
    340     auto_updater_notification( $message, $debug ); 
     447    update_option( 'automatic-updater', $options ); 
     448 
     449    auto_updater_notification( $message, $debug, $upgrade_failed ); 
    341450 
    342451    wp_update_themes(); 
     
    373482add_action( 'auto_updater_svn_event', 'auto_updater_svn' ); 
    374483 
    375 function auto_updater_notification( $info = '', $debug = '' ) { 
    376     $options = get_option( 'automatic-updater', array() ); 
     484function auto_updater_notification( $info = '', $debug = '', $upgrade_failed = false ) { 
     485    $options = get_option( 'automatic-updater' ); 
    377486 
    378487    if ( $options['disable-email'] ) 
     
    394503 
    395504    $message .= '<br>'; 
     505 
     506    if ( $upgrade_failed ) { 
     507        $message .= esc_html__( 'It looks like something went wrong during the update. Note that, if Automatic Updater continues to encounter problems, it will stop trying to do this update, and will not try again until after you manually update.', 'automatic-updater' ); 
     508        $message .= '<br><br>'; 
     509    } 
     510 
    396511    $message .= esc_html__( 'Thanks for using the Automatic Updater plugin!', 'automatic-updater' ); 
    397512 
  • automatic-updater/trunk/readme.txt

    r628763 r629846  
    4343 
    4444== Changelog == 
     45 
     46= 0.8 = 
     47* ADDED: Retry limits, so broken updates won't keep trying to install 
    4548 
    4649= 0.7.2 = 
Note: See TracChangeset for help on using the changeset viewer.