PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 All 156 releases
← All changes | assets/js/mainwp-updates.js +290 -55 6.2 → 6.2.1 View file →
@@ -44,20 +44,36 @@
44 44 });
45 45 };
46 46
47 47 // Decode slug safely.
48 -globalThis.mainwp_decode_slug = function (value) { // NOSONAR
48 +globalThis.mainwp_decode_slug = function (value, escape ) { // NOSONAR
49 49 if (typeof value !== 'string' || !value.includes('%')) {
50 - return value;
50 + return (true === escape && typeof value === 'string') ? mainwp_escape_html(value) : value;
51 51 }
52 52
53 53 try {
54 - return decodeURIComponent(value);
54 + value = decodeURIComponent(value);
55 55 } catch {
56 - return value;
56 + // nothing.
57 57 }
58 +
59 + if(true === escape){
60 + return mainwp_escape_html(value);
61 + }
62 +
63 + return value;
58 64 };
59 65
66 +globalThis.mainwp_escape_html = function (value) { // NOSONAR
67 + const div = document.createElement('div');
68 + div.textContent = value ?? '';
69 +
70 + return div.innerHTML
71 + .replace(/"/g, '"')
72 + .replace(/'/g, ''');
73 +};
74 +
75 +
60 76 // Normalize slug list to array.
61 77 globalThis.mainwp_slug_list_to_array = function (value) { // NOSONAR.
62 78 if (Array.isArray(value)) {
63 79 return value.filter(function (v) { return v !== null && v !== undefined && String(v).trim() !== ''; });
@@ -1039,11 +1055,99 @@
1039 1055 while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxUpdateThreads) && (mainwpVars.websitesLeft > 0)) {
1040 1056 updatesoverview_plugins_upgrade_all_upgrade_next();
1041 1057 }
1042 1058 };
1043 -let updatesoverview_plugins_upgrade_all_update_site_status = function (siteId, newStatus) {
1044 - jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus);
1059 +let updatesoverview_plugins_upgrade_all_update_site_status = function (siteId, newStatus, append) {
1060 + const $status = jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]');
1061 +
1062 + if (append) {
1063 + $status.append(newStatus);
1064 + } else {
1065 + $status.html(newStatus);
1066 + }
1045 1067 };
1068 +
1069 +/**
1070 + * Updates the status popup for a site upgrade item.
1071 + *
1072 + * @param {number|string} siteId The site ID.
1073 + * @param {number} itemnumber The upgrade item number.
1074 + * @param {Object} options Options for updating the popup status.
1075 + * @param {*} options.status The status content or value.
1076 + * @param {boolean} options.ispopup Whether to display the status in a popup.
1077 + * @param {*} options.icon The icon to display with the status.
1078 + * @param {boolean} options.append Whether to append the content instead of replacing it.
1079 + * @param {*} options.addition Additional content or data to include.
1080 + * @param {boolean} options.isHidden Whether to hide the status.
1081 + *
1082 + * @returns {void}
1083 + */
1084 +let upgradeall_update_site_popup_multi_status = function (siteId, itemnumber, options = {}) {
1085 + if (!siteId) {
1086 + return;
1087 + }
1088 + const {
1089 + status = false,
1090 + ispopup = false,
1091 + icon = false,
1092 + append = false,
1093 + addition = false,
1094 + isHidden = false,
1095 + } = options;
1096 +
1097 + const $sitestatus = jQuery(`.updatesoverview-upgrade-status-wp[siteid="${siteId}"]`);
1098 + const clsitem = Number.isInteger(itemnumber) ? `status-item-${itemnumber}` : 'status-item-1';
1099 + const clspop = true === ispopup ? 'mainwp-html-popup' : '';
1100 +
1101 + let $item = $sitestatus.find(`.${clspop ? clspop + '.' : ''}${clsitem}`);
1102 +
1103 + if ( ! $item.length ) {
1104 + const item = true === ispopup
1105 + ? `<span class="${clspop} ${clsitem}" data-position="left center" data-html=""></span>`
1106 + : `<span class="${clsitem}" data-position="left center" data-tooltip=""></span>`;
1107 + $sitestatus.append(item);
1108 + $item = $sitestatus.find(`.${clspop ? clspop + '.' : ''}${clsitem}`);
1109 + }
1110 +
1111 + if(true === isHidden){
1112 + $item.hide();
1113 + } else {
1114 + $item.show();
1115 + }
1116 +
1117 + if ( typeof icon === 'string' ) {
1118 + $item.html(icon);
1119 + }
1120 +
1121 + if ( typeof status === 'string' ) {
1122 + if(true === ispopup){
1123 + let content = status;
1124 + if (append) {
1125 + const existingContent = $item?.attr('data-html') || '';
1126 + content = existingContent
1127 + ? `${existingContent}<br>${status}`
1128 + : status;
1129 + }
1130 + $item.attr('data-html', content);
1131 + mainwp_init_html_popup($item, content);
1132 + } else {
1133 + let content = status;
1134 + if (append) {
1135 + const existingContent = $item?.attr('data-tooltip') || '';
1136 + content = existingContent
1137 + ? `${existingContent}; ${status}`
1138 + : status;
1139 + }
1140 + $item.attr('data-tooltip', content);
1141 + }
1142 + }
1143 +
1144 + if ( typeof addition === 'string' ) {
1145 + $sitestatus.append(addition);
1146 + }
1147 +};
1148 +
1149 +
1046 1150 let updatesoverview_plugins_upgrade_all_upgrade_next = function () {
1047 1151 mainwpVars.currentThreads++;
1048 1152 mainwpVars.websitesLeft--;
1049 1153
@@ -1064,13 +1168,18 @@
1064 1168 };
1065 1169
1066 1170 let updatesoverview_check_to_continue_updates = function () {
1067 1171 mainwpVars.bulkTaskRunning = false;
1068 - setTimeout(function () {
1069 - if (!mainwpVars?.errorCount && jQuery('.updates-regression-score-red-flag').length === 0) {
1070 - mainwpPopup('#mainwp-sync-sites-modal').close(true);
1071 - }
1072 - }, 3000);
1172 + if (!mainwpVars?.errorCount){
1173 + setTimeout(function () {
1174 + // wait for generated updates-regression-score-red-flag.
1175 + if (jQuery('.updates-regression-score-red-flag').length === 0) {
1176 + mainwpPopup('#mainwp-sync-sites-modal').close(true);
1177 + }
1178 + }, 3000);
1179 + } else {
1180 + mainwpPopup('#mainwp-sync-sites-modal').updateStatusLabel(MainWP.I18n.t('processed'));
1181 + }
1073 1182 return false;
1074 1183 }
1075 1184
1076 1185 let updatesoverview_plugins_upgrade_all_update_done = function () {
@@ -1097,9 +1206,9 @@
1097 1206 );
1098 1207 };
1099 1208 }
1100 1209
1101 -let updatesoverview_plugins_upgrade_int_after_backup = function (pSlug, pWebsiteId, pBulkMode, pLastResult) { // NOSONAR - nest functions.
1210 +let updatesoverview_plugins_upgrade_int_after_backup = function (pSlug, pWebsiteId, pBulkMode, pLastResult, errorHappen) { // NOSONAR - nest functions.
1102 1211 return function () {
1103 1212 let slugList = globalThis.mainwp_slug_list_to_array(pSlug); // NOSONAR -- window is ok.
1104 1213
1105 1214 const yithSlugList = slugList.filter(slg => slg.startsWith('yith-'));
@@ -1133,8 +1242,12 @@
1133 1242 }
1134 1243 websiteHolder.find('td:last-child').html(waiting_icon);
1135 1244 }
1136 1245
1246 + if( errorHappen === undefined ){
1247 + errorHappen = false;
1248 + }
1249 +
1137 1250 let data = mainwp_secure_data({
1138 1251 action: 'mainwp_upgradeplugintheme',
1139 1252 websiteId: pWebsiteId,
1140 1253 type: 'plugin',
@@ -1168,12 +1281,13 @@
1168 1281 if (!done && pBulkMode)
1169 1282 updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, extErr);
1170 1283 websiteHolder.find('td:last-child').html(extErr);
1171 1284 mainwpVars.errorCount++;
1285 + errorHappen = true;
1172 1286 } else {
1173 1287 let res = response.result;
1174 1288 let res_error = response.result_error;
1175 - res_started = response.result_started;
1289 + res_started = response.result_started; // for backward compatibility.
1176 1290 if (mainwp_get_result_entry(res, sid)) {
1177 1291 lastResult = res;
1178 1292 let _success_icon = `<i class="green check icon"></i>`;
1179 1293 let success_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Update successful', 'mainwp') + '">' + _success_icon + '</span>';
@@ -1178,26 +1292,30 @@
1178 1292 let _success_icon = `<i class="green check icon"></i>`;
1179 1293 let success_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Update successful', 'mainwp') + '">' + _success_icon + '</span>';
1180 1294 websiteHolder.attr('updated', 1);
1181 1295 websiteHolder.find('td:last-child').html(success_icon + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId));
1182 - } else if (res_started[sid]) {
1296 + } else if (mainwp_get_result_entry(res_started, sid)) { // for backward compatibility.
1183 1297 let _success_icon = `<i class="green check icon"></i>`;
1184 - let success_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + __('Premium update started. Please wait a moment, then sync the data again.') + '">' + _success_icon + '</span>';
1298 + let success_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Premium update started. Please wait a moment, then sync the data again.') + '">' + _success_icon + '</span>';
1185 1299 websiteHolder.attr('updated', 1);
1186 1300 websiteHolder.find('td:last-child').html(success_icon + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId));
1187 - } else if (res_error[sid]) {
1188 - let _error = res_error[sid];
1301 + } else if (mainwp_get_result_entry(res_error, sid)) {
1302 + let _error = mainwp_get_result_entry(res_error, sid);
1189 1303 let roll_error = mainwp_updates_get_rollback_msg(_error);
1304 + let roll_icon = _icon;
1190 1305 if (roll_error) {
1191 1306 _error = roll_error;
1192 - _icon = mainwpParams.roll_ui_icon;
1307 + roll_icon = mainwpParams.roll_ui_icon;
1193 1308 }
1194 - bulk_errors.push(_error);
1195 - websiteHolder.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + _error + '">' + _icon + '</span>');
1309 + bulk_errors.push(mainwp_escape_html(_error));
1310 + websiteHolder.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + mainwp_escape_html(_error) + '">' + roll_icon + '</span>');
1196 1311 mainwpVars.errorCount++;
1312 + errorHappen = true;
1197 1313 } else {
1314 + bulk_errors.push(MainWP.I18n.t('Update failed. Please try again.'));
1198 1315 websiteHolder.find('td:last-child').html('<i class="red times icon"></i>');
1199 1316 mainwpVars.errorCount++;
1317 + errorHappen = true;
1200 1318 }
1201 1319 }
1202 1320 }
1203 1321
@@ -1206,9 +1324,9 @@
1206 1324 mainwp_init_html_popup('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"] .mainwp-html-popup', bulk_errors.join('<br />'));
1207 1325 }
1208 1326
1209 1327 if (remainingSlugs && remainingSlugs.length > 0) {
1210 - updatesoverview_plugins_upgrade_int_after_backup(remainingSlugs, pWebsiteId, pBulkMode, lastResult)();
1328 + updatesoverview_plugins_upgrade_int_after_backup(remainingSlugs, pWebsiteId, pBulkMode, lastResult, errorHappen)();
1211 1329 return;
1212 1330 }
1213 1331 if (
1214 1332 pBulkMode &&
@@ -1213,9 +1331,10 @@
1213 1331 if (
1214 1332 pBulkMode &&
1215 1333 !bulk_errors.length &&
1216 1334 !response.error &&
1217 - !response.notices
1335 + !response.notices &&
1336 + !errorHappen
1218 1337 ) {
1219 1338 if (
1220 1339 lastResult &&
1221 1340 typeof mainwp_html_regression !== "undefined" &&
@@ -1230,14 +1349,15 @@
1230 1349 success_icon + ' ' + regression_icon_loading
1231 1350 );
1232 1351 } else if (typeof mainwp_html_regression === "undefined" || mainwp_html_regression.use_after_updates !== "1") {
1233 1352 let success_icon = `<i class="green check icon"></i>`;
1353 + // for backward compatibility.
1234 1354 if (
1235 1355 res_started !== null &&
1236 1356 typeof res_started === 'object' &&
1237 1357 Object.keys(res_started).length > 0
1238 1358 ) {
1239 - success_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + __('Premium update started. Please wait a moment, then sync the data again.') + '">' + success_icon + '</span>';
1359 + success_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Premium update started. Please wait a moment, then sync the data again.') + '">' + success_icon + '</span>';
1240 1360 }
1241 1361 updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, success_icon);
1242 1362 }
1243 1363 }
@@ -1275,8 +1395,9 @@
1275 1395 }(pSlug, pWebsiteId, pBulkMode),
1276 1396 error: function (xhr) {
1277 1397 this.tryCount++;
1278 1398 if (this.tryCount >= this.retryLimit) {
1399 + mainwpVars.errorCount++;
1279 1400 this.endError();
1280 1401 return;
1281 1402 }
1282 1403 let pXhr = xhr;
@@ -1663,8 +1784,9 @@
1663 1784 let extErr = getErrorMessageInfo(response.error, 'ui')
1664 1785 if (!done && pBulkMode)
1665 1786 updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, extErr);
1666 1787 websiteHolder.find('td:last-child').html(extErr);
1788 + mainwpVars.errorCount++;
1667 1789 } else {
1668 1790 let res = response.result;
1669 1791 let res_error = response.result_error;
1670 1792 if (mainwp_get_result_entry(res, sid)) {
@@ -1684,14 +1806,14 @@
1684 1806 _error = roll_error;
1685 1807 _icon = mainwpParams.roll_ui_icon;
1686 1808 bulk_icon = mainwpParams.roll_ui_icon;
1687 1809 }
1688 - bulk_errors.push(_error);
1810 + bulk_errors.push(mainwp_escape_html(_error));
1689 1811 mainwpVars.errorCount++;
1690 1812 }
1691 1813 if (_error) {
1692 1814 websiteHolder.find('td:last-child').html('<span class="mainwp-html-popup" data-position="left center" data-html="">' + _icon + '</span>');
1693 - mainwp_init_html_popup(websiteHolder.find('td:last-child').find('.mainwp-html-popup'), _error);
1815 + mainwp_init_html_popup(websiteHolder.find('td:last-child').find('.mainwp-html-popup'), mainwp_escape_html(_error));
1694 1816 }
1695 1817 }
1696 1818 }
1697 1819
@@ -1760,8 +1882,9 @@
1760 1882 }(slug, websiteId, bulkMode),
1761 1883 error: function (xhr) {
1762 1884 this.tryCount++;
1763 1885 if (this.tryCount >= this.retryLimit) {
1886 + mainwpVars.errorCount++;
1764 1887 this.endError();
1765 1888 return;
1766 1889 }
1767 1890
@@ -2184,8 +2307,10 @@
2184 2307 setTimeout(function () {
2185 2308 // close and refresh page
2186 2309 mainwpPopup('#mainwp-sync-sites-modal').close(true);
2187 2310 }, 3000);
2311 + } else {
2312 + mainwpPopup('#mainwp-sync-sites-modal').updateStatusLabel(MainWP.I18n.t('processed'));
2188 2313 }
2189 2314 return;
2190 2315 }
2191 2316
@@ -2257,8 +2382,9 @@
2257 2382 let isError = true;
2258 2383 if (response.error) {
2259 2384 result = getErrorMessage(response.error);
2260 2385 pErrorMessage = result;
2386 + mainwpVars.errorCount++;
2261 2387 } else {
2262 2388 let res = response.result;
2263 2389 if (mainwp_get_result_entry(res, sid)) {
2264 2390 mainwpVars.lastUpdateResultBySite[pWebsiteId] = response.result;
@@ -2343,8 +2469,9 @@
2343 2469 }(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pPluginDone, pUpgradeDone, pTransSlugToUpgrade, pTransDone),
2344 2470 error: function (xhr) {
2345 2471 this.tryCount++;
2346 2472 if (this.tryCount >= this.retryLimit) {
2473 + mainwpVars.errorCount++;
2347 2474 this.endError();
2348 2475 return;
2349 2476 }
2350 2477 let pXhr = xhr;
@@ -2417,8 +2544,9 @@
2417 2544 }
2418 2545 if (response.error) {
2419 2546 result = getErrorMessage(response.error);
2420 2547 pErrorMessage = result;
2548 + mainwpVars.errorCount++;
2421 2549 }
2422 2550 else {
2423 2551 let res = response.result; // result is an object
2424 2552 let res_error = response.result_error;
@@ -2496,8 +2624,9 @@
2496 2624 }(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pTransSlugToUpgrade, pTransDone),
2497 2625 error: function (xhr) {
2498 2626 this.tryCount++;
2499 2627 if (this.tryCount >= this.retryLimit) {
2628 + mainwpVars.errorCount++;
2500 2629 this.endError();
2501 2630 return;
2502 2631 }
2503 2632 setTimeout(function (pRqst, pXhr) {
@@ -2674,8 +2803,9 @@
2674 2803 }
2675 2804 if (response.error) {
2676 2805 result = getErrorMessage(response.error);
2677 2806 pErrorMessage = result;
2807 + mainwpVars.errorCount++;
2678 2808 } else {
2679 2809 let res = response.result;
2680 2810 if (mainwp_get_result_entry(res, sid)) {
2681 2811 mainwpVars.lastUpdateResultBySite[pWebsiteId] = response.result;
@@ -3911,41 +4041,87 @@
3911 4041 };
3912 4042 updatesoverview_update_popup_init(initData);
3913 4043
3914 4044 // Show icon waiting
4045 + let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i>');
4046 + // init sites status items.
4047 + const statuses = [
4048 + {
4049 + item: 1,
4050 + icon: waiting_icon,
4051 + },
4052 + {
4053 + item: 2,
4054 + ispopup: true,
4055 + icon: '<i class="green check icon"></i>',
4056 + isHidden: true,
4057 + },
4058 + {
4059 + item: 3,
4060 + ispopup: true,
4061 + icon: '<i class="red times icon"></i>',
4062 + isHidden: true,
4063 + },
4064 + {
4065 + item: 5,
4066 + ispopup: true,
4067 + icon: '', // Reserved for future use.
4068 + isHidden: true,
4069 + },
4070 + ];
4071 +
3915 4072 const regression_waiting_icon = render_html_regression_waiting_icon();
3916 - let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i>');
3917 - if (regression_waiting_icon && "" !== regression_waiting_icon) {
3918 - waiting_icon += regression_waiting_icon;
4073 +
4074 + if (regression_waiting_icon) {
4075 + statuses.push({
4076 + item: 4,
4077 + icon: regression_waiting_icon,
4078 + isHidden: true,
4079 + });
3919 4080 }
3920 4081
3921 - updatesoverview_plugins_upgrade_all_update_site_status(pId, waiting_icon);
4082 + updatesoverview_plugins_upgrade_all_update_site_status(pId,''); // clear status first.
3922 4083
4084 + statuses.forEach((status) => {
4085 + const { item, ...options } = status;
4086 + upgradeall_update_site_popup_multi_status(pId, item, options);
4087 + });
4088 +
3923 4089 let queue = list.slice();
3924 - let lastResult = null;
4090 + let countError = 0;
4091 + let lastResult = '';
3925 4092
3926 - let processNext = function () {
4093 + let processLoop = function (response) {
3927 4094 if (queue.length === 0) {
3928 4095 mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(1);
3929 - let success_icon = '<i class="green check icon"></i>';
3930 4096 if (
3931 4097 lastResult &&
3932 4098 typeof mainwp_html_regression !== "undefined" &&
3933 4099 mainwp_html_regression.use_after_updates === "1"
3934 4100 ) {
3935 - let regression_icon_loading = render_html_regression_icon(lastResult, function (regression_final_icon) {
3936 - const final_icon = `${success_icon} ${regression_final_icon}`;
3937 - updatesoverview_plugins_upgrade_all_update_site_status(pId, final_icon);
4101 + let regression_icon_callback = render_html_regression_icon(lastResult, function (regression_final_icon) {
4102 + upgradeall_update_site_popup_multi_status(pId, 4, {
4103 + icon: regression_final_icon,
4104 + });
3938 4105 });
3939 - updatesoverview_plugins_upgrade_all_update_site_status(pId, `${success_icon} ${regression_icon_loading}`);
3940 - } else {
3941 - updatesoverview_plugins_upgrade_all_update_site_status(pId, success_icon);
4106 + upgradeall_update_site_popup_multi_status(pId, 4, {
4107 + icon: regression_icon_callback,
4108 + });
3942 4109 }
3943 - if (jQuery('.updates-regression-score-red-flag').length === 0) {
4110 + upgradeall_update_site_popup_multi_status(pId, 1, {
4111 + isHidden: true // hide spinner.
4112 + });
4113 +
4114 + if ( countError === 0 ) {
3944 4115 setTimeout(function () {
3945 - mainwpPopup('#mainwp-sync-sites-modal').close();
3946 - globalThis.location.href = location.href; // NOSONAR - window is ok.
4116 + // wait for generated updates-regression-score-red-flag.
4117 + if( jQuery('.updates-regression-score-red-flag').length === 0 ) {
4118 + mainwpPopup('#mainwp-sync-sites-modal').close();
4119 + globalThis.location.href = location.href; // NOSONAR - window is ok.
4120 + }
3947 4121 }, 3000);
4122 + } else {
4123 + mainwpPopup('#mainwp-sync-sites-modal').updateStatusLabel(MainWP.I18n.t('processed'));
3948 4124 }
3949 4125 return;
3950 4126 }
3951 4127
@@ -3955,37 +4131,96 @@
3955 4131 websiteId: pId,
3956 4132 type: what,
3957 4133 slug: item
3958 4134 });
3959 -
4135 + let decoded = mainwp_decode_slug(item, true);
3960 4136 jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex.
3961 4137 let res_error = response.result_error;
3962 - let _icon = '<i class="red times icon"></i>';
3963 4138 let hasError = false;
3964 -
3965 4139 if (response.error) {
3966 - let extErr = getErrorMessageInfo(response.error, 'ui');
3967 - updatesoverview_plugins_upgrade_all_update_site_status(pId, extErr);
4140 + let extErr = getErrorMessageInfo(response.error);
4141 + let new_status = decoded + ` - ${mainwp_escape_html(extErr)}`;
4142 + upgradeall_update_site_popup_multi_status(pId, 3, {
4143 + status:new_status,
4144 + append:true,
4145 + ispopup: true
4146 + });
3968 4147 hasError = true;
3969 4148 } else if (res_error && mainwp_get_result_entry(res_error, item)) {
4149 + let new_status = decoded;
3970 4150 let _error = mainwp_get_result_entry(res_error, item);
3971 4151 let roll_error = mainwp_updates_get_rollback_msg(_error);
3972 4152 if (roll_error) {
3973 - _error = roll_error;
3974 - _icon = mainwpParams.roll_ui_icon;
4153 + new_status += ` - ${mainwp_escape_html(roll_error)}`;
4154 + let _icon = mainwpParams.roll_ui_icon;
4155 + upgradeall_update_site_popup_multi_status(pId, 5, {
4156 + icon: _icon,
4157 + ispopup: true,
4158 + });
4159 + upgradeall_update_site_popup_multi_status(pId, 5, {
4160 + status: new_status,
4161 + ispopup: true,
4162 + append:true
4163 + });
4164 + } else {
4165 + new_status += ` - ${mainwp_escape_html(_error)}`;
4166 + upgradeall_update_site_popup_multi_status(pId, 3, {
4167 + status: new_status,
4168 + ispopup: true,
4169 + append:true
4170 + });
3975 4171 }
3976 - jQuery('.updatesoverview-upgrade-status-wp[siteid="' + pId + '"]').html('<span class="mainwp-html-popup" data-position="left center" data-html="">' + _icon + '</span>');
3977 - mainwp_init_html_popup('.updatesoverview-upgrade-status-wp[siteid="' + pId + '"] .mainwp-html-popup', _error);
3978 4172 hasError = true;
4173 + } else {
4174 + let new_status = decoded;
4175 + let statusItem = 2;
4176 + // for backward compatibility.
4177 + if (mainwp_get_result_entry(response.result_started, item)) {
4178 + new_status = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Premium update started. Please wait a moment, then sync the data again.') + '">' + new_status + '</span>';
4179 + hasError = true; // Prevent the popup from closing automatically.
4180 + } else if (!mainwp_get_result_entry(response.result, item)) {
4181 + new_status += ` - ${MainWP.I18n.t('Failed to update. Please try again.')}`;
4182 + hasError = true; // Prevent the popup from closing automatically.
4183 + statusItem = 3;
4184 + } else {
4185 + new_status += ` - ${MainWP.I18n.t('Updated successfully')}`;
4186 + }
4187 + upgradeall_update_site_popup_multi_status(pId, statusItem, {
4188 + status: new_status,
4189 + ispopup: true,
4190 + append:true
4191 + });
3979 4192 }
3980 4193
3981 - if (!hasError) {
3982 - lastResult = response.result;
4194 + if( !hasError ){
4195 + lastResult = response?.result;
4196 + } else {
4197 + ++countError;
3983 4198 }
3984 - processNext();
3985 - }, 'json');
4199 +
4200 + processLoop(response);
4201 + }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
4202 + let errorMessage = errorThrown || textStatus || MainWP.I18n.t('Invalid response from the server');
4203 + let new_status = decoded + ` - ${MainWP.I18n.t('Failed to update')}: ${mainwp_escape_html(errorMessage)}`;
4204 +
4205 + upgradeall_update_site_popup_multi_status(pId, 3, {
4206 + status: new_status,
4207 + ispopup: true,
4208 + append: true
4209 + });
4210 +
4211 + ++countError; // Prevent the popup from closing automatically.
4212 +
4213 + processLoop({
4214 + error: errorMessage,
4215 + result: {},
4216 + result_error: {},
4217 + result_started: {}
4218 + });
4219 + });
3986 4220 };
3987 - processNext();
4221 +
4222 + processLoop();
3988 4223 }
3989 4224
3990 4225 // for semantic ui checkboxes
3991 4226 jQuery(function () {