Background Updates: Record Plugin & Theme update statistics like we for for Core updates, Pass Plugin/Theme update objects into the Background updater for consistency with Core & Translations. See #27633

Built from https://develop.svn.wordpress.org/trunk@27905


git-svn-id: http://core.svn.wordpress.org/trunk@27736 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2014-04-02 13:05:15 +00:00
parent 12e182d929
commit 50a7503c2e
2 changed files with 38 additions and 12 deletions

View File

@ -1974,18 +1974,21 @@ class WP_Automatic_Updater {
if ( ! $this->should_update( $type, $item, $context ) )
return false;
$upgrader_item = $item;
switch ( $type ) {
case 'core':
$skin->feedback( __( 'Updating to WordPress %s' ), $item->version );
$item_name = sprintf( __( 'WordPress %s' ), $item->version );
break;
case 'theme':
$theme = wp_get_theme( $item );
$upgrader_item = $item->theme;
$theme = wp_get_theme( $upgrader_item );
$item_name = $theme->Get( 'Name' );
$skin->feedback( __( 'Updating theme: %s' ), $item_name );
break;
case 'plugin':
$plugin_data = get_plugin_data( $context . '/' . $item );
$upgrader_item = $item->plugin;
$plugin_data = get_plugin_data( $context . '/' . $upgrader_item );
$item_name = $plugin_data['Name'];
$skin->feedback( __( 'Updating plugin: %s' ), $item_name );
break;
@ -1997,7 +2000,7 @@ class WP_Automatic_Updater {
}
// Boom, This sites about to get a whole new splash of paint!
$upgrade_result = $upgrader->upgrade( $item, array(
$upgrade_result = $upgrader->upgrade( $upgrader_item, array(
'clear_update_cache' => false,
'pre_check_md5' => false, /* always use partial builds if possible for core updates */
'attempt_rollback' => true, /* only available for core updates */
@ -2071,7 +2074,7 @@ class WP_Automatic_Updater {
wp_update_plugins(); // Check for Plugin updates
$plugin_updates = get_site_transient( 'update_plugins' );
if ( $plugin_updates && !empty( $plugin_updates->response ) ) {
foreach ( array_keys( $plugin_updates->response ) as $plugin ) {
foreach ( $plugin_updates->response as $plugin ) {
$this->update( 'plugin', $plugin );
}
// Force refresh of plugin update information
@ -2082,8 +2085,8 @@ class WP_Automatic_Updater {
wp_update_themes(); // Check for Theme updates
$theme_updates = get_site_transient( 'update_themes' );
if ( $theme_updates && !empty( $theme_updates->response ) ) {
foreach ( array_keys( $theme_updates->response ) as $theme ) {
$this->update( 'theme', $theme );
foreach ( $theme_updates->response as $theme ) {
$this->update( 'theme', (object) $theme );
}
// Force refresh of theme update information
wp_clean_themes_cache();
@ -2098,8 +2101,21 @@ class WP_Automatic_Updater {
// Clean up, and check for any pending translations
// (Core_Upgrader checks for core updates)
wp_update_themes(); // Check for Theme updates
wp_update_plugins(); // Check for Plugin updates
$theme_stats = array();
if ( isset( $this->update_results['theme'] ) ) {
foreach ( $this->update_results['theme'] as $upgrade ) {
$theme_stats[ $upgrade->item->theme ] = ( true === $upgrade->result );
}
}
wp_update_themes( $theme_stats ); // Check for Theme updates
$plugin_stats = array();
if ( isset( $this->update_results['plugin'] ) ) {
foreach ( $this->update_results['plugin'] as $upgrade ) {
$plugin_stats[ $upgrade->item->plugin ] = ( true === $upgrade->result );
}
}
wp_update_plugins( $plugin_stats ); // Check for Plugin updates
// Finally, Process any new translations
$language_updates = wp_get_translation_updates();

View File

@ -166,9 +166,10 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) {
* @since 2.3.0
* @uses $wp_version Used to notify the WordPress version.
*
* @param array $extra_stats Extra statistics to report to the WordPress.org API.
* @return mixed Returns null if update is unsupported. Returns false if check is too soon.
*/
function wp_update_plugins() {
function wp_update_plugins( $extra_stats = array() ) {
include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
if ( defined('WP_INSTALLING') )
@ -207,7 +208,7 @@ function wp_update_plugins() {
$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
if ( $time_not_changed ) {
if ( $time_not_changed && ! $extra_stats ) {
$plugin_changed = false;
foreach ( $plugins as $file => $p ) {
$new_option->checked[ $file ] = $p['Version'];
@ -256,6 +257,10 @@ function wp_update_plugins() {
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
);
if ( $plugin_update_stats ) {
$options['body']['update_stats'] = json_encode( $extra_stats );
}
$url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/';
if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
$url = set_url_scheme( $url, 'https' );
@ -296,9 +301,10 @@ function wp_update_plugins() {
* @since 2.7.0
* @uses $wp_version Used to notify the WordPress version.
*
* @param array $extra_stats Extra statistics to report to the WordPress.org API.
* @return mixed Returns null if update is unsupported. Returns false if check is too soon.
*/
function wp_update_themes() {
function wp_update_themes( $extra_stats = array() ) {
include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
if ( defined( 'WP_INSTALLING' ) )
@ -348,7 +354,7 @@ function wp_update_themes() {
$time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
if ( $time_not_changed ) {
if ( $time_not_changed && ! $extra_stats ) {
$theme_changed = false;
foreach ( $checked as $slug => $v ) {
if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
@ -395,6 +401,10 @@ function wp_update_themes() {
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
);
if ( $theme_update_stats ) {
$options['body']['update_stats'] = json_encode( $extra_stats );
}
$url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
$url = set_url_scheme( $url, 'https' );