Make WordPress Core

Changeset 17580


Ignore:
Timestamp:
04/01/2011 09:50:01 AM (16 years ago)
Author:
dd32
Message:

Back-compat for core upgrades with pre-3.2. Utilises a temporary _copy_dir() function which can be removed in 3.3-dev to bring immediate wp-content relief to the 3.1-3.2 upgrades. See #14484

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/update-core.php

    r17578 r17580  
    364364
    365365        // Copy new versions of WP files into place.
    366         $result = copy_dir($from . $distro, $to, array('wp-content') );
     366        $result = _copy_dir($from . $distro, $to, array('wp-content') );
    367367
    368368        // Custom Content Directory needs updating now.
    … …  
    395395                                $directory = ('/' == $file[ strlen($file)-1 ]);
    396396                                list($type, $filename) = explode('/', $file, 2);
     397
    397398                                if ( 'plugins' == $type )
    398399                                        $dest = $wp_filesystem->wp_plugins_dir();
    399400                                elseif ( 'themes' == $type )
    400                                         $dest = $wp_filesystem->wp_themes_dir();
     401                                        $dest = trailingslashit($wp_filesystem->wp_themes_dir()); // Back-compat, ::wp_themes_dir() did not return trailingslash'd pre-3.2
     402                                else
     403                                        continue;
    401404
    402405                                if ( ! $directory ) {
    403                                         if ( $wp_filesystem->exists($dest . '/' . $filename) )
     406                                        if ( $wp_filesystem->exists($dest . $filename) )
    404407                                                continue;
    405408
    406                                         if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . '/' . $filename, FS_CHMOD_FILE) )
    407                                                 $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . '/' . $filename);
     409                                        if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) )
     410                                                $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
    408411                                } else {
    409                                         if ( $wp_filesystem->is_dir($dest . '/' . $filename) )
     412                                        if ( $wp_filesystem->is_dir($dest . $filename) )
    410413                                                continue;
    411414
    … …  
    452455}
    453456
     457/**#@+
     458 * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
     459 * Assumes that WP_Filesystem() has already been called and setup.
     460 *
     461 * This is a temporary function for the 3.1 -> 3.2 upgrade only and will be removed in 3.3
     462 *
     463 * @since 3.2
     464 * @see copy_dir()
     465 *
     466 * @param string $from source directory
     467 * @param string $to destination directory
     468 * @param array $skip_list a list of files/folders to skip copying
     469 * @return mixed WP_Error on failure, True on success.
     470 */
     471function _copy_dir($from, $to, $skip_list = array() ) {
     472        global $wp_filesystem;
     473
     474        $dirlist = $wp_filesystem->dirlist($from);
     475
     476        $from = trailingslashit($from);
     477        $to = trailingslashit($to);
     478
     479        $skip_regex = '';
     480        foreach ( (array)$skip_list as $key => $skip_file )
     481                $skip_regex .= preg_quote($skip_file, '!') . '|';
     482
     483        if ( !empty($skip_regex) )
     484                $skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
     485
     486        foreach ( (array) $dirlist as $filename => $fileinfo ) {
     487                if ( !empty($skip_regex) )
     488                        if ( preg_match($skip_regex, $from . $filename) )
     489                                continue;
     490
     491                if ( 'f' == $fileinfo['type'] ) {
     492                        if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
     493                                // If copy failed, chmod file to 0644 and try again.
     494                                $wp_filesystem->chmod($to . $filename, 0644);
     495                                if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
     496                                        return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
     497                        }
     498                } elseif ( 'd' == $fileinfo['type'] ) {
     499                        if ( !$wp_filesystem->is_dir($to . $filename) ) {
     500                                if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
     501                                        return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
     502                        }
     503                        $result = _copy_dir($from . $filename, $to . $filename, $skip_list);
     504                        if ( is_wp_error($result) )
     505                                return $result;
     506                }
     507        }
     508        return true;
     509}
     510/**#@-*/
     511
    454512?>
Note: See TracChangeset for help on using the changeset viewer.