mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 17:48:01 +01:00
Eliminate the use of extract()
in WP_Upgrader
.
See #22400. Built from https://develop.svn.wordpress.org/trunk@28418 git-svn-id: http://core.svn.wordpress.org/trunk@28245 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d74272ecf5
commit
b2d1e73fd5
@ -190,14 +190,15 @@ class WP_Upgrader {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$args = wp_parse_args($args, $defaults);
|
$args = wp_parse_args($args, $defaults);
|
||||||
extract($args);
|
$destination = $args['destination'];
|
||||||
|
$clear_destination = $args['clear_destination'];
|
||||||
|
|
||||||
@set_time_limit( 300 );
|
@set_time_limit( 300 );
|
||||||
|
|
||||||
if ( empty($source) || empty($destination) )
|
if ( empty( $source ) || empty( $destination ) ) {
|
||||||
return new WP_Error('bad_request', $this->strings['bad_request']);
|
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
|
||||||
|
}
|
||||||
$this->skin->feedback('installing_package');
|
$this->skin->feedback( 'installing_package' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the install response before the installation has started.
|
* Filter the install response before the installation has started.
|
||||||
@ -211,24 +212,26 @@ class WP_Upgrader {
|
|||||||
* @param bool|WP_Error $response Response.
|
* @param bool|WP_Error $response Response.
|
||||||
* @param array $hook_extra Extra arguments passed to hooked filters.
|
* @param array $hook_extra Extra arguments passed to hooked filters.
|
||||||
*/
|
*/
|
||||||
$res = apply_filters( 'upgrader_pre_install', true, $hook_extra );
|
$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
|
||||||
if ( is_wp_error($res) )
|
if ( is_wp_error( $res ) ) {
|
||||||
return $res;
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
//Retain the Original source and destinations
|
//Retain the Original source and destinations
|
||||||
$remote_source = $source;
|
$remote_source = $args['source'];
|
||||||
$local_destination = $destination;
|
$local_destination = $destination;
|
||||||
|
|
||||||
$source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
|
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
|
||||||
$remote_destination = $wp_filesystem->find_folder($local_destination);
|
$remote_destination = $wp_filesystem->find_folder( $local_destination );
|
||||||
|
|
||||||
//Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
|
//Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
|
||||||
if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
|
if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents.
|
||||||
$source = trailingslashit($source) . trailingslashit($source_files[0]);
|
$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
|
||||||
elseif ( count($source_files) == 0 )
|
} elseif ( count( $source_files ) == 0 ) {
|
||||||
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
|
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
|
||||||
else //It's only a single file, the upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
|
} else { //It's only a single file, the upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
|
||||||
$source = trailingslashit($source);
|
$source = trailingslashit( $args['source'] );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the source file location for the upgrade package.
|
* Filter the source file location for the upgrade package.
|
||||||
@ -240,30 +243,33 @@ class WP_Upgrader {
|
|||||||
* @param WP_Upgrader $this WP_Upgrader instance.
|
* @param WP_Upgrader $this WP_Upgrader instance.
|
||||||
*/
|
*/
|
||||||
$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this );
|
$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this );
|
||||||
if ( is_wp_error($source) )
|
if ( is_wp_error( $source ) ) {
|
||||||
return $source;
|
return $source;
|
||||||
|
}
|
||||||
|
|
||||||
//Has the source location changed? If so, we need a new source_files list.
|
//Has the source location changed? If so, we need a new source_files list.
|
||||||
if ( $source !== $remote_source )
|
if ( $source !== $remote_source ) {
|
||||||
$source_files = array_keys( $wp_filesystem->dirlist($source) );
|
$source_files = array_keys( $wp_filesystem->dirlist( $source ) );
|
||||||
|
}
|
||||||
// Protection against deleting files in any important base directories.
|
// Protection against deleting files in any important base directories.
|
||||||
// Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the destination directory (WP_PLUGIN_DIR / wp-content/themes)
|
// Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the destination directory (WP_PLUGIN_DIR / wp-content/themes)
|
||||||
// intending to copy the directory into the directory, whilst they pass the source as the actual files to copy.
|
// intending to copy the directory into the directory, whilst they pass the source as the actual files to copy.
|
||||||
$protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
|
$protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
|
||||||
if ( is_array( $wp_theme_directories ) )
|
if ( is_array( $wp_theme_directories ) ) {
|
||||||
$protected_directories = array_merge( $protected_directories, $wp_theme_directories );
|
$protected_directories = array_merge( $protected_directories, $wp_theme_directories );
|
||||||
|
}
|
||||||
if ( in_array( $destination, $protected_directories ) ) {
|
if ( in_array( $destination, $protected_directories ) ) {
|
||||||
$remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
|
$remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
|
||||||
$destination = trailingslashit($destination) . trailingslashit(basename($source));
|
$destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $clear_destination ) {
|
if ( $clear_destination ) {
|
||||||
//We're going to clear the destination if there's something there
|
//We're going to clear the destination if there's something there
|
||||||
$this->skin->feedback('remove_old');
|
$this->skin->feedback('remove_old');
|
||||||
$removed = true;
|
$removed = true;
|
||||||
if ( $wp_filesystem->exists($remote_destination) )
|
if ( $wp_filesystem->exists( $remote_destination ) ) {
|
||||||
$removed = $wp_filesystem->delete($remote_destination, true);
|
$removed = $wp_filesystem->delete( $remote_destination, true );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter whether the upgrader cleared the destination.
|
* Filter whether the upgrader cleared the destination.
|
||||||
@ -275,13 +281,14 @@ class WP_Upgrader {
|
|||||||
* @param string $remote_destination The remote package destination.
|
* @param string $remote_destination The remote package destination.
|
||||||
* @param array $hook_extra Extra arguments passed to hooked filters.
|
* @param array $hook_extra Extra arguments passed to hooked filters.
|
||||||
*/
|
*/
|
||||||
$removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra );
|
$removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
|
||||||
|
|
||||||
if ( is_wp_error($removed) )
|
if ( is_wp_error($removed) ) {
|
||||||
return $removed;
|
return $removed;
|
||||||
else if ( ! $removed )
|
} else if ( ! $removed ) {
|
||||||
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
|
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
|
||||||
} elseif ( $abort_if_destination_exists && $wp_filesystem->exists($remote_destination) ) {
|
}
|
||||||
|
} elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists($remote_destination) ) {
|
||||||
//If we're not clearing the destination folder and something exists there already, Bail.
|
//If we're not clearing the destination folder and something exists there already, Bail.
|
||||||
//But first check to see if there are actually any files in the folder.
|
//But first check to see if there are actually any files in the folder.
|
||||||
$_files = $wp_filesystem->dirlist($remote_destination);
|
$_files = $wp_filesystem->dirlist($remote_destination);
|
||||||
@ -292,25 +299,29 @@ class WP_Upgrader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Create destination if needed
|
//Create destination if needed
|
||||||
if ( !$wp_filesystem->exists($remote_destination) )
|
if ( ! $wp_filesystem->exists( $remote_destination ) ) {
|
||||||
if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
|
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
|
||||||
return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
|
return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
|
||||||
|
}
|
||||||
|
}
|
||||||
// Copy new version of item into place.
|
// Copy new version of item into place.
|
||||||
$result = copy_dir($source, $remote_destination);
|
$result = copy_dir($source, $remote_destination);
|
||||||
if ( is_wp_error($result) ) {
|
if ( is_wp_error($result) ) {
|
||||||
if ( $clear_working )
|
if ( $args['clear_working'] ) {
|
||||||
$wp_filesystem->delete($remote_source, true);
|
$wp_filesystem->delete( $remote_source, true );
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Clear the Working folder?
|
//Clear the Working folder?
|
||||||
if ( $clear_working )
|
if ( $args['clear_working'] ) {
|
||||||
$wp_filesystem->delete($remote_source, true);
|
$wp_filesystem->delete( $remote_source, true );
|
||||||
|
}
|
||||||
|
|
||||||
$destination_name = basename( str_replace($local_destination, '', $destination) );
|
$destination_name = basename( str_replace($local_destination, '', $destination) );
|
||||||
if ( '.' == $destination_name )
|
if ( '.' == $destination_name ) {
|
||||||
$destination_name = '';
|
$destination_name = '';
|
||||||
|
}
|
||||||
|
|
||||||
$this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
|
$this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
|
||||||
|
|
||||||
@ -323,7 +334,7 @@ class WP_Upgrader {
|
|||||||
* @param array $hook_extra Extra arguments passed to hooked filters.
|
* @param array $hook_extra Extra arguments passed to hooked filters.
|
||||||
* @param array $result Installation result data.
|
* @param array $result Installation result data.
|
||||||
*/
|
*/
|
||||||
$res = apply_filters( 'upgrader_post_install', true, $hook_extra, $this->result );
|
$res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
|
||||||
|
|
||||||
if ( is_wp_error($res) ) {
|
if ( is_wp_error($res) ) {
|
||||||
$this->result = $res;
|
$this->result = $res;
|
||||||
@ -334,7 +345,7 @@ class WP_Upgrader {
|
|||||||
return $this->result;
|
return $this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function run($options) {
|
function run( $options ) {
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'package' => '', // Please always pass this.
|
'package' => '', // Please always pass this.
|
||||||
@ -346,18 +357,19 @@ class WP_Upgrader {
|
|||||||
'hook_extra' => array() // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
|
'hook_extra' => array() // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
|
||||||
);
|
);
|
||||||
|
|
||||||
$options = wp_parse_args($options, $defaults);
|
$options = wp_parse_args( $options, $defaults );
|
||||||
extract($options);
|
|
||||||
|
|
||||||
if ( ! $is_multi ) // call $this->header separately if running multiple times
|
if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times
|
||||||
$this->skin->header();
|
$this->skin->header();
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to the Filesystem first.
|
// Connect to the Filesystem first.
|
||||||
$res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
|
$res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) );
|
||||||
// Mainly for non-connected filesystem.
|
// Mainly for non-connected filesystem.
|
||||||
if ( ! $res ) {
|
if ( ! $res ) {
|
||||||
if ( ! $is_multi )
|
if ( ! $options['is_multi'] ) {
|
||||||
$this->skin->footer();
|
$this->skin->footer();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,41 +378,44 @@ class WP_Upgrader {
|
|||||||
if ( is_wp_error($res) ) {
|
if ( is_wp_error($res) ) {
|
||||||
$this->skin->error($res);
|
$this->skin->error($res);
|
||||||
$this->skin->after();
|
$this->skin->after();
|
||||||
if ( ! $is_multi )
|
if ( ! $options['is_multi'] ) {
|
||||||
$this->skin->footer();
|
$this->skin->footer();
|
||||||
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Download the package (Note, This just returns the filename of the file if the package is a local file)
|
//Download the package (Note, This just returns the filename of the file if the package is a local file)
|
||||||
$download = $this->download_package( $package );
|
$download = $this->download_package( $options['package'] );
|
||||||
if ( is_wp_error($download) ) {
|
if ( is_wp_error($download) ) {
|
||||||
$this->skin->error($download);
|
$this->skin->error($download);
|
||||||
$this->skin->after();
|
$this->skin->after();
|
||||||
if ( ! $is_multi )
|
if ( ! $options['is_multi'] ) {
|
||||||
$this->skin->footer();
|
$this->skin->footer();
|
||||||
|
}
|
||||||
return $download;
|
return $download;
|
||||||
}
|
}
|
||||||
|
|
||||||
$delete_package = ($download != $package); // Do not delete a "local" file
|
$delete_package = ( $download != $options['package'] ); // Do not delete a "local" file
|
||||||
|
|
||||||
//Unzips the file into a temporary directory
|
//Unzips the file into a temporary directory
|
||||||
$working_dir = $this->unpack_package( $download, $delete_package );
|
$working_dir = $this->unpack_package( $download, $delete_package );
|
||||||
if ( is_wp_error($working_dir) ) {
|
if ( is_wp_error($working_dir) ) {
|
||||||
$this->skin->error($working_dir);
|
$this->skin->error($working_dir);
|
||||||
$this->skin->after();
|
$this->skin->after();
|
||||||
if ( ! $is_multi )
|
if ( ! $options['is_multi'] ) {
|
||||||
$this->skin->footer();
|
$this->skin->footer();
|
||||||
|
}
|
||||||
return $working_dir;
|
return $working_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
//With the given options, this installs it to the destination directory.
|
//With the given options, this installs it to the destination directory.
|
||||||
$result = $this->install_package( array(
|
$result = $this->install_package( array(
|
||||||
'source' => $working_dir,
|
'source' => $working_dir,
|
||||||
'destination' => $destination,
|
'destination' => $options['destination'],
|
||||||
'clear_destination' => $clear_destination,
|
'clear_destination' => $options['clear_destination'],
|
||||||
'abort_if_destination_exists' => $abort_if_destination_exists,
|
'abort_if_destination_exists' => $options['abort_if_destination_exists'],
|
||||||
'clear_working' => $clear_working,
|
'clear_working' => $options['clear_working'],
|
||||||
'hook_extra' => $hook_extra
|
'hook_extra' => $options['hook_extra']
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$this->skin->set_result($result);
|
$this->skin->set_result($result);
|
||||||
@ -414,10 +429,10 @@ class WP_Upgrader {
|
|||||||
|
|
||||||
$this->skin->after();
|
$this->skin->after();
|
||||||
|
|
||||||
if ( ! $is_multi ) {
|
if ( ! $options['is_multi'] ) {
|
||||||
|
|
||||||
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
|
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
|
||||||
do_action( 'upgrader_process_complete', $this, $hook_extra );
|
do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
|
||||||
$this->skin->footer();
|
$this->skin->footer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user