Ticket #11869: ajax_upgrade_works.diff
File ajax_upgrade_works.diff, 8.6 KB (added by , 15 years ago) |
---|
-
wp-admin/admin-ajax.php
1422 1422 update_post_meta( $link_id, '_menu_item_url', $link_url ); 1423 1423 1424 1424 die( json_encode($link_id) ); 1425 case 'wpms-upgrade-site': 1426 if ( is_multisite() && ! current_user_can( 'manage_network' ) ) 1427 die( '-1' ); 1428 1429 $site_id = intval( $_POST['site_id'] ); 1430 $site_url = esc_url_raw( $_POST['site_url'] ); 1431 1432 // Perform a request to update the site 1433 $response = wp_remote_get( trailingslashit( $site_url ) . "wp-admin/upgrade.php?step=1", array( 'timeout' => 120, 'httpversion' => '1.1' ) ); 1434 1435 if ( !is_wp_error( $response ) ) 1436 $result = '1'; 1437 else 1438 $result = '0'; 1439 1440 do_action( 'after_mu_upgrade', $response ); 1441 do_action( 'wpmu_upgrade_site', $site_id ); 1442 1443 die( $result ); 1444 break; 1425 1445 default : 1426 1446 do_action( 'wp_ajax_' . $_POST['action'] ); 1427 1447 die('0'); -
wp-admin/ms-upgrade-network.php
10 10 require_once('admin.php'); 11 11 12 12 if ( !is_multisite() ) 13 wp_die( __( 'Multisite support is not enabled.') );13 wp_die( __( 'Multisite support is not enabled.' ) ); 14 14 15 require_once( ABSPATH . WPINC . '/http.php' ); 15 if ( ! current_user_can( 'manage_network' ) ) 16 wp_die( __( 'You do not have permission to access this page.' ) ); 16 17 17 $title = __( 'Update Network');18 $title = __( 'Update Network' ); 18 19 $parent_file = 'ms-admin.php'; 19 20 require_once('admin-header.php'); 20 21 21 if ( ! current_user_can( 'manage_network' ) )22 wp_die( __('You do not have permission to access this page.') );23 24 22 echo '<div class="wrap">'; 25 23 screen_icon(); 26 24 echo '<h2>'.__('Update Network').'</h2>'; … … 28 26 $action = isset($_GET['action']) ? $_GET['action'] : 'show'; 29 27 30 28 switch ( $action ) { 31 case "upgrade": 32 $n = ( isset($_GET['n']) ) ? intval($_GET['n']) : 0; 29 case 'upgrade': 30 // Get all the blogs of the site. 31 $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 ); 32 $total = count( $blogs ); 33 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>"; 34 // Feedback 35 echo '<div id="message" class="updated">'; 36 echo '<p><strong>Updating sites <span id="update_site_count">0</span> of '. $total .'</strong></p>'; 37 echo '</div>'; 38 39 echo '<ul id="updating">'; 45 40 foreach ( (array) $blogs as $details ) { 46 if ( $details['spam'] == 0 && $details['deleted'] == 0 && $details['archived'] == 0 ) {47 41 $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' ] ); 54 } 42 echo '<li class="hidden" id="site-id-'. $details['blog_id'] .'" value="'. $details['blog_id'] .'"><span class="site_url">'. $siteurl .'</span> <strong class="status"></strong> <a href="#retry" class="button hidden">retry</a></li>' . "\n"; 55 43 } 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&n=<?php echo ($n + 5) ?>"><?php _e("Next Sites"); ?></a></p> 44 echo '</ul>'; 45 echo '<p id="alldone"></p>'; 46 ?> 58 47 <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; 48 jQuery(document).ready(function(){ 49 // Get all mu sites 50 var sites = jQuery('#updating li'); 51 52 // Number of concurrent sites to perform the upgrade 53 var num = 5; 54 var offset = 0; 55 56 // number for successful, error and total sites 57 var e = 0; 58 var s = 0; 59 var t = <?php echo $total; ?>; 60 61 // array for queue 62 var sites_queue =[]; 63 64 // Run the upgrade script 65 wpms_get_sites_to_update( offset, num ); 66 67 function wpms_get_sites_to_update( offset, num ) { 68 for ( var i = offset; i < num; i++ ) { 69 if ( undefined == sites[i] ) // sites[i] doesn't exists 70 break; 71 72 if ( '-1' != jQuery.inArray(sites[i], sites_queue) ) // duplicate 73 break; 74 75 // set sites[i] it into an array to avoid duplicates 76 sites_queue.push( sites[i] ); 77 78 var site_id = sites[i].value; 79 var site_url = jQuery( '#site-id-' + site_id + ' .site_url' ).text(); 80 81 // Update the site status. 82 jQuery( '#site-id-' + site_id + ' .status' ).text('<?php echo esc_js( __( 'updating...' ) );?>'); 83 84 // update counting 85 var c = jQuery('span#update_site_count'); 86 c.text( parseInt( c.text() ) + 1 ); 87 88 // Show the site. 89 jQuery( '#site-id-' + site_id ).removeClass('hidden'); 90 91 // update the offset 92 offset = num; 93 94 // Perform the upgrade 95 wpms_upgrade_site( site_id, site_url, offset ); 96 }; 97 } 98 99 jQuery('#updating li a.button').click(function() { 100 // get site_id for retry 101 var site_id = jQuery(this).parent().get(0).value; 102 var site_url = jQuery( '#site-id-' + site_id + ' .site_url' ).text(); 103 104 // update the site status 105 jQuery( '#site-id-' + site_id + ' .status' ).text('<?php echo esc_js( __( 'updating...' ) );?>'); 106 107 // remove retry button 108 jQuery('#site-id-' + site_id).find('.button').addClass('hidden'); 109 110 // update error count 111 e = e - 1; 112 113 // next try 114 wpms_upgrade_site( site_id, site_url, null ); 115 }) 116 117 function wpms_upgrade_site( site_id, site_url, offset ) { 118 params = { 119 action: 'wpms-upgrade-site', 120 site_id: site_id, 121 site_url: site_url, 122 }; 123 124 jQuery.post( ajaxurl, params, function(response) { 125 126 if ( '1' == response ) { 127 // Update the site status 128 jQuery('#site-id-' + site_id).find('.status').html( '<?php echo esc_js( __( 'Successfully updated!' ) );?>' ); 129 130 // update successful count 131 s = s + 1; 132 } else { 133 // Update the site status 134 jQuery('#site-id-' + site_id).find('.status').html( '<?php echo esc_js( __( 'Update failed.' ) );?>' ); 135 136 // show retry button 137 jQuery('#site-id-' + site_id).find('.button').removeClass('hidden'); 138 139 // update error count 140 e = e + 1; 141 }; 142 // Update the status 143 if ( s == t ) 144 jQuery('div#message p strong').html( '<?php echo esc_js( __( 'All sites successfully updated!' ) );?>'); 145 else if ( (s + e) == t) 146 jQuery('div#message p strong').html( s + ' sites successfully updated and ' + e + ' updates failed!'); // translation ? 147 148 // next sites 149 if ( null != offset ) { 150 num = num + 5; 151 wpms_get_sites_to_update( offset, num ); 152 } 153 154 }, 'json'); 155 } 156 }); 157 </script> 158 <?php 159 break; 160 67 161 case 'show': 68 162 default: 69 ?><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>70 <p><a class="button" href="ms-upgrade-network.php?action=upgrade"><?php _e( "Update Network"); ?></a></p><?php163 ?><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> 164 <p><a class="button" href="ms-upgrade-network.php?action=upgrade"><?php _e( 'Update Network' ); ?></a></p><?php 71 165 do_action( 'wpmu_upgrade_page' ); 72 166 break; 73 167 } 74 ?> 75 </div> 168 echo '</div>'; 76 169 77 <?phpinclude('admin-footer.php'); ?>170 include('admin-footer.php'); ?>