Changeset 25496 for trunk/src/wp-admin/includes/class-wp-upgrader.php
- Timestamp:
- 09/19/2013 08:45:06 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-upgrader.php
r25495 r25496 1184 1184 1185 1185 // 2: If we're running a newer version, that's a nope 1186 if ( version_compare( $wp_version, $offered_ver, '> =' ) )1186 if ( version_compare( $wp_version, $offered_ver, '>' ) ) 1187 1187 return false; 1188 1188 … … 1289 1289 class WP_Automatic_Upgrader { 1290 1290 1291 static $ skin;1291 static $upgrade_results = array(); 1292 1292 1293 1293 static function upgrader_disabled() { … … 1363 1363 1364 1364 // Checks to see if WP_Filesystem is setup to allow unattended upgrades 1365 static function can_auto_update( $context ) {1366 if ( ! self::$skin )1367 self::$skin = new Automatic_Upgrader_Skin();1368 return (bool) self::$skin->request_filesystem_credentials( false, $context );1365 static function can_auto_update( $context, $skin = false ) { 1366 if ( ! $skin ) 1367 $skin = new Automatic_Upgrader_Skin(); 1368 return (bool) $skin->request_filesystem_credentials( false, $context ); 1369 1369 } 1370 1370 1371 1371 static function upgrade( $type, $item ) { 1372 1372 1373 if ( ! self::$skin ) 1374 self::$skin = new Automatic_Upgrader_Skin(); 1373 $skin = new Automatic_Upgrader_Skin(); 1375 1374 1376 1375 switch ( $type ) { 1377 1376 case 'core': 1378 1377 // The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter 1379 add_filter( 'update_feedback', array( self::$skin, 'feedback' ) );1380 $upgrader = new Core_Upgrader( self::$skin );1378 add_filter( 'update_feedback', array( $skin, 'feedback' ) ); 1379 $upgrader = new Core_Upgrader( $skin ); 1381 1380 $context = ABSPATH; 1382 1381 break; 1383 1382 case 'plugin': 1384 $upgrader = new Plugin_Upgrader( self::$skin );1383 $upgrader = new Plugin_Upgrader( $skin ); 1385 1384 $context = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR 1386 1385 break; 1387 1386 case 'theme': 1388 $upgrader = new Theme_Upgrader( self::$skin );1387 $upgrader = new Theme_Upgrader( $skin ); 1389 1388 $context = get_theme_root( $item ); 1390 1389 break; … … 1392 1391 1393 1392 // Determine if we can perform this upgrade or not 1394 if ( ! self::should_auto_update( $type, $item, $context ) || ! self::can_auto_update( $context ) )1393 if ( ! self::should_auto_update( $type, $item, $context ) || ! self::can_auto_update( $context, $skin ) ) 1395 1394 return false; 1395 1396 switch ( $type ) { 1397 case 'core': 1398 $skin->feedback( __( 'Updating to WordPress %s' ), $item->version ); 1399 $item_name = sprintf( __( 'WordPress %s' ), $item->version ); 1400 break; 1401 case 'theme': 1402 $theme = wp_get_theme( $item ); 1403 $item_name = $theme->Get( 'Name' ); 1404 $skin->feedback( __( 'Updating Theme: %s' ), $item_name ); 1405 break; 1406 case 'plugin': 1407 $plugin_data = get_plugin_data( $context . '/' . $item ); 1408 $item_name = $plugin_data['Name']; 1409 $skin->feedback( __( 'Updating Plugin: %s' ), $item_name ); 1410 break; 1411 } 1396 1412 1397 1413 // Boom, This sites about to get a whole new splash of paint! … … 1403 1419 if ( 'core' == $type ) { 1404 1420 if ( is_wp_error( $upgrade_result ) ) { 1405 self::$skin->error( __( 'Installation Failed' ), $upgrade_result );1421 $skin->error( __( 'Installation Failed' ), $upgrade_result ); 1406 1422 } else { 1407 self::$skin->feedback( __( 'WordPress updated successfully' ) );1423 $skin->feedback( __( 'WordPress updated successfully' ) ); 1408 1424 } 1409 1425 } 1410 1426 1411 // Clear cache's and transients 1412 switch ( $type ) { 1413 case 'core': 1414 delete_site_transient( 'update_core' ); 1415 break; 1416 case 'theme': 1417 wp_clean_themes_cache(); 1418 break; 1419 case 'plugin': 1420 wp_clean_plugins_cache(); 1421 break; 1422 } 1423 1424 wp_mail( 1425 get_site_option( 'admin_email' ), 1426 __METHOD__, 1427 var_export( array( 1428 $upgrade_result, 1429 $upgrader, 1430 self::$skin, 1431 ), true ) 1427 self::$upgrade_results[ $type ][] = (object) array( 1428 'item' => $item, 1429 'result' => ! is_wp_error( $upgrade_result ) && $upgrade_result, 1430 'name' => $item_name, 1431 'messages' => $skin->get_upgrade_messages() 1432 1432 ); 1433 1433 … … 1477 1477 wp_version_check(); // Check for Core updates 1478 1478 $core_update = find_core_auto_update(); 1479 if ( $core_update ) 1479 if ( $core_update ) { 1480 1480 self::upgrade( 'core', $core_update ); 1481 delete_site_transient( 'update_core' ); 1482 } 1481 1483 1482 1484 // Cleanup, These won't trigger any updates this time due to the locking transient … … 1485 1487 wp_update_plugins(); // Check for Plugin updates 1486 1488 1489 self::send_email(); 1490 1487 1491 // Clear the lock 1488 1492 delete_site_option( $lock_name ); … … 1490 1494 } 1491 1495 1496 static function send_email() { 1497 1498 if ( empty( self::$upgrade_results ) ) 1499 return; 1500 1501 $upgrade_count = 0; 1502 foreach ( self::$upgrade_results as $type => $upgrades ) 1503 $upgrade_count += count( $upgrades ); 1504 1505 $subject = sprintf( '[%s] %s updates have finished', get_bloginfo( 'name' ), $upgrade_count ); 1506 1507 $body = ''; 1508 if ( isset( self::$upgrade_results['core'] ) ) { 1509 $result = self::$upgrade_results['core'][0]; 1510 if ( $result->result && ! is_wp_error( $result->result ) ) 1511 $body[] = sprintf( __( 'WordPress was successfully updated to %s' ), $result->name ); 1512 else 1513 $body[] = sprintf( __( 'WordPress unsuccessfully attempted to update to %s' ), $result->name ); 1514 } 1515 1516 // Plugins 1517 if ( isset( self::$upgrade_results['plugin'] ) ) { 1518 $success_plugins = wp_list_filter( self::$upgrade_results['plugin'], array( 'result' => true ) ); 1519 1520 if ( $success_plugins ) 1521 $body[] = sprintf( _n( 'The following plugin was successfully updated: %s', 'The following plugins were successfully updated: %s', count( $success_plugins ) ), implode( ', ', wp_list_pluck( $success_plugins, 'name' ) ) ); 1522 if ( $success_plugins != self::$upgrade_results['plugin'] ) { 1523 // Failed updates 1524 $failed_plugins = array(); 1525 foreach ( self::$upgrade_results['plugin'] as $plugin ) { 1526 if ( ! $plugin->result || is_wp_error( $plugin->result ) ) 1527 $failed_plugins[] = $plugin; 1528 } 1529 $body[] = sprintf( _n( 'The following plugin failed to successfully update: %s', 'The following plugins failed to successfully update: %s', count( $success_plugins ) ), implode( ', ', wp_list_pluck( $failed_plugins, 'name' ) ) ); 1530 } 1531 } 1532 1533 // Themes 1534 if ( isset( self::$upgrade_results['theme'] ) ) { 1535 $success_themes = wp_list_filter( self::$upgrade_results['theme'], array( 'result' => true ) ); 1536 1537 if ( $success_themes ) 1538 $body[] = sprintf( _n( 'The following theme was successfully updated: %s', 'The following themes were successfully updated: %s', count( $success_themes ) ), implode( ', ', wp_list_pluck( $success_themes, 'name' ) ) ); 1539 if ( $success_themes != self::$upgrade_results['theme'] ) { 1540 // Failed updates 1541 $failed_themes = array(); 1542 foreach ( self::$upgrade_results['theme'] as $theme ) { 1543 if ( ! $theme->result || is_wp_error( $theme->result ) ) 1544 $failed_themes[] = $theme; 1545 } 1546 $body[] = sprintf( _n( 'The following theme failed to successfully update: %s', 'The following themes failed to successfully update: %s', count( $failed_themes ) ), implode( ', ', wp_list_pluck( $failed_themes, 'name' ) ) ); 1547 } 1548 } 1549 1550 $body[] = ''; 1551 $body[] = __( 'Below is the upgrade logs for update performed' ); 1552 1553 foreach ( array( 'core', 'plugin', 'theme' ) as $type ) { 1554 if ( ! isset( self::$upgrade_results[ $type ] ) ) 1555 continue; 1556 foreach ( self::$upgrade_results[ $type ] as $upgrade ) { 1557 $body[] = $upgrade->name; 1558 $body[] = str_repeat( '=', strlen( $upgrade->name ) ); 1559 foreach ( $upgrade->messages as $message ) 1560 $body[] = " " . html_entity_decode( $message ); 1561 $body[] = ''; 1562 } 1563 } 1564 1565 //echo "<h1>$subject</h1>"; 1566 //echo '<pre>' . implode( "\n", $body ) . '</pre>'; 1567 1568 wp_mail( 1569 get_site_option( 'admin_email' ), 1570 $subject, 1571 implode( "\n", $body ) 1572 ); 1573 } 1574 1492 1575 }
Note: See TracChangeset
for help on using the changeset viewer.