<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[25568] trunk/src/wp-admin/includes/class-wp-upgrader.php: Language Packs: Integrate Language Packs into the Auto-upgrader.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/25568">25568</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2013-09-23 09:37:25 +0000 (Mon, 23 Sep 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Language Packs: Integrate Language Packs into the Auto-upgrader. See <a href="http://core.trac.wordpress.org/ticket/18200">#18200</a> See <a href="http://core.trac.wordpress.org/ticket/22704">#22704</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesclasswpupgraderphp">trunk/src/wp-admin/includes/class-wp-upgrader.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesclasswpupgraderphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-admin/includes/class-wp-upgrader.php (25567 => 25568)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-admin/includes/class-wp-upgrader.php        2013-09-23 04:15:41 UTC (rev 25567)
+++ trunk/src/wp-admin/includes/class-wp-upgrader.php   2013-09-23 09:37:25 UTC (rev 25568)
</span><span class="lines">@@ -1098,21 +1098,25 @@
</span><span class="cx">          $this->strings['process_success'] = __( 'Language updated successfully.' );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       function upgrade() {
-               return $this->bulk_upgrade();
</del><ins>+        function upgrade( $update = false ) {
+               if ( $update )
+                       $update = array( $update );
+               return $this->bulk_upgrade( $update );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-       function bulk_upgrade() {
</del><ins>+        function bulk_upgrade( $language_updates = array() ) {
</ins><span class="cx"> 
</span><span class="cx">          $this->init();
</span><span class="cx">          $this->upgrade_strings();
</span><span class="cx"> 
</span><del>-               $language_updates = wp_get_translation_updates();
</del><ins>+                if ( ! $language_updates )
+                       $language_updates = wp_get_translation_updates();
</ins><span class="cx"> 
</span><span class="cx">          if ( empty( $language_updates ) )
</span><span class="cx">                  return true;
</span><span class="cx"> 
</span><del>-               $this->skin->feedback( 'starting_upgrade' );
</del><ins>+                if ( 'upgrader_process_complete' == current_filter() )
+                       $this->skin->feedback( 'starting_upgrade' );
</ins><span class="cx"> 
</span><span class="cx">          add_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 3 );
</span><span class="cx"> 
</span><span class="lines">@@ -1287,8 +1291,8 @@
</span><span class="cx">          $current_is_development_version = (bool) strpos( $wp_version, '-' );
</span><span class="cx"> 
</span><span class="cx">          // Defaults:
</span><del>-               $upgrade_dev   = false;
-               $upgrade_minor = false; // @TODO: Update for release by toggling to true.
</del><ins>+                $upgrade_dev   = false; // TODO Enable
+               $upgrade_minor = false; // TODO Enable
</ins><span class="cx">           $upgrade_major = false;
</span><span class="cx"> 
</span><span class="cx">          // WP_AUTO_UPDATE_CORE = true (all), 'minor', false.
</span><span class="lines">@@ -1472,6 +1476,9 @@
</span><span class="cx"> 
</span><span class="cx">          // Next up, do we actually have it enabled for this type of update?
</span><span class="cx">          switch ( $type ) {
</span><ins>+                       case 'language':
+                               $upgrade = false; // TODO Enable
+                               break;
</ins><span class="cx">                   case 'core':
</span><span class="cx">                          $upgrade = Core_Upgrader::should_upgrade_to_version( $item->current );
</span><span class="cx">                          break;
</span><span class="lines">@@ -1530,6 +1537,10 @@
</span><span class="cx">                          $upgrader = new Theme_Upgrader( $skin );
</span><span class="cx">                          $context  = get_theme_root( $item );
</span><span class="cx">                          break;
</span><ins>+                       case 'language':
+                               $upgrader = new Language_Pack_Upgrader( $skin );
+                               $context  = WP_LANG_DIR;
+                               break;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          // Determine if we can perform this upgrade or not
</span><span class="lines">@@ -1551,6 +1562,44 @@
</span><span class="cx">                          $item_name = $plugin_data['Name'];
</span><span class="cx">                          $skin->feedback( __( 'Updating Plugin: %s' ), $item_name );
</span><span class="cx">                          break;
</span><ins>+                       case 'language':
+                               if ( 'theme' == $item->type ) {
+                                       $theme = wp_get_theme( $item->slug );
+                                       $skin->feedback( sprintf(
+                                               __( 'Updating the %1$s language files for the %2$s Theme' ),
+                                               $item->language,
+                                               $theme->Get( 'Name' )
+                                       ) );
+                                       $item_name = sprintf(
+                                               __( '%1$s translation for the %2$s Theme' ),
+                                               $item->language,
+                                               $theme->Get( 'Name' )
+                                       );
+                               } elseif ( 'plugin' == $item->type ) {
+                                       $plugin_data = get_plugins( '/' . $item->slug );
+                                       $plugin_data = array_shift( $plugin_data );
+                                       $skin->feedback( sprintf(
+                                               __( 'Updating the %1$s language files for the %2$s Plugin' ),
+                                               $item->language,
+                                               $plugin_data['Name']
+                                       ) );
+                                       $item_name = sprintf(
+                                               __( '%1$s translation for the %2$s Plugin' ),
+                                               $item->language,
+                                               $plugin_data['Name']
+                                       );
+                               } else {
+                                       $skin->feedback( sprintf(
+                                               __( 'Updating %s translation' ),
+                                               $item->language
+                                       ) );
+                                       $item_name = sprintf(
+                                               __( '%s translation' ),
+                                               $item->language
+                                       );
+                               }
+                               
+                               break;
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          // Boom, This sites about to get a whole new splash of paint!
</span><span class="lines">@@ -1594,6 +1643,12 @@
</span><span class="cx">          if ( ! add_site_option( $lock_name, microtime( true ), HOUR_IN_SECONDS / 2 ) )
</span><span class="cx">                  return;
</span><span class="cx"> 
</span><ins>+               // Don't automatically run these thins, as we'll handle it ourselves
+               remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 ); 
+               remove_action( 'upgrader_process_complete', 'wp_version_check' ); 
+               remove_action( 'upgrader_process_complete', 'wp_update_plugins' ); 
+               remove_action( 'upgrader_process_complete', 'wp_update_themes' ); 
+
</ins><span class="cx">           // Next, Plugins
</span><span class="cx">          wp_update_plugins(); // Check for Plugin updates
</span><span class="cx">          $plugin_updates = get_site_transient( 'update_plugins' );
</span><span class="lines">@@ -1616,7 +1671,7 @@
</span><span class="cx">                  wp_clean_themes_cache();
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               // Finally, Process any core upgrade
</del><ins>+                // Next, Process any core upgrade
</ins><span class="cx">           wp_version_check(); // Check for Core updates
</span><span class="cx">          $core_update = find_core_auto_update();
</span><span class="cx">          if ( $core_update ) {
</span><span class="lines">@@ -1624,23 +1679,40 @@
</span><span class="cx">                  delete_site_transient( 'update_core' );
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               // Cleanup, These won't trigger any updates this time due to the locking transient
</del><ins>+                // Cleanup, and check for any pending translations
</ins><span class="cx">           wp_version_check();  // check for Core updates
</span><span class="cx">          wp_update_themes();  // Check for Theme updates
</span><span class="cx">          wp_update_plugins(); // Check for Plugin updates
</span><span class="cx"> 
</span><ins>+               // Finally, Process any new translations
+               $language_updates = wp_get_translation_updates();
+               if ( $language_updates ) {
+                       foreach ( $language_updates as $update ) {
+                               self::upgrade( 'language', $update );
+                       }
+                       // Clear existing caches
+                       wp_clean_plugins_cache();
+                       wp_clean_themes_cache();
+                       delete_site_transient( 'update_core' );
+
+                       wp_version_check();  // check for Core updates
+                       wp_update_themes();  // Check for Theme updates
+                       wp_update_plugins(); // Check for Plugin updates
+               }
+
</ins><span class="cx">           /**
</span><span class="cx">           * Filter whether to email an update summary to the site administrator.
</span><span class="cx">           *
</span><span class="cx">           * @since 3.7.0
</span><span class="cx">           *
</span><del>-                * @param bool                        Whether or not email should be sent to administrator. Default true.
-                * @param bool|array $core_update     An array of core update data, false otherwise.
-                * @param object     $theme_updates   Object containing theme update properties.
-                * @param object     $plugin_updates  Object containing plugin update properties.
-                * @param array      $upgrade_results An array of the upgrade results keyed by upgrade type, and plugin/theme slug.
</del><ins>+                 * @param bool                         Whether or not email should be sent to administrator. Default true.
+                * @param bool|array $core_update      An array of core update data, false otherwise.
+                * @param object     $theme_updates    Object containing theme update properties.
+                * @param object     $plugin_updates   Object containing plugin update properties.
+                * @param array      $language_updates Array containing the Language updates available.
+                * @param array      $upgrade_results  Array of the upgrade results keyed by upgrade type, and plugin/theme slug.
</ins><span class="cx">            */
</span><del>-               if ( apply_filters( 'enable_auto_upgrade_email', true, $core_update, $theme_updates, $plugin_updates, self::$upgrade_results ) )
</del><ins>+                if ( apply_filters( 'enable_auto_upgrade_email', true, $core_update, $theme_updates, $plugin_updates, $language_updates, self::$upgrade_results ) )
</ins><span class="cx">                   self::send_email();
</span><span class="cx"> 
</span><span class="cx">          // Clear the lock
</span><span class="lines">@@ -1702,10 +1774,27 @@
</span><span class="cx">                  }
</span><span class="cx">          }
</span><span class="cx"> 
</span><ins>+               // Languages
+               if ( isset( self::$upgrade_results['language'] ) ) {
+                       $success_languages = wp_list_filter( self::$upgrade_results['language'], array( 'result' => true ) );
+
+                       if ( $success_languages )
+                               $body[] = sprintf( _n( 'The following language file was successfully updated: %s', 'The following language files were successfully updated: %s', count( $success_languages ) ), implode( ', ', wp_list_pluck( $success_languages, 'name' ) ) );
+                       if ( $success_languages != self::$upgrade_results['language'] ) {
+                               // Failed updates
+                               $failed_languages = array();
+                               foreach ( self::$upgrade_results['language'] as $language ) {
+                                       if ( ! $language->result || is_wp_error( $language->result ) )
+                                               $failed_languages[] = $language;
+                               }
+                               $body[] = sprintf( _n( 'The following language file failed to successfully update: %s', 'The following language files failed to successfully update: %s', count( $failed_languages ) ), implode( ', ', wp_list_pluck( $failed_languages, 'name' ) ) );
+                       }
+               }
+
</ins><span class="cx">           $body[] = '';
</span><span class="cx">          $body[] = __( 'Below is the upgrade logs for update performed' );
</span><span class="cx"> 
</span><del>-               foreach ( array( 'core', 'plugin', 'theme' ) as $type ) {
</del><ins>+                foreach ( array( 'core', 'plugin', 'theme', 'language' ) as $type ) {
</ins><span class="cx">                   if ( ! isset( self::$upgrade_results[ $type ] ) )
</span><span class="cx">                          continue;
</span><span class="cx">                  foreach ( self::$upgrade_results[ $type ] as $upgrade ) {
</span></span></pre>
</div>
</div>

</body>
</html>