Changeset 28418
- Timestamp:
- 05/15/2014 05:01:02 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-upgrader.php
r28253 r28418 191 191 192 192 $args = wp_parse_args($args, $defaults); 193 extract($args); 193 $destination = $args['destination']; 194 $clear_destination = $args['clear_destination']; 194 195 195 196 @set_time_limit( 300 ); 196 197 197 if ( empty( $source) || empty($destination) )198 return new WP_Error( 'bad_request', $this->strings['bad_request']);199 200 $this->skin->feedback( 'installing_package');198 if ( empty( $source ) || empty( $destination ) ) { 199 return new WP_Error( 'bad_request', $this->strings['bad_request'] ); 200 } 201 $this->skin->feedback( 'installing_package' ); 201 202 202 203 /** … … 212 213 * @param array $hook_extra Extra arguments passed to hooked filters. 213 214 */ 214 $res = apply_filters( 'upgrader_pre_install', true, $ hook_extra);215 if ( is_wp_error( $res) )215 $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] ); 216 if ( is_wp_error( $res ) ) { 216 217 return $res; 218 } 217 219 218 220 //Retain the Original source and destinations 219 $remote_source = $ source;221 $remote_source = $args['source']; 220 222 $local_destination = $destination; 221 223 222 $source_files = array_keys( $wp_filesystem->dirlist( $remote_source) );223 $remote_destination = $wp_filesystem->find_folder( $local_destination);224 $source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) ); 225 $remote_destination = $wp_filesystem->find_folder( $local_destination ); 224 226 225 227 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files. 226 if ( 1 == count( $source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') )//Only one folder? Then we want its contents.227 $source = trailingslashit( $source) . trailingslashit($source_files[0]);228 elseif ( count($source_files) == 0 )228 if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents. 229 $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] ); 230 } elseif ( count( $source_files ) == 0 ) { 229 231 return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files? 230 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. 231 $source = trailingslashit($source); 232 } 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. 233 $source = trailingslashit( $args['source'] ); 234 } 232 235 233 236 /** … … 241 244 */ 242 245 $source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this ); 243 if ( is_wp_error( $source) )246 if ( is_wp_error( $source ) ) { 244 247 return $source; 248 } 245 249 246 250 //Has the source location changed? If so, we need a new source_files list. 247 if ( $source !== $remote_source ) 248 $source_files = array_keys( $wp_filesystem->dirlist( $source) );249 251 if ( $source !== $remote_source ) { 252 $source_files = array_keys( $wp_filesystem->dirlist( $source ) ); 253 } 250 254 // Protection against deleting files in any important base directories. 251 255 // Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the destination directory (WP_PLUGIN_DIR / wp-content/themes) 252 256 // intending to copy the directory into the directory, whilst they pass the source as the actual files to copy. 253 257 $protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' ); 254 if ( is_array( $wp_theme_directories ) ) 258 if ( is_array( $wp_theme_directories ) ) { 255 259 $protected_directories = array_merge( $protected_directories, $wp_theme_directories ); 260 } 256 261 if ( in_array( $destination, $protected_directories ) ) { 257 $remote_destination = trailingslashit( $remote_destination) . trailingslashit(basename($source));258 $destination = trailingslashit( $destination) . trailingslashit(basename($source));262 $remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) ); 263 $destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) ); 259 264 } 260 265 … … 263 268 $this->skin->feedback('remove_old'); 264 269 $removed = true; 265 if ( $wp_filesystem->exists($remote_destination) ) 266 $removed = $wp_filesystem->delete($remote_destination, true); 270 if ( $wp_filesystem->exists( $remote_destination ) ) { 271 $removed = $wp_filesystem->delete( $remote_destination, true ); 272 } 267 273 268 274 /** … … 276 282 * @param array $hook_extra Extra arguments passed to hooked filters. 277 283 */ 278 $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $ hook_extra);279 280 if ( is_wp_error($removed) ) 284 $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] ); 285 286 if ( is_wp_error($removed) ) { 281 287 return $removed; 282 else if ( ! $removed )288 } else if ( ! $removed ) { 283 289 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); 284 } elseif ( $abort_if_destination_exists && $wp_filesystem->exists($remote_destination) ) { 290 } 291 } elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists($remote_destination) ) { 285 292 //If we're not clearing the destination folder and something exists there already, Bail. 286 293 //But first check to see if there are actually any files in the folder. … … 293 300 294 301 //Create destination if needed 295 if ( ! $wp_filesystem->exists($remote_destination) )296 if ( ! $wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )302 if ( ! $wp_filesystem->exists( $remote_destination ) ) { 303 if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { 297 304 return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination ); 298 305 } 306 } 299 307 // Copy new version of item into place. 300 308 $result = copy_dir($source, $remote_destination); 301 309 if ( is_wp_error($result) ) { 302 if ( $clear_working ) 303 $wp_filesystem->delete($remote_source, true); 310 if ( $args['clear_working'] ) { 311 $wp_filesystem->delete( $remote_source, true ); 312 } 304 313 return $result; 305 314 } 306 315 307 316 //Clear the Working folder? 308 if ( $clear_working ) 309 $wp_filesystem->delete($remote_source, true); 317 if ( $args['clear_working'] ) { 318 $wp_filesystem->delete( $remote_source, true ); 319 } 310 320 311 321 $destination_name = basename( str_replace($local_destination, '', $destination) ); 312 if ( '.' == $destination_name ) 322 if ( '.' == $destination_name ) { 313 323 $destination_name = ''; 324 } 314 325 315 326 $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir'); … … 324 335 * @param array $result Installation result data. 325 336 */ 326 $res = apply_filters( 'upgrader_post_install', true, $ hook_extra, $this->result );337 $res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result ); 327 338 328 339 if ( is_wp_error($res) ) { … … 335 346 } 336 347 337 function run( $options) {348 function run( $options ) { 338 349 339 350 $defaults = array( … … 347 358 ); 348 359 349 $options = wp_parse_args($options, $defaults); 350 extract($options); 351 352 if ( ! $is_multi ) // call $this->header separately if running multiple times 360 $options = wp_parse_args( $options, $defaults ); 361 362 if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times 353 363 $this->skin->header(); 364 } 354 365 355 366 // Connect to the Filesystem first. 356 $res = $this->fs_connect( array( WP_CONTENT_DIR, $destination) );367 $res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) ); 357 368 // Mainly for non-connected filesystem. 358 369 if ( ! $res ) { 359 if ( ! $ is_multi )370 if ( ! $options['is_multi'] ) { 360 371 $this->skin->footer(); 372 } 361 373 return false; 362 374 } … … 367 379 $this->skin->error($res); 368 380 $this->skin->after(); 369 if ( ! $ is_multi )381 if ( ! $options['is_multi'] ) { 370 382 $this->skin->footer(); 383 } 371 384 return $res; 372 385 } 373 386 374 387 //Download the package (Note, This just returns the filename of the file if the package is a local file) 375 $download = $this->download_package( $ package);388 $download = $this->download_package( $options['package'] ); 376 389 if ( is_wp_error($download) ) { 377 390 $this->skin->error($download); 378 391 $this->skin->after(); 379 if ( ! $ is_multi )392 if ( ! $options['is_multi'] ) { 380 393 $this->skin->footer(); 394 } 381 395 return $download; 382 396 } 383 397 384 $delete_package = ( $download != $package); // Do not delete a "local" file398 $delete_package = ( $download != $options['package'] ); // Do not delete a "local" file 385 399 386 400 //Unzips the file into a temporary directory … … 389 403 $this->skin->error($working_dir); 390 404 $this->skin->after(); 391 if ( ! $ is_multi )405 if ( ! $options['is_multi'] ) { 392 406 $this->skin->footer(); 407 } 393 408 return $working_dir; 394 409 } … … 397 412 $result = $this->install_package( array( 398 413 'source' => $working_dir, 399 'destination' => $ destination,400 'clear_destination' => $ clear_destination,401 'abort_if_destination_exists' => $ abort_if_destination_exists,402 'clear_working' => $ clear_working,403 'hook_extra' => $ hook_extra414 'destination' => $options['destination'], 415 'clear_destination' => $options['clear_destination'], 416 'abort_if_destination_exists' => $options['abort_if_destination_exists'], 417 'clear_working' => $options['clear_working'], 418 'hook_extra' => $options['hook_extra'] 404 419 ) ); 405 420 … … 415 430 $this->skin->after(); 416 431 417 if ( ! $ is_multi) {432 if ( ! $options['is_multi'] ) { 418 433 419 434 /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ 420 do_action( 'upgrader_process_complete', $this, $ hook_extra);435 do_action( 'upgrader_process_complete', $this, $options['hook_extra'] ); 421 436 $this->skin->footer(); 422 437 }
Note: See TracChangeset
for help on using the changeset viewer.