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

see #22704.

Built from https://develop.svn.wordpress.org/trunk@25763


git-svn-id: http://core.svn.wordpress.org/trunk@25676 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-10-11 16:06:11 +00:00
parent 7d22195cbb
commit 29f5f5b5fd
3 changed files with 28 additions and 25 deletions

View File

@ -213,7 +213,7 @@ class WP_Upgrader {
if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
$source = trailingslashit($source) . trailingslashit($source_files[0]);
elseif ( count($source_files) == 0 )
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $this->strings['no_files'] ); //There are no files?
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
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.
$source = trailingslashit($source);
@ -262,7 +262,7 @@ class WP_Upgrader {
//Create destination if needed
if ( !$wp_filesystem->exists($remote_destination) )
if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
// Copy new version of item into place.
$result = copy_dir($source, $remote_destination);
@ -623,7 +623,7 @@ class Plugin_Upgrader extends WP_Upgrader {
}
if ( ! $plugins_found )
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') );
return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
return $source;
}
@ -989,16 +989,16 @@ class Theme_Upgrader extends WP_Upgrader {
// A proper archive should have a style.css file in the single subdirectory
if ( ! file_exists( $working_directory . 'style.css' ) )
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'], __( 'The theme is missing the <code>style.css</code> stylesheet.' ) );
$info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
if ( empty( $info['Name'] ) )
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
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." ) );
// If it's not a child theme, it must have at least an index.php to be legit.
if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) )
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'], __( 'The theme is missing the <code>index.php</code> file.' ) );
return $source;
}
@ -1141,7 +1141,7 @@ class Language_Pack_Upgrader extends WP_Upgrader {
$remote_destination = $wp_filesystem->find_folder( WP_LANG_DIR );
if ( ! $wp_filesystem->exists( $remote_destination ) )
if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) )
return new WP_Error( 'mkdir_failed', $this->strings['mkdir_failed'], $remote_destination );
return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination );
foreach ( $language_updates as $language_update ) {
@ -1200,7 +1200,7 @@ class Language_Pack_Upgrader extends WP_Upgrader {
}
if ( ! $mo || ! $po )
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'],
return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'],
__( 'The language pack is missing either the <code>.po</code> or <code>.mo</code> files.' ) );
return $source;
@ -1287,7 +1287,7 @@ class Core_Upgrader extends WP_Upgrader {
// 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);
return new WP_Error('copy_failed', $this->strings['copy_failed']);
return new WP_Error( 'copy_failed_for_update_core_file', $this->strings['copy_failed'] );
}
$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);

View File

@ -603,7 +603,7 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
for ( $i = 0; $i < $z->numFiles; $i++ ) {
if ( ! $info = $z->statIndex($i) )
return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
continue;
@ -633,13 +633,13 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
// Create those directories if need be:
foreach ( $needed_dirs as $_dir ) {
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.
return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir);
return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), $_dir );
}
unset($needed_dirs);
for ( $i = 0; $i < $z->numFiles; $i++ ) {
if ( ! $info = $z->statIndex($i) )
return new WP_Error('stat_failed', __('Could not retrieve file from archive.'));
return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
if ( '/' == substr($info['name'], -1) ) // directory
continue;
@ -649,10 +649,10 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
$contents = $z->getFromIndex($i);
if ( false === $contents )
return new WP_Error('extract_failed', __('Could not extract file from archive.'), $info['name']);
return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] );
if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) )
return new WP_Error('copy_failed', __('Could not copy file.'), $to . $info['name']);
return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $to . $info['name'] );
}
$z->close();
@ -691,7 +691,7 @@ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) {
return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true));
if ( 0 == count($archive_files) )
return new WP_Error('empty_archive', __('Empty archive.'));
return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
// Determine any children directories needed (From within the archive)
foreach ( $archive_files as $file ) {
@ -720,7 +720,7 @@ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) {
// Create those directories if need be:
foreach ( $needed_dirs as $_dir ) {
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.
return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir);
return new WP_Error( 'mkdir_failed_pclzip', __( 'Could not create directory.' ), $_dir );
}
unset($needed_dirs);
@ -733,7 +733,7 @@ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) {
continue;
if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']);
return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $to . $file['filename'] );
}
return true;
}
@ -766,12 +766,12 @@ function copy_dir($from, $to, $skip_list = array() ) {
// If copy failed, chmod file to 0644 and try again.
$wp_filesystem->chmod($to . $filename, 0644);
if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
}
} elseif ( 'd' == $fileinfo['type'] ) {
if ( !$wp_filesystem->is_dir($to . $filename) ) {
if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );
}
// generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list

View File

@ -661,7 +661,7 @@ function update_core($from, $to) {
$versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) {
$wp_filesystem->delete( $from, true );
return new WP_Error( 'copy_failed', __('Could not copy file.') );
return new WP_Error( 'copy_failed_for_version_file', __( 'Could not copy file.' ) );
}
$wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE );
@ -741,10 +741,13 @@ function update_core($from, $to) {
$total_size += filesize( $working_dir_local . '/' . $file );
// If we don't have enough free space, it isn't worth trying again
if ( $total_size >= disk_free_space( ABSPATH ) )
if ( $total_size >= disk_free_space( ABSPATH ) ) {
$result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ), $to );
else
} else {
$result = _copy_dir( $from . $distro, $to, $skip );
if ( is_wp_error( $result ) )
$result = new WP_Error( $result->get_error_code() . '_retry', $result->get_error_message(), $result->get_error_data() );
}
}
// Custom Content Directory needs updating now.
@ -800,7 +803,7 @@ function update_core($from, $to) {
continue;
if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) )
$result = new WP_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
$result = new WP_Error( 'copy_failed_for_new_bundled', __( 'Could not copy file.' ), $dest . $filename );
} else {
if ( ! $development_build && $wp_filesystem->is_dir( $dest . $filename ) )
continue;
@ -887,12 +890,12 @@ function _copy_dir($from, $to, $skip_list = array() ) {
// If copy failed, chmod file to 0644 and try again.
$wp_filesystem->chmod($to . $filename, 0644);
if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
}
} elseif ( 'd' == $fileinfo['type'] ) {
if ( !$wp_filesystem->is_dir($to . $filename) ) {
if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
}
// generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list