WordPress.org

Make WordPress Core

Changeset 25763


Ignore:
Timestamp:
10/11/2013 04:05:13 PM (5 years ago)
Author:
nacin
Message:

Refine error codes throughout the upgrader so we can better detect at what stage updates fail.

see #22704.

Location:
trunk/src/wp-admin/includes
Files:
3 edited

Legend:

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

    r25755 r25763  
    214214            $source = trailingslashit($source) . trailingslashit($source_files[0]);
    215215        elseif ( count($source_files) == 0 )
    216             return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $this->strings['no_files'] ); //There are no files?
     216            return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
    217217        else //It's only a single file, the upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
    218218            $source = trailingslashit($source);
     
    263263        if ( !$wp_filesystem->exists($remote_destination) )
    264264            if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
    265                 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
     265                return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
    266266
    267267        // Copy new version of item into place.
     
    624624
    625625        if ( ! $plugins_found )
    626             return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') );
     626            return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
    627627
    628628        return $source;
     
    990990        // A proper archive should have a style.css file in the single subdirectory
    991991        if ( ! file_exists( $working_directory . 'style.css' ) )
    992             return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
     992            return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], __( 'The theme is missing the <code>style.css</code> stylesheet.' ) );
    993993
    994994        $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
    995995
    996996        if ( empty( $info['Name'] ) )
    997             return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
     997            return new WP_Error( 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'], __( "The <code>style.css</code> stylesheet doesn't contain a valid theme header." ) );
    998998
    999999        // If it's not a child theme, it must have at least an index.php to be legit.
    10001000        if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) )
    1001             return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
     1001            return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], __( 'The theme is missing the <code>index.php</code> file.' ) );
    10021002
    10031003        return $source;
     
    11421142        if ( ! $wp_filesystem->exists( $remote_destination ) )
    11431143            if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) )
    1144                 return new WP_Error( 'mkdir_failed', $this->strings['mkdir_failed'], $remote_destination );
     1144                return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination );
    11451145
    11461146        foreach ( $language_updates as $language_update ) {
     
    12011201
    12021202        if ( ! $mo || ! $po )
    1203             return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'],
     1203            return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'],
    12041204                __( 'The language pack is missing either the <code>.po</code> or <code>.mo</code> files.' ) );
    12051205
     
    12881288        if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
    12891289            $wp_filesystem->delete($working_dir, true);
    1290             return new WP_Error('copy_failed', $this->strings['copy_failed']);
     1290            return new WP_Error( 'copy_failed_for_update_core_file', $this->strings['copy_failed'] );
    12911291        }
    12921292        $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
  • trunk/src/wp-admin/includes/file.php

    r25739 r25763  
    604604    for ( $i = 0; $i < $z->numFiles; $i++ ) {
    605605        if ( ! $info = $z->statIndex($i) )
    606             return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
     606            return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
    607607
    608608        if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
     
    634634    foreach ( $needed_dirs as $_dir ) {
    635635        if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the Dir exists upon creation failure. Less I/O this way.
    636             return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir);
     636            return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), $_dir );
    637637    }
    638638    unset($needed_dirs);
     
    640640    for ( $i = 0; $i < $z->numFiles; $i++ ) {
    641641        if ( ! $info = $z->statIndex($i) )
    642             return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
     642            return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
    643643
    644644        if ( '/' == substr($info['name'], -1) ) // directory
     
    650650        $contents = $z->getFromIndex($i);
    651651        if ( false === $contents )
    652             return new WP_Error('extract_failed', __('Could not extract file from archive.'), $info['name']);
     652            return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] );
    653653
    654654        if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) )
    655             return new WP_Error('copy_failed', __('Could not copy file.'), $to . $info['name']);
     655            return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $to . $info['name'] );
    656656    }
    657657
     
    692692
    693693    if ( 0 == count($archive_files) )
    694         return new WP_Error('empty_archive', __('Empty archive.'));
     694        return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
    695695
    696696    // Determine any children directories needed (From within the archive)
     
    721721    foreach ( $needed_dirs as $_dir ) {
    722722        if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the dir exists upon creation failure. Less I/O this way.
    723             return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir);
     723            return new WP_Error( 'mkdir_failed_pclzip', __( 'Could not create directory.' ), $_dir );
    724724    }
    725725    unset($needed_dirs);
     
    734734
    735735        if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
    736             return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']);
     736            return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $to . $file['filename'] );
    737737    }
    738738    return true;
     
    767767                $wp_filesystem->chmod($to . $filename, 0644);
    768768                if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
    769                     return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
     769                    return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
    770770            }
    771771        } elseif ( 'd' == $fileinfo['type'] ) {
    772772            if ( !$wp_filesystem->is_dir($to . $filename) ) {
    773773                if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
    774                     return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
     774                    return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );
    775775            }
    776776
  • trunk/src/wp-admin/includes/update-core.php

    r25658 r25763  
    662662    if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) {
    663663         $wp_filesystem->delete( $from, true );
    664          return new WP_Error( 'copy_failed', __('Could not copy file.') );
     664         return new WP_Error( 'copy_failed_for_version_file', __( 'Could not copy file.' ) );
    665665    }
    666666
     
    742742
    743743        // If we don't have enough free space, it isn't worth trying again
    744         if ( $total_size >= disk_free_space( ABSPATH ) )
     744        if ( $total_size >= disk_free_space( ABSPATH ) ) {
    745745            $result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ), $to );
    746         else
     746        } else {
    747747            $result = _copy_dir( $from . $distro, $to, $skip );
     748            if ( is_wp_error( $result ) )
     749                $result = new WP_Error( $result->get_error_code() . '_retry', $result->get_error_message(), $result->get_error_data() );
     750        }
    748751    }
    749752
     
    801804
    802805                    if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) )
    803                         $result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
     806                        $result = new WP_Error( 'copy_failed_for_new_bundled', __( 'Could not copy file.' ), $dest . $filename );
    804807                } else {
    805808                    if ( ! $development_build && $wp_filesystem->is_dir( $dest . $filename ) )
     
    888891                $wp_filesystem->chmod($to . $filename, 0644);
    889892                if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
    890                     return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
     893                    return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
    891894            }
    892895        } elseif ( 'd' == $fileinfo['type'] ) {
    893896            if ( !$wp_filesystem->is_dir($to . $filename) ) {
    894897                if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
    895                     return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
     898                    return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
    896899            }
    897900
Note: See TracChangeset for help on using the changeset viewer.