Ticket #37531: 37531.7.diff
File 37531.7.diff, 11.1 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/ajax-actions.php
3345 3345 wp_send_json_error( $status ); 3346 3346 } 3347 3347 3348 $upgrader = new Theme_Upgrader( new Automatic_Upgrader_Skin() ); 3348 $skin = new WP_Ajax_Upgrader_Skin(); 3349 $upgrader = new Theme_Upgrader( $skin ); 3349 3350 $result = $upgrader->install( $api->download_link ); 3350 3351 3351 3352 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3352 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3353 $status['debug'] = $skin->get_upgrade_messages(); 3353 3354 } 3354 3355 3355 3356 if ( is_wp_error( $result ) ) { 3357 $status['errorCode'] = $result->get_error_code(); 3356 3358 $status['errorMessage'] = $result->get_error_message(); 3357 3359 wp_send_json_error( $status ); 3360 } elseif ( is_wp_error( $skin->result ) ) { 3361 $status['errorCode'] = $skin->result->get_error_code(); 3362 $status['errorMessage'] = $skin->result->get_error_message(); 3363 wp_send_json_error( $status ); 3364 } elseif ( $skin->get_errors()->get_error_code() ) { 3365 $status['errorMessage'] = $skin->get_error_messages(); 3366 wp_send_json_error( $status ); 3358 3367 } elseif ( is_null( $result ) ) { 3359 3368 global $wp_filesystem; 3360 3369 … … 3437 3446 wp_update_themes(); 3438 3447 } 3439 3448 3440 $upgrader = new Theme_Upgrader( new Automatic_Upgrader_Skin() ); 3449 $skin = new WP_Ajax_Upgrader_Skin(); 3450 $upgrader = new Theme_Upgrader( $skin ); 3441 3451 $result = $upgrader->bulk_upgrade( array( $stylesheet ) ); 3442 3452 3443 3453 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3444 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3454 $status['debug'] = $skin->get_upgrade_messages(); 3445 3455 } 3446 3456 3447 if ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { 3457 if ( is_wp_error( $result ) ) { 3458 $status['errorCode'] = $result->get_error_code(); 3459 $status['errorMessage'] = $result->get_error_message(); 3460 wp_send_json_error( $status ); 3461 } elseif ( is_wp_error( $skin->result ) ) { 3462 $status['errorCode'] = $skin->result->get_error_code(); 3463 $status['errorMessage'] = $skin->result->get_error_message(); 3464 wp_send_json_error( $status ); 3465 } elseif ( $skin->get_errors()->get_error_code() ) { 3466 $status['errorMessage'] = $skin->get_error_messages(); 3467 wp_send_json_error( $status ); 3468 } elseif ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) { 3448 3469 3449 3470 // Theme is already at the latest version. 3450 3471 if ( true === $result[ $stylesheet ] ) { … … 3458 3479 } 3459 3480 3460 3481 wp_send_json_success( $status ); 3461 } elseif ( is_wp_error( $upgrader->skin->result ) ) {3462 $status['errorCode'] = $upgrader->skin->result->get_error_code();3463 $status['errorMessage'] = $upgrader->skin->result->get_error_message();3464 wp_send_json_error( $status );3465 3482 } elseif ( false === $result ) { 3466 3483 global $wp_filesystem; 3467 3484 … … 3594 3611 3595 3612 $status['pluginName'] = $api->name; 3596 3613 3597 $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); 3614 $skin = new WP_Ajax_Upgrader_Skin(); 3615 $upgrader = new Plugin_Upgrader( $skin ); 3598 3616 $result = $upgrader->install( $api->download_link ); 3599 3617 3600 3618 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3601 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3619 $status['debug'] = $skin->get_upgrade_messages(); 3602 3620 } 3603 3621 3604 3622 if ( is_wp_error( $result ) ) { 3623 $status['errorCode'] = $result->get_error_code(); 3605 3624 $status['errorMessage'] = $result->get_error_message(); 3606 3625 wp_send_json_error( $status ); 3626 } elseif ( is_wp_error( $skin->result ) ) { 3627 $status['errorCode'] = $skin->result->get_error_code(); 3628 $status['errorMessage'] = $skin->result->get_error_message(); 3629 wp_send_json_error( $status ); 3630 } elseif ( $skin->get_errors()->get_error_code() ) { 3631 $status['errorMessage'] = $skin->get_error_messages(); 3632 wp_send_json_error( $status ); 3607 3633 } elseif ( is_null( $result ) ) { 3608 3634 global $wp_filesystem; 3609 3635 … … 3680 3706 3681 3707 wp_update_plugins(); 3682 3708 3683 $skin = new Automatic_Upgrader_Skin();3709 $skin = new WP_Ajax_Upgrader_Skin(); 3684 3710 $upgrader = new Plugin_Upgrader( $skin ); 3685 3711 $result = $upgrader->bulk_upgrade( array( $plugin ) ); 3686 3712 3687 3713 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 3688 $status['debug'] = $ upgrader->skin->get_upgrade_messages();3714 $status['debug'] = $skin->get_upgrade_messages(); 3689 3715 } 3690 3716 3691 if ( is_array( $result ) && empty( $result[ $plugin ] ) && is_wp_error( $skin->result ) ) { 3692 $result = $skin->result; 3693 } 3694 3695 if ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { 3717 if ( is_wp_error( $result ) ) { 3718 $status['errorCode'] = $result->get_error_code(); 3719 $status['errorMessage'] = $result->get_error_message(); 3720 wp_send_json_error( $status ); 3721 } elseif ( is_wp_error( $skin->result ) ) { 3722 $status['errorCode'] = $skin->result->get_error_code(); 3723 $status['errorMessage'] = $skin->result->get_error_message(); 3724 wp_send_json_error( $status ); 3725 } elseif ( $skin->get_errors()->get_error_code() ) { 3726 $status['errorMessage'] = $skin->get_error_messages(); 3727 wp_send_json_error( $status ); 3728 } elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) { 3696 3729 $plugin_update_data = current( $result ); 3697 3730 3698 3731 /* … … 3716 3749 $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); 3717 3750 } 3718 3751 wp_send_json_success( $status ); 3719 } elseif ( is_wp_error( $result ) ) {3720 $status['errorMessage'] = $result->get_error_message();3721 wp_send_json_error( $status );3722 3752 } elseif ( false === $result ) { 3723 3753 global $wp_filesystem; 3724 3754 -
src/wp-admin/includes/class-wp-ajax-upgrader-skin.php
1 <?php 2 /** 3 * Upgrader API: WP_Ajax_Upgrader_Skin class 4 * 5 * @package WordPress 6 * @subpackage Upgrader 7 * @since 4.6.0 8 */ 9 10 /** 11 * Upgrader Skin for Ajax WordPress Upgrades 12 * 13 * This skin is designed to be used for Ajax updates. 14 * 15 * @since 4.6.0 16 * 17 * @see Automatic_Upgrader_Skin 18 */ 19 class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin { 20 21 /** 22 * Holds the WP_Error object. 23 * 24 * @since 4.6.0 25 * @access protected 26 * 27 * @var null|WP_Error 28 */ 29 protected $errors = null; 30 31 /** 32 * Constructor. 33 * 34 * @since 4.6.0 35 * @access public 36 * 37 * @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct(). 38 */ 39 public function __construct( $args = array() ) { 40 parent::__construct( $args ); 41 42 $this->errors = new WP_Error(); 43 } 44 45 /** 46 * Retrieves the list of errors. 47 * 48 * @since 4.6.0 49 * @access public 50 * 51 * @return WP_Error Errors during an upgrade. 52 */ 53 public function get_errors() { 54 return $this->errors; 55 } 56 57 /** 58 * Retrieves a string for error messages 59 * 60 * @since 4.6.0 61 * @access public 62 * 63 * @return string Error messages during an upgrade. 64 */ 65 public function get_error_messages() { 66 $messages = array(); 67 68 foreach ( $this->errors->get_error_codes() as $error_code ) { 69 if ( $this->errors->get_error_data( $error_code ) && is_string( $this->errors->get_error_data( $error_code ) ) ) { 70 $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $this->errors->get_error_data( $error_code ) ) ); 71 } else { 72 $messages[] = $this->errors->get_error_message( $error_code ); 73 } 74 } 75 76 return implode( ', ', $messages ); 77 } 78 79 /** 80 * Stores a log entry for an error. 81 * 82 * @since 4.6.0 83 * @access public 84 * 85 * @param string|WP_Error $errors 86 */ 87 public function error( $errors ) { 88 if ( is_string( $errors ) ) { 89 $string = $errors; 90 if ( ! empty( $this->upgrader->strings[ $string ] ) ) { 91 $string = $this->upgrader->strings[ $string ]; 92 } 93 94 if ( false !== strpos( $string, '%' ) ) { 95 $args = func_get_args(); 96 $args = array_splice( $args, 1 ); 97 if ( ! empty( $args ) ) { 98 $string = vsprintf( $string, $args ); 99 } 100 } 101 102 // Count existing errors to generate an unique error code. 103 $errors_count = count( $errors->get_error_codes() ); 104 $this->errors->add( 'unknown_upgrade_error_' . $errors_count + 1 , $string ); 105 } elseif ( is_wp_error( $errors ) ) { 106 foreach ( $errors->get_error_codes() as $error_code ) { 107 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); 108 } 109 } 110 111 $args = func_get_args(); 112 call_user_func_array( array( $this, 'parent::error' ), $args ); 113 } 114 115 /** 116 * Stores a log entry. 117 * 118 * @since 4.6.0 119 * @access public 120 * 121 * @param string|array|WP_Error $data 122 */ 123 public function feedback( $data ) { 124 if ( is_wp_error( $data ) ) { 125 foreach ( $data->get_error_codes() as $error_code ) { 126 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) ); 127 } 128 } 129 130 $args = func_get_args(); 131 call_user_func_array( array( $this, 'parent::feedback' ), $args ); 132 } 133 } -
src/wp-admin/includes/class-wp-upgrader-skins.php
36 36 37 37 /** Automatic_Upgrader_Skin class */ 38 38 require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php'; 39 40 /** WP_Ajax_Upgrader_Skin class */ 41 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; -
src/wp-admin/includes/class-wp-upgrader.php
39 39 /** Automatic_Upgrader_Skin class */ 40 40 require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php'; 41 41 42 /** WP_Ajax_Upgrader_Skin class */ 43 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; 44 42 45 /** 43 46 * Core class used for upgrading/installing a local set of files via 44 47 * the Filesystem Abstraction classes from a Zip file. -
src/wp-admin/js/updates.js
244 244 * @param {string=} response.errorCode Optional. Error code for an error that occurred. 245 245 */ 246 246 wp.updates.ajaxAlways = function( response ) { 247 if ( ! response.errorCode &&'unable_to_connect_to_filesystem' !== response.errorCode ) {247 if ( ! response.errorCode || 'unable_to_connect_to_filesystem' !== response.errorCode ) { 248 248 wp.updates.ajaxLocked = false; 249 249 wp.updates.queueChecker(); 250 250 } … … 1524 1524 * @returns {boolean} Whether there is an error that needs to be handled or not. 1525 1525 */ 1526 1526 wp.updates.maybeHandleCredentialError = function( response, action ) { 1527 if ( response.errorCode && 'unable_to_connect_to_filesystem' === response.errorCode ) {1527 if ( wp.updates.shouldRequestFilesystemCredentials && response.errorCode && 'unable_to_connect_to_filesystem' === response.errorCode ) { 1528 1528 wp.updates.credentialError( response, action ); 1529 1529 return true; 1530 1530 }