Make WordPress Core

Changeset 13686


Ignore:
Timestamp:
03/13/2010 03:59:40 AM (16 years ago)
Author:
dd32
Message:

Bulk Theme Upgrades. See #12528 See #11232 for Bulk UI

Location:
trunk/wp-admin
Files:
3 edited

Legend:

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

    r13602 r13686  
    470470                $results = array();
    471471
    472                 $this->plugin_count = count($plugins);
    473                 $this->plugin_current = 0;
     472                $this->update_count = count($plugins);
     473                $this->update_current = 0;
    474474                foreach ( $plugins as $plugin ) {
    475                         $this->plugin_current++;
     475                        $this->update_current++;
    476476                        $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
    477477
     
    683683        }
    684684
     685        function bulk_upgrade($themes) {
     686
     687                $this->init();
     688                $this->bulk = true;
     689                $this->upgrade_strings();
     690
     691                $current = get_site_transient( 'update_themes' );
     692
     693                add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
     694                add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
     695                add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
     696
     697                $this->skin->header();
     698
     699                // Connect to the Filesystem first.
     700                $res = $this->fs_connect( array(WP_CONTENT_DIR) );
     701                if ( ! $res ) {
     702                        $this->skin->footer();
     703                        return false;
     704                }
     705
     706                $this->maintenance_mode(true);
     707
     708                $results = array();
     709
     710                $this->update_count = count($themes);
     711                $this->update_current = 0;
     712                foreach ( $themes as $theme ) {
     713                        $this->update_current++;
     714
     715                        if ( !isset( $current->response[ $theme ] ) ) {
     716                                $this->skin->set_result(false);
     717                                $this->skin->before();
     718                                $this->skin->error('up_to_date');
     719                                $this->skin->after();
     720                                $results[$theme] = false;
     721                                continue;
     722                        }
     723
     724                        $this->skin->theme_info = $this->theme_info($theme);
     725
     726                        // Get the URL to the zip file
     727                        $r = $current->response[ $theme ];
     728
     729                        $options = array(
     730                                                        'package' => $r['package'],
     731                                                        'destination' => WP_CONTENT_DIR . '/themes',
     732                                                        'clear_destination' => true,
     733                                                        'clear_working' => true,
     734                                                        'hook_extra' => array(
     735                                                                                                'theme' => $theme
     736                                                                                                )
     737                                                        );
     738
     739                        $result = $this->run($options);
     740
     741                        $results[$theme] = $this->result;
     742
     743                        // Prevent credentials auth screen from displaying multiple times
     744                        if ( false === $result )
     745                                break;
     746                } //end foreach $plugins
     747                $this->maintenance_mode(false);
     748                $this->skin->footer();
     749
     750                // Cleanup our hooks, incase something else does a upgrade on this connection.
     751                remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
     752                remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
     753                remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
     754
     755                // Force refresh of theme update information
     756                delete_site_transient('update_themes');
     757
     758                return $results;
     759        }
     760
    685761        function current_before($return, $theme) {
    686762
     
    693769                        return $return;
    694770                //Change to maintainence mode now.
    695                 $this->maintenance_mode(true);
     771                if ( ! $this->bulk )
     772                        $this->maintenance_mode(true);
    696773
    697774                return $return;
     
    715792
    716793                //Time to remove maintainence mode
    717                 $this->maintenance_mode(false);
     794                if ( ! $this->bulk )
     795                        $this->maintenance_mode(false);
    718796                return $return;
    719797        }
     
    734812        }
    735813
    736         function theme_info() {
    737                 if ( empty($this->result['destination_name']) )
    738                         return false;
    739                 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $this->result['destination_name'] . '/style.css');
     814        function theme_info($theme = null) {
     815
     816                if ( empty($theme) ) {
     817                        if ( !empty($this->result['destination_name']) )
     818                                $theme = $this->result['destination_name'];
     819                        else
     820                                return false;
     821                }
     822                return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
    740823        }
    741824
     
    827910                if ( is_object($upgrader) )
    828911                        $this->upgrader =& $upgrader;
    829         }
     912                $this->add_strings();
     913        }
     914
     915        function add_strings() {
     916        }
     917
    830918        function set_result($result) {
    831919                $this->result = $result;
     
    9501038 * @since 3.0
    9511039 */
    952 class Bulk_Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
     1040class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
    9531041        var $in_loop = false;
    9541042        var $error = false;
    9551043
    956         function Plugin_Upgrader_Skin($args = array()) {
     1044        function Bulk_Upgrader_Skin($args = array()) {
    9571045                return $this->__construct($args);
    9581046        }
     
    9641052                parent::__construct($args);
    9651053        }
    966        
     1054
     1055        function add_strings() {
     1056                $this->upgrader->strings['skin_update_failed_error'] = __('An error occured while updating %1$s: <strong>%2$s</strong>.');
     1057                $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
     1058                $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully. <a onclick="%2$s" href="#">See Details</a>.');
     1059        }
     1060
    9671061        function feedback($string) {
    9681062                if ( isset( $this->upgrader->strings[$string] ) )
     
    10051099        }
    10061100
    1007         function before() {
     1101        function before($title = '') {
    10081102                $this->in_loop = true;
    1009                 printf( '<h4>' . __('Updating Plugin %1$s (%2$d/%3$d)') . '</h4>',  $this->plugin_info['Title'], $this->upgrader->plugin_current, $this->upgrader->plugin_count);
    1010                 echo '<div class="update-messages" style="display:none" id="progress-' . esc_attr($this->upgrader->plugin_current) . '"><p>';
     1103                printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . '</h4>',  $title, $this->upgrader->update_current, $this->upgrader->update_count);
     1104                echo '<div class="update-messages" style="display:none" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
    10111105                $this->flush_output();
    10121106        }
    10131107
    1014         function after() {
     1108        function after($title = '') {
    10151109                echo '</p></div>';
    10161110                if ( $this->error || ! $this->result ) {
    10171111                        if ( $this->error )
    1018                                 echo '<div class="error"><p>' . sprintf(__('An error occured while updating %1$s: <strong>%2$s</strong>.'), $this->plugin_info['Title'], $this->error) . '</p></div>';
     1112                                echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title, $this->error) . '</p></div>';
    10191113                        else
    1020                                 echo '<div class="error"><p>' . sprintf(__('The update of %1$s failed.'), $this->plugin_info['Title']) . '</p></div>';
    1021                         echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->plugin_current) . '\').show();</script>';
     1114                                echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
     1115
     1116                        echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
    10221117                }
    10231118                if ( !empty($this->result) && !is_wp_error($this->result) ) {
    1024                         echo '<div class="updated"><p>' . sprintf(__('%1$s updated successfully. <a onclick="%2$s" href="#">See Details</a>.'), $this->plugin_info['Title'], 'jQuery(\'#progress-' . esc_js($this->upgrader->plugin_current) . '\').toggle(); return false;') . '</p></div>';
     1119                        echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle(); return false;') . '</p></div>';
    10251120                }
    10261121                $this->reset();
     
    10371132                flush();
    10381133        }
    1039 
     1134}
     1135
     1136class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
     1137        var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
     1138        function Plugin_Upgrader_Skin($args = array()) {
     1139                parent::__construct($args);
     1140        }
     1141
     1142        function add_strings() {
     1143                parent::add_strings();
     1144                $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
     1145        }
     1146
     1147        function before() {
     1148                parent::before($this->plugin_info['Title']);
     1149        }
     1150
     1151        function after() {
     1152                parent::after($this->plugin_info['Title']);
     1153        }
     1154}
     1155
     1156class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
     1157        var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
     1158        function Theme_Upgrader_Skin($args = array()) {
     1159                parent::__construct($args);
     1160        }
     1161
     1162        function add_strings() {
     1163                parent::add_strings();
     1164                $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
     1165        }
     1166
     1167        function before() {
     1168                parent::before($this->theme_info['Name']);
     1169        }
     1170
     1171        function after() {
     1172                parent::after($this->theme_info['Name']);
     1173        }
    10401174}
    10411175
  • trunk/wp-admin/update-core.php

    r13604 r13686  
    442442        screen_icon('themes');
    443443        echo '<h2>' . esc_html__('Update Themes') . '</h2>';
    444         echo "<p>@TODO: Sorry, This part of the functionality hasnt been written yet.</p>";
    445444        echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
    446445        echo '</div>';
  • trunk/wp-admin/update.php

    r13602 r13686  
    4343
    4444                iframe_footer();
    45                 exit;
    4645                       
    4746        } elseif ( 'upgrade-plugin' == $action ) {
     
    164163
    165164                include('admin-footer.php');
    166 
     165        } elseif ( 'update-selected-themes' == $action ) {
     166                if ( ! current_user_can( 'update_themes' ) )
     167                        wp_die( __( 'You do not have sufficient permissions to update themes for this blog.' ) );
     168
     169                check_admin_referer( 'bulk-update-themes' );
     170
     171                if ( isset( $_GET['themes'] ) )
     172                        $themes = explode( ',', stripslashes($_GET['themes']) );
     173                elseif ( isset( $_POST['checked'] ) )
     174                        $themes = (array) $_POST['checked'];
     175                else
     176                        $themes = array();
     177
     178                $themes = array_map('urldecode', $themes);
     179
     180                $url = 'update.php?action=update-selected-themes&amp;themess=' . urlencode(implode(',', $themes));
     181                $nonce = 'bulk-update-themes';
     182
     183                require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
     184                wp_enqueue_script('jquery');
     185                iframe_header();
     186
     187                $upgrader = new Theme_Upgrader( new Bulk_Theme_Upgrader_Skin( compact( 'nonce', 'url' ) ) );
     188                $upgrader->bulk_upgrade( $themes );
     189
     190                iframe_footer();
    167191        } elseif ( 'install-theme' == $action ) {
    168192
Note: See TracChangeset for help on using the changeset viewer.