Changeset 42343 for trunk/src/wp-admin/includes/class-core-upgrader.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-core-upgrader.php
r41908 r42343 27 27 */ 28 28 public function upgrade_strings() { 29 $this->strings['up_to_date'] = __( 'WordPress is at the latest version.');30 $this->strings['locked'] = __('Another update is currently in progress.');31 $this->strings['no_package'] = __( 'Update package not available.');29 $this->strings['up_to_date'] = __( 'WordPress is at the latest version.' ); 30 $this->strings['locked'] = __( 'Another update is currently in progress.' ); 31 $this->strings['no_package'] = __( 'Update package not available.' ); 32 32 /* translators: %s: package URL */ 33 $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' );34 $this->strings['unpack_package'] = __('Unpacking the update…');35 $this->strings['copy_failed'] = __('Could not copy files.');36 $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' );37 $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' );33 $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' ); 34 $this->strings['unpack_package'] = __( 'Unpacking the update…' ); 35 $this->strings['copy_failed'] = __( 'Could not copy files.' ); 36 $this->strings['copy_failed_space'] = __( 'Could not copy files. You may have run out of disk space.' ); 37 $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' ); 38 38 $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' ); 39 39 } … … 67 67 $start_time = time(); 68 68 69 $defaults = array(70 'pre_check_md5' => true,71 'attempt_rollback' => false,72 'do_rollback' => false,69 $defaults = array( 70 'pre_check_md5' => true, 71 'attempt_rollback' => false, 72 'do_rollback' => false, 73 73 'allow_relaxed_file_ownership' => false, 74 74 ); … … 79 79 80 80 // Is an update available? 81 if ( !isset( $current->response ) || $current->response == 'latest' ) 82 return new WP_Error('up_to_date', $this->strings['up_to_date']); 81 if ( ! isset( $current->response ) || $current->response == 'latest' ) { 82 return new WP_Error( 'up_to_date', $this->strings['up_to_date'] ); 83 } 83 84 84 85 $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] ); … … 87 88 } 88 89 89 $wp_dir = trailingslashit( $wp_filesystem->abspath());90 $wp_dir = trailingslashit( $wp_filesystem->abspath() ); 90 91 91 92 $partial = true; 92 if ( $parsed_args['do_rollback'] ) 93 if ( $parsed_args['do_rollback'] ) { 93 94 $partial = false; 94 elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() )95 } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) { 95 96 $partial = false; 97 } 96 98 97 99 /* … … 101 103 * If the API returns a no_content zip, go with it. Finally, default to the full zip. 102 104 */ 103 if ( $parsed_args['do_rollback'] && $current->packages->rollback ) 105 if ( $parsed_args['do_rollback'] && $current->packages->rollback ) { 104 106 $to_download = 'rollback'; 105 elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial )107 } elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial ) { 106 108 $to_download = 'partial'; 107 elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )108 && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) 109 } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) 110 && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) { 109 111 $to_download = 'new_bundled'; 110 elseif ( $current->packages->no_content )112 } elseif ( $current->packages->no_content ) { 111 113 $to_download = 'no_content'; 112 else114 } else { 113 115 $to_download = 'full'; 116 } 114 117 115 118 // Lock to prevent multiple Core Updates occurring … … 132 135 133 136 // Copy update-core.php from the new version into place. 134 if ( ! $wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {135 $wp_filesystem->delete( $working_dir, true);137 if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) { 138 $wp_filesystem->delete( $working_dir, true ); 136 139 WP_Upgrader::release_lock( 'core_updater' ); 137 140 return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' ); 138 141 } 139 $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);142 $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE ); 140 143 141 144 require_once( ABSPATH . 'wp-admin/includes/update-core.php' ); … … 158 161 * do_rollback allows for update_core() to trigger a rollback if needed. 159 162 */ 160 if ( false !== strpos( $error_code, 'do_rollback' ) ) 163 if ( false !== strpos( $error_code, 'do_rollback' ) ) { 161 164 $try_rollback = true; 162 elseif ( false !== strpos( $error_code, '__copy_dir' ) )165 } elseif ( false !== strpos( $error_code, '__copy_dir' ) ) { 163 166 $try_rollback = true; 164 elseif ( 'disk_full' === $error_code )167 } elseif ( 'disk_full' === $error_code ) { 165 168 $try_rollback = true; 169 } 166 170 } 167 171 … … 176 180 177 181 $original_result = $result; 178 $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 'update' => $original_result, 'rollback' => $rollback_result ) ); 182 $result = new WP_Error( 183 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 184 'update' => $original_result, 185 'rollback' => $rollback_result, 186 ) 187 ); 179 188 } 180 189 } 181 190 182 191 /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ 183 do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ) ); 192 do_action( 193 'upgrader_process_complete', $this, array( 194 'action' => 'update', 195 'type' => 'core', 196 ) 197 ); 184 198 185 199 // Clear the current updates … … 192 206 'fs_method' => $wp_filesystem->method, 193 207 'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ), 194 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',208 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '', 195 209 'time_taken' => time() - $start_time, 196 210 'reported' => $wp_version, … … 237 251 include( ABSPATH . WPINC . '/version.php' ); // $wp_version; // x.y.z 238 252 239 $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version), 0, 2 ) ); // x.y240 $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y253 $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y 254 $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y 241 255 $current_is_development_version = (bool) strpos( $wp_version, '-' ); 242 256 … … 256 270 } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { 257 271 // Only minor updates for core 258 $upgrade_dev = $upgrade_major = false;272 $upgrade_dev = $upgrade_major = false; 259 273 $upgrade_minor = true; 260 274 } … … 262 276 263 277 // 1: If we're already on that version, not much point in updating? 264 if ( $offered_ver == $wp_version ) 278 if ( $offered_ver == $wp_version ) { 265 279 return false; 280 } 266 281 267 282 // 2: If we're running a newer version, that's a nope 268 if ( version_compare( $wp_version, $offered_ver, '>' ) ) 283 if ( version_compare( $wp_version, $offered_ver, '>' ) ) { 269 284 return false; 285 } 270 286 271 287 $failure_data = get_site_option( 'auto_core_update_failed' ); 272 288 if ( $failure_data ) { 273 289 // If this was a critical update failure, cannot update. 274 if ( ! empty( $failure_data['critical'] ) ) 275 return false; 290 if ( ! empty( $failure_data['critical'] ) ) { 291 return false; 292 } 276 293 277 294 // Don't claim we can update on update-core.php if we have a non-critical failure logged. 278 if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) 279 return false; 295 if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) { 296 return false; 297 } 280 298 281 299 // Cannot update if we're retrying the same A to B update that caused a non-critical failure. 282 300 // Some non-critical failures do allow retries, like download_failed. 283 301 // 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2. 284 if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) 285 return false; 302 if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) { 303 return false; 304 } 286 305 } 287 306 … … 297 316 * development versions. 298 317 */ 299 if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) 300 return false; 318 if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) { 319 return false; 320 } 301 321 // Else fall through to minor + major branches below. 302 322 } … … 347 367 $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); 348 368 349 if ( ! is_array( $checksums ) ) 369 if ( ! is_array( $checksums ) ) { 350 370 return false; 371 } 351 372 352 373 foreach ( $checksums as $file => $checksum ) { 353 374 // Skip files which get updated 354 if ( 'wp-content' == substr( $file, 0, 10 ) ) 375 if ( 'wp-content' == substr( $file, 0, 10 ) ) { 355 376 continue; 356 if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) 357 return false; 377 } 378 if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) { 379 return false; 380 } 358 381 } 359 382
Note: See TracChangeset
for help on using the changeset viewer.