| @@ -6,8 +6,13 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace MainWP\Dashboard; |
| 9 | 9 | |
| 10 | +// Exit if accessed directly. | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 10 | 15 | /** |
| 11 | 16 | * Class MainWP_Updates_Handler |
| 12 | 17 | * |
| 13 | 18 | * @package MainWP\Dashboard |
| @@ -44,31 +49,56 @@ | ||
| 44 | 49 | |
| 45 | 50 | $website = MainWP_DB::instance()->get_website_by_id( $id ); |
| 46 | 51 | |
| 47 | 52 | if ( MainWP_System_Utility::is_suspended_site( $website ) ) { |
| 48 | - throw new MainWP_Exception( 'ERROR', '<i class="pause circular yellow inverted icon"></i> ' . esc_html__( 'Suspended site.', 'mainwp' ) ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 53 | + throw new MainWP_Exception( 'ERROR', '<i class="pause circular yellow inverted icon"></i> ' . esc_html__( 'Suspended site.', 'mainwp' ), 'SUSPENDED_SITE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 49 | 54 | } |
| 50 | 55 | |
| 51 | 56 | $information = static::upgrade_website( $website ); |
| 52 | 57 | |
| 53 | 58 | if ( is_array( $information ) ) { |
| 54 | - if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { | |
| 59 | + $thrw_error = ''; | |
| 60 | + $thrw_extra = ''; | |
| 61 | + $success = false; | |
| 62 | + if ( isset( $information['upgrade'] ) && 'SUCCESS' === $information['upgrade'] ) { | |
| 55 | 63 | MainWP_DB::instance()->update_website_option( $website, 'wp_upgrades', wp_json_encode( array() ) ); |
| 56 | 64 | do_action( 'mainwp_after_upgrade_wp_success', $website, $information ); |
| 57 | - return '<i class="green check icon"></i>'; | |
| 65 | + // Get Icon for the largest change scope of ext regression testing. | |
| 66 | + $html_regression_icon = apply_filters( 'mainwp_html_regression_largest_change_scope', $website->id, true ) ?: ''; // phpcs:ignore -- NOSONAR | |
| 67 | + if ( $website->id === $html_regression_icon ) { | |
| 68 | + $html_regression_icon = ''; | |
| 69 | + } | |
| 70 | + $raw_msg = esc_html__( 'Update successful', 'mainwp' ); | |
| 71 | + $msg_success = '<span data-inverted="" data-position="left center" data-tooltip="' . esc_html__( 'Update successful', 'mainwp' ) . '"><i class="green check icon"></i></span>' . $html_regression_icon; | |
| 72 | + $success = true; | |
| 58 | 73 | } elseif ( isset( $information['upgrade'] ) ) { |
| 59 | 74 | $errorMsg = ''; |
| 60 | 75 | if ( 'LOCALIZATION' === $information['upgrade'] ) { |
| 76 | + $raw_msg = esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 61 | 77 | $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No update found for the set locale.', 'mainwp' ); |
| 62 | 78 | } elseif ( 'NORESPONSE' === $information['upgrade'] ) { |
| 79 | + $raw_msg = esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 63 | 80 | $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No response from the child site server.', 'mainwp' ); |
| 64 | 81 | } |
| 65 | - throw new MainWP_Exception( 'WPERROR', $errorMsg ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 82 | + $thrw_error = 'WPERROR'; | |
| 83 | + $thrw_extra = $errorMsg; | |
| 66 | 84 | } elseif ( isset( $information['error'] ) ) { |
| 67 | - throw new MainWP_Exception( 'WPERROR', esc_html( $information['error'] ) ); | |
| 85 | + $thrw_error = 'WPERROR'; | |
| 86 | + $thrw_extra = esc_html( $information['error'] ); | |
| 87 | + $raw_msg = esc_html( $information['error'] ); | |
| 68 | 88 | } else { |
| 69 | - throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Invalid response from child site.', 'mainwp' ) ); | |
| 89 | + $thrw_error = 'ERROR'; | |
| 90 | + $thrw_extra = '<i class="red times icon"></i> ' . esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 91 | + $raw_msg = esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 70 | 92 | } |
| 93 | + | |
| 94 | + do_action( 'mainwp_after_upgrade_wp_core', $website, $information, $success, $raw_msg ); | |
| 95 | + | |
| 96 | + if ( ! empty( $thrw_error ) ) { | |
| 97 | + throw new MainWP_Exception( $thrw_error, $thrw_extra ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- NOSONAR -escaped. | |
| 98 | + } elseif ( ! empty( $msg_success ) ) { | |
| 99 | + return $msg_success; | |
| 100 | + } | |
| 71 | 101 | } |
| 72 | 102 | } |
| 73 | 103 | |
| 74 | 104 | throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); |
| @@ -103,36 +133,10 @@ | ||
| 103 | 133 | do_action( 'mainwp_before_wp_update', $website ); |
| 104 | 134 | |
| 105 | 135 | $information = MainWP_Connect::fetch_url_authed( $website, 'upgrade' ); |
| 106 | 136 | |
| 107 | - // logging feature. | |
| 108 | - $error = ''; | |
| 109 | - $success = false; | |
| 137 | + static::activity_log_upgrade( $website, $information ); | |
| 110 | 138 | |
| 111 | - if ( is_array( $information ) ) { | |
| 112 | - if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { | |
| 113 | - $success = true; | |
| 114 | - } elseif ( isset( $information['upgrade'] ) ) { | |
| 115 | - if ( 'LOCALIZATION' === $information['upgrade'] ) { | |
| 116 | - $error = esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 117 | - } elseif ( 'NORESPONSE' === $information['upgrade'] ) { | |
| 118 | - $error = esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 119 | - } | |
| 120 | - } elseif ( isset( $information['error'] ) ) { | |
| 121 | - $error = esc_html( $information['error'] ); | |
| 122 | - } else { | |
| 123 | - $error = esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 124 | - } | |
| 125 | - } | |
| 126 | - | |
| 127 | - $output_array = array( | |
| 128 | - 'old_version' => isset( $information['old_version'] ) ? $information['old_version'] : '', | |
| 129 | - 'version' => isset( $information['version'] ) ? $information['version'] : '', | |
| 130 | - 'success' => $success ? 1 : 0, | |
| 131 | - 'error' => $error, | |
| 132 | - ); | |
| 133 | - mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, 'core' ); | |
| 134 | - | |
| 135 | 139 | /** |
| 136 | 140 | * Action: mainwp_after_wp_update |
| 137 | 141 | * |
| 138 | 142 | * Fires after WP update. |
| @@ -146,8 +150,53 @@ | ||
| 146 | 150 | return false; |
| 147 | 151 | } |
| 148 | 152 | |
| 149 | 153 | /** |
| 154 | + * Log upgrade activities. | |
| 155 | + * | |
| 156 | + * @param object $website Child site object. | |
| 157 | + * @param array $information Upgrade information. | |
| 158 | + * @param bool $is_auto_update Whether the update is automatic. | |
| 159 | + */ | |
| 160 | + public static function activity_log_upgrade( $website, $information, $is_auto_update = false ) { // phpcs:ignore -- NOSONAR - complex. | |
| 161 | + // Implementation for logging upgrade activities. | |
| 162 | + $error = ''; | |
| 163 | + $success = false; | |
| 164 | + | |
| 165 | + if ( is_array( $information ) ) { | |
| 166 | + if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { | |
| 167 | + $success = true; | |
| 168 | + } elseif ( isset( $information['upgrade'] ) ) { | |
| 169 | + if ( 'LOCALIZATION' === $information['upgrade'] ) { | |
| 170 | + $error = esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 171 | + } elseif ( 'NORESPONSE' === $information['upgrade'] ) { | |
| 172 | + $error = esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 173 | + } | |
| 174 | + } elseif ( isset( $information['error'] ) ) { | |
| 175 | + $error = esc_html( $information['error'] ); | |
| 176 | + } else { | |
| 177 | + $error = esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 178 | + } | |
| 179 | + } | |
| 180 | + | |
| 181 | + $output_array = array( | |
| 182 | + 'old_version' => is_array( $information ) && isset( $information['old_version'] ) ? $information['old_version'] : '', | |
| 183 | + 'version' => is_array( $information ) && isset( $information['version'] ) ? $information['version'] : '', | |
| 184 | + 'success' => $success ? 1 : 0, | |
| 185 | + 'error' => $error, | |
| 186 | + ); | |
| 187 | + | |
| 188 | + if ( $is_auto_update ) { | |
| 189 | + MainWP_Updates_Report_Manager::save_update_info( $website, $output_array, 'core' ); | |
| 190 | + } | |
| 191 | + | |
| 192 | + $actions_handler = mainwp_get_actions_handler_instance(); | |
| 193 | + if ( is_object( $actions_handler ) ) { | |
| 194 | + $actions_handler->do_action_mainwp_install_actions( $website, 'updated', $output_array, 'core' ); | |
| 195 | + } | |
| 196 | + } | |
| 197 | + | |
| 198 | + /** | |
| 150 | 199 | * Add a plugin or theme to the ignor list. |
| 151 | 200 | * |
| 152 | 201 | * @param mixed $type plugin|theme. |
| 153 | 202 | * @param mixed $slug Plugin or Theme Slug. |
| @@ -720,9 +769,9 @@ | ||
| 720 | 769 | } elseif ( 'theme' === $type ) { |
| 721 | 770 | if ( '_ALL_' === $slug ) { |
| 722 | 771 | $decodedIgnoredThemes = array(); |
| 723 | 772 | } else { |
| 724 | - $decodedIgnoredThemes = json_decode( $userExtension->ignored_plugins, true ); | |
| 773 | + $decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true ); | |
| 725 | 774 | if ( ! is_array( $decodedIgnoredThemes ) ) { |
| 726 | 775 | $decodedIgnoredThemes = array(); |
| 727 | 776 | } |
| 728 | 777 | if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { |
| @@ -993,8 +1042,19 @@ | ||
| 993 | 1042 | } |
| 994 | 1043 | |
| 995 | 1044 | $undefined = true; |
| 996 | 1045 | |
| 1046 | + // Keep this for backward compatibility. | |
| 1047 | + if ( ! empty( $result['upgrades_started'] ) && is_array( $result['upgrades_started'] ) ) { | |
| 1048 | + foreach ( $result['upgrades_started'] as $k => $v ) { | |
| 1049 | + if ( empty( $v ) ) { | |
| 1050 | + $return_results['result_error'][ rawurlencode( $k ) ] = esc_html__( 'Premium action request failed. Please try again later.', 'mainwp' ); | |
| 1051 | + } else { | |
| 1052 | + $return_results['result_started'][ rawurlencode( $k ) ] = esc_html( $v ); | |
| 1053 | + } | |
| 1054 | + } | |
| 1055 | + } | |
| 1056 | + | |
| 997 | 1057 | if ( isset( $result['upgrades_error'] ) ) { |
| 998 | 1058 | foreach ( $result['upgrades_error'] as $k => $v ) { |
| 999 | 1059 | $return_results['result_error'][ rawurlencode( $k ) ] = esc_html( $v ); |
| 1000 | 1060 | } |
| @@ -1064,8 +1124,9 @@ | ||
| 1064 | 1124 | } |
| 1065 | 1125 | } |
| 1066 | 1126 | |
| 1067 | 1127 | if ( 'plugin' === $type ) { |
| 1128 | + $website = MainWP_DB::instance()->get_website_by_id( $id, false ); // Call new data the before a updated. | |
| 1068 | 1129 | if ( ! empty( $website->plugin_upgrades ) ) { |
| 1069 | 1130 | $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); |
| 1070 | 1131 | if ( is_array( $plugin_upgrades ) ) { |
| 1071 | 1132 | $updated = false; |
| @@ -1103,9 +1164,24 @@ | ||
| 1103 | 1164 | } |
| 1104 | 1165 | } |
| 1105 | 1166 | return $return_results; |
| 1106 | 1167 | } elseif ( isset( $result['error'] ) ) { |
| 1107 | - throw new MainWP_Exception( 'WPERROR', esc_html( $result['error'] ) ); | |
| 1168 | + $error_message = esc_html( $result['error'] ); | |
| 1169 | + | |
| 1170 | + if ( ! empty( $result['http_code'] ) ) { | |
| 1171 | + $error_message .= ' HTTP code: ' . esc_html( $result['http_code'] ) . '.'; | |
| 1172 | + } | |
| 1173 | + | |
| 1174 | + if ( ! empty( $result['rep_error'] ) ) { | |
| 1175 | + $error_message .= ' Connection error: ' . esc_html( $result['rep_error'] ) . '.'; | |
| 1176 | + } | |
| 1177 | + | |
| 1178 | + if ( ! empty( $result['rep_error_code'] ) ) { | |
| 1179 | + $error_message .= ' Error code: ' . esc_html( $result['rep_error_code'] ) . '.'; | |
| 1180 | + } | |
| 1181 | + | |
| 1182 | + throw new MainWP_Exception( 'WPERROR', $error_message ); // phpcs:ignore --NOSONAR - escaped. | |
| 1183 | + | |
| 1108 | 1184 | } elseif ( isset( $result['notices'] ) ) { |
| 1109 | 1185 | $noti = $result['notices']; |
| 1110 | 1186 | if ( ! empty( $noti ) && is_string( $noti ) ) { |
| 1111 | 1187 | throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |