Updates: Correctly identify more failed update cases.

This checks for a WP_Error being raised during an individual update, in addition to just the bootstrap error cases.
When a error occurs during the connection phase, pass the error message back as the ajax failure message.

Merges [32571] & [32778] to the 4.2 branch

See #32473, #32435

Built from https://develop.svn.wordpress.org/branches/4.2@33302


git-svn-id: http://core.svn.wordpress.org/branches/4.2@33274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2015-07-17 03:59:28 +00:00
parent 8e96288144
commit b6058e2231

View File

@ -2883,6 +2883,8 @@ function wp_ajax_destroy_sessions() {
* @see Plugin_Upgrader
*/
function wp_ajax_update_plugin() {
global $wp_filesystem;
$plugin = urldecode( $_POST['plugin'] );
$status = array(
@ -2909,10 +2911,15 @@ function wp_ajax_update_plugin() {
wp_update_plugins();
$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$result = $upgrader->bulk_upgrade( array( $plugin ) );
if ( is_array( $result ) ) {
if ( is_array( $result ) && empty( $result[$plugin] ) && is_wp_error( $skin->result ) ) {
$result = $skin->result;
}
if ( is_array( $result ) && !empty( $result[ $plugin ] ) ) {
$plugin_update_data = current( $result );
/*
@ -2938,10 +2945,18 @@ function wp_ajax_update_plugin() {
} else if ( is_wp_error( $result ) ) {
$status['error'] = $result->get_error_message();
wp_send_json_error( $status );
} else if ( is_bool( $result ) && ! $result ) {
} else if ( is_bool( $result ) && ! $result ) {
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
$status['error'] = $wp_filesystem->errors->get_error_message();
}
wp_send_json_error( $status );
}
}