Ticket #51857: 51857.5.diff
File 51857.5.diff, 7.7 KB (added by , 5 years ago) |
---|
-
wp-admin/includes/class-wp-upgrader.php
diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php index 5faac56213..4fdb35b244 100644
a b class WP_Upgrader { 594 594 // Copy new version of item into place. 595 595 $result = copy_dir( $source, $remote_destination ); 596 596 if ( is_wp_error( $result ) ) { 597 $this->extract_rollback( $destination, $args['hook_extra'] ); 597 598 if ( $args['clear_working'] ) { 598 599 $wp_filesystem->delete( $remote_source, true ); 599 600 } … … class WP_Upgrader { 775 776 776 777 $delete_package = ( $download != $options['package'] ); // Do not delete a "local" file. 777 778 779 // Zip the plugin/theme being updated to rollback directory. 780 add_filter( 'upgrader_pre_install', array( $this, 'zip_to_rollback_dir' ), 15, 2 ); 781 778 782 // Unzips the file into a temporary directory. 779 783 $working_dir = $this->unpack_package( $download, $delete_package ); 780 784 if ( is_wp_error( $working_dir ) ) { … … class WP_Upgrader { 937 941 return delete_option( $lock_name . '.lock' ); 938 942 } 939 943 944 945 /** 946 * Create a zip archive of the plugin/theme being upgraded into a rollback directory. 947 * 948 * @since 5.7.0 949 * @uses 'upgrader_pre_install' filter. 950 * 951 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. 952 * @param bool $true Boolean response to 'upgrader_pre_install' filter. 953 * Default is true. 954 * @param array $hook_extra Array of data for plugin/theme being updated. 955 * 956 * @return bool 957 */ 958 public function zip_to_rollback_dir( $true, $hook_extra ) { 959 global $wp_filesystem; 960 961 $rollback_dir = $wp_filesystem->wp_content_dir() . 'upgrade/rollback/'; 962 $type = key( $hook_extra ); 963 $slug = 'plugin' === $type ? dirname( $hook_extra['plugin'] ) : $hook_extra['theme']; 964 $src = 'plugin' === $type ? WP_PLUGIN_DIR . "/{$slug}" : get_theme_root(). "/{$slug}"; 965 if ( $wp_filesystem->mkdir( $rollback_dir ) ) { 966 $path_prefix = strlen( $src ) + 1; 967 $zip = new ZipArchive(); 968 969 if ( true === $zip->open( "{$rollback_dir}{$slug}.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) { 970 $files = new RecursiveIteratorIterator( 971 new RecursiveDirectoryIterator( $src ), 972 RecursiveIteratorIterator::LEAVES_ONLY 973 ); 974 975 foreach ( $files as $name => $file ) { 976 // Skip directories (they would be added automatically). 977 if ( ! $file->isDir() ) { 978 // Get real and relative path for current file. 979 $file_path = $file->getRealPath(); 980 $relative_path = substr( $file_path, $path_prefix ); 981 982 // Add current file to archive. 983 $zip->addFile( $file_path, $relative_path ); 984 } 985 } 986 987 $zip->close(); 988 } else { 989 return new WP_Error( 'zip_rollback_failed', __( 'Zip plugin/theme to rollback directory failed.' ) ); 990 } 991 } 992 993 return $true; 994 } 995 996 /** 997 * Extract zipped rollback to original location. 998 * 999 * @since 5.7.0 1000 * 1001 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. 1002 * @param string $destination File path of plugin/theme. 1003 * @param array $hook_extra Array of data for plugin/theme being updated. 1004 * 1005 * @return bool 1006 */ 1007 public function extract_rollback( $destination, $hook_extra ) { 1008 global $wp_filesystem; 1009 1010 // Start with a clean slate. 1011 if ( $wp_filesystem->is_dir( $destination ) ) { 1012 $wp_filesystem->delete( $destination, true ); 1013 } 1014 1015 $rollback_dir = $wp_filesystem->wp_content_dir() . 'upgrade/rollback/'; 1016 $type = key( $hook_extra ); 1017 $slug = 'plugin' === $type ? dirname( $hook_extra['plugin'] ) : $hook_extra['theme']; 1018 $src = 'plugin' === $type ? WP_PLUGIN_DIR . "/{$slug}" : get_theme_root() . "/{$slug}"; 1019 $rollback = $rollback_dir . "{$slug}.zip"; 1020 1021 $zip = new \ZipArchive(); 1022 if ( true === $zip->open( "$rollback", ZipArchive::CHECKCONS ) ) { 1023 $zip->extractTo( "$destination" ); 1024 $zip->close(); 1025 return true; 1026 } else { 1027 return new WP_Error( 'extract_rollback_failed', __( "Extract rollback of {$type} {$slug} failed." ) ); 1028 } 1029 } 940 1030 } 941 1031 942 1032 /** Plugin_Upgrader class */ -
wp-admin/includes/file.php
diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 993635e460..f04acf625f 100644
a b function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) { 1730 1730 * Assumes that WP_Filesystem() has already been called and setup. 1731 1731 * 1732 1732 * @since 2.5.0 1733 * @since 5.7.0 Add $first_pass parameter. 1733 1734 * 1734 1735 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. 1735 1736 * 1736 * @param string $from Source directory. 1737 * @param string $to Destination directory. 1738 * @param string[] $skip_list An array of files/folders to skip copying. 1737 * @param string $from Source directory. 1738 * @param string $to Destination directory. 1739 * @param string[] $skip_list An array of files/folders to skip copying. 1740 * @param bool $first_pass True on the initial call, but false on subsequent calls. 1739 1741 * @return true|WP_Error True on success, WP_Error on failure. 1740 1742 */ 1741 function copy_dir( $from, $to, $skip_list = array() ) {1743 function copy_dir( $from, $to, $skip_list = array(), $first_pass = true ) { 1742 1744 global $wp_filesystem; 1743 1745 1744 1746 $dirlist = $wp_filesystem->dirlist( $from ); 1745 1747 1748 if ( ! $dirlist && $first_pass ) { 1749 return new WP_Error( 'dirlist_failed_copy_dir', __( 'Directory listing failed.' ), basename( $to ) ); 1750 } 1751 1746 1752 $from = trailingslashit( $from ); 1747 1753 $to = trailingslashit( $to ); 1748 1754 … … function copy_dir( $from, $to, $skip_list = array() ) { 1776 1782 } 1777 1783 } 1778 1784 1779 $result = copy_dir( $from . $filename, $to . $filename, $sub_skip_list );1785 $result = copy_dir( $from . $filename, $to . $filename, $sub_skip_list, false ); 1780 1786 if ( is_wp_error( $result ) ) { 1781 1787 return $result; 1782 1788 } -
wp-admin/includes/update-core.php
diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php index aee5436305..ebe4e8e36d 100644
a b function update_core( $from, $to ) { 1333 1333 * @ignore 1334 1334 * @since 3.2.0 1335 1335 * @since 3.7.0 Updated not to use a regular expression for the skip list. 1336 * @since 5.7.0 Add $first_pass parameter. 1336 1337 * 1337 1338 * @see copy_dir() 1338 1339 * @link https://core.trac.wordpress.org/ticket/17173 1339 1340 * 1340 1341 * @global WP_Filesystem_Base $wp_filesystem 1341 1342 * 1342 * @param string $from Source directory. 1343 * @param string $to Destination directory. 1344 * @param string[] $skip_list Array of files/folders to skip copying. 1343 * @param string $from Source directory. 1344 * @param string $to Destination directory. 1345 * @param string[] $skip_list Array of files/folders to skip copying. 1346 * @param bool $first_pass True on the initial call, but false on subsequent calls. 1345 1347 * @return true|WP_Error True on success, WP_Error on failure. 1346 1348 */ 1347 function _copy_dir( $from, $to, $skip_list = array() ) {1349 function _copy_dir( $from, $to, $skip_list = array(), $first_pass = true ) { 1348 1350 global $wp_filesystem; 1349 1351 1350 1352 $dirlist = $wp_filesystem->dirlist( $from ); 1351 1353 1354 if ( ! $dirlist && $first_pass ) { 1355 return new WP_Error( 'dirlist_failed__copy_dir', __( 'Directory listing failed.' ), basename( $to ) ); 1356 } 1357 1352 1358 $from = trailingslashit( $from ); 1353 1359 $to = trailingslashit( $to ); 1354 1360 … … function _copy_dir( $from, $to, $skip_list = array() ) { 1388 1394 } 1389 1395 } 1390 1396 1391 $result = _copy_dir( $from . $filename, $to . $filename, $sub_skip_list );1397 $result = _copy_dir( $from . $filename, $to . $filename, $sub_skip_list, false ); 1392 1398 if ( is_wp_error( $result ) ) { 1393 1399 return $result; 1394 1400 }