Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-core-upgrader.php

    r41908 r42343  
    2727     */
    2828    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.' );
    3232        /* translators: %s: package URL */
    33         $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' );
    34         $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
    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&#8230;' ), '<span class="code">%s</span>' );
     34        $this->strings['unpack_package']        = __( 'Unpacking the update&#8230;' );
     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.' );
    3838        $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' );
    3939    }
     
    6767        $start_time = time();
    6868
    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,
    7373            'allow_relaxed_file_ownership' => false,
    7474        );
     
    7979
    8080        // 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        }
    8384
    8485        $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] );
     
    8788        }
    8889
    89         $wp_dir = trailingslashit($wp_filesystem->abspath());
     90        $wp_dir = trailingslashit( $wp_filesystem->abspath() );
    9091
    9192        $partial = true;
    92         if ( $parsed_args['do_rollback'] )
     93        if ( $parsed_args['do_rollback'] ) {
    9394            $partial = false;
    94         elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() )
     95        } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) {
    9596            $partial = false;
     97        }
    9698
    9799        /*
     
    101103         * If the API returns a no_content zip, go with it. Finally, default to the full zip.
    102104         */
    103         if ( $parsed_args['do_rollback'] && $current->packages->rollback )
     105        if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
    104106            $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 ) {
    106108            $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 ) ) {
    109111            $to_download = 'new_bundled';
    110         elseif ( $current->packages->no_content )
     112        } elseif ( $current->packages->no_content ) {
    111113            $to_download = 'no_content';
    112         else
     114        } else {
    113115            $to_download = 'full';
     116        }
    114117
    115118        // Lock to prevent multiple Core Updates occurring
     
    132135
    133136        // 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 );
    136139            WP_Upgrader::release_lock( 'core_updater' );
    137140            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' );
    138141        }
    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 );
    140143
    141144        require_once( ABSPATH . 'wp-admin/includes/update-core.php' );
     
    158161                 * do_rollback allows for update_core() to trigger a rollback if needed.
    159162                 */
    160                 if ( false !== strpos( $error_code, 'do_rollback' ) )
     163                if ( false !== strpos( $error_code, 'do_rollback' ) ) {
    161164                    $try_rollback = true;
    162                 elseif ( false !== strpos( $error_code, '__copy_dir' ) )
     165                } elseif ( false !== strpos( $error_code, '__copy_dir' ) ) {
    163166                    $try_rollback = true;
    164                 elseif ( 'disk_full' === $error_code )
     167                } elseif ( 'disk_full' === $error_code ) {
    165168                    $try_rollback = true;
     169                }
    166170            }
    167171
     
    176180
    177181                $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                );
    179188            }
    180189        }
    181190
    182191        /** 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        );
    184198
    185199        // Clear the current updates
     
    192206                'fs_method'        => $wp_filesystem->method,
    193207                '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'] : '',
    195209                'time_taken'       => time() - $start_time,
    196210                'reported'         => $wp_version,
     
    237251        include( ABSPATH . WPINC . '/version.php' ); // $wp_version; // x.y.z
    238252
    239         $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
    240         $new_branch     = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
     253        $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
    241255        $current_is_development_version = (bool) strpos( $wp_version, '-' );
    242256
     
    256270            } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
    257271                // Only minor updates for core
    258                 $upgrade_dev = $upgrade_major = false;
     272                $upgrade_dev   = $upgrade_major = false;
    259273                $upgrade_minor = true;
    260274            }
     
    262276
    263277        // 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 ) {
    265279            return false;
     280        }
    266281
    267282        // 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, '>' ) ) {
    269284            return false;
     285        }
    270286
    271287        $failure_data = get_site_option( 'auto_core_update_failed' );
    272288        if ( $failure_data ) {
    273289            // 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            }
    276293
    277294            // 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            }
    280298
    281299            // Cannot update if we're retrying the same A to B update that caused a non-critical failure.
    282300            // Some non-critical failures do allow retries, like download_failed.
    283301            // 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            }
    286305        }
    287306
     
    297316             *                          development versions.
    298317             */
    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            }
    301321            // Else fall through to minor + major branches below.
    302322        }
     
    347367        $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
    348368
    349         if ( ! is_array( $checksums ) )
     369        if ( ! is_array( $checksums ) ) {
    350370            return false;
     371        }
    351372
    352373        foreach ( $checksums as $file => $checksum ) {
    353374            // Skip files which get updated
    354             if ( 'wp-content' == substr( $file, 0, 10 ) )
     375            if ( 'wp-content' == substr( $file, 0, 10 ) ) {
    355376                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            }
    358381        }
    359382
Note: See TracChangeset for help on using the changeset viewer.