Make WordPress Core

Changeset 25568


Ignore:
Timestamp:
09/23/2013 09:37:25 AM (13 years ago)
Author:
dd32
Message:

Language Packs: Integrate Language Packs into the Auto-upgrader. See #18200 See #22704

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r25566 r25568  
    10991099        }
    11001100
    1101         function upgrade() {
    1102                 return $this->bulk_upgrade();
    1103         }
    1104 
    1105         function bulk_upgrade() {
     1101        function upgrade( $update = false ) {
     1102                if ( $update )
     1103                        $update = array( $update );
     1104                return $this->bulk_upgrade( $update );
     1105        }
     1106
     1107        function bulk_upgrade( $language_updates = array() ) {
    11061108
    11071109                $this->init();
    11081110                $this->upgrade_strings();
    11091111
    1110                 $language_updates = wp_get_translation_updates();
     1112                if ( ! $language_updates )
     1113                        $language_updates = wp_get_translation_updates();
    11111114
    11121115                if ( empty( $language_updates ) )
    11131116                        return true;
    11141117
    1115                 $this->skin->feedback( 'starting_upgrade' );
     1118                if ( 'upgrader_process_complete' == current_filter() )
     1119                        $this->skin->feedback( 'starting_upgrade' );
    11161120
    11171121                add_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 3 );
     
    12881292
    12891293                // Defaults:
    1290                 $upgrade_dev   = false;
    1291                 $upgrade_minor = false; // @TODO: Update for release by toggling to true.
     1294                $upgrade_dev   = false; // TODO Enable
     1295                $upgrade_minor = false; // TODO Enable
    12921296                $upgrade_major = false;
    12931297
     
    14731477                // Next up, do we actually have it enabled for this type of update?
    14741478                switch ( $type ) {
     1479                        case 'language':
     1480                                $upgrade = false; // TODO Enable
     1481                                break;
    14751482                        case 'core':
    14761483                                $upgrade = Core_Upgrader::should_upgrade_to_version( $item->current );
     
    15311538                                $context  = get_theme_root( $item );
    15321539                                break;
     1540                        case 'language':
     1541                                $upgrader = new Language_Pack_Upgrader( $skin );
     1542                                $context  = WP_LANG_DIR;
     1543                                break;
    15331544                }
    15341545
     
    15521563                                $skin->feedback( __( 'Updating Plugin: %s' ), $item_name );
    15531564                                break;
     1565                        case 'language':
     1566                                if ( 'theme' == $item->type ) {
     1567                                        $theme = wp_get_theme( $item->slug );
     1568                                        $skin->feedback( sprintf(
     1569                                                __( 'Updating the %1$s language files for the %2$s Theme' ),
     1570                                                $item->language,
     1571                                                $theme->Get( 'Name' )
     1572                                        ) );
     1573                                        $item_name = sprintf(
     1574                                                __( '%1$s translation for the %2$s Theme' ),
     1575                                                $item->language,
     1576                                                $theme->Get( 'Name' )
     1577                                        );
     1578                                } elseif ( 'plugin' == $item->type ) {
     1579                                        $plugin_data = get_plugins( '/' . $item->slug );
     1580                                        $plugin_data = array_shift( $plugin_data );
     1581                                        $skin->feedback( sprintf(
     1582                                                __( 'Updating the %1$s language files for the %2$s Plugin' ),
     1583                                                $item->language,
     1584                                                $plugin_data['Name']
     1585                                        ) );
     1586                                        $item_name = sprintf(
     1587                                                __( '%1$s translation for the %2$s Plugin' ),
     1588                                                $item->language,
     1589                                                $plugin_data['Name']
     1590                                        );
     1591                                } else {
     1592                                        $skin->feedback( sprintf(
     1593                                                __( 'Updating %s translation' ),
     1594                                                $item->language
     1595                                        ) );
     1596                                        $item_name = sprintf(
     1597                                                __( '%s translation' ),
     1598                                                $item->language
     1599                                        );
     1600                                }
     1601                               
     1602                                break;
    15541603                }
    15551604
     
    15941643                if ( ! add_site_option( $lock_name, microtime( true ), HOUR_IN_SECONDS / 2 ) )
    15951644                        return;
     1645
     1646                // Don't automatically run these thins, as we'll handle it ourselves
     1647                remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20, 3 );
     1648                remove_action( 'upgrader_process_complete', 'wp_version_check' );
     1649                remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
     1650                remove_action( 'upgrader_process_complete', 'wp_update_themes' );
    15961651
    15971652                // Next, Plugins
     
    16171672                }
    16181673
    1619                 // Finally, Process any core upgrade
     1674                // Next, Process any core upgrade
    16201675                wp_version_check(); // Check for Core updates
    16211676                $core_update = find_core_auto_update();
     
    16251680                }
    16261681
    1627                 // Cleanup, These won't trigger any updates this time due to the locking transient
     1682                // Cleanup, and check for any pending translations
    16281683                wp_version_check();  // check for Core updates
    16291684                wp_update_themes();  // Check for Theme updates
    16301685                wp_update_plugins(); // Check for Plugin updates
     1686
     1687                // Finally, Process any new translations
     1688                $language_updates = wp_get_translation_updates();
     1689                if ( $language_updates ) {
     1690                        foreach ( $language_updates as $update ) {
     1691                                self::upgrade( 'language', $update );
     1692                        }
     1693                        // Clear existing caches
     1694                        wp_clean_plugins_cache();
     1695                        wp_clean_themes_cache();
     1696                        delete_site_transient( 'update_core' );
     1697
     1698                        wp_version_check();  // check for Core updates
     1699                        wp_update_themes();  // Check for Theme updates
     1700                        wp_update_plugins(); // Check for Plugin updates
     1701                }
    16311702
    16321703                /**
     
    16351706                 * @since 3.7.0
    16361707                 *
    1637                  * @param bool                        Whether or not email should be sent to administrator. Default true.
    1638                  * @param bool|array $core_update     An array of core update data, false otherwise.
    1639                  * @param object     $theme_updates   Object containing theme update properties.
    1640                  * @param object     $plugin_updates  Object containing plugin update properties.
    1641                  * @param array      $upgrade_results An array of the upgrade results keyed by upgrade type, and plugin/theme slug.
     1708                 * @param bool                         Whether or not email should be sent to administrator. Default true.
     1709                 * @param bool|array $core_update      An array of core update data, false otherwise.
     1710                 * @param object     $theme_updates    Object containing theme update properties.
     1711                 * @param object     $plugin_updates   Object containing plugin update properties.
     1712                 * @param array      $language_updates Array containing the Language updates available.
     1713                 * @param array      $upgrade_results  Array of the upgrade results keyed by upgrade type, and plugin/theme slug.
    16421714                 */
    1643                 if ( apply_filters( 'enable_auto_upgrade_email', true, $core_update, $theme_updates, $plugin_updates, self::$upgrade_results ) )
     1715                if ( apply_filters( 'enable_auto_upgrade_email', true, $core_update, $theme_updates, $plugin_updates, $language_updates, self::$upgrade_results ) )
    16441716                        self::send_email();
    16451717
     
    17031775                }
    17041776
     1777                // Languages
     1778                if ( isset( self::$upgrade_results['language'] ) ) {
     1779                        $success_languages = wp_list_filter( self::$upgrade_results['language'], array( 'result' => true ) );
     1780
     1781                        if ( $success_languages )
     1782                                $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' ) ) );
     1783                        if ( $success_languages != self::$upgrade_results['language'] ) {
     1784                                // Failed updates
     1785                                $failed_languages = array();
     1786                                foreach ( self::$upgrade_results['language'] as $language ) {
     1787                                        if ( ! $language->result || is_wp_error( $language->result ) )
     1788                                                $failed_languages[] = $language;
     1789                                }
     1790                                $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' ) ) );
     1791                        }
     1792                }
     1793
    17051794                $body[] = '';
    17061795                $body[] = __( 'Below is the upgrade logs for update performed' );
    17071796
    1708                 foreach ( array( 'core', 'plugin', 'theme' ) as $type ) {
     1797                foreach ( array( 'core', 'plugin', 'theme', 'language' ) as $type ) {
    17091798                        if ( ! isset( self::$upgrade_results[ $type ] ) )
    17101799                                continue;
Note: See TracChangeset for help on using the changeset viewer.