| @@ -133,36 +133,10 @@ | ||
| 133 | 133 | do_action( 'mainwp_before_wp_update', $website ); |
| 134 | 134 | |
| 135 | 135 | $information = MainWP_Connect::fetch_url_authed( $website, 'upgrade' ); |
| 136 | 136 | |
| 137 | - // logging feature. | |
| 138 | - $error = ''; | |
| 139 | - $success = false; | |
| 137 | + static::activity_log_upgrade( $website, $information ); | |
| 140 | 138 | |
| 141 | - if ( is_array( $information ) ) { | |
| 142 | - if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { | |
| 143 | - $success = true; | |
| 144 | - } elseif ( isset( $information['upgrade'] ) ) { | |
| 145 | - if ( 'LOCALIZATION' === $information['upgrade'] ) { | |
| 146 | - $error = esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 147 | - } elseif ( 'NORESPONSE' === $information['upgrade'] ) { | |
| 148 | - $error = esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 149 | - } | |
| 150 | - } elseif ( isset( $information['error'] ) ) { | |
| 151 | - $error = esc_html( $information['error'] ); | |
| 152 | - } else { | |
| 153 | - $error = esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 154 | - } | |
| 155 | - } | |
| 156 | - | |
| 157 | - $output_array = array( | |
| 158 | - 'old_version' => isset( $information['old_version'] ) ? $information['old_version'] : '', | |
| 159 | - 'version' => isset( $information['version'] ) ? $information['version'] : '', | |
| 160 | - 'success' => $success ? 1 : 0, | |
| 161 | - 'error' => $error, | |
| 162 | - ); | |
| 163 | - mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, 'core' ); | |
| 164 | - | |
| 165 | 139 | /** |
| 166 | 140 | * Action: mainwp_after_wp_update |
| 167 | 141 | * |
| 168 | 142 | * Fires after WP update. |
| @@ -176,8 +150,53 @@ | ||
| 176 | 150 | return false; |
| 177 | 151 | } |
| 178 | 152 | |
| 179 | 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 | + /** | |
| 180 | 199 | * Add a plugin or theme to the ignor list. |
| 181 | 200 | * |
| 182 | 201 | * @param mixed $type plugin|theme. |
| 183 | 202 | * @param mixed $slug Plugin or Theme Slug. |
| @@ -1023,8 +1042,19 @@ | ||
| 1023 | 1042 | } |
| 1024 | 1043 | |
| 1025 | 1044 | $undefined = true; |
| 1026 | 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 | + | |
| 1027 | 1057 | if ( isset( $result['upgrades_error'] ) ) { |
| 1028 | 1058 | foreach ( $result['upgrades_error'] as $k => $v ) { |
| 1029 | 1059 | $return_results['result_error'][ rawurlencode( $k ) ] = esc_html( $v ); |
| 1030 | 1060 | } |
| @@ -1134,9 +1164,24 @@ | ||
| 1134 | 1164 | } |
| 1135 | 1165 | } |
| 1136 | 1166 | return $return_results; |
| 1137 | 1167 | } elseif ( isset( $result['error'] ) ) { |
| 1138 | - 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 | + | |
| 1139 | 1184 | } elseif ( isset( $result['notices'] ) ) { |
| 1140 | 1185 | $noti = $result['notices']; |
| 1141 | 1186 | if ( ! empty( $noti ) && is_string( $noti ) ) { |
| 1142 | 1187 | throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |