27 */ |
27 */ |
28 public function upgrade_strings() { |
28 public function upgrade_strings() { |
29 $this->strings['up_to_date'] = __( 'WordPress is at the latest version.' ); |
29 $this->strings['up_to_date'] = __( 'WordPress is at the latest version.' ); |
30 $this->strings['locked'] = __( 'Another update is currently in progress.' ); |
30 $this->strings['locked'] = __( 'Another update is currently in progress.' ); |
31 $this->strings['no_package'] = __( 'Update package not available.' ); |
31 $this->strings['no_package'] = __( 'Update package not available.' ); |
32 /* translators: %s: package URL */ |
32 /* translators: %s: Package URL. */ |
33 $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' ); |
33 $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' ); |
34 $this->strings['unpack_package'] = __( 'Unpacking the update…' ); |
34 $this->strings['unpack_package'] = __( 'Unpacking the update…' ); |
35 $this->strings['copy_failed'] = __( 'Could not copy files.' ); |
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.' ); |
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.' ); |
37 $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' ); |
55 * @type bool $attempt_rollback Whether to attempt to rollback the chances if |
55 * @type bool $attempt_rollback Whether to attempt to rollback the chances if |
56 * there is a problem. Default false. |
56 * there is a problem. Default false. |
57 * @type bool $do_rollback Whether to perform this "upgrade" as a rollback. |
57 * @type bool $do_rollback Whether to perform this "upgrade" as a rollback. |
58 * Default false. |
58 * Default false. |
59 * } |
59 * } |
60 * @return null|false|WP_Error False or WP_Error on failure, null on success. |
60 * @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure. |
61 */ |
61 */ |
62 public function upgrade( $current, $args = array() ) { |
62 public function upgrade( $current, $args = array() ) { |
63 global $wp_filesystem; |
63 global $wp_filesystem; |
64 |
64 |
65 include( ABSPATH . WPINC . '/version.php' ); // $wp_version; |
65 require ABSPATH . WPINC . '/version.php'; // $wp_version; |
66 |
66 |
67 $start_time = time(); |
67 $start_time = time(); |
68 |
68 |
69 $defaults = array( |
69 $defaults = array( |
70 'pre_check_md5' => true, |
70 'pre_check_md5' => true, |
76 |
76 |
77 $this->init(); |
77 $this->init(); |
78 $this->upgrade_strings(); |
78 $this->upgrade_strings(); |
79 |
79 |
80 // Is an update available? |
80 // Is an update available? |
81 if ( ! isset( $current->response ) || $current->response == 'latest' ) { |
81 if ( ! isset( $current->response ) || 'latest' === $current->response ) { |
82 return new WP_Error( 'up_to_date', $this->strings['up_to_date'] ); |
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'] ); |
85 $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] ); |
86 if ( ! $res || is_wp_error( $res ) ) { |
86 if ( ! $res || is_wp_error( $res ) ) { |
102 * the new_bundled zip. Don't though if the constant is set to skip bundled items. |
102 * the new_bundled zip. Don't though if the constant is set to skip bundled items. |
103 * If the API returns a no_content zip, go with it. Finally, default to the full zip. |
103 * If the API returns a no_content zip, go with it. Finally, default to the full zip. |
104 */ |
104 */ |
105 if ( $parsed_args['do_rollback'] && $current->packages->rollback ) { |
105 if ( $parsed_args['do_rollback'] && $current->packages->rollback ) { |
106 $to_download = 'rollback'; |
106 $to_download = 'rollback'; |
107 } 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 ) { |
108 $to_download = 'partial'; |
108 $to_download = 'partial'; |
109 } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->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 ) ) { |
110 && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) { |
111 $to_download = 'new_bundled'; |
111 $to_download = 'new_bundled'; |
112 } elseif ( $current->packages->no_content ) { |
112 } elseif ( $current->packages->no_content ) { |
113 $to_download = 'no_content'; |
113 $to_download = 'no_content'; |
114 } else { |
114 } else { |
115 $to_download = 'full'; |
115 $to_download = 'full'; |
116 } |
116 } |
117 |
117 |
118 // Lock to prevent multiple Core Updates occurring |
118 // Lock to prevent multiple Core Updates occurring. |
119 $lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS ); |
119 $lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS ); |
120 if ( ! $lock ) { |
120 if ( ! $lock ) { |
121 return new WP_Error( 'locked', $this->strings['locked'] ); |
121 return new WP_Error( 'locked', $this->strings['locked'] ); |
122 } |
122 } |
123 |
123 |
125 |
125 |
126 // Allow for signature soft-fail. |
126 // Allow for signature soft-fail. |
127 // WARNING: This may be removed in the future. |
127 // WARNING: This may be removed in the future. |
128 if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) { |
128 if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) { |
129 // Outout the failure error as a normal feedback, and not as an error: |
129 // Outout the failure error as a normal feedback, and not as an error: |
|
130 /** This filter is documented in wp-admin/includes/update-core.php */ |
130 apply_filters( 'update_feedback', $download->get_error_message() ); |
131 apply_filters( 'update_feedback', $download->get_error_message() ); |
131 |
132 |
132 // Report this failure back to WordPress.org for debugging purposes. |
133 // Report this failure back to WordPress.org for debugging purposes. |
133 wp_version_check( |
134 wp_version_check( |
134 array( |
135 array( |
158 WP_Upgrader::release_lock( 'core_updater' ); |
159 WP_Upgrader::release_lock( 'core_updater' ); |
159 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' ); |
160 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' ); |
160 } |
161 } |
161 $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE ); |
162 $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE ); |
162 |
163 |
163 require_once( ABSPATH . 'wp-admin/includes/update-core.php' ); |
164 wp_opcache_invalidate( ABSPATH . 'wp-admin/includes/update-core.php' ); |
|
165 require_once ABSPATH . 'wp-admin/includes/update-core.php'; |
164 |
166 |
165 if ( ! function_exists( 'update_core' ) ) { |
167 if ( ! function_exists( 'update_core' ) ) { |
166 WP_Upgrader::release_lock( 'core_updater' ); |
168 WP_Upgrader::release_lock( 'core_updater' ); |
167 return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] ); |
169 return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] ); |
168 } |
170 } |
267 * |
269 * |
268 * @param string $offered_ver The offered version, of the format x.y.z. |
270 * @param string $offered_ver The offered version, of the format x.y.z. |
269 * @return bool True if we should update to the offered version, otherwise false. |
271 * @return bool True if we should update to the offered version, otherwise false. |
270 */ |
272 */ |
271 public static function should_update_to_version( $offered_ver ) { |
273 public static function should_update_to_version( $offered_ver ) { |
272 include( ABSPATH . WPINC . '/version.php' ); // $wp_version; // x.y.z |
274 require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z |
273 |
275 |
274 $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y |
276 $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y |
275 $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y |
277 $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y |
|
278 |
276 $current_is_development_version = (bool) strpos( $wp_version, '-' ); |
279 $current_is_development_version = (bool) strpos( $wp_version, '-' ); |
277 |
280 |
278 // Defaults: |
281 // Defaults: |
279 $upgrade_dev = true; |
282 $upgrade_dev = true; |
280 $upgrade_minor = true; |
283 $upgrade_minor = true; |
281 $upgrade_major = false; |
284 $upgrade_major = false; |
282 |
285 |
283 // WP_AUTO_UPDATE_CORE = true (all), 'minor', false. |
286 // WP_AUTO_UPDATE_CORE = true (all), 'minor', false. |
284 if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { |
287 if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { |
285 if ( false === WP_AUTO_UPDATE_CORE ) { |
288 if ( false === WP_AUTO_UPDATE_CORE ) { |
286 // Defaults to turned off, unless a filter allows it |
289 // Defaults to turned off, unless a filter allows it. |
287 $upgrade_dev = $upgrade_minor = $upgrade_major = false; |
290 $upgrade_dev = false; |
|
291 $upgrade_minor = false; |
|
292 $upgrade_major = false; |
288 } elseif ( true === WP_AUTO_UPDATE_CORE ) { |
293 } elseif ( true === WP_AUTO_UPDATE_CORE ) { |
289 // ALL updates for core |
294 // ALL updates for core. |
290 $upgrade_dev = $upgrade_minor = $upgrade_major = true; |
295 $upgrade_dev = true; |
|
296 $upgrade_minor = true; |
|
297 $upgrade_major = true; |
291 } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { |
298 } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { |
292 // Only minor updates for core |
299 // Only minor updates for core. |
293 $upgrade_dev = $upgrade_major = false; |
300 $upgrade_dev = false; |
294 $upgrade_minor = true; |
301 $upgrade_minor = true; |
|
302 $upgrade_major = false; |
295 } |
303 } |
296 } |
304 } |
297 |
305 |
298 // 1: If we're already on that version, not much point in updating? |
306 // 1: If we're already on that version, not much point in updating? |
299 if ( $offered_ver == $wp_version ) { |
307 if ( $offered_ver == $wp_version ) { |
300 return false; |
308 return false; |
301 } |
309 } |
302 |
310 |
303 // 2: If we're running a newer version, that's a nope |
311 // 2: If we're running a newer version, that's a nope. |
304 if ( version_compare( $wp_version, $offered_ver, '>' ) ) { |
312 if ( version_compare( $wp_version, $offered_ver, '>' ) ) { |
305 return false; |
313 return false; |
306 } |
314 } |
307 |
315 |
308 $failure_data = get_site_option( 'auto_core_update_failed' ); |
316 $failure_data = get_site_option( 'auto_core_update_failed' ); |
315 // Don't claim we can update on update-core.php if we have a non-critical failure logged. |
323 // Don't claim we can update on update-core.php if we have a non-critical failure logged. |
316 if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) { |
324 if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) { |
317 return false; |
325 return false; |
318 } |
326 } |
319 |
327 |
320 // Cannot update if we're retrying the same A to B update that caused a non-critical failure. |
328 /* |
321 // Some non-critical failures do allow retries, like download_failed. |
329 * Cannot update if we're retrying the same A to B update that caused a non-critical failure. |
322 // 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. |
330 * Some non-critical failures do allow retries, like download_failed. |
|
331 * 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. |
|
332 */ |
323 if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) { |
333 if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) { |
324 return false; |
334 return false; |
325 } |
335 } |
326 } |
336 } |
327 |
337 |
328 // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2 |
338 // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2. |
329 if ( $current_is_development_version ) { |
339 if ( $current_is_development_version ) { |
330 |
340 |
331 /** |
341 /** |
332 * Filters whether to enable automatic core updates for development versions. |
342 * Filters whether to enable automatic core updates for development versions. |
333 * |
343 * |
366 * @param bool $upgrade_major Whether to enable major automatic core updates. |
376 * @param bool $upgrade_major Whether to enable major automatic core updates. |
367 */ |
377 */ |
368 return apply_filters( 'allow_major_auto_core_updates', $upgrade_major ); |
378 return apply_filters( 'allow_major_auto_core_updates', $upgrade_major ); |
369 } |
379 } |
370 |
380 |
371 // If we're not sure, we don't want it |
381 // If we're not sure, we don't want it. |
372 return false; |
382 return false; |
373 } |
383 } |
374 |
384 |
375 /** |
385 /** |
376 * Compare the disk file checksums against the expected checksums. |
386 * Compare the disk file checksums against the expected checksums. |
377 * |
387 * |
378 * @since 3.7.0 |
388 * @since 3.7.0 |
379 * |
389 * |
380 * @global string $wp_version |
390 * @global string $wp_version The WordPress version string. |
381 * @global string $wp_local_package |
391 * @global string $wp_local_package Locale code of the package. |
382 * |
392 * |
383 * @return bool True if the checksums match, otherwise false. |
393 * @return bool True if the checksums match, otherwise false. |
384 */ |
394 */ |
385 public function check_files() { |
395 public function check_files() { |
386 global $wp_version, $wp_local_package; |
396 global $wp_version, $wp_local_package; |