--- a/wp/wp-admin/includes/class-core-upgrader.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-admin/includes/class-core-upgrader.php Mon Oct 14 18:28:13 2019 +0200
@@ -26,15 +26,15 @@
* @since 2.8.0
*/
public function upgrade_strings() {
- $this->strings['up_to_date'] = __('WordPress is at the latest version.');
- $this->strings['locked'] = __('Another update is currently in progress.');
- $this->strings['no_package'] = __('Update package not available.');
+ $this->strings['up_to_date'] = __( 'WordPress is at the latest version.' );
+ $this->strings['locked'] = __( 'Another update is currently in progress.' );
+ $this->strings['no_package'] = __( 'Update package not available.' );
/* translators: %s: package URL */
- $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' );
- $this->strings['unpack_package'] = __('Unpacking the update…');
- $this->strings['copy_failed'] = __('Could not copy files.');
- $this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' );
- $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' );
+ $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' );
+ $this->strings['unpack_package'] = __( 'Unpacking the update…' );
+ $this->strings['copy_failed'] = __( 'Could not copy files.' );
+ $this->strings['copy_failed_space'] = __( 'Could not copy files. You may have run out of disk space.' );
+ $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' );
$this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' );
}
@@ -43,7 +43,7 @@
*
* @since 2.8.0
*
- * @global WP_Filesystem_Base $wp_filesystem Subclass
+ * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @global callable $_wp_filesystem_direct_method
*
* @param object $current Response object for whether WordPress is current.
@@ -66,10 +66,10 @@
$start_time = time();
- $defaults = array(
- 'pre_check_md5' => true,
- 'attempt_rollback' => false,
- 'do_rollback' => false,
+ $defaults = array(
+ 'pre_check_md5' => true,
+ 'attempt_rollback' => false,
+ 'do_rollback' => false,
'allow_relaxed_file_ownership' => false,
);
$parsed_args = wp_parse_args( $args, $defaults );
@@ -78,21 +78,23 @@
$this->upgrade_strings();
// Is an update available?
- if ( !isset( $current->response ) || $current->response == 'latest' )
- return new WP_Error('up_to_date', $this->strings['up_to_date']);
+ if ( ! isset( $current->response ) || $current->response == 'latest' ) {
+ return new WP_Error( 'up_to_date', $this->strings['up_to_date'] );
+ }
$res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] );
if ( ! $res || is_wp_error( $res ) ) {
return $res;
}
- $wp_dir = trailingslashit($wp_filesystem->abspath());
+ $wp_dir = trailingslashit( $wp_filesystem->abspath() );
$partial = true;
- if ( $parsed_args['do_rollback'] )
+ if ( $parsed_args['do_rollback'] ) {
$partial = false;
- elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() )
+ } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) {
$partial = false;
+ }
/*
* If partial update is returned from the API, use that, unless we're doing
@@ -100,17 +102,18 @@
* the new_bundled zip. Don't though if the constant is set to skip bundled items.
* If the API returns a no_content zip, go with it. Finally, default to the full zip.
*/
- if ( $parsed_args['do_rollback'] && $current->packages->rollback )
+ if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
$to_download = 'rollback';
- elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial )
+ } elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial ) {
$to_download = 'partial';
- elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
- && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
+ } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
+ && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
$to_download = 'new_bundled';
- elseif ( $current->packages->no_content )
+ } elseif ( $current->packages->no_content ) {
$to_download = 'no_content';
- else
+ } else {
$to_download = 'full';
+ }
// Lock to prevent multiple Core Updates occurring
$lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS );
@@ -118,7 +121,26 @@
return new WP_Error( 'locked', $this->strings['locked'] );
}
- $download = $this->download_package( $current->packages->$to_download );
+ $download = $this->download_package( $current->packages->$to_download, true );
+
+ // Allow for signature soft-fail.
+ // WARNING: This may be removed in the future.
+ if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {
+ // Outout the failure error as a normal feedback, and not as an error:
+ apply_filters( 'update_feedback', $download->get_error_message() );
+
+ // Report this failure back to WordPress.org for debugging purposes.
+ wp_version_check(
+ array(
+ 'signature_failure_code' => $download->get_error_code(),
+ 'signature_failure_data' => $download->get_error_data(),
+ )
+ );
+
+ // Pretend this error didn't happen.
+ $download = $download->get_error_data( 'softfail-filename' );
+ }
+
if ( is_wp_error( $download ) ) {
WP_Upgrader::release_lock( 'core_updater' );
return $download;
@@ -131,12 +153,12 @@
}
// Copy update-core.php from the new version into place.
- if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
- $wp_filesystem->delete($working_dir, true);
+ if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) {
+ $wp_filesystem->delete( $working_dir, true );
WP_Upgrader::release_lock( 'core_updater' );
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' );
}
- $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
+ $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE );
require_once( ABSPATH . 'wp-admin/includes/update-core.php' );
@@ -157,12 +179,13 @@
* mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full.
* do_rollback allows for update_core() to trigger a rollback if needed.
*/
- if ( false !== strpos( $error_code, 'do_rollback' ) )
+ if ( false !== strpos( $error_code, 'do_rollback' ) ) {
+ $try_rollback = true;
+ } elseif ( false !== strpos( $error_code, '__copy_dir' ) ) {
$try_rollback = true;
- elseif ( false !== strpos( $error_code, '__copy_dir' ) )
+ } elseif ( 'disk_full' === $error_code ) {
$try_rollback = true;
- elseif ( 'disk_full' === $error_code )
- $try_rollback = true;
+ }
}
if ( $try_rollback ) {
@@ -175,12 +198,26 @@
$rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) );
$original_result = $result;
- $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 'update' => $original_result, 'rollback' => $rollback_result ) );
+ $result = new WP_Error(
+ 'rollback_was_required',
+ $this->strings['rollback_was_required'],
+ (object) array(
+ 'update' => $original_result,
+ 'rollback' => $rollback_result,
+ )
+ );
}
}
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
- do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core' ) );
+ do_action(
+ 'upgrader_process_complete',
+ $this,
+ array(
+ 'action' => 'update',
+ 'type' => 'core',
+ )
+ );
// Clear the current updates
delete_site_transient( 'update_core' );
@@ -191,7 +228,7 @@
'success' => true,
'fs_method' => $wp_filesystem->method,
'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ),
- 'fs_method_direct' => !empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',
+ 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',
'time_taken' => time() - $start_time,
'reported' => $wp_version,
'attempted' => $current->version,
@@ -228,16 +265,14 @@
*
* @since 3.7.0
*
- * @static
- *
* @param string $offered_ver The offered version, of the format x.y.z.
* @return bool True if we should update to the offered version, otherwise false.
*/
public static function should_update_to_version( $offered_ver ) {
include( ABSPATH . WPINC . '/version.php' ); // $wp_version; // x.y.z
- $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
- $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
+ $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
+ $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
$current_is_development_version = (bool) strpos( $wp_version, '-' );
// Defaults:
@@ -255,34 +290,39 @@
$upgrade_dev = $upgrade_minor = $upgrade_major = true;
} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
// Only minor updates for core
- $upgrade_dev = $upgrade_major = false;
+ $upgrade_dev = $upgrade_major = false;
$upgrade_minor = true;
}
}
// 1: If we're already on that version, not much point in updating?
- if ( $offered_ver == $wp_version )
+ if ( $offered_ver == $wp_version ) {
return false;
+ }
// 2: If we're running a newer version, that's a nope
- if ( version_compare( $wp_version, $offered_ver, '>' ) )
+ if ( version_compare( $wp_version, $offered_ver, '>' ) ) {
return false;
+ }
$failure_data = get_site_option( 'auto_core_update_failed' );
if ( $failure_data ) {
// If this was a critical update failure, cannot update.
- if ( ! empty( $failure_data['critical'] ) )
+ if ( ! empty( $failure_data['critical'] ) ) {
return false;
+ }
// Don't claim we can update on update-core.php if we have a non-critical failure logged.
- if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) )
+ if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) {
return false;
+ }
// Cannot update if we're retrying the same A to B update that caused a non-critical failure.
// Some non-critical failures do allow retries, like download_failed.
// 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.
- if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] )
+ if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) {
return false;
+ }
}
// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2
@@ -296,8 +336,9 @@
* @param bool $upgrade_dev Whether to enable automatic updates for
* development versions.
*/
- if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) )
+ if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) {
return false;
+ }
// Else fall through to minor + major branches below.
}
@@ -346,15 +387,18 @@
$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
- if ( ! is_array( $checksums ) )
+ if ( ! is_array( $checksums ) ) {
return false;
+ }
foreach ( $checksums as $file => $checksum ) {
// Skip files which get updated
- if ( 'wp-content' == substr( $file, 0, 10 ) )
+ if ( 'wp-content' == substr( $file, 0, 10 ) ) {
continue;
- if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum )
+ }
+ if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
return false;
+ }
}
return true;