Make WordPress Core

Ticket #10205: 10205.2.diff

File 10205.2.diff, 5.4 KB (added by dd32, 11 years ago)

Allow Partial core upgrades to make use of Direct when it wouldn't normally. Core Partial upgrades do not create new files, and thus, do not need as stringent tests.

  • src/wp-admin/includes/class-wp-upgrader.php

     
    10741074                global $wp_filesystem, $wp_version;
    10751075
    10761076                $defaults = array(
     1077                        'to_download' => 'full',
    10771078                );
    10781079                $parsed_args = wp_parse_args( $defaults, $args );
    10791080
     
    10901091
    10911092                $wp_dir = trailingslashit($wp_filesystem->abspath());
    10921093
    1093                 // If partial update is returned from the API, use that, unless we're doing a reinstall.
    1094                 // If we cross the new_bundled version number, then use the new_bundled zip.
    1095                 // Don't though if the constant is set to skip bundled items.
    1096                 // If the API returns a no_content zip, go with it. Finally, default to the full zip.
    1097                 if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version )
    1098                         $to_download = 'partial';
    1099                 elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
    1100                         && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
    1101                         $to_download = 'new_bundled';
    1102                 elseif ( $current->packages->no_content )
    1103                         $to_download = 'no_content';
    1104                 else
    1105                         $to_download = 'full';
    1106 
    1107                 $download = $this->download_package( $current->packages->$to_download );
     1094                $download = $this->download_package( $update->packages->{$parsed_args['to_download']} );
    11081095                if ( is_wp_error($download) )
    11091096                        return $download;
    11101097
  • src/wp-admin/includes/file.php

     
    833833function get_filesystem_method($args = array(), $context = false) {
    834834        $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
    835835
     836        if ( ! $context )
     837                $context = WP_CONTENT_DIR;
     838
    836839        if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
    837                 if ( !$context )
    838                         $context = WP_CONTENT_DIR;
    839840                $context = trailingslashit($context);
    840841                $temp_file_name = $context . 'temp-write-test-' . time();
    841842                $temp_handle = @fopen($temp_file_name, 'w');
     
    847848                }
    848849        }
    849850
     851        // If group-writable is OK, check that the current file, and the destination( $context ) is writable.
     852        // Group-writable is only enabled for Partial Core Upgrades at present due to them only modifying changed files, not creating new files
     853        if ( ! $method && !empty( $args['allow_group_writable'] ) && is_writable( $context ) && is_writable( __FILE__ ) )
     854                $method = 'direct';
     855
    850856        if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2';
    851857        if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
    852858        if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
  • src/wp-admin/update-core.php

     
    314314function do_core_upgrade( $reinstall = false ) {
    315315        global $wp_filesystem;
    316316
     317        include ABSPATH . WPINC . '/version.php'; // $wp_version
    317318        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    318319
    319320        if ( $reinstall )
     
    327328        $version = isset( $_POST['version'] )? $_POST['version'] : false;
    328329        $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
    329330        $update = find_core_update( $version, $locale );
    330         if ( !$update )
     331
     332        if ( !$update || !isset( $update->response ) )
    331333                return;
    332334
    333         if ( ! WP_Filesystem($credentials, ABSPATH) ) {
     335        if ( $reinstall )
     336                $update->response = 'reinstall';
     337
     338        if ( $update->response == 'latest' )
     339                return;
     340
     341        // If partial update is returned from the API, use that, unless we're doing a reinstall.
     342        // If we cross the new_bundled version number, then use the new_bundled zip.
     343        // Don't though if the constant is set to skip bundled items.
     344        // If the API returns a no_content zip, go with it. Finally, default to the full zip.
     345        if ( $update->packages->partial && ! $reinstall && $wp_version == $update->partial_version )
     346                $to_download = 'partial';
     347        elseif ( $update->packages->new_bundled && version_compare( $wp_version, $update->new_bundled, '<' )
     348                && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) )
     349                $to_download = 'new_bundled';
     350        elseif ( $update->packages->no_content )
     351                $to_download = 'no_content';
     352        else
     353                $to_download = 'full';
     354
     355        $credentials['allow_group_writable'] = ( 'partial' == $to_download );
     356
     357        if ( ! WP_Filesystem( $credentials, ABSPATH ) ) {
    334358                request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
    335359                return;
    336360        }
     
    346370                return;
    347371        }
    348372
    349         if ( $reinstall )
    350                 $update->response = 'reinstall';
     373        $args = array(
     374                'to_download' => $to_download,
     375        );
    351376
    352377        add_filter( 'update_feedback', 'show_message' );
    353378
    354379        $upgrader = new Core_Upgrader();
    355         $result = $upgrader->upgrade( $update );
     380        $result = $upgrader->upgrade( $update, $args );
    356381
    357382        if ( is_wp_error($result) ) {
    358383                show_message($result);