Advertisement
MarkdeScande

cli-ms-upgrade.php

Jan 3rd, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. <?php
  2. /**
  3. * WordPress Multisite upgrade script
  4. *
  5. * IMPORTANT: While a simple safeguard has been added to the script,
  6. * you'll want to add another layer that prevents this script from
  7. * being called via the browser.
  8. *
  9. * Usage:
  10. * 1) Place in the root of your install (or another place, but modify the wp-load.php path to match)
  11. * 2) Modify the $_SERVER['HTTP_HOST'] variable below
  12. * 3) > php cli-ms-upgrade.php
  13. *
  14. * @author Mo Jangda batmoo@gmail.com
  15. * @license GPL2
  16. */
  17.  
  18. // Modify this based on site domain
  19. $_SERVER['HTTP_HOST'] = 'bloglines.co.za';
  20.  
  21. // Script can only be called from command line
  22. if( ! defined( 'STDIN' ) )
  23. die( 'This script can only be called from the command line.' );
  24.  
  25. set_time_limit( 0 );
  26. ini_set( 'display_errors', 'off' );
  27. error_reporting(-1);
  28.  
  29. // Load WordPress Administration Bootstrap
  30. require_once( dirname( __FILE__ ) . '/wp-load.php' );
  31.  
  32. if ( ! function_exists( 'wp' ) )
  33. die( 'Couldn\'t load WordPress :(' );
  34.  
  35. // Kill if we're not running multisite
  36. if ( ! is_multisite() )
  37. die( __( 'Multisite is not enabled.' ) );
  38.  
  39. // Add the HTTP Utility class
  40. require_once( ABSPATH . WPINC . '/http.php' );
  41.  
  42. global $wp_db_version;
  43. update_site_option( 'wpmu_upgrade_site', $wp_db_version );
  44.  
  45. $upgrade_count = 0;
  46. $n = 0;
  47.  
  48. do {
  49. $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 );
  50.  
  51. foreach ( (array) $blogs as $details ) {
  52. $siteurl = get_blog_option( $details['blog_id'], 'siteurl' );
  53. echo "* $siteurl \n";
  54.  
  55. // Do the actual upgrade
  56. $response = wp_remote_get( trailingslashit( $siteurl ) . "wp-admin/upgrade.php?step=upgrade_db", array( 'timeout' => 120, 'httpversion' => '1.1' ) );
  57.  
  58. // TODO: Option to not die on fail
  59. if ( is_wp_error( $response ) ) {
  60. sprintf( __( '** Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>' ), $siteurl, $response->get_error_message() ) ;
  61. }
  62. else
  63. _e( "** Upgraded! \n\n" );
  64.  
  65. $upgrade_count++;
  66.  
  67. do_action( 'after_mu_upgrade', $response );
  68. do_action( 'wpmu_upgrade_site', $details[ 'blog_id' ] );
  69. }
  70.  
  71. $n += 5;
  72.  
  73. } while ( !empty( $blogs ) );
  74.  
  75. _e( sprintf( "All done! Upgraded %d site(s). \n", $upgrade_count ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement