Make WordPress Core

Ticket #11869: ajax_upgrade_script_incomplete.diff

File ajax_upgrade_script_incomplete.diff, 5.9 KB (added by ptahdunbar, 15 years ago)
  • wp-admin/admin-ajax.php

     
    14221422        update_post_meta( $link_id, '_menu_item_url', $link_url );
    14231423
    14241424        die( json_encode($link_id) );
     1425case 'wpms-upgrade-site':
     1426        $site_id = intval( $_POST['site_id'] );
     1427        $site_url = esc_url_raw( $_POST['site_url'] );
     1428
     1429        // die(json_encode( array($site_id, $site_url) )); // debug
     1430
     1431        // Perform a request to update the site
     1432        $response = wp_remote_get( trailingslashit( $site_url ) . "wp-admin/upgrade.php?step=1", array( 'timeout' => 120, 'httpversion' => '1.1' ) );
     1433
     1434        if ( !is_wp_error( $response ) )
     1435                $result = '1';
     1436        else
     1437                $result = '-1';
     1438
     1439        do_action( 'after_mu_upgrade', $response );
     1440        do_action( 'wpmu_upgrade_site', $site_id );
     1441
     1442        die( $result );
     1443        break;
    14251444default :
    14261445        do_action( 'wp_ajax_' . $_POST['action'] );
    14271446        die('0');
  • wp-admin/ms-upgrade-network.php

     
    2828$action = isset($_GET['action']) ? $_GET['action'] : 'show';
    2929
    3030switch ( $action ) {
    31         case "upgrade":
    32                 $n = ( isset($_GET['n']) ) ? intval($_GET['n']) : 0;
    33 
    34                 if ( $n < 5 ) {
    35                         global $wp_db_version;
    36                         update_site_option( 'wpmu_upgrade_site', $wp_db_version );
    37                 }
    38 
    39                 $blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );
    40                 if ( empty( $blogs ) ) {
    41                         echo '<p>' . __( 'All done!' ) . '</p>';
    42                         break;
    43                 }
    44                 echo "<ul>";
     31        case 'upgrade':         
     32                // Get all the blogs of the site.
     33                $blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC", ARRAY_A );
     34               
     35                // Feedback
     36                echo '<div id="message" class="updated">';
     37                echo '<p><strong>Updating sites <span id="update_site_count">1</span> of '. count($blogs) .'</strong></p>';
     38                echo '</div>';
     39               
     40                echo '<ul id="updating">';
    4541                foreach ( (array) $blogs as $details ) {
    4642                        if ( $details['spam'] == 0 && $details['deleted'] == 0 && $details['archived'] == 0 ) {
    4743                                $siteurl = get_blog_option( $details['blog_id'], 'siteurl' );
    48                                 echo "<li>$siteurl</li>";
    49                                 $response = wp_remote_get( trailingslashit( $siteurl ) . "wp-admin/upgrade.php?step=1", array( 'timeout' => 120, 'httpversion' => '1.1' ) );
    50                                 if ( is_wp_error( $response ) )
    51                                         wp_die( "<strong>Warning!</strong> Problem updating {$siteurl}. Your server may not be able to connect to sites running on it.<br /> Error message: <em>" . $response->get_error_message() ."</em>" );
    52                                 do_action( 'after_mu_upgrade', $response );
    53                                 do_action( 'wpmu_upgrade_site', $details[ 'blog_id' ] );
     44                                echo '<li class="hidden" id="site-id-'. $details['blog_id'] .'" value="'. $details['blog_id'] .'"><span class="site_url">'. $siteurl .'</span> <strong class="status"></strong></li>';
    5445                        }
    5546                }
    56                 echo "</ul>";
    57                 ?><p><?php _e("If your browser doesn't start loading the next page automatically click this link:"); ?> <a class="button" href="ms-upgrade-network.php?action=upgrade&amp;n=<?php echo ($n + 5) ?>"><?php _e("Next Sites"); ?></a></p>
     47                echo '</ul>';
     48                echo '<p id="alldone"></p>';
     49                ?>
    5850                <script type='text/javascript'>
    59                 <!--
    60                 function nextpage() {
    61                         location.href = "ms-upgrade-network.php?action=upgrade&n=<?php echo ($n + 5) ?>";
    62                 }
    63                 setTimeout( "nextpage()", 250 );
    64                 //-->
    65                 </script><?php
    66         break;
     51                        <!--
     52                        jQuery(document).ready(function(){                             
     53                                // Get all mu sites
     54                                var sites = jQuery('#updating li');
     55                               
     56                                // Number of concurrent sites to perform the upgrade
     57                                var num = 5;
     58                                var offset = 0;
     59                               
     60                                // Run the upgrade script
     61                                wpms_get_sites_to_update( offset, num );
     62                               
     63                                function wpms_get_sites_to_update( offset, num ) {                                     
     64                                        for ( var i = offset; i <= num; i++ ) {
     65                                                console.log(  undefined == sites[i] );
     66                                               
     67                                                // console.log(sites[i]);
     68                                                var site_id  = sites[i].value;
     69                                                var site_url = jQuery( '#site-id-' + site_id + ' .site_url' ).text();
     70                                               
     71                                                // Update the site status.
     72                                                jQuery( '#site-id-' + site_id + ' .status' ).text('updating...');
     73
     74                                                // Show the site.
     75                                                jQuery( '#site-id-' + site_id ).removeClass('hidden');
     76                                               
     77                                                // update the offset
     78                                                offset = num;
     79                                               
     80                                                // Perform the upgrade
     81                                                wpms_upgrade_site( site_id, site_url, offset );
     82                                        };
     83                                }
     84                               
     85                                function wpms_upgrade_site( site_id, site_url, offset ) {                                       
     86                                        params = {
     87                                                action: 'wpms-upgrade-site',
     88                                                site_id: site_id,
     89                                                site_url: site_url,
     90                                        };
     91                                       
     92                                        wpms_get_sites_to_update( offset, num + num );
     93                                        // return;
     94                                        // wpms_get_sites_to_update( num );
     95                                       
     96                                        // save the link
     97                                        /*
     98                                        jQuery.post( ajaxurl, params, function(response) {
     99                                                console.log(response);
     100                                               
     101                                                if ( '1' == response ) {
     102                                                        // Update the site status
     103                                                        jQuery('#site-id-' + site_id).find('.status').html( 'successfully updated!' );
     104                                                } else {
     105                                                        // Update the site status
     106                                                        jQuery('#site-id-' + site_id).find('.status').html( 'update failed. <a href="#" class="button">retry</a>' );
     107                                                };
     108                                               
     109                                                num = num + num;
     110                                                wpms_get_sites_to_update( num );
     111                                        }, 'json');
     112                                        */
     113                                }
     114                        });
     115                       
     116                        //-->
     117                </script>
     118                <?php   
     119                break;
     120               
    67121        case 'show':
    68122        default:
    69123                ?><p><?php _e("You can update all the sites on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update."); ?></p>
     
    71125                do_action( 'wpmu_upgrade_page' );
    72126        break;
    73127}
    74 ?>
    75 </div>
     128echo '</div>';
    76129
    77 <?php include('admin-footer.php'); ?>
     130include('admin-footer.php'); ?>
     131 No newline at end of file