Ticket #20974: 20974.diff

File 20974.diff, 5.0 KB (added by nacin, 11 months ago)

Includes some debug to allow for repeated update testing.

Line 
1Index: wp-admin/includes/class-wp-upgrader.php
2===================================================================
3--- wp-admin/includes/class-wp-upgrader.php     (revision 21131)
4+++ wp-admin/includes/class-wp-upgrader.php     (working copy)
5@@ -1055,13 +1055,13 @@
6                if ( is_wp_error($working_dir) )
7                        return $working_dir;
8 
9-               // Copy update-core.php from the new version into place.
10+/*             // Copy update-core.php from the new version into place.
11                if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
12                        $wp_filesystem->delete($working_dir, true);
13                        return new WP_Error('copy_failed', $this->strings['copy_failed']);
14                }
15                $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
16-
17+*/
18                require(ABSPATH . 'wp-admin/includes/update-core.php');
19 
20                if ( ! function_exists( 'update_core' ) )
21Index: wp-admin/includes/update-core.php
22===================================================================
23--- wp-admin/includes/update-core.php   (revision 21130)
24+++ wp-admin/includes/update-core.php   (working copy)
25@@ -398,6 +398,31 @@
26 );
27 
28 /**
29+ * Stores locale files to be deleted.
30+ *
31+ * @since 3.5.0
32+ * @global array $_old_locale_files
33+ * @var array
34+ * @name $_old_locale_files
35+ */
36+global $_old_locale_files;
37+
38+$_old_locale_files = array(
39+       // 3.4
40+       'sv_SE.php',
41+       'pl_PL.php',
42+       'ar.php',
43+       'id_ID.php',
44+       'nb_NO.php',
45+       'fi.php',
46+       'en_CA.php',
47+       'nn_NO.php',
48+       'eo.php',
49+       'ckb.php',
50+       'pt_BR.php',
51+);
52+
53+/**
54  * Stores new files in wp-content to copy
55  *
56  * The contents of this array indicate any new bundled plugins/themes which
57@@ -469,7 +494,7 @@
58  * @return WP_Error|null WP_Error on failure, null on success.
59  */
60 function update_core($from, $to) {
61-       global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
62+       global $wp_filesystem, $_old_files, $_old_locale_files, $_new_bundled_files, $wpdb;
63 
64        @set_time_limit( 300 );
65 
66@@ -518,31 +543,35 @@
67        $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
68 
69        // Copy new versions of WP files into place.
70-       $result = _copy_dir($from . $distro, $to, array('wp-content') );
71+       $result = true; // @DEBUG _copy_dir($from . $distro, $to, array('wp-content') );
72 
73        // Custom Content Directory needs updating now.
74        // Copy Languages
75-       if ( !is_wp_error($result) && $wp_filesystem->is_dir($from . $distro . 'wp-content/languages') ) {
76+       if ( !is_wp_error($result) ) {
77                if ( WP_LANG_DIR != ABSPATH . WPINC . '/languages' || @is_dir(WP_LANG_DIR) )
78                        $lang_dir = WP_LANG_DIR;
79                else
80                        $lang_dir = WP_CONTENT_DIR . '/languages';
81+       
82+               if ( $wp_filesystem->is_dir($from . $distro . 'wp-content/languages') ) {
83+                       if ( !@is_dir($lang_dir) && 0 === strpos($lang_dir, ABSPATH) ) { // Check the language directory exists first
84+                               $wp_filesystem->mkdir($to . str_replace(ABSPATH, '', $lang_dir), FS_CHMOD_DIR); // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.
85+                               clearstatcache(); // for FTP, Need to clear the stat cache
86+                       }
87 
88-               if ( !@is_dir($lang_dir) && 0 === strpos($lang_dir, ABSPATH) ) { // Check the language directory exists first
89-                       $wp_filesystem->mkdir($to . str_replace(ABSPATH, '', $lang_dir), FS_CHMOD_DIR); // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.
90-                       clearstatcache(); // for FTP, Need to clear the stat cache
91+                       if ( @is_dir($lang_dir) ) {
92+                               $wp_lang_dir = $wp_filesystem->find_folder($lang_dir);
93+                               if ( $wp_lang_dir )
94+                                       $result = copy_dir($from . $distro . 'wp-content/languages/', $wp_lang_dir);
95+                       }
96+               } elseif ( @is_dir( $lang_dir ) ) {
97+                       $wp_lang_dir = $wp_filesystem->find_folder( $lang_dir );
98                }
99-
100-               if ( @is_dir($lang_dir) ) {
101-                       $wp_lang_dir = $wp_filesystem->find_folder($lang_dir);
102-                       if ( $wp_lang_dir )
103-                               $result = copy_dir($from . $distro . 'wp-content/languages/', $wp_lang_dir);
104-               }
105        }
106 
107        // Copy New bundled plugins & themes
108        // This gives us the ability to install new plugins & themes bundled with future versions of WordPress whilst avoiding the re-install upon upgrade issue.
109-       if ( !is_wp_error($result) && ( ! defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
110+       if ( false ) { // @DEBUG !is_wp_error($result) && ( ! defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
111                $old_version = $GLOBALS['wp_version']; // $wp_version in local scope == new version
112                foreach ( (array) $_new_bundled_files as $file => $introduced_version ) {
113                        // If $introduced version is greater than what the site was previously running
114@@ -591,6 +620,15 @@
115                $wp_filesystem->delete($old_file, true);
116        }
117 
118+       if ( ! empty( $wp_lang_dir ) ) {
119+               foreach ( $_old_locale_files as $old_file ) {
120+                       $old_file = $wp_lang_dir . $old_file;
121+                       if ( ! $wp_filesystem->exists( $old_file ) )
122+                               continue;
123+                       $wp_filesystem->delete( $old_file, true );
124+               }
125+       }
126+
127        // Upgrade DB with separate request
128        apply_filters('update_feedback', __('Upgrading database…'));
129        $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');