Changeset 50785
- Timestamp:
- 04/23/2021 02:49:51 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/update-core.php
r50561 r50785 925 925 $distro = ''; 926 926 $roots = array( '/wordpress/', '/wordpress-mu/' ); 927 927 928 foreach ( $roots as $root ) { 928 if ( $wp_filesystem->exists( $from . $root . 'readme.html' ) && $wp_filesystem->exists( $from . $root . 'wp-includes/version.php' ) ) { 929 if ( $wp_filesystem->exists( $from . $root . 'readme.html' ) 930 && $wp_filesystem->exists( $from . $root . 'wp-includes/version.php' ) 931 ) { 929 932 $distro = $root; 930 933 break; 931 934 } 932 935 } 936 933 937 if ( ! $distro ) { 934 938 $wp_filesystem->delete( $from, true ); 939 935 940 return new WP_Error( 'insane_distro', __( 'The update could not be unpacked' ) ); 936 941 } … … 943 948 */ 944 949 $versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php'; 950 945 951 if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) { 946 952 $wp_filesystem->delete( $from, true ); 947 return new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' ); 953 954 return new WP_Error( 955 'copy_failed_for_version_file', 956 __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 957 'wp-includes/version.php' 958 ); 948 959 } 949 960 … … 966 977 $development_build = ( false !== strpos( $old_wp_version . $wp_version, '-' ) ); // A dash in the version indicates a development release. 967 978 $php_compat = version_compare( $php_version, $required_php_version, '>=' ); 979 968 980 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) { 969 981 $mysql_compat = true; … … 1058 1070 1059 1071 $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); 1072 1060 1073 if ( is_array( $checksums ) && isset( $checksums[ $wp_version ] ) ) { 1061 1074 $checksums = $checksums[ $wp_version ]; // Compat code for 3.7-beta2. 1062 1075 } 1076 1063 1077 if ( is_array( $checksums ) ) { 1064 1078 foreach ( $checksums as $file => $checksum ) { … … 1066 1080 continue; 1067 1081 } 1082 1068 1083 if ( ! file_exists( ABSPATH . $file ) ) { 1069 1084 continue; 1070 1085 } 1086 1071 1087 if ( ! file_exists( $working_dir_local . $file ) ) { 1072 1088 continue; 1073 1089 } 1074 if ( '.' === dirname( $file ) && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true ) ) { 1090 1091 if ( '.' === dirname( $file ) 1092 && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true ) 1093 ) { 1075 1094 continue; 1076 1095 } 1096 1077 1097 if ( md5_file( ABSPATH . $file ) === $checksum ) { 1078 1098 $skip[] = $file; … … 1087 1107 if ( $check_is_writable && 'direct' === $wp_filesystem->method ) { 1088 1108 $files_writable = array_filter( $check_is_writable, array( $wp_filesystem, 'is_writable' ) ); 1109 1089 1110 if ( $files_writable !== $check_is_writable ) { 1090 1111 $files_not_writable = array_diff_key( $check_is_writable, $files_writable ); 1112 1091 1113 foreach ( $files_not_writable as $relative_file_not_writable => $file_not_writable ) { 1092 1114 // If the writable check failed, chmod file to 0644 and try again, same as copy_dir(). 1093 1115 $wp_filesystem->chmod( $file_not_writable, FS_CHMOD_FILE ); 1116 1094 1117 if ( $wp_filesystem->is_writable( $file_not_writable ) ) { 1095 1118 unset( $files_not_writable[ $relative_file_not_writable ] ); … … 1101 1124 1102 1125 if ( $files_not_writable ) { 1103 return new WP_Error( 'files_not_writable', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), implode( ', ', $error_data ) ); 1126 return new WP_Error( 1127 'files_not_writable', 1128 __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 1129 implode( ', ', $error_data ) 1130 ); 1104 1131 } 1105 1132 } … … 1108 1135 /** This filter is documented in wp-admin/includes/update-core.php */ 1109 1136 apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) ); 1137 1110 1138 // Create maintenance file to signal that we are upgrading. 1111 1139 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; … … 1116 1144 /** This filter is documented in wp-admin/includes/update-core.php */ 1117 1145 apply_filters( 'update_feedback', __( 'Copying the required files…' ) ); 1146 1118 1147 // Copy new versions of WP files into place. 1119 1148 $result = _copy_dir( $from . $distro, $to, $skip ); 1149 1120 1150 if ( is_wp_error( $result ) ) { 1121 $result = new WP_Error( $result->get_error_code(), $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) ); 1151 $result = new WP_Error( 1152 $result->get_error_code(), 1153 $result->get_error_message(), 1154 substr( $result->get_error_data(), strlen( $to ) ) 1155 ); 1122 1156 } 1123 1157 … … 1126 1160 if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $to . 'wp-includes/version.php', true /* overwrite */ ) ) { 1127 1161 $wp_filesystem->delete( $from, true ); 1128 $result = new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' ); 1129 } 1162 $result = new WP_Error( 1163 'copy_failed_for_version_file', 1164 __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 1165 'wp-includes/version.php' 1166 ); 1167 } 1168 1130 1169 $wp_filesystem->chmod( $to . 'wp-includes/version.php', FS_CHMOD_FILE ); 1131 1170 … … 1142 1181 $skip = array( 'wp-content' ); 1143 1182 $failed = array(); 1183 1144 1184 if ( isset( $checksums ) && is_array( $checksums ) ) { 1145 1185 foreach ( $checksums as $file => $checksum ) { … … 1147 1187 continue; 1148 1188 } 1189 1149 1190 if ( ! file_exists( $working_dir_local . $file ) ) { 1150 1191 continue; 1151 1192 } 1152 if ( '.' === dirname( $file ) && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true ) ) { 1193 1194 if ( '.' === dirname( $file ) 1195 && in_array( pathinfo( $file, PATHINFO_EXTENSION ), array( 'html', 'txt' ), true ) 1196 ) { 1153 1197 $skip[] = $file; 1154 1198 continue; 1155 1199 } 1156 if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) == $checksum ) { 1200 1201 if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) === $checksum ) { 1157 1202 $skip[] = $file; 1158 1203 } else { … … 1165 1210 if ( ! empty( $failed ) ) { 1166 1211 $total_size = 0; 1212 1167 1213 foreach ( $failed as $file ) { 1168 1214 if ( file_exists( $working_dir_local . $file ) ) { … … 1174 1220 // Unlikely to be hit due to the check in unzip_file(). 1175 1221 $available_space = @disk_free_space( ABSPATH ); 1222 1176 1223 if ( $available_space && $total_size >= $available_space ) { 1177 1224 $result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ) ); 1178 1225 } else { 1179 1226 $result = _copy_dir( $from . $distro, $to, $skip ); 1227 1180 1228 if ( is_wp_error( $result ) ) { 1181 $result = new WP_Error( $result->get_error_code() . '_retry', $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) ); 1229 $result = new WP_Error( 1230 $result->get_error_code() . '_retry', 1231 $result->get_error_message(), 1232 substr( $result->get_error_data(), strlen( $to ) ) 1233 ); 1182 1234 } 1183 1235 } … … 1187 1239 // Copy languages. 1188 1240 if ( ! is_wp_error( $result ) && $wp_filesystem->is_dir( $from . $distro . 'wp-content/languages' ) ) { 1189 if ( WP_LANG_DIR != ABSPATH . WPINC . '/languages' || @is_dir( WP_LANG_DIR ) ) {1241 if ( WP_LANG_DIR !== ABSPATH . WPINC . '/languages' || @is_dir( WP_LANG_DIR ) ) { 1190 1242 $lang_dir = WP_LANG_DIR; 1191 1243 } else { … … 1202 1254 if ( @is_dir( $lang_dir ) ) { 1203 1255 $wp_lang_dir = $wp_filesystem->find_folder( $lang_dir ); 1256 1204 1257 if ( $wp_lang_dir ) { 1205 1258 $result = copy_dir( $from . $distro . 'wp-content/languages/', $wp_lang_dir ); 1259 1206 1260 if ( is_wp_error( $result ) ) { 1207 $result = new WP_Error( $result->get_error_code() . '_languages', $result->get_error_message(), substr( $result->get_error_data(), strlen( $wp_lang_dir ) ) ); 1261 $result = new WP_Error( 1262 $result->get_error_code() . '_languages', 1263 $result->get_error_message(), 1264 substr( $result->get_error_data(), strlen( $wp_lang_dir ) ) 1265 ); 1208 1266 } 1209 1267 } … … 1213 1271 /** This filter is documented in wp-admin/includes/update-core.php */ 1214 1272 apply_filters( 'update_feedback', __( 'Disabling Maintenance mode…' ) ); 1273 1215 1274 // Remove maintenance file, we're done with potential site-breaking changes. 1216 1275 $wp_filesystem->delete( $maintenance_file ); 1217 1276 1218 // 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users, preventing installation of Twenty Twelve. 1277 // 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users, 1278 // preventing installation of Twenty Twelve. 1219 1279 if ( '3.5' === $old_wp_version ) { 1220 if ( is_dir( WP_CONTENT_DIR . '/themes/twentytwelve' ) && ! file_exists( WP_CONTENT_DIR . '/themes/twentytwelve/style.css' ) ) { 1280 if ( is_dir( WP_CONTENT_DIR . '/themes/twentytwelve' ) 1281 && ! file_exists( WP_CONTENT_DIR . '/themes/twentytwelve/style.css' ) 1282 ) { 1221 1283 $wp_filesystem->delete( $wp_filesystem->wp_themes_dir() . 'twentytwelve/' ); 1222 1284 } … … 1229 1291 * $development_build controls us overwriting bundled themes and plugins when a non-stable release is being updated. 1230 1292 */ 1231 if ( ! is_wp_error( $result ) && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) { 1293 if ( ! is_wp_error( $result ) 1294 && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) 1295 ) { 1232 1296 foreach ( (array) $_new_bundled_files as $file => $introduced_version ) { 1233 1297 // If a $development_build or if $introduced version is greater than what the site was previously running. … … 1272 1336 $result = new WP_Error; 1273 1337 } 1274 $result->add( $_result->get_error_code() . "_$type", $_result->get_error_message(), substr( $_result->get_error_data(), strlen( $dest ) ) ); 1338 1339 $result->add( 1340 $_result->get_error_code() . "_$type", 1341 $_result->get_error_message(), 1342 substr( $_result->get_error_data(), strlen( $dest ) ) 1343 ); 1275 1344 } 1276 1345 } … … 1282 1351 if ( is_wp_error( $result ) ) { 1283 1352 $wp_filesystem->delete( $from, true ); 1353 1284 1354 return $result; 1285 1355 } … … 1288 1358 foreach ( $_old_files as $old_file ) { 1289 1359 $old_file = $to . $old_file; 1360 1290 1361 if ( ! $wp_filesystem->exists( $old_file ) ) { 1291 1362 continue; … … 1307 1378 /** This filter is documented in wp-admin/includes/update-core.php */ 1308 1379 apply_filters( 'update_feedback', __( 'Upgrading database…' ) ); 1380 1309 1381 $db_upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' ); 1310 1382 wp_remote_post( $db_upgrade_url, array( 'timeout' => 60 ) ); … … 1388 1460 // If copy failed, chmod file to 0644 and try again. 1389 1461 $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE ); 1462 1390 1463 if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) { 1391 1464 return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename ); … … 1412 1485 */ 1413 1486 $sub_skip_list = array(); 1487 1414 1488 foreach ( $skip_list as $skip_item ) { 1415 1489 if ( 0 === strpos( $skip_item, $filename . '/' ) ) { … … 1419 1493 1420 1494 $result = _copy_dir( $from . $filename, $to . $filename, $sub_skip_list ); 1495 1421 1496 if ( is_wp_error( $result ) ) { 1422 1497 return $result; … … 1424 1499 } 1425 1500 } 1501 1426 1502 return true; 1427 1503 } … … 1517 1593 foreach ( $affected_files as $file ) { 1518 1594 $gen_dir = $wp_filesystem->find_folder( trailingslashit( dirname( $file ) ) ); 1595 1519 1596 if ( empty( $gen_dir ) ) { 1520 1597 continue; … … 1547 1624 $files = array(); 1548 1625 1549 if ( file_exists( "{$directory}example.html" ) && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) ) { 1626 if ( file_exists( "{$directory}example.html" ) 1627 && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) 1628 ) { 1550 1629 $files[] = "{$directory}example.html"; 1551 1630 } 1552 1631 1553 1632 $dirs = glob( $directory . '*', GLOB_ONLYDIR ); 1633 1554 1634 if ( $dirs ) { 1555 1635 foreach ( $dirs as $dir ) {
Note: See TracChangeset
for help on using the changeset viewer.