Make WordPress Core


Ignore:
Timestamp:
09/06/2013 01:32:09 AM (11 years ago)
Author:
dd32
Message:

Upgrader: Make clearing the Plugin and Theme update caches optional during install and upgrade proceedures. See #22704

File:
1 edited

Legend:

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

    r25254 r25272  
    164164    }
    165165
    166     function install_package($args = array()) {
     166    function install_package( $args = array() ) {
    167167        global $wp_filesystem, $wp_theme_directories;
    168168
    169         $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
    170                         'clear_destination' => false, 'clear_working' => false,
    171                         'abort_if_destination_exists' => true,
    172                         'hook_extra' => array());
     169        $defaults = array(
     170            'source' => '', // Please always pass this
     171            'destination' => '', // and this
     172            'clear_destination' => false,
     173            'clear_working' => false,
     174            'abort_if_destination_exists' => true,
     175            'hook_extra' => array()
     176        );
    173177
    174178        $args = wp_parse_args($args, $defaults);
     
    278282    function run($options) {
    279283
    280         $defaults = array(  'package' => '', //Please always pass this.
    281                             'destination' => '', //And this
    282                             'clear_destination' => false,
    283                             'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
    284                             'clear_working' => true,
    285                             'is_multi' => false,
    286                             'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
    287                         );
     284        $defaults = array(
     285            'package' => '', // Please always pass this.
     286            'destination' => '', // And this
     287            'clear_destination' => false,
     288            'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
     289            'clear_working' => true,
     290            'is_multi' => false,
     291            'hook_extra' => array() // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
     292        );
    288293
    289294        $options = wp_parse_args($options, $defaults);
     
    325330        //With the given options, this installs it to the destination directory.
    326331        $result = $this->install_package( array(
    327                                             'source' => $working_dir,
    328                                             'destination' => $destination,
    329                                             'clear_destination' => $clear_destination,
    330                                             'abort_if_destination_exists' => $abort_if_destination_exists,
    331                                             'clear_working' => $clear_working,
    332                                             'hook_extra' => $hook_extra
    333                                         ) );
     332            'source' => $working_dir,
     333            'destination' => $destination,
     334            'clear_destination' => $clear_destination,
     335            'abort_if_destination_exists' => $abort_if_destination_exists,
     336            'clear_working' => $clear_working,
     337            'hook_extra' => $hook_extra
     338        ) );
     339
    334340        $this->skin->set_result($result);
    335341        if ( is_wp_error($result) ) {
     
    399405    }
    400406
    401     function install($package) {
     407    function install( $package, $args = array() ) {
     408
     409        $defaults = array(
     410            'clear_update_cache' => true,
     411        );
     412        $parsed_args = wp_parse_args( $defaults, $args );
    402413
    403414        $this->init();
     
    406417        add_filter('upgrader_source_selection', array($this, 'check_package') );
    407418
    408         $this->run(array(
    409                     'package' => $package,
    410                     'destination' => WP_PLUGIN_DIR,
    411                     'clear_destination' => false, //Do not overwrite files.
    412                     'clear_working' => true,
    413                     'hook_extra' => array()
    414                     ));
     419        $this->run( array(
     420            'package' => $package,
     421            'destination' => WP_PLUGIN_DIR,
     422            'clear_destination' => false, // Do not overwrite files.
     423            'clear_working' => true,
     424            'hook_extra' => array()
     425        ) );
    415426
    416427        remove_filter('upgrader_source_selection', array($this, 'check_package') );
     
    420431
    421432        // Force refresh of plugin update information
    422         delete_site_transient('update_plugins');
    423         wp_cache_delete( 'plugins', 'plugins' );
     433        wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
     434
    424435        do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin' ), $package );
    425436
     
    427438    }
    428439
    429     function upgrade($plugin) {
     440    function upgrade( $plugin, $args = array() ) {
     441
     442        $defaults = array(
     443            'clear_update_cache' => true,
     444        );
     445        $parsed_args = wp_parse_args( $defaults, $args );
    430446
    431447        $this->init();
     
    448464        //'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
    449465
    450         $this->run(array(
    451                     'package' => $r->package,
    452                     'destination' => WP_PLUGIN_DIR,
    453                     'clear_destination' => true,
    454                     'clear_working' => true,
    455                     'hook_extra' => array(
    456                                 'plugin' => $plugin
    457                     )
    458                 ));
     466        $this->run( array(
     467            'package' => $r->package,
     468            'destination' => WP_PLUGIN_DIR,
     469            'clear_destination' => true,
     470            'clear_working' => true,
     471            'hook_extra' => array(
     472                'plugin' => $plugin
     473            ),
     474        ) );
    459475
    460476        // Cleanup our hooks, in case something else does a upgrade on this connection.
     
    466482
    467483        // Force refresh of plugin update information
    468         delete_site_transient('update_plugins');
    469         wp_cache_delete( 'plugins', 'plugins' );
     484        wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
     485
    470486        do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin' ), $plugin );
    471487
     
    473489    }
    474490
    475     function bulk_upgrade($plugins) {
     491    function bulk_upgrade( $plugins, $args = array() ) {
     492
     493        $defaults = array(
     494            'clear_update_cache' => true,
     495        );
     496        $parsed_args = wp_parse_args( $defaults, $args );
    476497
    477498        $this->init();
     
    526547            $this->skin->plugin_active = is_plugin_active($plugin);
    527548
    528             $result = $this->run(array(
    529                         'package' => $r->package,
    530                         'destination' => WP_PLUGIN_DIR,
    531                         'clear_destination' => true,
    532                         'clear_working' => true,
    533                         'is_multi' => true,
    534                         'hook_extra' => array(
    535                                     'plugin' => $plugin
    536                         )
    537                     ));
     549            $result = $this->run( array(
     550                'package' => $r->package,
     551                'destination' => WP_PLUGIN_DIR,
     552                'clear_destination' => true,
     553                'clear_working' => true,
     554                'is_multi' => true,
     555                'hook_extra' => array(
     556                    'plugin' => $plugin
     557                )
     558            ) );
    538559
    539560            $results[$plugin] = $this->result;
     
    554575
    555576        // Force refresh of plugin update information
    556         delete_site_transient('update_plugins');
    557         wp_cache_delete( 'plugins', 'plugins' );
     577        wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
     578
    558579        do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true ), $plugins );
    559580
     
    756777    }
    757778
    758     function install($package) {
     779    function install( $package, $args = array() ) {
     780
     781        $defaults = array(
     782            'clear_update_cache' => true,
     783        );
     784        $parsed_args = wp_parse_args( $defaults, $args );
    759785
    760786        $this->init();
     
    764790        add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3);
    765791
    766         $options = array(
     792        $this->run( array(
    767793            'package' => $package,
    768794            'destination' => get_theme_root(),
    769795            'clear_destination' => false, //Do not overwrite files.
    770796            'clear_working' => true
    771         );
    772 
    773         $this->run($options);
     797        ) );
    774798
    775799        remove_filter('upgrader_source_selection', array($this, 'check_package') );
     
    779803            return $this->result;
    780804
    781         // Force refresh of theme update information
    782         wp_clean_themes_cache();
     805        // Refresh the Theme Update information
     806        wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
     807
    783808        do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'theme' ), $package );
    784809
     
    786811    }
    787812
    788     function upgrade($theme) {
     813    function upgrade( $theme, $args = array() ) {
     814
     815        $defaults = array(
     816            'clear_update_cache' => true,
     817        );
     818        $parsed_args = wp_parse_args( $defaults, $args );
    789819
    790820        $this->init();
     
    807837        add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);
    808838
    809         $options = array(
     839        $this->run( array(
    810840            'package' => $r['package'],
    811841            'destination' => get_theme_root( $theme ),
     
    815845                'theme' => $theme
    816846            ),
    817         );
    818 
    819         $this->run($options);
     847        ) );
    820848
    821849        remove_filter('upgrader_pre_install', array($this, 'current_before'));
     
    826854            return $this->result;
    827855
    828         // Force refresh of theme update information
    829         wp_clean_themes_cache();
     856        wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
     857
    830858        do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme' ), $theme );
    831859
     
    833861    }
    834862
    835     function bulk_upgrade($themes) {
     863    function bulk_upgrade( $themes, $args = array() ) {
     864
     865        $defaults = array(
     866            'clear_update_cache' => true,
     867        );
     868        $parsed_args = wp_parse_args( $defaults, $args );
    836869
    837870        $this->init();
     
    887920            $r = $current->response[ $theme ];
    888921
    889             $options = array(
     922            $result = $this->run( array(
    890923                'package' => $r['package'],
    891924                'destination' => get_theme_root( $theme ),
     
    895928                    'theme' => $theme
    896929                ),
    897             );
    898 
    899             $result = $this->run($options);
     930            ) );
    900931
    901932            $results[$theme] = $this->result;
     
    917948        remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
    918949
    919         // Force refresh of theme update information
    920         wp_clean_themes_cache();
     950        // Refresh the Theme Update information
     951        wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
     952
    921953        do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'theme', 'bulk' => true ), $themes );
    922954
     
    10391071    }
    10401072
    1041     function upgrade($current) {
     1073    function upgrade( $current, $args = array() ) {
    10421074        global $wp_filesystem, $wp_version;
     1075
     1076        $defaults = array(
     1077        );
     1078        $parsed_args = wp_parse_args( $defaults, $args );
    10431079
    10441080        $this->init();
Note: See TracChangeset for help on using the changeset viewer.