From d5744d72dc91f76bdb14bad93bf3ee7203f07909 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Thu, 3 Apr 2014 04:03:09 +0000 Subject: [PATCH] Background Updates: Record plugin & theme update statistics like we do for core updates. Pass plugin/theme update objects into the Background updater for consistency with core & translations. Merges [27905] to the 3.7 branch. props dd32. fixes #27633. Built from https://develop.svn.wordpress.org/branches/3.7@27924 git-svn-id: http://core.svn.wordpress.org/branches/3.7@27754 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-upgrader.php | 32 ++++++++++++++++++------- wp-includes/update.php | 18 ++++++++++---- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 72314eae56..330f5ea055 100644 --- a/wp-admin/includes/class-wp-upgrader.php +++ b/wp-admin/includes/class-wp-upgrader.php @@ -1872,18 +1872,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; @@ -1895,7 +1898,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 */ @@ -1969,7 +1972,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 @@ -1980,8 +1983,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(); @@ -1996,8 +1999,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(); diff --git a/wp-includes/update.php b/wp-includes/update.php index 5d283ebd0e..756c593591 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -160,9 +160,10 @@ function wp_version_check( $extra_stats = array() ) { * @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') ) @@ -201,7 +202,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']; @@ -250,6 +251,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' ); @@ -291,9 +296,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' ) ) @@ -343,7 +349,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) ) @@ -390,6 +396,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' );