Ticket #37531: 37531.8.diff
File 37531.8.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(); 3689 } 3690 3691 if ( is_array( $result ) && empty( $result[ $plugin ] ) && is_wp_error( $skin->result ) ) { 3692 $result = $skin->result; 3714 $status['debug'] = $skin->get_upgrade_messages(); 3693 3715 } 3694 3716 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 * @var null|WP_Error 27 */ 28 protected $errors = null; 29 30 /** 31 * Constructor. 32 * 33 * @since 4.6.0 34 * @access public 35 * 36 * @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct(). 37 */ 38 public function __construct( $args = array() ) { 39 parent::__construct( $args ); 40 41 $this->errors = new WP_Error(); 42 } 43 44 /** 45 * Retrieves the list of errors. 46 * 47 * @since 4.6.0 48 * @access public 49 * 50 * @return WP_Error Errors during an upgrade. 51 */ 52 public function get_errors() { 53 return $this->errors; 54 } 55 56 /** 57 * Retrieves a string for error messages 58 * 59 * @since 4.6.0 60 * @access public 61 * 62 * @return string Error messages during an upgrade. 63 */ 64 public function get_error_messages() { 65 $messages = array(); 66 67 foreach ( $this->errors->get_error_codes() as $error_code ) { 68 if ( $this->errors->get_error_data( $error_code ) && is_string( $this->errors->get_error_data( $error_code ) ) ) { 69 $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $this->errors->get_error_data( $error_code ) ) ); 70 } else { 71 $messages[] = $this->errors->get_error_message( $error_code ); 72 } 73 } 74 75 return implode( ', ', $messages ); 76 } 77 78 /** 79 * Stores a log entry for an error. 80 * 81 * @since 4.6.0 82 * @access public 83 * 84 * @param string|WP_Error $errors Errors. 85 */ 86 public function error( $errors ) { 87 if ( is_string( $errors ) ) { 88 $string = $errors; 89 if ( ! empty( $this->upgrader->strings[ $string ] ) ) { 90 $string = $this->upgrader->strings[ $string ]; 91 } 92 93 if ( false !== strpos( $string, '%' ) ) { 94 $args = func_get_args(); 95 $args = array_splice( $args, 1 ); 96 if ( ! empty( $args ) ) { 97 $string = vsprintf( $string, $args ); 98 } 99 } 100 101 // Count existing errors to generate an unique error code. 102 $errors_count = count( $errors->get_error_codes() ); 103 $this->errors->add( 'unknown_upgrade_error_' . $errors_count + 1 , $string ); 104 } elseif ( is_wp_error( $errors ) ) { 105 foreach ( $errors->get_error_codes() as $error_code ) { 106 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); 107 } 108 } 109 110 $args = func_get_args(); 111 call_user_func_array( array( $this, 'parent::error' ), $args ); 112 } 113 114 /** 115 * Stores a log entry. 116 * 117 * @since 4.6.0 118 * @access public 119 * 120 * @param string|array|WP_Error $data Log entry data. 121 */ 122 public function feedback( $data ) { 123 if ( is_wp_error( $data ) ) { 124 foreach ( $data->get_error_codes() as $error_code ) { 125 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) ); 126 } 127 } 128 129 $args = func_get_args(); 130 call_user_func_array( array( $this, 'parent::feedback' ), $args ); 131 } 132 } -
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 }