| 1 |
/* eslint-disable complexity */ |
| 2 |
// current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 3 |
|
| 4 |
globalThis.mainwpVars = globalThis.mainwpVars || {}; |
| 5 |
mainwpVars.errorCount = 0; |
| 6 |
mainwpVars.actionsErrors = {}; |
| 7 |
|
| 8 |
globalThis.mainwp_put_actions_errors_msg = function (action, itemId, msgType, errorMsg) { |
| 9 |
mainwpVars.actionsErrors[action] = mainwpVars.actionsErrors?.[action] || {}; |
| 10 |
mainwpVars.actionsErrors[action][itemId] = mainwpVars.actionsErrors[action]?.[itemId] || {}; |
| 11 |
mainwpVars.actionsErrors[action][itemId][msgType] = mainwpVars.actionsErrors[action]?.[itemId]?.[msgType] || []; |
| 12 |
mainwpVars.actionsErrors[action][itemId][msgType].push(errorMsg); |
| 13 |
} |
| 14 |
|
| 15 |
globalThis.mainwp_get_actions_errors_msg = function (action, itemId, msgType) { |
| 16 |
let errors = mainwpVars.actionsErrors?.[action]?.[itemId]?.[msgType] || []; |
| 17 |
let array = errors.map(function (val) { |
| 18 |
return val; |
| 19 |
}); |
| 20 |
array = array.filter(Boolean); |
| 21 |
return array.join('<br/>'); |
| 22 |
} |
| 23 |
|
| 24 |
globalThis.mainwp_updates_get_rollback_msg = function (error) { |
| 25 |
if (error && typeof error == "string") { |
| 26 |
if (error.startsWith('[Roll]')) { |
| 27 |
return error.replace('[Roll]', ''); |
| 28 |
} |
| 29 |
} |
| 30 |
return ''; |
| 31 |
} |
| 32 |
|
| 33 |
globalThis.mainwp_init_html_popup = function (popupSelector, content) { |
| 34 |
jQuery(popupSelector).popup({ |
| 35 |
html: function () { |
| 36 |
if (content === undefined) { |
| 37 |
if (typeof popupSelector !== 'string') { |
| 38 |
// popup selector is object. |
| 39 |
content = jQuery(popupSelector).attr('html-popup-content') ?? '' |
| 40 |
} |
| 41 |
} |
| 42 |
return '<div class="mainwp-html-popup-body">' + content + '</div>'; |
| 43 |
} |
| 44 |
}); |
| 45 |
}; |
| 46 |
|
| 47 |
// Decode slug safely. |
| 48 |
globalThis.mainwp_decode_slug = function (value, escape ) { // NOSONAR |
| 49 |
if (typeof value !== 'string' || !value.includes('%')) { |
| 50 |
return (true === escape && typeof value === 'string') ? mainwp_escape_html(value) : value; |
| 51 |
} |
| 52 |
|
| 53 |
try { |
| 54 |
value = decodeURIComponent(value); |
| 55 |
} catch { |
| 56 |
// nothing. |
| 57 |
} |
| 58 |
|
| 59 |
if(true === escape){ |
| 60 |
return mainwp_escape_html(value); |
| 61 |
} |
| 62 |
|
| 63 |
return value; |
| 64 |
}; |
| 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 |
|
| 76 |
// Normalize slug list to array. |
| 77 |
globalThis.mainwp_slug_list_to_array = function (value) { // NOSONAR. |
| 78 |
if (Array.isArray(value)) { |
| 79 |
return value.filter(function (v) { return v !== null && v !== undefined && String(v).trim() !== ''; }); |
| 80 |
} |
| 81 |
if (typeof value !== 'string') { |
| 82 |
value = (value === null || value === undefined) ? '' : String(value); |
| 83 |
} |
| 84 |
if (value === '') return []; |
| 85 |
return value.split(',').map(function (v) { return v.trim(); }).filter(function (v) { return v !== ''; }); |
| 86 |
}; |
| 87 |
|
| 88 |
// Safely read result/error entries. |
| 89 |
globalThis.mainwp_get_result_entry = function (obj, key) { // NOSONAR. |
| 90 |
if (!obj || typeof obj !== 'object') return undefined; |
| 91 |
if (obj[key] !== undefined) return obj[key]; |
| 92 |
let enc = encodeURIComponent(key); |
| 93 |
return obj[enc]; |
| 94 |
}; |
| 95 |
|
| 96 |
// Init Per Group data. |
| 97 |
let updatesoverview_updates_init_group_view = function () { |
| 98 |
jQuery('.element_ui_view_values').each(function () { |
| 99 |
let parent = jQuery(this).parent(); |
| 100 |
let uid = jQuery(this).attr('elem-uid'); |
| 101 |
let total = jQuery(this).attr('total'); |
| 102 |
let can_update = jQuery(this).attr('can-update'); |
| 103 |
|
| 104 |
if (total == 0) { |
| 105 |
// carefully remove this, or it will causing error with display or according sorting |
| 106 |
jQuery(parent).find("[row-uid='" + uid + "']").next().remove(); // remove content according part |
| 107 |
jQuery(parent).find("[row-uid='" + uid + "']").remove(); // remove title according part |
| 108 |
} else { |
| 109 |
jQuery(parent).find("[total-uid='" + uid + "']").html(total + ' ' + (total == 1 ? MainWP.I18n.t('Update') : MainWP.I18n.t('Updates'))); |
| 110 |
jQuery(parent).find("[total-uid='" + uid + "']").attr('sort-value', total); |
| 111 |
} |
| 112 |
|
| 113 |
if (can_update) { |
| 114 |
jQuery(parent).find("[btn-all-uid='" + uid + "']").text(total == 1 ? MainWP.I18n.t('Update') : MainWP.I18n.t('Update All')).show(); |
| 115 |
} |
| 116 |
}); |
| 117 |
} |
| 118 |
|
| 119 |
// Update individual WP |
| 120 |
let updatesoverview_upgrade = function (id, obj) { |
| 121 |
|
| 122 |
let parent = jQuery(obj).closest('.mainwp-wordpress-update'); |
| 123 |
let upgradeElement = jQuery(parent).find('#wp-updated-' + id); |
| 124 |
|
| 125 |
if (upgradeElement.val() != 0) |
| 126 |
return false; |
| 127 |
// Show icon waiting |
| 128 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 129 |
let waiting_icon = ''; |
| 130 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 131 |
waiting_icon += regression_waiting_icon; |
| 132 |
} |
| 133 |
|
| 134 |
updatesoverviewContinueAfterBackup = function (pId, pUpgradeElement) { |
| 135 |
return function () { |
| 136 |
jQuery('.mainwp-wordpress-update[site_id="' + pId + '"] > td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Updating...', 'mainwp') + '"><i class="notched circle loading icon"></i></span> ' + MainWP.I18n.t('Updating. Please wait...') + waiting_icon); |
| 137 |
pUpgradeElement.val(1); |
| 138 |
let data = mainwp_secure_data({ |
| 139 |
action: 'mainwp_upgradewp', |
| 140 |
id: pId |
| 141 |
}); |
| 142 |
|
| 143 |
jQuery.post(ajaxurl, data, function (response) { |
| 144 |
if (response.error) { |
| 145 |
let err_msg = ''; |
| 146 |
if (response.error.extra) { |
| 147 |
err_msg = response.error.extra + ' '; |
| 148 |
} |
| 149 |
let errIcon = '<i class="pause yellow icon"></i>'; |
| 150 |
if (response?.error?.errorCode == 'SUSPENDED_SITE') { |
| 151 |
errIcon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '">' + errIcon + '</span>'; |
| 152 |
} |
| 153 |
jQuery('.mainwp-wordpress-update[site_id="' + pId + '"] > td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + err_msg + '">' + errIcon + '</span>'); |
| 154 |
} else { |
| 155 |
|
| 156 |
jQuery('.mainwp-wordpress-update[site_id="' + pId + '"] > td:last-child').html(response.result); |
| 157 |
|
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
}, 'json'); |
| 162 |
} |
| 163 |
}(id, upgradeElement); |
| 164 |
|
| 165 |
let sitesToUpdate = [id]; |
| 166 |
let siteNames = []; |
| 167 |
|
| 168 |
siteNames[id] = jQuery('.mainwp-wordpress-update[site_id="' + id + '"]').attr('site_name'); |
| 169 |
|
| 170 |
let msg = MainWP.I18n.t('Are you sure you want to update the Wordpress core files on the selected site?'); |
| 171 |
mainwp_confirm(msg, function () { |
| 172 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 173 |
}, false, 1); |
| 174 |
}; |
| 175 |
|
| 176 |
/** Update bulk **/ |
| 177 |
|
| 178 |
mainwpVars.websitesToUpgrade = []; |
| 179 |
let updatesoverviewContinueAfterBackup; |
| 180 |
let limitUpdateAll = 0; |
| 181 |
let continueUpdatesAll = '', continueUpdatesSlug = ''; |
| 182 |
let continueUpdating = false; |
| 183 |
let updatesoverview_update_popup_init = function (data) { |
| 184 |
data = data || {}; |
| 185 |
let settings = { |
| 186 |
allowMultiple: true, |
| 187 |
statusText: MainWP.I18n.t('updated'), |
| 188 |
callback: function () { |
| 189 |
mainwpVars.bulkTaskRunning = false; |
| 190 |
mainwp_forceReload(); |
| 191 |
} |
| 192 |
} |
| 193 |
jQuery.extend(settings, data); |
| 194 |
mainwpPopup('#mainwp-sync-sites-modal').init(settings); |
| 195 |
} |
| 196 |
|
| 197 |
let updatesmanage_link_to_site = function (name, siteid) { |
| 198 |
return '<a href="admin.php?page=managesites&dashboard=' + siteid + '">' + name + '</a>'; |
| 199 |
} |
| 200 |
|
| 201 |
// Update Group |
| 202 |
let updatesoverview_wordpress_global_upgrade_all = function (groupId, updatesSelected) { |
| 203 |
if (mainwpVars.bulkTaskRunning) |
| 204 |
return; |
| 205 |
|
| 206 |
//Step 1: build form |
| 207 |
let sitesToUpdate = []; |
| 208 |
let siteNames = {}; |
| 209 |
let foundChildren = updatesoverview_wordpress_get_global_upgrade_all(groupId, updatesSelected); |
| 210 |
|
| 211 |
if (foundChildren.length == 0) |
| 212 |
return; |
| 213 |
|
| 214 |
let sitesCount = 0; |
| 215 |
|
| 216 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 217 |
|
| 218 |
for (let i = 0; i < foundChildren.length; i++) { |
| 219 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && groupId === undefined) { |
| 220 |
continueUpdatesAll = 'wpcore_global_upgrade_all'; |
| 221 |
break; |
| 222 |
} |
| 223 |
|
| 224 |
let child = foundChildren[i]; |
| 225 |
let siteId = jQuery(child).attr('site_id'); |
| 226 |
let siteName = jQuery(child).attr('site_name'); |
| 227 |
|
| 228 |
if (!sitesToUpdate.includes(siteId)) { |
| 229 |
sitesCount++; |
| 230 |
sitesToUpdate.push(siteId); |
| 231 |
siteNames[siteId] = siteName; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
let _callback = function () { |
| 236 |
for (let id of sitesToUpdate) { |
| 237 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', id) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteNames[id]), id) + ' (WordPress update)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + id + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 238 |
} |
| 239 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate) { |
| 240 |
return function () { |
| 241 |
let initData = { |
| 242 |
title: MainWP.I18n.t('Updating All'), |
| 243 |
progressMax: pSitesCount, |
| 244 |
}; |
| 245 |
|
| 246 |
updatesoverview_update_popup_init(initData); |
| 247 |
//Step 3: start updates |
| 248 |
updatesoverview_wordpress_upgrade_all_int(pSitesToUpdate); |
| 249 |
|
| 250 |
updatesoverviewContinueAfterBackup = undefined; |
| 251 |
} |
| 252 |
}(sitesCount, sitesToUpdate); |
| 253 |
|
| 254 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 255 |
}; |
| 256 |
|
| 257 |
// new confirm message |
| 258 |
if (!continueUpdating) { |
| 259 |
if (jQuery(siteNames).length > 0) { |
| 260 |
let sitesList = []; |
| 261 |
jQuery.each(siteNames, function (index, value) { |
| 262 |
if (value) { // to fix |
| 263 |
sitesList.push(decodeURIComponent(value)); |
| 264 |
} |
| 265 |
}); |
| 266 |
let confirmMsg = MainWP.I18n.t('You are about to update %1 on the following site(s): <br/><div class="ui message">%2</div> <strong>Do you want to proceed?</strong>', MainWP.I18n.t('WordPress Core'), sitesList.join('<br />')); |
| 267 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 268 |
} |
| 269 |
return; |
| 270 |
} |
| 271 |
_callback(); |
| 272 |
}; |
| 273 |
|
| 274 |
|
| 275 |
let mainwp_updates_get_selected_rows_values = function (selector, item_selector) { |
| 276 |
let foundChildren = []; |
| 277 |
if (selector && item_selector) { |
| 278 |
jQuery(selector).find(item_selector).each( |
| 279 |
function () { |
| 280 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 281 |
foundChildren.push(this); |
| 282 |
} |
| 283 |
} |
| 284 |
); |
| 285 |
} else { |
| 286 |
jQuery(selector).each( |
| 287 |
function () { |
| 288 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 289 |
foundChildren.push(this); |
| 290 |
} |
| 291 |
} |
| 292 |
); |
| 293 |
} |
| 294 |
return foundChildren; |
| 295 |
} |
| 296 |
|
| 297 |
let updatesoverview_wordpress_get_global_upgrade_all = function (groupId, updatesSelected) { |
| 298 |
let foundChildren = []; |
| 299 |
if (updatesSelected !== undefined && updatesSelected) { |
| 300 |
if (groupId !== undefined && false !== groupId) { |
| 301 |
foundChildren = mainwp_updates_get_selected_rows_values('#update_wrapper_wp_upgrades_group_' + groupId, 'tr.mainwp-wordpress-update[updated="0"]'); |
| 302 |
} else { |
| 303 |
foundChildren = mainwp_updates_get_selected_rows_values('tr.mainwp-wordpress-update[updated="0"]'); |
| 304 |
} |
| 305 |
if (foundChildren.length == 0) { |
| 306 |
updates_please_select_items_notice(); |
| 307 |
return false; |
| 308 |
} |
| 309 |
} else if (groupId !== undefined && false !== groupId) { |
| 310 |
// groups selector is only one for each screen. |
| 311 |
foundChildren = jQuery('#update_wrapper_wp_upgrades_group_' + groupId).find('tr.mainwp-wordpress-update[updated="0"]'); |
| 312 |
} else { |
| 313 |
// childs selector is only one for each screen. |
| 314 |
foundChildren = jQuery('tr.mainwp-wordpress-update[updated="0"]'); |
| 315 |
} |
| 316 |
return foundChildren; |
| 317 |
} |
| 318 |
|
| 319 |
let updatesoverview_wordpress_upgrade_all_int = function (websiteIds) { |
| 320 |
mainwpVars.websitesToUpgrade = websiteIds; |
| 321 |
mainwpVars.currentWebsite = 0; |
| 322 |
mainwpVars.websitesDone = 0; |
| 323 |
mainwpVars.websitesTotal = mainwpVars.websitesLeft = mainwpVars.websitesToUpgrade.length; |
| 324 |
|
| 325 |
mainwpVars.bulkTaskRunning = true; |
| 326 |
updatesoverview_wordpress_upgrade_all_loop_next(); |
| 327 |
}; |
| 328 |
let updatesoverview_wordpress_upgrade_all_loop_next = function () { |
| 329 |
while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxUpdateThreads) && (mainwpVars.websitesLeft > 0)) { |
| 330 |
updatesoverview_wordpress_upgrade_all_upgrade_next(); |
| 331 |
} |
| 332 |
}; |
| 333 |
let updatesoverview_wordpress_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 334 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 335 |
}; |
| 336 |
let updatesoverview_wordpress_upgrade_all_upgrade_next = function () { |
| 337 |
mainwpVars.currentThreads++; |
| 338 |
mainwpVars.websitesLeft--; |
| 339 |
// Show icon waiting |
| 340 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 341 |
let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i>'); |
| 342 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 343 |
waiting_icon += regression_waiting_icon; |
| 344 |
} |
| 345 |
|
| 346 |
let websiteId = mainwpVars.websitesToUpgrade[mainwpVars.currentWebsite++]; |
| 347 |
updatesoverview_wordpress_upgrade_all_update_site_status(websiteId, waiting_icon); |
| 348 |
|
| 349 |
updatesoverview_wordpress_upgrade_int(websiteId, true); |
| 350 |
}; |
| 351 |
let updatesoverview_wordpress_upgrade_all_update_done = function () { |
| 352 |
mainwpVars.currentThreads--; |
| 353 |
if (!mainwpVars.bulkTaskRunning) |
| 354 |
return; |
| 355 |
mainwpVars.websitesDone++; |
| 356 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 357 |
|
| 358 |
updatesoverview_wordpress_upgrade_all_loop_next(); |
| 359 |
}; |
| 360 |
let updatesoverview_wordpress_upgrade_int = function (websiteId, bulkMode) { |
| 361 |
|
| 362 |
let data = mainwp_secure_data({ |
| 363 |
action: 'mainwp_upgradewp', |
| 364 |
id: websiteId |
| 365 |
}); |
| 366 |
jQuery.post(ajaxurl, data, function (pWebsiteId, pBulkMode) { |
| 367 |
return function (response) { |
| 368 |
if (response.error) { |
| 369 |
let err_msg = ''; |
| 370 |
if (response.error.extra) { |
| 371 |
err_msg = response.error.extra + ' '; |
| 372 |
} |
| 373 |
let errIcon = '<i class="red times icon"></i>'; |
| 374 |
if (response?.error?.errorCode == 'SUSPENDED_SITE') { |
| 375 |
errIcon = '<i class="pause yellow icon"></i>'; |
| 376 |
} |
| 377 |
if (pBulkMode) |
| 378 |
updatesoverview_wordpress_upgrade_all_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + err_msg + '">' + errIcon + '</span>'); |
| 379 |
} else if (pBulkMode) { |
| 380 |
updatesoverview_wordpress_upgrade_all_update_site_status(pWebsiteId, response.result); |
| 381 |
} |
| 382 |
updatesoverview_wordpress_upgrade_all_update_done(); |
| 383 |
} |
| 384 |
}(websiteId, bulkMode), 'json'); |
| 385 |
|
| 386 |
return false; |
| 387 |
}; |
| 388 |
|
| 389 |
let currentTranslationSlugToUpgrade; |
| 390 |
let websitesTranslationSlugsToUpgrade; |
| 391 |
let updatesoverview_translations_global_upgrade_all = function (groupId, updatesSelected) { // NOSONAR - Complexity 18/15. |
| 392 |
if (mainwpVars.bulkTaskRunning) |
| 393 |
return; |
| 394 |
|
| 395 |
//Step 1: build form |
| 396 |
let sitesToUpdate = []; |
| 397 |
let siteNames = {}; |
| 398 |
let sitesTranslationSlugs = {}; |
| 399 |
let foundChildren = updatesoverview_translations_get_global_upgrade_all(groupId, updatesSelected); |
| 400 |
if (foundChildren.length == 0) |
| 401 |
return; |
| 402 |
let sitesCount = 0; |
| 403 |
|
| 404 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 405 |
|
| 406 |
for (let i = 0; i < foundChildren.length; i++) { |
| 407 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && groupId === undefined) { |
| 408 |
continueUpdatesAll = 'translations_global_upgrade_all'; |
| 409 |
break; |
| 410 |
} |
| 411 |
let child = jQuery(foundChildren[i]); |
| 412 |
let parent = child.parent(); // to fix |
| 413 |
|
| 414 |
let siteElement; |
| 415 |
let translationElement; |
| 416 |
|
| 417 |
let checkAttr = child.attr('site_id'); |
| 418 |
if (checkAttr !== undefined && (checkAttr !== false)) { |
| 419 |
siteElement = child; |
| 420 |
translationElement = parent; |
| 421 |
} else { |
| 422 |
siteElement = parent; |
| 423 |
translationElement = child; |
| 424 |
} |
| 425 |
|
| 426 |
let siteId = siteElement.attr('site_id'); |
| 427 |
let siteName = siteElement.attr('site_name'); |
| 428 |
let translationSlug = mainwp_decode_slug(translationElement.attr('translation_slug')); |
| 429 |
|
| 430 |
if (!sitesToUpdate.includes(siteId)) { |
| 431 |
sitesCount++; |
| 432 |
sitesToUpdate.push(siteId); |
| 433 |
siteNames[siteId] = siteName; |
| 434 |
} |
| 435 |
if (sitesTranslationSlugs[siteId] == undefined) { |
| 436 |
sitesTranslationSlugs[siteId] = translationSlug; |
| 437 |
} else { |
| 438 |
sitesTranslationSlugs[siteId] += ',' + translationSlug; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
let _callback = function () { |
| 443 |
for (let id of sitesToUpdate) { |
| 444 |
let updateCount = sitesTranslationSlugs[id].match(/,/g); |
| 445 |
if (updateCount == null) |
| 446 |
updateCount = 1; |
| 447 |
else |
| 448 |
updateCount = updateCount.length + 1; |
| 449 |
|
| 450 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', id) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteNames[id]), id) + ' (' + updateCount + ' translations)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + id + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 451 |
} |
| 452 |
|
| 453 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate, pSitesTranslationSlugs) { |
| 454 |
return function () { |
| 455 |
|
| 456 |
let initData = { |
| 457 |
title: MainWP.I18n.t('Updating all...'), |
| 458 |
progressMax: pSitesCount |
| 459 |
}; |
| 460 |
updatesoverview_update_popup_init(initData); |
| 461 |
|
| 462 |
//Step 3: start updates |
| 463 |
updatesoverview_translations_upgrade_all_int(undefined, pSitesToUpdate, pSitesTranslationSlugs); |
| 464 |
|
| 465 |
updatesoverviewContinueAfterBackup = undefined; |
| 466 |
} |
| 467 |
}(sitesCount, sitesToUpdate, sitesTranslationSlugs); |
| 468 |
|
| 469 |
|
| 470 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
// new confirm message |
| 475 |
if (!continueUpdating) { |
| 476 |
if (jQuery(siteNames).length > 0) { |
| 477 |
let sitesList = []; |
| 478 |
jQuery.each(siteNames, function (index, value) { |
| 479 |
if (value) { // to fix |
| 480 |
sitesList.push(decodeURIComponent(value)); |
| 481 |
} |
| 482 |
}); |
| 483 |
let confirmMsg = MainWP.I18n.t('You are about to update %1 on the following site(s):\n%2?', 'translations', sitesList.join(', ')); |
| 484 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 485 |
} |
| 486 |
return false; |
| 487 |
} |
| 488 |
_callback(); |
| 489 |
}; |
| 490 |
|
| 491 |
let updatesoverview_translations_get_global_upgrade_all = function (groupId, updatesSelected) { |
| 492 |
let foundChildren = []; |
| 493 |
if (updatesSelected !== undefined && updatesSelected) { |
| 494 |
if (groupId !== undefined && false !== groupId) { |
| 495 |
foundChildren = mainwp_updates_get_selected_rows_values('#update_wrapper_translation_upgrades_group_' + groupId, 'tr.mainwp-translation-update[updated="0"]'); |
| 496 |
} else { |
| 497 |
foundChildren = mainwp_updates_get_selected_rows_values('#translations-updates-global', 'table tr[updated="0"]'); |
| 498 |
} |
| 499 |
if (foundChildren.length == 0) { |
| 500 |
updates_please_select_items_notice(); |
| 501 |
return; |
| 502 |
} |
| 503 |
} else if (groupId !== undefined && false !== groupId) { |
| 504 |
foundChildren = jQuery('#update_wrapper_translation_upgrades_group_' + groupId).find('tr.mainwp-translation-update[updated="0"]'); |
| 505 |
} else { |
| 506 |
foundChildren = jQuery('#translations-updates-global').find('table tr[updated="0"]'); |
| 507 |
} |
| 508 |
return foundChildren; |
| 509 |
} |
| 510 |
|
| 511 |
let updatesoverview_translations_upgrade_all = function (slug, translationName) { |
| 512 |
if (mainwpVars.bulkTaskRunning) |
| 513 |
return; |
| 514 |
//Step 1: build form |
| 515 |
let sitesToUpdate = []; |
| 516 |
let siteNames = []; |
| 517 |
let foundChildren = jQuery('.translations-bulk-updates[translation_slug="' + slug + '"]').find('tr[updated="0"]'); |
| 518 |
|
| 519 |
if (foundChildren.length == 0) |
| 520 |
return; |
| 521 |
|
| 522 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 523 |
|
| 524 |
for (let i = 0; i < foundChildren.length; i++) { |
| 525 |
if (limitUpdateAll > 0 && i >= limitUpdateAll) { |
| 526 |
continueUpdatesAll = 'translations_upgrade_all'; |
| 527 |
continueUpdatesSlug = slug; |
| 528 |
break; |
| 529 |
} |
| 530 |
let child = foundChildren[i]; |
| 531 |
let siteId = jQuery(child).attr('site_id'); |
| 532 |
let siteName = jQuery(child).attr('site_name'); |
| 533 |
siteNames[siteId] = siteName; |
| 534 |
sitesToUpdate.push(siteId); |
| 535 |
} |
| 536 |
|
| 537 |
translationName = decodeURIComponent(translationName); |
| 538 |
translationName = translationName.replaceAll('+', ' '); |
| 539 |
|
| 540 |
let _callback = function () { |
| 541 |
|
| 542 |
for (let id of sitesToUpdate) { |
| 543 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', id) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteNames[id]), id), '<span class="updatesoverview-upgrade-status-wp" siteid="' + id + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 544 |
} |
| 545 |
|
| 546 |
let sitesCount = sitesToUpdate.length; |
| 547 |
|
| 548 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSlug, pSitesToUpdate) { |
| 549 |
return function () { |
| 550 |
|
| 551 |
// init and show popup |
| 552 |
|
| 553 |
let initData = { |
| 554 |
title: MainWP.I18n.t('Updating %1', decodeURIComponent(translationName)), |
| 555 |
progressMax: pSitesCount |
| 556 |
}; |
| 557 |
updatesoverview_update_popup_init(initData); |
| 558 |
//Step 3: start updates |
| 559 |
updatesoverview_translations_upgrade_all_int(pSlug, pSitesToUpdate); |
| 560 |
|
| 561 |
updatesoverviewContinueAfterBackup = undefined; |
| 562 |
} |
| 563 |
}(sitesCount, slug, sitesToUpdate); |
| 564 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 565 |
} |
| 566 |
|
| 567 |
// new confirm message |
| 568 |
if (!continueUpdating) { |
| 569 |
if (jQuery(siteNames).length > 0) { |
| 570 |
let sitesList = []; |
| 571 |
jQuery.each(siteNames, function (index, value) { |
| 572 |
if (value) { // to fix |
| 573 |
sitesList.push(decodeURIComponent(value)); |
| 574 |
} |
| 575 |
}); |
| 576 |
let confirmMsg = MainWP.I18n.t('You are about to update the %1 translation on the following site(s): <br/><div class="ui message">%2</div> <strong>Do you want to proceed?</strong>', translationName, sitesList.join('<br />')); |
| 577 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 578 |
} |
| 579 |
return; |
| 580 |
} |
| 581 |
|
| 582 |
_callback(); |
| 583 |
}; |
| 584 |
let updatesoverview_translations_upgrade_all_int = function (slug, websiteIds, sitesTranslationSlugs) { |
| 585 |
currentTranslationSlugToUpgrade = slug; |
| 586 |
websitesTranslationSlugsToUpgrade = sitesTranslationSlugs; |
| 587 |
mainwpVars.websitesToUpdateTranslations = websiteIds; |
| 588 |
mainwpVars.currentWebsite = 0; |
| 589 |
mainwpVars.websitesDone = 0; |
| 590 |
mainwpVars.websitesTotal = mainwpVars.websitesLeft = mainwpVars.websitesToUpdateTranslations.length; |
| 591 |
|
| 592 |
mainwpVars.bulkTaskRunning = true; |
| 593 |
updatesoverview_translations_upgrade_all_loop_next(); |
| 594 |
}; |
| 595 |
let updatesoverview_translations_upgrade_all_loop_next = function () { |
| 596 |
while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxUpdateThreads) && (mainwpVars.websitesLeft > 0)) { |
| 597 |
updatesoverview_translations_upgrade_all_upgrade_next(); |
| 598 |
} |
| 599 |
}; |
| 600 |
let updatesoverview_translations_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 601 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 602 |
}; |
| 603 |
let updatesoverview_translations_upgrade_all_upgrade_next = function () { |
| 604 |
mainwpVars.currentThreads++; |
| 605 |
mainwpVars.websitesLeft--; |
| 606 |
// Show icon waiting |
| 607 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 608 |
let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i>'); |
| 609 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 610 |
waiting_icon += regression_waiting_icon; |
| 611 |
} |
| 612 |
|
| 613 |
let websiteId = mainwpVars.websitesToUpdateTranslations[mainwpVars.currentWebsite++]; |
| 614 |
updatesoverview_translations_upgrade_all_update_site_status(websiteId, waiting_icon); |
| 615 |
|
| 616 |
let slugToUpgrade = currentTranslationSlugToUpgrade; |
| 617 |
if (slugToUpgrade == undefined) |
| 618 |
slugToUpgrade = websitesTranslationSlugsToUpgrade[websiteId]; |
| 619 |
updatesoverview_translations_upgrade_int(slugToUpgrade, websiteId, true, true); |
| 620 |
}; |
| 621 |
|
| 622 |
let updatesoverview_translations_upgrade_all_update_done = function () { |
| 623 |
mainwpVars.currentThreads--; |
| 624 |
if (!mainwpVars.bulkTaskRunning) |
| 625 |
return; |
| 626 |
mainwpVars.websitesDone++; |
| 627 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 628 |
|
| 629 |
if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { |
| 630 |
updatesoverview_check_to_continue_updates(); |
| 631 |
return; |
| 632 |
} |
| 633 |
|
| 634 |
updatesoverview_translations_upgrade_all_loop_next(); |
| 635 |
}; |
| 636 |
let updatesoverview_translations_upgrade_int = function (slug, websiteId, bulkMode, noCheck) { //NOSONAR |
| 637 |
|
| 638 |
updatesoverviewContinueAfterBackup = function () { //NOSONAR |
| 639 |
// need declare variables. |
| 640 |
let pSlug = slug; |
| 641 |
let pWebsiteId = websiteId; |
| 642 |
let pBulkMode = bulkMode; |
| 643 |
|
| 644 |
let slugList = globalThis.mainwp_slug_list_to_array(pSlug); |
| 645 |
|
| 646 |
const yithSlugList = slugList.filter(slg => slg.startsWith('yith-')); |
| 647 |
const noneYithSlugs = slugList.filter(slg => !slg.startsWith('yith-')); |
| 648 |
|
| 649 |
let currentSlug = ''; |
| 650 |
let slugParts = []; |
| 651 |
let remainingSlugs = []; |
| 652 |
|
| 653 |
if (noneYithSlugs.length > 0) { |
| 654 |
currentSlug = noneYithSlugs.join(','); |
| 655 |
slugParts = noneYithSlugs; |
| 656 |
remainingSlugs = yithSlugList; |
| 657 |
} else if (yithSlugList.length > 0) { |
| 658 |
currentSlug = yithSlugList.shift(); |
| 659 |
remainingSlugs = yithSlugList; |
| 660 |
slugParts = [currentSlug]; |
| 661 |
} |
| 662 |
|
| 663 |
// Show icon waiting |
| 664 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 665 |
let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Updating. Please wait...')); |
| 666 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 667 |
waiting_icon += regression_waiting_icon; |
| 668 |
} |
| 669 |
|
| 670 |
for (let sid of slugParts) { |
| 671 |
let websiteHolder = jQuery('.translations-bulk-updates[translation_slug="' + sid + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 672 |
if (!websiteHolder.exists()) { |
| 673 |
websiteHolder = jQuery('.translations-bulk-updates[site_id="' + pWebsiteId + '"] tr[translation_slug="' + sid + '"]'); |
| 674 |
} |
| 675 |
|
| 676 |
websiteHolder.find('td:last-child').html(waiting_icon); |
| 677 |
} |
| 678 |
|
| 679 |
let data = mainwp_secure_data({ |
| 680 |
action: 'mainwp_upgradeplugintheme', |
| 681 |
websiteId: pWebsiteId, |
| 682 |
type: 'translation', |
| 683 |
slug: currentSlug |
| 684 |
}); |
| 685 |
|
| 686 |
jQuery.ajax({ |
| 687 |
type: "POST", |
| 688 |
url: ajaxurl, |
| 689 |
data: data, |
| 690 |
success: function (pSlug, pWebsiteId, pBulkMode) { //NOSONAR |
| 691 |
return function (response) { //NOSONAR |
| 692 |
let slugParts = []; |
| 693 |
if (pSlug.includes(',')) { |
| 694 |
slugParts = pSlug.split(','); |
| 695 |
} else { |
| 696 |
slugParts = [pSlug]; |
| 697 |
} |
| 698 |
|
| 699 |
let done = false; |
| 700 |
for (let sid of slugParts) { |
| 701 |
let _error = ''; |
| 702 |
let websiteHolder = jQuery('.translations-bulk-updates[translation_slug="' + sid + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 703 |
if (!websiteHolder.exists()) { |
| 704 |
websiteHolder = jQuery('.translations-bulk-updates[site_id="' + pWebsiteId + '"] tr[translation_slug="' + sid + '"]'); |
| 705 |
} |
| 706 |
|
| 707 |
if (response.error) { |
| 708 |
mainwpVars.errorCount++; |
| 709 |
_error = getErrorMessageInfo(response.error); |
| 710 |
let extErr = getErrorMessageInfo(response.error, 'ui'); |
| 711 |
if (!done && pBulkMode) |
| 712 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, extErr); |
| 713 |
websiteHolder.find('td:last-child').html(extErr); |
| 714 |
} else { |
| 715 |
let res = response.result; |
| 716 |
if (mainwp_get_result_entry(res, sid)) { |
| 717 |
// Show icon success + icon loading |
| 718 |
let regression_loading_icon = render_html_regression_icon(res, function (regression_final_icon) { //NOSONAR |
| 719 |
// After 1,5s, update the element in the dom with the icon |
| 720 |
const final_icon = `<i class="green check icon"></i> ${regression_final_icon}`; |
| 721 |
if (!done && pBulkMode) { |
| 722 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, final_icon); |
| 723 |
} |
| 724 |
websiteHolder.find('td:last-child').html(final_icon); |
| 725 |
}); |
| 726 |
|
| 727 |
const success_icon = `<i class="green check icon"></i> ${regression_loading_icon}`; |
| 728 |
if (!done && pBulkMode) { |
| 729 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, success_icon); |
| 730 |
} |
| 731 |
websiteHolder.attr('updated', 1); |
| 732 |
websiteHolder.find('td:last-child').html(success_icon); |
| 733 |
} else { |
| 734 |
mainwpVars.errorCount++; |
| 735 |
_error = MainWP.I18n.t('Update failed. Please try again.'); |
| 736 |
if (!done && pBulkMode) { |
| 737 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, '<span class="mainwp-html-popup" data-position="left center" data-html=""><i class="red times icon"></i></span>'); |
| 738 |
mainwp_init_html_popup('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"] .mainwp-html-popup', _error); |
| 739 |
} |
| 740 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 741 |
} |
| 742 |
} |
| 743 |
if (!done && pBulkMode) { |
| 744 |
if (remainingSlugs && remainingSlugs.length > 0) { |
| 745 |
updatesoverview_translations_upgrade_int(remainingSlugs, pWebsiteId, pBulkMode, true); |
| 746 |
} else { |
| 747 |
if ( |
| 748 |
!response.error && |
| 749 |
(typeof mainwp_html_regression === "undefined" || mainwp_html_regression.use_after_updates !== "1") |
| 750 |
) { |
| 751 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, '<i class="green check icon"></i>'); |
| 752 |
} |
| 753 |
updatesoverview_translations_upgrade_all_update_done(); |
| 754 |
} |
| 755 |
done = true; |
| 756 |
} |
| 757 |
} |
| 758 |
} |
| 759 |
}(currentSlug, pWebsiteId, pBulkMode), |
| 760 |
tryCount: 0, |
| 761 |
retryLimit: 3, |
| 762 |
endError: function (pSlug, pWebsiteId, pBulkMode) { |
| 763 |
return function () { |
| 764 |
let slugParts = []; |
| 765 |
if (pSlug.includes(',')) { |
| 766 |
slugParts = pSlug.split(','); |
| 767 |
} else { |
| 768 |
slugParts = [pSlug]; |
| 769 |
} |
| 770 |
let done = false; |
| 771 |
for (let sid of slugParts) { |
| 772 |
let result; |
| 773 |
let websiteHolder = jQuery('.translations-bulk-updates[translation_slug="' + sid + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 774 |
if (!websiteHolder.exists()) { |
| 775 |
websiteHolder = jQuery('.translations-bulk-updates[site_id="' + pWebsiteId + '"] tr[translation_slug="' + sid + '"]'); |
| 776 |
} |
| 777 |
|
| 778 |
result = MainWP.I18n.t('FAILED'); |
| 779 |
if (!done && pBulkMode) { |
| 780 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, '<span class="mainwp-red"><i class="exclamation icon"></i> ' + MainWP.I18n.t('FAILED') + '</span>'); |
| 781 |
updatesoverview_translations_upgrade_all_update_done(); |
| 782 |
done = true; |
| 783 |
} |
| 784 |
|
| 785 |
websiteHolder.find('td:last-child').html(result); |
| 786 |
} |
| 787 |
} |
| 788 |
}(pSlug, pWebsiteId, pBulkMode), |
| 789 |
error: function (xhr) { |
| 790 |
this.tryCount++; |
| 791 |
if (this.tryCount >= this.retryLimit) { |
| 792 |
this.endError(); |
| 793 |
return; |
| 794 |
} |
| 795 |
|
| 796 |
let pXhr = xhr; |
| 797 |
|
| 798 |
setTimeout(() => { |
| 799 |
if (pXhr.status == 404) { |
| 800 |
//handle error |
| 801 |
jQuery.ajax(this); |
| 802 |
} else if (pXhr.status == 500) { |
| 803 |
//handle error |
| 804 |
} else { |
| 805 |
//handle error |
| 806 |
} |
| 807 |
}, 500); |
| 808 |
}, |
| 809 |
dataType: 'json' |
| 810 |
}); |
| 811 |
updatesoverviewContinueAfterBackup = undefined; |
| 812 |
}; |
| 813 |
|
| 814 |
if (noCheck) { |
| 815 |
updatesoverviewContinueAfterBackup(); |
| 816 |
return false; |
| 817 |
} |
| 818 |
|
| 819 |
let sitesToUpdate = [websiteId]; |
| 820 |
let siteNames = []; |
| 821 |
siteNames[websiteId] = jQuery('div[site_id="' + websiteId + '"]').attr('site_name'); |
| 822 |
|
| 823 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 824 |
}; |
| 825 |
|
| 826 |
let currentPluginSlugToUpgrade; |
| 827 |
let websitesPluginSlugsToUpgrade; |
| 828 |
let updatesoverview_plugins_global_upgrade_all = function (groupId, updatesSelected) { // NOSONAR - Complexity 18/15. |
| 829 |
if (mainwpVars.bulkTaskRunning) |
| 830 |
return; |
| 831 |
|
| 832 |
//Step 1: build form |
| 833 |
let sitesToUpdate = []; |
| 834 |
let siteNames = {}; |
| 835 |
let sitesPluginSlugs = {}; |
| 836 |
|
| 837 |
let foundChildren = updatesoverview_plugins_get_global_upgrade_all(groupId, updatesSelected); |
| 838 |
|
| 839 |
if (foundChildren.length == 0) |
| 840 |
return; |
| 841 |
let sitesCount = 0; |
| 842 |
|
| 843 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 844 |
|
| 845 |
for (let i = 0; i < foundChildren.length; i++) { |
| 846 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && groupId === undefined) { |
| 847 |
continueUpdatesAll = 'plugins_global_upgrade_all'; |
| 848 |
break; |
| 849 |
} |
| 850 |
let child = jQuery(foundChildren[i]); |
| 851 |
let parent = child.parent(); // to fix |
| 852 |
|
| 853 |
let siteElement; |
| 854 |
let pluginElement; |
| 855 |
|
| 856 |
let checkAttr = child.attr('site_id'); |
| 857 |
if (checkAttr !== undefined && (checkAttr !== false)) { |
| 858 |
siteElement = child; |
| 859 |
pluginElement = parent; |
| 860 |
} else { |
| 861 |
siteElement = parent; |
| 862 |
pluginElement = child; |
| 863 |
} |
| 864 |
|
| 865 |
let siteId = siteElement.attr('site_id'); |
| 866 |
let siteName = siteElement.attr('site_name'); |
| 867 |
let pluginSlug = mainwp_decode_slug(pluginElement.attr('plugin_slug')); |
| 868 |
|
| 869 |
if (!sitesToUpdate.includes(siteId)) { |
| 870 |
sitesCount++; |
| 871 |
sitesToUpdate.push(siteId); |
| 872 |
siteNames[siteId] = siteName; |
| 873 |
} |
| 874 |
if (sitesPluginSlugs[siteId] == undefined) { |
| 875 |
sitesPluginSlugs[siteId] = pluginSlug; |
| 876 |
} else { |
| 877 |
sitesPluginSlugs[siteId] += ',' + pluginSlug; |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
let _callback = function () { |
| 882 |
|
| 883 |
for (let id of sitesToUpdate) { |
| 884 |
let updateCount = sitesPluginSlugs[id].match(/,/g); |
| 885 |
if (updateCount == null) |
| 886 |
updateCount = 1; |
| 887 |
else |
| 888 |
updateCount = updateCount.length + 1; |
| 889 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', id) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteNames[id]), id) + ' (' + updateCount + ' plugins)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + id + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 890 |
} |
| 891 |
|
| 892 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate, pSitesPluginSlugs) { |
| 893 |
return function () { |
| 894 |
|
| 895 |
let initData = { |
| 896 |
title: MainWP.I18n.t('Updating all'), |
| 897 |
progressMax: pSitesCount |
| 898 |
}; |
| 899 |
updatesoverview_update_popup_init(initData); |
| 900 |
|
| 901 |
//Step 3: start updates |
| 902 |
updatesoverview_plugins_upgrade_all_int(undefined, pSitesToUpdate, pSitesPluginSlugs); |
| 903 |
|
| 904 |
updatesoverviewContinueAfterBackup = undefined; |
| 905 |
} |
| 906 |
}(sitesCount, sitesToUpdate, sitesPluginSlugs); |
| 907 |
|
| 908 |
|
| 909 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 910 |
} |
| 911 |
|
| 912 |
// new confirm message |
| 913 |
if (!continueUpdating) { |
| 914 |
if (jQuery(siteNames).length > 0) { |
| 915 |
let sitesList = []; |
| 916 |
jQuery.each(siteNames, function (index, value) { |
| 917 |
if (value) { // to fix |
| 918 |
sitesList.push(decodeURIComponent(value)); |
| 919 |
} |
| 920 |
}); |
| 921 |
let confirmMsg = MainWP.I18n.t('You are about to update %1 on the following site(s): <br/><div class="ui message">%2</div> <strong>Do you want to proceed?</strong>', MainWP.I18n.t('plugins'), sitesList.join('<br />')); |
| 922 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 923 |
} |
| 924 |
return; |
| 925 |
} |
| 926 |
_callback(); |
| 927 |
}; |
| 928 |
|
| 929 |
let updatesoverview_plugins_get_global_upgrade_all = function (groupId, updatesSelected) { |
| 930 |
let foundChildren = []; |
| 931 |
if (updatesSelected !== undefined && updatesSelected) { |
| 932 |
if (groupId !== undefined && false !== groupId) { |
| 933 |
foundChildren = mainwp_updates_get_selected_rows_values('#update_wrapper_plugin_upgrades_group_' + groupId, 'tr.mainwp-plugin-update[updated="0"]'); |
| 934 |
} else { |
| 935 |
foundChildren = mainwp_updates_get_selected_rows_values('#plugins-updates-global', 'table tr[updated="0"]'); |
| 936 |
} |
| 937 |
if (foundChildren.length == 0) { |
| 938 |
updates_please_select_items_notice(); |
| 939 |
return; |
| 940 |
} |
| 941 |
} else if (groupId !== undefined && false !== groupId) { |
| 942 |
foundChildren = jQuery('#update_wrapper_plugin_upgrades_group_' + groupId).find('tr.mainwp-plugin-update[updated="0"]'); |
| 943 |
} else { |
| 944 |
foundChildren = jQuery('#plugins-updates-global').find('table tr[updated="0"]'); |
| 945 |
} |
| 946 |
return foundChildren; |
| 947 |
} |
| 948 |
|
| 949 |
let updatesoverview_plugins_upgrade_all = function (slug, pluginName, updatesSelected) { |
| 950 |
if (mainwpVars.bulkTaskRunning) |
| 951 |
return; |
| 952 |
|
| 953 |
//Step 1: build form |
| 954 |
let sitesToUpdate = []; |
| 955 |
let siteNames = []; |
| 956 |
let foundChildren = updatesoverview_plugins_get_upgrade_all(slug, updatesSelected); |
| 957 |
|
| 958 |
if (foundChildren.length == 0) |
| 959 |
return; |
| 960 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 961 |
|
| 962 |
for (let i = 0; i < foundChildren.length; i++) { |
| 963 |
if (limitUpdateAll > 0 && i >= limitUpdateAll) { |
| 964 |
continueUpdatesAll = 'plugins_upgrade_all'; |
| 965 |
continueUpdatesSlug = slug; |
| 966 |
break; |
| 967 |
} |
| 968 |
let child = foundChildren[i]; |
| 969 |
let siteId = jQuery(child).attr('site_id'); |
| 970 |
let siteName = jQuery(child).attr('site_name'); |
| 971 |
siteNames[siteId] = siteName; |
| 972 |
sitesToUpdate.push(siteId); |
| 973 |
} |
| 974 |
|
| 975 |
pluginName = decodeURIComponent(pluginName); |
| 976 |
pluginName = pluginName.replaceAll('+', ' '); |
| 977 |
|
| 978 |
let _callback = function () { |
| 979 |
|
| 980 |
for (let id of sitesToUpdate) { |
| 981 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', id) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteNames[id]), id), '<span class="updatesoverview-upgrade-status-wp" siteid="' + id + '">' + '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Pending', 'mainwp') + '"><i class="clock outline icon"></i></span> ' + '</span>'); |
| 982 |
} |
| 983 |
|
| 984 |
let sitesCount = sitesToUpdate.length; |
| 985 |
|
| 986 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSlug, pSitesToUpdate) { |
| 987 |
return function () { |
| 988 |
|
| 989 |
let initData = { |
| 990 |
title: MainWP.I18n.t('Updating %1', decodeURIComponent(pluginName)), |
| 991 |
progressMax: pSitesCount |
| 992 |
}; |
| 993 |
updatesoverview_update_popup_init(initData); |
| 994 |
|
| 995 |
//Step 3: start updates |
| 996 |
updatesoverview_plugins_upgrade_all_int(pSlug, pSitesToUpdate); |
| 997 |
|
| 998 |
updatesoverviewContinueAfterBackup = undefined; |
| 999 |
} |
| 1000 |
}(sitesCount, slug, sitesToUpdate); |
| 1001 |
|
| 1002 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1003 |
} |
| 1004 |
|
| 1005 |
// new confirm message |
| 1006 |
if (!continueUpdating) { |
| 1007 |
if (siteNames.length > 0) { |
| 1008 |
let sitesList = []; |
| 1009 |
jQuery.each(siteNames, function (index, value) { |
| 1010 |
if (value) { // to fix |
| 1011 |
sitesList.push(decodeURIComponent(value)); |
| 1012 |
} |
| 1013 |
}); |
| 1014 |
let confirmMsg = MainWP.I18n.t('You are about to update the %1 plugin on the following site(s): <br/><div class="ui message">%2</div> <strong>Do you want to proceed?</strong>', pluginName, sitesList.join('<br />')); |
| 1015 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 1016 |
} |
| 1017 |
return; |
| 1018 |
} |
| 1019 |
_callback(); |
| 1020 |
}; |
| 1021 |
|
| 1022 |
let updatesoverview_plugins_get_upgrade_all = function (slug, updatesSelected) { |
| 1023 |
let foundChildren = []; |
| 1024 |
if (updatesSelected !== undefined && updatesSelected) { |
| 1025 |
jQuery('tr[plugin_slug="' + slug + '"]').find('table tr[updated="0"]').each( |
| 1026 |
function () { |
| 1027 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 1028 |
foundChildren.push(this); |
| 1029 |
} |
| 1030 |
} |
| 1031 |
); |
| 1032 |
if (foundChildren.length == 0) { |
| 1033 |
updates_please_select_items_notice(); |
| 1034 |
return false; |
| 1035 |
} |
| 1036 |
} else { |
| 1037 |
foundChildren = jQuery('tr[plugin_slug="' + slug + '"]').find('table tr[updated="0"]'); |
| 1038 |
} |
| 1039 |
return foundChildren; |
| 1040 |
} |
| 1041 |
|
| 1042 |
let updatesoverview_plugins_upgrade_all_int = function (slug, websiteIds, sitesPluginSlugs) { |
| 1043 |
currentPluginSlugToUpgrade = slug; |
| 1044 |
websitesPluginSlugsToUpgrade = sitesPluginSlugs; |
| 1045 |
mainwpVars.websitesToUpdatePlugins = websiteIds; |
| 1046 |
mainwpVars.currentWebsite = 0; |
| 1047 |
mainwpVars.websitesDone = 0; |
| 1048 |
mainwpVars.errorCount = 0; |
| 1049 |
mainwpVars.websitesTotal = mainwpVars.websitesLeft = mainwpVars.websitesToUpdatePlugins.length; |
| 1050 |
|
| 1051 |
mainwpVars.bulkTaskRunning = true; |
| 1052 |
updatesoverview_plugins_upgrade_all_loop_next(); |
| 1053 |
}; |
| 1054 |
let updatesoverview_plugins_upgrade_all_loop_next = function () { |
| 1055 |
while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxUpdateThreads) && (mainwpVars.websitesLeft > 0)) { |
| 1056 |
updatesoverview_plugins_upgrade_all_upgrade_next(); |
| 1057 |
} |
| 1058 |
}; |
| 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 |
} |
| 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 |
|
| 1150 |
let updatesoverview_plugins_upgrade_all_upgrade_next = function () { |
| 1151 |
mainwpVars.currentThreads++; |
| 1152 |
mainwpVars.websitesLeft--; |
| 1153 |
|
| 1154 |
// Show icon waiting |
| 1155 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 1156 |
let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i>'); |
| 1157 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 1158 |
waiting_icon += regression_waiting_icon; |
| 1159 |
} |
| 1160 |
let websiteId = mainwpVars.websitesToUpdatePlugins[mainwpVars.currentWebsite++]; |
| 1161 |
|
| 1162 |
updatesoverview_plugins_upgrade_all_update_site_status(websiteId, waiting_icon); |
| 1163 |
|
| 1164 |
let slugToUpgrade = currentPluginSlugToUpgrade; |
| 1165 |
if (slugToUpgrade == undefined) |
| 1166 |
slugToUpgrade = websitesPluginSlugsToUpgrade[websiteId]; |
| 1167 |
updatesoverview_plugins_upgrade_int(slugToUpgrade, websiteId, true, true); |
| 1168 |
}; |
| 1169 |
|
| 1170 |
let updatesoverview_check_to_continue_updates = function () { |
| 1171 |
mainwpVars.bulkTaskRunning = false; |
| 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 |
} |
| 1182 |
return false; |
| 1183 |
} |
| 1184 |
|
| 1185 |
let updatesoverview_plugins_upgrade_all_update_done = function () { |
| 1186 |
mainwpVars.currentThreads--; |
| 1187 |
if (!mainwpVars.bulkTaskRunning) |
| 1188 |
return; |
| 1189 |
mainwpVars.websitesDone++; |
| 1190 |
|
| 1191 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 1192 |
|
| 1193 |
if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { |
| 1194 |
updatesoverview_check_to_continue_updates(); |
| 1195 |
return; |
| 1196 |
} |
| 1197 |
|
| 1198 |
updatesoverview_plugins_upgrade_all_loop_next(); |
| 1199 |
}; |
| 1200 |
|
| 1201 |
let mainwp_handle_regression_final_icon = function (pWebsiteId, success_icon) { |
| 1202 |
return function (regression_final_icon) { |
| 1203 |
updatesoverview_plugins_upgrade_all_update_site_status( |
| 1204 |
pWebsiteId, |
| 1205 |
success_icon + ' ' + regression_final_icon |
| 1206 |
); |
| 1207 |
}; |
| 1208 |
} |
| 1209 |
|
| 1210 |
let updatesoverview_plugins_upgrade_int_after_backup = function (pSlug, pWebsiteId, pBulkMode, pLastResult, errorHappen) { // NOSONAR - nest functions. |
| 1211 |
return function () { |
| 1212 |
let slugList = globalThis.mainwp_slug_list_to_array(pSlug); // NOSONAR -- window is ok. |
| 1213 |
|
| 1214 |
const yithSlugList = slugList.filter(slg => slg.startsWith('yith-')); |
| 1215 |
const noneYithSlugs = slugList.filter(slg => !slg.startsWith('yith-')); |
| 1216 |
|
| 1217 |
let currentSlug = ''; |
| 1218 |
let slugParts = []; |
| 1219 |
let remainingSlugs = []; |
| 1220 |
|
| 1221 |
if (noneYithSlugs.length > 0) { |
| 1222 |
currentSlug = noneYithSlugs.join(','); |
| 1223 |
slugParts = noneYithSlugs; |
| 1224 |
remainingSlugs = yithSlugList; |
| 1225 |
} else if (yithSlugList.length > 0) { |
| 1226 |
currentSlug = yithSlugList.shift(); |
| 1227 |
remainingSlugs = yithSlugList; |
| 1228 |
slugParts = [currentSlug]; |
| 1229 |
} |
| 1230 |
|
| 1231 |
let lastResult = pLastResult || null; |
| 1232 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 1233 |
let waiting_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Updating...', 'mainwp') + '"><i class="notched circle loading icon"></i></span> '; |
| 1234 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 1235 |
waiting_icon += regression_waiting_icon; |
| 1236 |
} |
| 1237 |
|
| 1238 |
for (let sid of slugParts) { |
| 1239 |
let websiteHolder = jQuery('.plugins-bulk-updates[plugin_slug="' + sid + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 1240 |
if (!websiteHolder.exists()) { |
| 1241 |
websiteHolder = jQuery('.plugins-bulk-updates[site_id="' + pWebsiteId + '"] tr[plugin_slug="' + sid + '"]'); |
| 1242 |
} |
| 1243 |
websiteHolder.find('td:last-child').html(waiting_icon); |
| 1244 |
} |
| 1245 |
|
| 1246 |
if( errorHappen === undefined ){ |
| 1247 |
errorHappen = false; |
| 1248 |
} |
| 1249 |
|
| 1250 |
let data = mainwp_secure_data({ |
| 1251 |
action: 'mainwp_upgradeplugintheme', |
| 1252 |
websiteId: pWebsiteId, |
| 1253 |
type: 'plugin', |
| 1254 |
slug: currentSlug, |
| 1255 |
bulkUpdate: mainwpVars.websitesTotal > 1 ? 1 : 0 |
| 1256 |
}); |
| 1257 |
jQuery.ajax({ |
| 1258 |
type: "POST", |
| 1259 |
url: ajaxurl, |
| 1260 |
data: data, |
| 1261 |
success: function (pSlug, pWebsiteId, pBulkMode) { |
| 1262 |
return function (response) { //NOSONAR |
| 1263 |
let slugParts = []; |
| 1264 |
if (pSlug.includes(',')) { |
| 1265 |
slugParts = pSlug.split(','); |
| 1266 |
} else { |
| 1267 |
slugParts = [pSlug]; |
| 1268 |
} |
| 1269 |
let done = false; |
| 1270 |
let bulk_errors = []; |
| 1271 |
let res_started; |
| 1272 |
let _icon = '<i class="red times icon"></i>'; |
| 1273 |
for (let sid of slugParts) { |
| 1274 |
let websiteHolder = jQuery('.plugins-bulk-updates[plugin_slug="' + sid + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 1275 |
if (!websiteHolder.exists()) { |
| 1276 |
websiteHolder = jQuery('.plugins-bulk-updates[site_id="' + pWebsiteId + '"] tr[plugin_slug="' + sid + '"]'); |
| 1277 |
} |
| 1278 |
|
| 1279 |
if (response.error || response.notices) { |
| 1280 |
let extErr = getErrorMessageInfo(response.error, 'ui'); |
| 1281 |
if (!done && pBulkMode) |
| 1282 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, extErr); |
| 1283 |
websiteHolder.find('td:last-child').html(extErr); |
| 1284 |
mainwpVars.errorCount++; |
| 1285 |
errorHappen = true; |
| 1286 |
} else { |
| 1287 |
let res = response.result; |
| 1288 |
let res_error = response.result_error; |
| 1289 |
res_started = response.result_started; // for backward compatibility. |
| 1290 |
if (mainwp_get_result_entry(res, sid)) { |
| 1291 |
lastResult = res; |
| 1292 |
let _success_icon = `<i class="green check icon"></i>`; |
| 1293 |
let success_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Update successful', 'mainwp') + '">' + _success_icon + '</span>'; |
| 1294 |
websiteHolder.attr('updated', 1); |
| 1295 |
websiteHolder.find('td:last-child').html(success_icon + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId)); |
| 1296 |
} else if (mainwp_get_result_entry(res_started, sid)) { // for backward compatibility. |
| 1297 |
let _success_icon = `<i class="green check icon"></i>`; |
| 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>'; |
| 1299 |
websiteHolder.attr('updated', 1); |
| 1300 |
websiteHolder.find('td:last-child').html(success_icon + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId)); |
| 1301 |
} else if (mainwp_get_result_entry(res_error, sid)) { |
| 1302 |
let _error = mainwp_get_result_entry(res_error, sid); |
| 1303 |
let roll_error = mainwp_updates_get_rollback_msg(_error); |
| 1304 |
let roll_icon = _icon; |
| 1305 |
if (roll_error) { |
| 1306 |
_error = roll_error; |
| 1307 |
roll_icon = mainwpParams.roll_ui_icon; |
| 1308 |
} |
| 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>'); |
| 1311 |
mainwpVars.errorCount++; |
| 1312 |
errorHappen = true; |
| 1313 |
} else { |
| 1314 |
bulk_errors.push(MainWP.I18n.t('Update failed. Please try again.')); |
| 1315 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 1316 |
mainwpVars.errorCount++; |
| 1317 |
errorHappen = true; |
| 1318 |
} |
| 1319 |
} |
| 1320 |
} |
| 1321 |
|
| 1322 |
if (pBulkMode && bulk_errors.length) { |
| 1323 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"]').html('<span class="mainwp-html-popup" data-position="left center" data-html="">' + _icon + '</span>'); |
| 1324 |
mainwp_init_html_popup('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"] .mainwp-html-popup', bulk_errors.join('<br />')); |
| 1325 |
} |
| 1326 |
|
| 1327 |
if (remainingSlugs && remainingSlugs.length > 0) { |
| 1328 |
updatesoverview_plugins_upgrade_int_after_backup(remainingSlugs, pWebsiteId, pBulkMode, lastResult, errorHappen)(); |
| 1329 |
return; |
| 1330 |
} |
| 1331 |
if ( |
| 1332 |
pBulkMode && |
| 1333 |
!bulk_errors.length && |
| 1334 |
!response.error && |
| 1335 |
!response.notices && |
| 1336 |
!errorHappen |
| 1337 |
) { |
| 1338 |
if ( |
| 1339 |
lastResult && |
| 1340 |
typeof mainwp_html_regression !== "undefined" && |
| 1341 |
mainwp_html_regression.use_after_updates === "1" |
| 1342 |
) { |
| 1343 |
let success_icon = '<i class="green check icon"></i>'; |
| 1344 |
const regressionCallback = mainwp_handle_regression_final_icon(pWebsiteId, success_icon); |
| 1345 |
const regression_icon_loading = render_html_regression_icon(lastResult, regressionCallback); |
| 1346 |
|
| 1347 |
updatesoverview_plugins_upgrade_all_update_site_status( |
| 1348 |
pWebsiteId, |
| 1349 |
success_icon + ' ' + regression_icon_loading |
| 1350 |
); |
| 1351 |
} else if (typeof mainwp_html_regression === "undefined" || mainwp_html_regression.use_after_updates !== "1") { |
| 1352 |
let success_icon = `<i class="green check icon"></i>`; |
| 1353 |
// for backward compatibility. |
| 1354 |
if ( |
| 1355 |
res_started !== null && |
| 1356 |
typeof res_started === 'object' && |
| 1357 |
Object.keys(res_started).length > 0 |
| 1358 |
) { |
| 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>'; |
| 1360 |
} |
| 1361 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, success_icon); |
| 1362 |
} |
| 1363 |
} |
| 1364 |
if (pBulkMode) { |
| 1365 |
updatesoverview_plugins_upgrade_all_update_done(); |
| 1366 |
} |
| 1367 |
} |
| 1368 |
}(pSlug, pWebsiteId, pBulkMode), |
| 1369 |
tryCount: 0, |
| 1370 |
retryLimit: 3, |
| 1371 |
endError: function (pSlug, pWebsiteId, pBulkMode) { |
| 1372 |
return function () { |
| 1373 |
let slugParts = []; |
| 1374 |
if (pSlug.includes(',')) { |
| 1375 |
slugParts = pSlug.split(','); |
| 1376 |
} else { |
| 1377 |
slugParts = [pSlug]; |
| 1378 |
} |
| 1379 |
let done = false; |
| 1380 |
for (let sid of slugParts) { |
| 1381 |
//Siteview |
| 1382 |
let websiteHolder = jQuery('div[plugin_slug="' + sid + '"] div[site_id="' + pWebsiteId + '"]'); |
| 1383 |
if (!websiteHolder.exists()) { |
| 1384 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[plugin_slug="' + sid + '"]'); |
| 1385 |
} |
| 1386 |
|
| 1387 |
if (!done && pBulkMode) { |
| 1388 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 1389 |
updatesoverview_plugins_upgrade_all_update_done(); |
| 1390 |
done = true; |
| 1391 |
} |
| 1392 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 1393 |
} |
| 1394 |
} |
| 1395 |
}(pSlug, pWebsiteId, pBulkMode), |
| 1396 |
error: function (xhr) { |
| 1397 |
this.tryCount++; |
| 1398 |
if (this.tryCount >= this.retryLimit) { |
| 1399 |
mainwpVars.errorCount++; |
| 1400 |
this.endError(); |
| 1401 |
return; |
| 1402 |
} |
| 1403 |
let pXhr = xhr; |
| 1404 |
setTimeout(() => { |
| 1405 |
if (pXhr.status == 404) { |
| 1406 |
//handle error |
| 1407 |
jQuery.ajax(this); |
| 1408 |
} else if (pXhr.status == 500) { |
| 1409 |
//handle error |
| 1410 |
} else { |
| 1411 |
//handle error |
| 1412 |
} |
| 1413 |
}, 500); |
| 1414 |
}, |
| 1415 |
dataType: 'json' |
| 1416 |
}); |
| 1417 |
|
| 1418 |
updatesoverviewContinueAfterBackup = undefined; |
| 1419 |
} |
| 1420 |
} |
| 1421 |
|
| 1422 |
let updatesoverview_plugins_upgrade_int = function (slug, websiteId, bulkMode, noCheck) { |
| 1423 |
|
| 1424 |
updatesoverviewContinueAfterBackup = function (pSlug, pWebsiteId, pBulkMode) { |
| 1425 |
return updatesoverview_plugins_upgrade_int_after_backup(pSlug, pWebsiteId, pBulkMode); |
| 1426 |
}(slug, websiteId, bulkMode); |
| 1427 |
|
| 1428 |
if (noCheck) { |
| 1429 |
updatesoverviewContinueAfterBackup(); |
| 1430 |
return false; |
| 1431 |
} |
| 1432 |
|
| 1433 |
let sitesToUpdate = [websiteId]; |
| 1434 |
let siteNames = []; |
| 1435 |
siteNames[websiteId] = jQuery('div[site_id="' + websiteId + '"]').attr('site_name'); |
| 1436 |
|
| 1437 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1438 |
}; |
| 1439 |
|
| 1440 |
let currentThemeSlugToUpgrade; |
| 1441 |
let websitesThemeSlugsToUpgrade; |
| 1442 |
let updatesoverview_themes_global_upgrade_all = function (groupId, updatesSelected) { // NOSONAR - complexity. |
| 1443 |
if (mainwpVars.bulkTaskRunning) |
| 1444 |
return; |
| 1445 |
|
| 1446 |
//Step 1: build form |
| 1447 |
let sitesToUpdate = []; |
| 1448 |
let siteNames = {}; |
| 1449 |
let sitesPluginSlugs = {}; |
| 1450 |
let foundChildren = updatesoverview_themes_get_global_upgrade_all(groupId, updatesSelected); |
| 1451 |
if (foundChildren.length == 0) { |
| 1452 |
updates_please_select_items_notice(); |
| 1453 |
return false; |
| 1454 |
} |
| 1455 |
let sitesCount = 0; |
| 1456 |
|
| 1457 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 1458 |
|
| 1459 |
for (let i = 0; i < foundChildren.length; i++) { |
| 1460 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && groupId === undefined) { |
| 1461 |
continueUpdatesAll = 'themes_global_upgrade_all'; |
| 1462 |
break; |
| 1463 |
} |
| 1464 |
let child = jQuery(foundChildren[i]); |
| 1465 |
let parent = child.parent(); // to fix |
| 1466 |
|
| 1467 |
let siteElement; |
| 1468 |
let themeElement; |
| 1469 |
|
| 1470 |
let checkAttr = child.attr('site_id'); |
| 1471 |
if ((checkAttr !== undefined) && (checkAttr !== false)) { |
| 1472 |
siteElement = child; |
| 1473 |
themeElement = parent; |
| 1474 |
} else { |
| 1475 |
siteElement = parent; |
| 1476 |
themeElement = child; |
| 1477 |
} |
| 1478 |
|
| 1479 |
let siteId = siteElement.attr('site_id'); |
| 1480 |
let siteName = siteElement.attr('site_name'); |
| 1481 |
let themeSlug = mainwp_decode_slug(themeElement.attr('theme_slug')); |
| 1482 |
|
| 1483 |
if (!sitesToUpdate.includes(siteId)) { |
| 1484 |
sitesCount++; |
| 1485 |
sitesToUpdate.push(siteId); |
| 1486 |
siteNames[siteId] = siteName; |
| 1487 |
} |
| 1488 |
if (sitesPluginSlugs[siteId] == undefined) { |
| 1489 |
sitesPluginSlugs[siteId] = themeSlug; |
| 1490 |
} else { |
| 1491 |
sitesPluginSlugs[siteId] += ',' + themeSlug; |
| 1492 |
} |
| 1493 |
} |
| 1494 |
|
| 1495 |
let _callback = function () { |
| 1496 |
|
| 1497 |
for (let id of sitesToUpdate) { |
| 1498 |
let updateCount = sitesPluginSlugs[id].match(/,/g); |
| 1499 |
if (updateCount == null) |
| 1500 |
updateCount = 1; |
| 1501 |
else |
| 1502 |
updateCount = updateCount.length + 1; |
| 1503 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', id) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteNames[id]), id) + ' (' + updateCount + ' themes)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + id + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 1504 |
} |
| 1505 |
|
| 1506 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate, pSitesPluginSlugs) { |
| 1507 |
return function () { |
| 1508 |
|
| 1509 |
let initData = { |
| 1510 |
title: MainWP.I18n.t('Updating all...'), |
| 1511 |
progressMax: pSitesCount |
| 1512 |
}; |
| 1513 |
updatesoverview_update_popup_init(initData); |
| 1514 |
|
| 1515 |
//Step 3: start updates |
| 1516 |
updatesoverview_themes_upgrade_all_int(undefined, pSitesToUpdate, pSitesPluginSlugs); |
| 1517 |
|
| 1518 |
updatesoverviewContinueAfterBackup = undefined; |
| 1519 |
} |
| 1520 |
}(sitesCount, sitesToUpdate, sitesPluginSlugs); |
| 1521 |
|
| 1522 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1523 |
} |
| 1524 |
|
| 1525 |
// new confirm message |
| 1526 |
if (!continueUpdating) { |
| 1527 |
if (jQuery(siteNames).length > 0) { |
| 1528 |
let sitesList = []; |
| 1529 |
jQuery.each(siteNames, function (index, value) { |
| 1530 |
if (value) { // to fix |
| 1531 |
sitesList.push(decodeURIComponent(value)); |
| 1532 |
} |
| 1533 |
}); |
| 1534 |
let confirmMsg = MainWP.I18n.t('You are about to update %1 on the following site(s): <br/><div class="ui message">%2</div> <strong>Do you want to proceed?</strong>', MainWP.I18n.t('themes'), sitesList.join('<br />')); |
| 1535 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 1536 |
} |
| 1537 |
return; |
| 1538 |
} |
| 1539 |
_callback(); |
| 1540 |
}; |
| 1541 |
|
| 1542 |
let updatesoverview_themes_get_global_upgrade_all = function (groupId, updatesSelected) { |
| 1543 |
let foundChildren = []; |
| 1544 |
if (updatesSelected !== undefined && updatesSelected) { |
| 1545 |
if (groupId !== undefined && false !== groupId) { |
| 1546 |
jQuery('#update_wrapper_theme_upgrades_group_' + groupId).find('tr.mainwp-theme-update[updated="0"]').each( |
| 1547 |
function () { |
| 1548 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 1549 |
foundChildren.push(this); |
| 1550 |
} |
| 1551 |
} |
| 1552 |
); |
| 1553 |
} else { |
| 1554 |
jQuery('#themes-updates-global').find('table tr[updated="0"]').each( |
| 1555 |
function () { |
| 1556 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 1557 |
foundChildren.push(this); |
| 1558 |
} |
| 1559 |
} |
| 1560 |
); |
| 1561 |
} |
| 1562 |
} else if (groupId !== undefined && false !== groupId) { |
| 1563 |
foundChildren = jQuery('#update_wrapper_theme_upgrades_group_' + groupId).find('tr.mainwp-theme-update[updated="0"]'); |
| 1564 |
} else { |
| 1565 |
foundChildren = jQuery('#themes-updates-global').find('table tr[updated="0"]'); |
| 1566 |
} |
| 1567 |
return foundChildren; |
| 1568 |
} |
| 1569 |
|
| 1570 |
let updates_please_select_items_notice = function () { |
| 1571 |
let msg = MainWP.I18n.t('Please, select items to update.'); |
| 1572 |
jQuery('#mainwp-modal-confirm-select .content-massage').html(msg); |
| 1573 |
jQuery('#mainwp-modal-confirm-select').modal('show'); |
| 1574 |
return false; |
| 1575 |
} |
| 1576 |
|
| 1577 |
let updatesoverview_themes_upgrade_all = function (slug, themeName, updatesSelected) { |
| 1578 |
if (mainwpVars.bulkTaskRunning) |
| 1579 |
return; |
| 1580 |
|
| 1581 |
//Step 1: build form |
| 1582 |
let sitesToUpdate = []; |
| 1583 |
let siteNames = []; |
| 1584 |
let foundChildren = updatesoverview_themes_get_upgrade_all(slug, updatesSelected); |
| 1585 |
|
| 1586 |
if (foundChildren.length == 0) |
| 1587 |
return; |
| 1588 |
|
| 1589 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 1590 |
|
| 1591 |
for (let i = 0; i < foundChildren.length; i++) { |
| 1592 |
if (limitUpdateAll > 0 && i >= limitUpdateAll) { |
| 1593 |
continueUpdatesAll = 'themes_upgrade_all'; |
| 1594 |
continueUpdatesSlug = slug; |
| 1595 |
break; |
| 1596 |
} |
| 1597 |
let child = foundChildren[i]; |
| 1598 |
let siteId = jQuery(child).attr('site_id'); |
| 1599 |
let siteName = jQuery(child).attr('site_name'); |
| 1600 |
siteNames[siteId] = siteName; |
| 1601 |
sitesToUpdate.push(siteId); |
| 1602 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', siteId) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteName), siteId), '<span class="updatesoverview-upgrade-status-wp" siteid="' + siteId + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 1603 |
} |
| 1604 |
|
| 1605 |
themeName = decodeURIComponent(themeName); |
| 1606 |
themeName = themeName.replaceAll('+', ' '); |
| 1607 |
|
| 1608 |
let _callback = function () { |
| 1609 |
|
| 1610 |
let sitesCount = sitesToUpdate.length; |
| 1611 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSlug, pSitesToUpdate) { |
| 1612 |
return function () { |
| 1613 |
//Step 2: show form |
| 1614 |
|
| 1615 |
let initData = { |
| 1616 |
title: MainWP.I18n.t('Updating %1', decodeURIComponent(themeName)), |
| 1617 |
progressMax: pSitesCount |
| 1618 |
}; |
| 1619 |
updatesoverview_update_popup_init(initData); |
| 1620 |
|
| 1621 |
//Step 3: start updates |
| 1622 |
updatesoverview_themes_upgrade_all_int(pSlug, pSitesToUpdate); |
| 1623 |
|
| 1624 |
updatesoverviewContinueAfterBackup = undefined; |
| 1625 |
} |
| 1626 |
}(sitesCount, slug, sitesToUpdate); |
| 1627 |
|
| 1628 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1629 |
} |
| 1630 |
|
| 1631 |
// new confirm message |
| 1632 |
if (!continueUpdating) { |
| 1633 |
if (jQuery(siteNames).length > 0) { |
| 1634 |
let sitesList = []; |
| 1635 |
jQuery.each(siteNames, function (index, value) { |
| 1636 |
if (value) { // to fix |
| 1637 |
sitesList.push(decodeURIComponent(value)); |
| 1638 |
} |
| 1639 |
}); |
| 1640 |
let confirmMsg = MainWP.I18n.t('You are about to update the %1 theme on the following site(s): <br/><div class="ui message">%2</div> <strong>Do you want to proceed?</strong>', themeName, sitesList.join('<br />')); |
| 1641 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 1642 |
} |
| 1643 |
return; |
| 1644 |
} |
| 1645 |
_callback(); |
| 1646 |
}; |
| 1647 |
|
| 1648 |
let updatesoverview_themes_get_upgrade_all = function (slug, updatesSelected) { |
| 1649 |
let foundChildren = []; |
| 1650 |
if (updatesSelected !== undefined && updatesSelected) { |
| 1651 |
jQuery('tr[theme_slug="' + slug + '"]').find('table tr[updated="0"]').each( |
| 1652 |
function () { |
| 1653 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 1654 |
foundChildren.push(this); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
); |
| 1658 |
if (foundChildren.length == 0) { |
| 1659 |
updates_please_select_items_notice(); |
| 1660 |
return false; |
| 1661 |
} |
| 1662 |
} else { |
| 1663 |
foundChildren = jQuery('tr[theme_slug="' + slug + '"]').find('table tr[updated="0"]'); |
| 1664 |
} |
| 1665 |
|
| 1666 |
return foundChildren; |
| 1667 |
} |
| 1668 |
|
| 1669 |
let updatesoverview_themes_upgrade_all_int = function (slug, websiteIds, sitesThemeSlugs) { |
| 1670 |
currentThemeSlugToUpgrade = slug; |
| 1671 |
websitesThemeSlugsToUpgrade = sitesThemeSlugs; |
| 1672 |
mainwpVars.websitesToUpdate = websiteIds; |
| 1673 |
mainwpVars.currentWebsite = 0; |
| 1674 |
mainwpVars.websitesDone = 0; |
| 1675 |
mainwpVars.websitesTotal = mainwpVars.websitesLeft = mainwpVars.websitesToUpdate.length; |
| 1676 |
|
| 1677 |
mainwpVars.bulkTaskRunning = true; |
| 1678 |
updatesoverview_themes_upgrade_all_loop_next(); |
| 1679 |
}; |
| 1680 |
let updatesoverview_themes_upgrade_all_loop_next = function () { |
| 1681 |
while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxUpdateThreads) && (mainwpVars.websitesLeft > 0)) { |
| 1682 |
updatesoverview_themes_upgrade_all_upgrade_next(); |
| 1683 |
} |
| 1684 |
}; |
| 1685 |
let updatesoverview_themes_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 1686 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 1687 |
}; |
| 1688 |
let updatesoverview_themes_upgrade_all_upgrade_next = function () { |
| 1689 |
mainwpVars.currentThreads++; |
| 1690 |
mainwpVars.websitesLeft--; |
| 1691 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 1692 |
let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i>'); |
| 1693 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 1694 |
waiting_icon += regression_waiting_icon; |
| 1695 |
} |
| 1696 |
let websiteId = mainwpVars.websitesToUpdate[mainwpVars.currentWebsite++]; |
| 1697 |
updatesoverview_themes_upgrade_all_update_site_status(websiteId, waiting_icon); |
| 1698 |
|
| 1699 |
let slugToUpgrade = currentThemeSlugToUpgrade; |
| 1700 |
if (slugToUpgrade == undefined) |
| 1701 |
slugToUpgrade = websitesThemeSlugsToUpgrade[websiteId]; |
| 1702 |
updatesoverview_themes_upgrade_int(slugToUpgrade, websiteId, true); |
| 1703 |
}; |
| 1704 |
let updatesoverview_themes_upgrade_all_update_done = function () { |
| 1705 |
mainwpVars.currentThreads--; |
| 1706 |
if (!mainwpVars.bulkTaskRunning) |
| 1707 |
return; |
| 1708 |
mainwpVars.websitesDone++; |
| 1709 |
|
| 1710 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 1711 |
|
| 1712 |
if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { |
| 1713 |
updatesoverview_check_to_continue_updates(); |
| 1714 |
return; |
| 1715 |
} |
| 1716 |
|
| 1717 |
updatesoverview_themes_upgrade_all_loop_next(); |
| 1718 |
}; |
| 1719 |
let updatesoverview_themes_upgrade_int = function (slug, websiteId, bulkMode, lastResult) { |
| 1720 |
let slugList = globalThis.mainwp_slug_list_to_array(slug); // NOSONAR -- window is ok. |
| 1721 |
|
| 1722 |
const yithSlugList = slugList.filter(slg => slg.startsWith('yith-')); |
| 1723 |
const noneYithSlugs = slugList.filter(slg => !slg.startsWith('yith-')); |
| 1724 |
|
| 1725 |
let currentSlug = ''; |
| 1726 |
let slugParts = []; |
| 1727 |
let remainingSlugs = []; |
| 1728 |
|
| 1729 |
if (noneYithSlugs.length > 0) { |
| 1730 |
currentSlug = noneYithSlugs.join(','); |
| 1731 |
slugParts = noneYithSlugs; |
| 1732 |
remainingSlugs = yithSlugList; |
| 1733 |
} else if (yithSlugList.length > 0) { |
| 1734 |
currentSlug = yithSlugList.shift(); |
| 1735 |
remainingSlugs = yithSlugList; |
| 1736 |
slugParts = [currentSlug]; |
| 1737 |
} |
| 1738 |
|
| 1739 |
let lastResultFinal = lastResult || null; |
| 1740 |
// Show icon waiting |
| 1741 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 1742 |
let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i> ' + MainWP.I18n.t('Updating. Please wait...')); |
| 1743 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 1744 |
waiting_icon += regression_waiting_icon; |
| 1745 |
} |
| 1746 |
|
| 1747 |
for (let sid of slugParts) { |
| 1748 |
let websiteHolder = jQuery('.themes-bulk-updates[theme_slug="' + sid + '"] tr[site_id="' + websiteId + '"]'); |
| 1749 |
if (!websiteHolder.exists()) { |
| 1750 |
websiteHolder = jQuery('.themes-bulk-updates[site_id="' + websiteId + '"] tr[theme_slug="' + sid + '"]'); |
| 1751 |
} |
| 1752 |
websiteHolder.find('td:last-child').html(waiting_icon); |
| 1753 |
} |
| 1754 |
|
| 1755 |
let data = mainwp_secure_data({ |
| 1756 |
action: 'mainwp_upgradeplugintheme', |
| 1757 |
websiteId: websiteId, |
| 1758 |
type: 'theme', |
| 1759 |
slug: currentSlug |
| 1760 |
}); |
| 1761 |
jQuery.ajax({ |
| 1762 |
type: "POST", |
| 1763 |
url: ajaxurl, |
| 1764 |
data: data, |
| 1765 |
success: function (pSlug, pWebsiteId, pBulkMode) { |
| 1766 |
return function (response) { // NOSONAR - complex. |
| 1767 |
let slugParts = []; |
| 1768 |
if (pSlug.includes(',')) { |
| 1769 |
slugParts = pSlug.split(','); |
| 1770 |
} else { |
| 1771 |
slugParts = [pSlug]; |
| 1772 |
} |
| 1773 |
let done = false; |
| 1774 |
|
| 1775 |
let bulk_errors = []; |
| 1776 |
let bulk_icon = '<i class="red times icon"></i>'; |
| 1777 |
|
| 1778 |
for (let sid of slugParts) { |
| 1779 |
let websiteHolder = jQuery('.themes-bulk-updates[theme_slug="' + sid + '"] tr[site_id="' + websiteId + '"]'); |
| 1780 |
if (!websiteHolder.exists()) { |
| 1781 |
websiteHolder = jQuery('.themes-bulk-updates[site_id="' + websiteId + '"] tr[theme_slug="' + sid + '"]'); |
| 1782 |
} |
| 1783 |
if (response.error) { |
| 1784 |
let extErr = getErrorMessageInfo(response.error, 'ui') |
| 1785 |
if (!done && pBulkMode) |
| 1786 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, extErr); |
| 1787 |
websiteHolder.find('td:last-child').html(extErr); |
| 1788 |
mainwpVars.errorCount++; |
| 1789 |
} else { |
| 1790 |
let res = response.result; |
| 1791 |
let res_error = response.result_error; |
| 1792 |
if (mainwp_get_result_entry(res, sid)) { |
| 1793 |
lastResultFinal = res; |
| 1794 |
let _success_icon = `<i class="green check icon"></i>`; |
| 1795 |
const success_icon = `<span data-inverted="" data-position="left center" data-tooltip="${MainWP.I18n.t('Update successful', 'mainwp')}">${_success_icon}</span>`; |
| 1796 |
websiteHolder.attr('updated', 1); |
| 1797 |
websiteHolder.find('td:last-child').html(success_icon); |
| 1798 |
} else { |
| 1799 |
let _error = ''; |
| 1800 |
let _icon = ''; |
| 1801 |
if (mainwp_get_result_entry(res_error, sid)) { |
| 1802 |
_error = mainwp_get_result_entry(res_error, sid); |
| 1803 |
_icon = '<i class="red times icon"></i>'; |
| 1804 |
let roll_error = mainwp_updates_get_rollback_msg(_error); |
| 1805 |
if (roll_error) { |
| 1806 |
_error = roll_error; |
| 1807 |
_icon = mainwpParams.roll_ui_icon; |
| 1808 |
bulk_icon = mainwpParams.roll_ui_icon; |
| 1809 |
} |
| 1810 |
bulk_errors.push(mainwp_escape_html(_error)); |
| 1811 |
mainwpVars.errorCount++; |
| 1812 |
} |
| 1813 |
if (_error) { |
| 1814 |
websiteHolder.find('td:last-child').html('<span class="mainwp-html-popup" data-position="left center" data-html="">' + _icon + '</span>'); |
| 1815 |
mainwp_init_html_popup(websiteHolder.find('td:last-child').find('.mainwp-html-popup'), mainwp_escape_html(_error)); |
| 1816 |
} |
| 1817 |
} |
| 1818 |
} |
| 1819 |
|
| 1820 |
} |
| 1821 |
|
| 1822 |
if (bulk_errors.length) { |
| 1823 |
if (pBulkMode) { |
| 1824 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"]').html('<span class="mainwp-html-popup" data-position="left center" data-html="">' + bulk_icon + '</span>'); |
| 1825 |
mainwp_init_html_popup('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"] .mainwp-html-popup', bulk_errors.join('<br />')); |
| 1826 |
} |
| 1827 |
} |
| 1828 |
|
| 1829 |
if (remainingSlugs && remainingSlugs.length > 0) { |
| 1830 |
updatesoverview_themes_upgrade_int(remainingSlugs, websiteId, bulkMode, lastResultFinal); |
| 1831 |
return; |
| 1832 |
} |
| 1833 |
if ( |
| 1834 |
pBulkMode && |
| 1835 |
!bulk_errors.length && |
| 1836 |
!response.error |
| 1837 |
) { |
| 1838 |
if ( |
| 1839 |
lastResultFinal && |
| 1840 |
typeof mainwp_html_regression !== "undefined" && |
| 1841 |
mainwp_html_regression.use_after_updates === "1" |
| 1842 |
) { |
| 1843 |
let success_icon = '<i class="green check icon"></i>'; |
| 1844 |
let regression_icon_loading = render_html_regression_icon(lastResultFinal, function (regression_icon_final) { |
| 1845 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, success_icon + ' ' + regression_icon_final); |
| 1846 |
}); |
| 1847 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, success_icon + ' ' + regression_icon_loading); |
| 1848 |
} else if (typeof mainwp_html_regression === "undefined" || mainwp_html_regression.use_after_updates !== "1") { |
| 1849 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, '<i class="green check icon"></i>'); |
| 1850 |
} |
| 1851 |
} |
| 1852 |
if (pBulkMode) { |
| 1853 |
updatesoverview_themes_upgrade_all_update_done(); |
| 1854 |
} |
| 1855 |
} |
| 1856 |
}(currentSlug, websiteId, bulkMode), |
| 1857 |
tryCount: 0, |
| 1858 |
retryLimit: 3, |
| 1859 |
endError: function (pSlug, pWebsiteId, pBulkMode) { |
| 1860 |
return function () { |
| 1861 |
let slugParts = []; |
| 1862 |
if (pSlug.includes(',')) { |
| 1863 |
slugParts = pSlug.split(','); |
| 1864 |
} else { |
| 1865 |
slugParts = [pSlug]; |
| 1866 |
} |
| 1867 |
let done = false; |
| 1868 |
for (let sid of slugParts) { |
| 1869 |
let websiteHolder = jQuery('div[theme_slug="' + sid + '"] div[site_id="' + pWebsiteId + '"]'); |
| 1870 |
if (!websiteHolder.exists()) { |
| 1871 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[theme_slug="' + sid + '"]'); |
| 1872 |
} |
| 1873 |
|
| 1874 |
if (!done && pBulkMode) { |
| 1875 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 1876 |
updatesoverview_themes_upgrade_all_update_done(); |
| 1877 |
done = true; |
| 1878 |
} |
| 1879 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 1880 |
} |
| 1881 |
} |
| 1882 |
}(slug, websiteId, bulkMode), |
| 1883 |
error: function (xhr) { |
| 1884 |
this.tryCount++; |
| 1885 |
if (this.tryCount >= this.retryLimit) { |
| 1886 |
mainwpVars.errorCount++; |
| 1887 |
this.endError(); |
| 1888 |
return; |
| 1889 |
} |
| 1890 |
|
| 1891 |
let pXhr = xhr; |
| 1892 |
setTimeout(() => { |
| 1893 |
if (pXhr.status == 404) { |
| 1894 |
//handle error |
| 1895 |
jQuery.ajax(this); |
| 1896 |
} else if (pXhr.status == 500) { |
| 1897 |
//handle error |
| 1898 |
} else { |
| 1899 |
//handle error |
| 1900 |
} |
| 1901 |
}, 500); |
| 1902 |
}, |
| 1903 |
dataType: 'json' |
| 1904 |
}); |
| 1905 |
|
| 1906 |
return false; |
| 1907 |
}; |
| 1908 |
|
| 1909 |
const updatesoverview_global_upgrade_all = function (which, current_siteid) { // NOSONAR - Complexity. |
| 1910 |
if (mainwpVars.bulkTaskRunning) { |
| 1911 |
return; |
| 1912 |
} |
| 1913 |
updatesoverview_global_prepare_upgrade_all(which, current_siteid); |
| 1914 |
} |
| 1915 |
|
| 1916 |
const updatesoverview_global_prepare_upgrade_all = function (which, current_siteid) { // NOSONAR - Complexity. |
| 1917 |
if (mainwpVars.bulkTaskRunning) { |
| 1918 |
return; |
| 1919 |
} |
| 1920 |
const onPrepared = () => updatesoverview_global_run_upgrade_all(which); |
| 1921 |
|
| 1922 |
updatesoverview_global_prepare_data_upgrade_all(which, onPrepared, current_siteid); |
| 1923 |
} |
| 1924 |
|
| 1925 |
const updatesoverview_global_prepare_data_upgrade_all = function (which, onPrepared, current_siteid) { |
| 1926 |
|
| 1927 |
let initData = { |
| 1928 |
title: MainWP.I18n.t('Updating All'), |
| 1929 |
initVisibleContentMsg: true, |
| 1930 |
contentMsg: MainWP.I18n.t('Preparing update data, please wait...'), |
| 1931 |
}; |
| 1932 |
mainwpPopup('#mainwp-prepare-data-modal').init(initData); |
| 1933 |
|
| 1934 |
let data = mainwp_secure_data({ |
| 1935 |
action: 'mainwp_overview_prepare_upgradeall', |
| 1936 |
which: which, |
| 1937 |
site_id: current_siteid |
| 1938 |
}); |
| 1939 |
|
| 1940 |
jQuery.ajax({ |
| 1941 |
type: "POST", |
| 1942 |
url: ajaxurl, |
| 1943 |
data: data, |
| 1944 |
dataType: 'html', |
| 1945 |
success: function (response) { |
| 1946 |
if (response && typeof onPrepared === 'function') { |
| 1947 |
jQuery('#mainwp_prepare_global_update_all_container').html(response); |
| 1948 |
onPrepared(); |
| 1949 |
} else { |
| 1950 |
setTimeout(function () { |
| 1951 |
mainwp_forceReload(); |
| 1952 |
}, 2000); |
| 1953 |
} |
| 1954 |
}, |
| 1955 |
error: function (xhr, status, error) { |
| 1956 |
console.error('Failed to prepare update data:', error); |
| 1957 |
setTimeout(function () { |
| 1958 |
mainwp_forceReload(); |
| 1959 |
}, 2000); |
| 1960 |
} |
| 1961 |
}); |
| 1962 |
} |
| 1963 |
|
| 1964 |
|
| 1965 |
/* eslint-disable complexity */ |
| 1966 |
const updatesoverview_global_run_upgrade_all = function (which) { // NOSONAR - Complexity. |
| 1967 |
|
| 1968 |
if (mainwpVars.bulkTaskRunning) { |
| 1969 |
return; |
| 1970 |
} |
| 1971 |
|
| 1972 |
//Step 1: build form |
| 1973 |
let sitesToUpdate = []; |
| 1974 |
let sitesToUpgrade = []; |
| 1975 |
let sitesPluginSlugs = {}; |
| 1976 |
let sitesThemeSlugs = {}; |
| 1977 |
let sitesTranslationSlugs = {}; |
| 1978 |
let siteNames = {}; |
| 1979 |
let suspendedWebsites = []; |
| 1980 |
|
| 1981 |
let sitesCount = 0; |
| 1982 |
let foundChildren; |
| 1983 |
|
| 1984 |
if (which == 'all' || which == 'wp') { |
| 1985 |
//Find wordpress to update |
| 1986 |
foundChildren = jQuery('#wp_upgrades').find('div[updated="0"]'); |
| 1987 |
if (foundChildren.length != 0) { |
| 1988 |
for (let child of foundChildren) { |
| 1989 |
let siteElement = jQuery(child); |
| 1990 |
let siteId = siteElement.attr('site_id'); |
| 1991 |
let siteName = siteElement.attr('site_name'); |
| 1992 |
if (!sitesToUpdate.includes(siteId)) { |
| 1993 |
sitesCount++; |
| 1994 |
sitesToUpdate.push(siteId); |
| 1995 |
siteNames[siteId] = siteName; |
| 1996 |
} |
| 1997 |
|
| 1998 |
if (!sitesToUpgrade.includes(siteId)) |
| 1999 |
sitesToUpgrade.push(siteId); |
| 2000 |
|
| 2001 |
if (!suspendedWebsites.includes(siteId) && siteElement.attr('is-suspended') == '1') { |
| 2002 |
suspendedWebsites.push(siteId); |
| 2003 |
} |
| 2004 |
} |
| 2005 |
} |
| 2006 |
} |
| 2007 |
|
| 2008 |
if (which == 'all' || which == 'plugin') { |
| 2009 |
//Find plugins to update |
| 2010 |
foundChildren = jQuery('#wp_plugin_upgrades').find('div[updated="0"]'); |
| 2011 |
if (foundChildren.length != 0) { |
| 2012 |
for (let item of foundChildren) { |
| 2013 |
let siteElement = jQuery(item); |
| 2014 |
let siteId = siteElement.attr('site_id'); |
| 2015 |
let siteName = siteElement.attr('site_name'); |
| 2016 |
let pluginSlug = mainwp_decode_slug(siteElement.attr('plugin_slug')); |
| 2017 |
|
| 2018 |
if (!sitesToUpdate.includes(siteId)) { |
| 2019 |
sitesCount++; |
| 2020 |
sitesToUpdate.push(siteId); |
| 2021 |
siteNames[siteId] = siteName; |
| 2022 |
} |
| 2023 |
|
| 2024 |
if (sitesPluginSlugs[siteId] == undefined) { |
| 2025 |
sitesPluginSlugs[siteId] = pluginSlug; |
| 2026 |
} else { |
| 2027 |
sitesPluginSlugs[siteId] += ',' + pluginSlug; |
| 2028 |
} |
| 2029 |
if (!suspendedWebsites.includes(siteId) && siteElement.attr('is-suspended') == '1') { |
| 2030 |
suspendedWebsites.push(siteId); |
| 2031 |
} |
| 2032 |
} |
| 2033 |
} |
| 2034 |
} |
| 2035 |
|
| 2036 |
if (which == 'all' || which == 'theme') { |
| 2037 |
//Find themes to update |
| 2038 |
foundChildren = jQuery('#wp_theme_upgrades').find('div[updated="0"]'); |
| 2039 |
if (foundChildren.length != 0) { |
| 2040 |
for (let item of foundChildren) { |
| 2041 |
let siteElement = jQuery(item); |
| 2042 |
let siteId = siteElement.attr('site_id'); |
| 2043 |
let siteName = siteElement.attr('site_name'); |
| 2044 |
let themeSlug = mainwp_decode_slug(siteElement.attr('theme_slug')); |
| 2045 |
|
| 2046 |
if (!sitesToUpdate.includes(siteId)) { |
| 2047 |
sitesCount++; |
| 2048 |
sitesToUpdate.push(siteId); |
| 2049 |
siteNames[siteId] = siteName; |
| 2050 |
} |
| 2051 |
|
| 2052 |
if (sitesThemeSlugs[siteId] == undefined) { |
| 2053 |
sitesThemeSlugs[siteId] = themeSlug; |
| 2054 |
} else { |
| 2055 |
sitesThemeSlugs[siteId] += ',' + themeSlug; |
| 2056 |
} |
| 2057 |
if (!suspendedWebsites.includes(siteId) && siteElement.attr('is-suspended') == '1') { |
| 2058 |
suspendedWebsites.push(siteId); |
| 2059 |
} |
| 2060 |
} |
| 2061 |
} |
| 2062 |
} |
| 2063 |
|
| 2064 |
if (which == 'all' || which == 'translation') { |
| 2065 |
//Find translation to update |
| 2066 |
foundChildren = jQuery('#wp_translation_upgrades').find('div[updated="0"]'); |
| 2067 |
if (foundChildren.length != 0) { |
| 2068 |
for (let item of foundChildren) { |
| 2069 |
let siteElement = jQuery(item); |
| 2070 |
let siteId = siteElement.attr('site_id'); |
| 2071 |
let siteName = siteElement.attr('site_name'); |
| 2072 |
let transSlug = mainwp_decode_slug(siteElement.attr('translation_slug')); |
| 2073 |
|
| 2074 |
if (!sitesToUpdate.includes(siteId)) { |
| 2075 |
sitesCount++; |
| 2076 |
sitesToUpdate.push(siteId); |
| 2077 |
siteNames[siteId] = siteName; |
| 2078 |
} |
| 2079 |
|
| 2080 |
if (sitesTranslationSlugs[siteId] == undefined) { |
| 2081 |
sitesTranslationSlugs[siteId] = transSlug; |
| 2082 |
} else { |
| 2083 |
sitesTranslationSlugs[siteId] += ',' + transSlug; |
| 2084 |
} |
| 2085 |
if (!suspendedWebsites.includes(siteId) && siteElement.attr('is-suspended') == '1') { |
| 2086 |
suspendedWebsites.push(siteId); |
| 2087 |
} |
| 2088 |
} |
| 2089 |
} |
| 2090 |
} |
| 2091 |
|
| 2092 |
let _callback = function () { // NOSONAR - Complexity. |
| 2093 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 2094 |
//Build form |
| 2095 |
for (let siteId of sitesToUpdate) { |
| 2096 |
let whatToUpgrade = ''; |
| 2097 |
if (sitesToUpgrade.includes(siteId)) |
| 2098 |
whatToUpgrade = '<span class="wordpress">WordPress core files</span>'; |
| 2099 |
|
| 2100 |
if (sitesPluginSlugs[siteId] != undefined) { |
| 2101 |
let updateCount = sitesPluginSlugs[siteId].match(/,/g); |
| 2102 |
if (updateCount == null) |
| 2103 |
updateCount = 1; |
| 2104 |
else |
| 2105 |
updateCount = updateCount.length + 1; |
| 2106 |
if (whatToUpgrade != '') |
| 2107 |
whatToUpgrade += ', '; |
| 2108 |
whatToUpgrade += '<span class="plugin">' + updateCount + ' plugin' + (updateCount > 1 ? 's' : '') + '</span>'; |
| 2109 |
} |
| 2110 |
|
| 2111 |
if (sitesThemeSlugs[siteId] != undefined) { |
| 2112 |
let updateCount = sitesThemeSlugs[siteId].match(/,/g); |
| 2113 |
|
| 2114 |
if (updateCount == null) |
| 2115 |
updateCount = 1; |
| 2116 |
else |
| 2117 |
updateCount = updateCount.length + 1; |
| 2118 |
|
| 2119 |
if (whatToUpgrade != '') |
| 2120 |
whatToUpgrade += ', '; |
| 2121 |
whatToUpgrade += '<span class="theme">' + updateCount + ' theme' + (updateCount > 1 ? 's' : '') + '</span>'; |
| 2122 |
} |
| 2123 |
|
| 2124 |
|
| 2125 |
if (sitesTranslationSlugs[siteId] != undefined) { |
| 2126 |
let updateCount = sitesTranslationSlugs[siteId].match(/,/g); |
| 2127 |
if (updateCount == null) |
| 2128 |
updateCount = 1; |
| 2129 |
else |
| 2130 |
updateCount = updateCount.length + 1; |
| 2131 |
|
| 2132 |
if (whatToUpgrade != '') |
| 2133 |
whatToUpgrade += ', '; |
| 2134 |
|
| 2135 |
whatToUpgrade += '<span class="translation">' + updateCount + ' translation' + (updateCount > 1 ? 's' : '') + '</span>'; |
| 2136 |
} |
| 2137 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', siteId) + ' ' + updatesmanage_link_to_site(decodeURIComponent(siteNames[siteId]), siteId) + ' (' + whatToUpgrade + ')', '<span class="updatesoverview-upgrade-status-wp" siteid="' + siteId + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 2138 |
} |
| 2139 |
|
| 2140 |
updatesoverviewContinueAfterBackup = updatesoverview_global_upgrade_all_after_backup(sitesCount, sitesToUpdate, sitesToUpgrade, sitesPluginSlugs, sitesThemeSlugs, sitesTranslationSlugs, suspendedWebsites); |
| 2141 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 2142 |
} // end _callback() |
| 2143 |
if (Object.keys(siteNames).length === 0) { |
| 2144 |
mainwpVars.bulkTaskRunning = false; |
| 2145 |
mainwpPopup('#mainwp-prepare-data-modal').getContentMsgEl().html('<div class="ui yellow message">' + MainWP.I18n.t('There are no updates available to process. Please try again.') + '</div>'); |
| 2146 |
} else { |
| 2147 |
updatesoverview_global_upgrade_all_start(which, siteNames, _callback); |
| 2148 |
} |
| 2149 |
}; |
| 2150 |
|
| 2151 |
let updatesoverview_global_upgrade_all_start = function (which, siteNames, _callback) { |
| 2152 |
// new confirm message |
| 2153 |
if (Object.keys(siteNames).length) { |
| 2154 |
let sitesList = []; |
| 2155 |
jQuery.each(siteNames, function (index, value) { |
| 2156 |
if (value) { // to fix |
| 2157 |
sitesList.push(decodeURIComponent(value)); |
| 2158 |
} |
| 2159 |
}); |
| 2160 |
|
| 2161 |
let whichUpdates = MainWP.I18n.t('WordPress core files, plugins, themes and translations'); |
| 2162 |
if (which == 'wp') { |
| 2163 |
whichUpdates = MainWP.I18n.t('WordPress core files'); |
| 2164 |
} else if (which == 'plugin') { |
| 2165 |
whichUpdates = MainWP.I18n.t('plugins'); |
| 2166 |
} else if (which == 'theme') { |
| 2167 |
whichUpdates = MainWP.I18n.t('themes'); |
| 2168 |
} else if (which == 'translation') { |
| 2169 |
whichUpdates = MainWP.I18n.t('translations'); |
| 2170 |
} |
| 2171 |
|
| 2172 |
let confirmMsg = MainWP.I18n.t('You are about to update %1 on the following site(s): <br/><div class="ui message">%2</div> <strong>Do you want to proceed?</strong>', whichUpdates, sitesList.join('<br />')); |
| 2173 |
|
| 2174 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 2175 |
} |
| 2176 |
} |
| 2177 |
|
| 2178 |
let updatesoverview_global_upgrade_all_after_backup = function (pSitesCount, pSitesToUpdate, pSitesToUpgrade, pSitesPluginSlugs, pSitesThemeSlugs, psitesTranslationSlugs, pSitesSuspended) { |
| 2179 |
return function () { |
| 2180 |
//Step 2: show form |
| 2181 |
|
| 2182 |
let initData = { |
| 2183 |
title: MainWP.I18n.t('Updating All'), |
| 2184 |
progressMax: pSitesCount, |
| 2185 |
}; |
| 2186 |
updatesoverview_update_popup_init(initData); |
| 2187 |
|
| 2188 |
//Step 3: start updates |
| 2189 |
updatesoverview_upgrade_all_int(pSitesToUpdate, pSitesToUpgrade, pSitesPluginSlugs, pSitesThemeSlugs, psitesTranslationSlugs, pSitesSuspended); |
| 2190 |
|
| 2191 |
updatesoverviewContinueAfterBackup = undefined; |
| 2192 |
}; |
| 2193 |
} |
| 2194 |
|
| 2195 |
/* eslint-enable complexity */ |
| 2196 |
let websitesTransSlugsToUpgrade; |
| 2197 |
|
| 2198 |
let updatesoverview_upgrade_all_int = function (pSitesToUpdate, pSitesToUpgrade, pSitesPluginSlugs, pSitesThemeSlugs, psitesTranslationSlugs, pSitesSuspended) { |
| 2199 |
mainwpVars.websitesToUpdate = pSitesToUpdate; |
| 2200 |
mainwpVars.websitesSuspended = pSitesSuspended; |
| 2201 |
|
| 2202 |
mainwpVars.websitesToUpgrade = pSitesToUpgrade; |
| 2203 |
|
| 2204 |
websitesPluginSlugsToUpgrade = pSitesPluginSlugs; |
| 2205 |
currentPluginSlugToUpgrade = undefined; |
| 2206 |
|
| 2207 |
websitesThemeSlugsToUpgrade = pSitesThemeSlugs; |
| 2208 |
currentThemeSlugToUpgrade = undefined; |
| 2209 |
|
| 2210 |
websitesTransSlugsToUpgrade = psitesTranslationSlugs; |
| 2211 |
|
| 2212 |
mainwpVars.currentWebsite = 0; |
| 2213 |
mainwpVars.websitesDone = 0; |
| 2214 |
mainwpVars.errorCount = 0; |
| 2215 |
mainwpVars.websitesTotal = mainwpVars.websitesLeft = mainwpVars.websitesToUpdate.length; |
| 2216 |
|
| 2217 |
mainwpVars.bulkTaskRunning = true; |
| 2218 |
|
| 2219 |
console.log('Suspended sites: ' + mainwpVars.websitesSuspended.join(', ')); |
| 2220 |
|
| 2221 |
updatesoverview_upgrade_all_loop_next(); |
| 2222 |
}; |
| 2223 |
|
| 2224 |
let updatesoverview_upgrade_all_loop_next = function () { |
| 2225 |
while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxUpdateThreads) && (mainwpVars.websitesLeft > 0)) { |
| 2226 |
updatesoverview_upgrade_all_upgrade_next(); |
| 2227 |
} |
| 2228 |
}; |
| 2229 |
let updatesoverview_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 2230 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 2231 |
}; |
| 2232 |
let updatesoverview_upgrade_all_update_site_bold = function (siteId, sub, msg) { |
| 2233 |
if (msg) { |
| 2234 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(msg); |
| 2235 |
} |
| 2236 |
if (false !== sub) { |
| 2237 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').parent().parent().find('.' + sub).css('font-weight', 'bold'); |
| 2238 |
} |
| 2239 |
}; |
| 2240 |
let updatesoverview_upgrade_all_upgrade_next = function () { |
| 2241 |
mainwpVars.currentThreads++; |
| 2242 |
mainwpVars.websitesLeft--; |
| 2243 |
// Show icon waiting |
| 2244 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 2245 |
let waiting_icon = render_tooltip_loading_icon('<i class="notched circle loading icon"></i>'); |
| 2246 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 2247 |
waiting_icon += regression_waiting_icon; |
| 2248 |
} |
| 2249 |
|
| 2250 |
let websiteId = mainwpVars.websitesToUpdate[mainwpVars.currentWebsite++]; |
| 2251 |
updatesoverview_upgrade_all_update_site_status(websiteId, waiting_icon); |
| 2252 |
|
| 2253 |
console.log('Starting upgrade process for site ' + websiteId); |
| 2254 |
|
| 2255 |
// process suspended site here to avoid starting the upgrade process and then showing the error after few seconds, also to avoid retrying the upgrade process for suspended sites in case of retry mechanism is triggered for some reason. |
| 2256 |
if (mainwpVars.websitesSuspended.includes(websiteId)) { |
| 2257 |
let msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '"><i class="pause yellow icon"></i></span>'; |
| 2258 |
updatesoverview_upgrade_all_update_site_bold(websiteId, false, msgUI); |
| 2259 |
mainwpVars.errorCount++; |
| 2260 |
updatesoverview_upgrade_all_update_done(); |
| 2261 |
return; |
| 2262 |
} |
| 2263 |
|
| 2264 |
let params = { |
| 2265 |
'websiteId': websiteId, |
| 2266 |
'pThemeSlugToUpgrade': websitesThemeSlugsToUpgrade[websiteId], |
| 2267 |
'pPluginSlugToUpgrade': websitesPluginSlugsToUpgrade[websiteId], |
| 2268 |
'pWordpressUpgrade': mainwpVars.websitesToUpgrade.includes(websiteId), |
| 2269 |
'pTransSlugToUpgrade': websitesTransSlugsToUpgrade[websiteId], |
| 2270 |
}; |
| 2271 |
updatesoverview_upgrade_int(params); |
| 2272 |
}; |
| 2273 |
|
| 2274 |
let updatesoverview_upgrade_int = function (params) { |
| 2275 |
let new_params = { |
| 2276 |
'pWebsiteId': params['websiteId'], |
| 2277 |
'pThemeSlugToUpgrade': params['pThemeSlugToUpgrade'], |
| 2278 |
'pPluginSlugToUpgrade': params['pPluginSlugToUpgrade'], |
| 2279 |
'pWordpressUpgrade': params['pWordpressUpgrade'], |
| 2280 |
'pThemeDone': params['pThemeSlugToUpgrade'] == undefined, |
| 2281 |
'pPluginDone': params['pPluginSlugToUpgrade'] == undefined, |
| 2282 |
'pUpgradeDone': !params['pWordpressUpgrade'], |
| 2283 |
'pErrorMessage': undefined, |
| 2284 |
'pTransSlugToUpgrade': params['pTransSlugToUpgrade'], |
| 2285 |
'pTransDone': params['pTransSlugToUpgrade'] == undefined |
| 2286 |
}; |
| 2287 |
updatesoverview_upgrade_int_flow(new_params); |
| 2288 |
return false; |
| 2289 |
}; |
| 2290 |
|
| 2291 |
let updatesoverview_upgrade_int_loop_flow = function (params) { |
| 2292 |
updatesoverview_upgrade_int_flow(params); |
| 2293 |
return false; |
| 2294 |
}; |
| 2295 |
|
| 2296 |
let updatesoverview_upgrade_all_update_done = function () { |
| 2297 |
mainwpVars.currentThreads--; |
| 2298 |
if (!mainwpVars.bulkTaskRunning) |
| 2299 |
return; |
| 2300 |
mainwpVars.websitesDone++; |
| 2301 |
|
| 2302 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 2303 |
|
| 2304 |
if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { |
| 2305 |
mainwpVars.bulkTaskRunning = false; |
| 2306 |
if (!mainwpVars?.errorCount) { |
| 2307 |
setTimeout(function () { |
| 2308 |
// close and refresh page |
| 2309 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 2310 |
}, 3000); |
| 2311 |
} else { |
| 2312 |
mainwpPopup('#mainwp-sync-sites-modal').updateStatusLabel(MainWP.I18n.t('processed')); |
| 2313 |
} |
| 2314 |
return; |
| 2315 |
} |
| 2316 |
|
| 2317 |
updatesoverview_upgrade_all_loop_next(); |
| 2318 |
}; |
| 2319 |
|
| 2320 |
/* eslint-disable complexity */ |
| 2321 |
let updatesoverview_upgrade_int_flow = function (params) { // NOSONAR - complex. |
| 2322 |
mainwpVars.lastUpdateResultBySite = mainwpVars.lastUpdateResultBySite || {}; |
| 2323 |
let pWebsiteId = params['pWebsiteId']; |
| 2324 |
let pThemeSlugToUpgrade = params['pThemeSlugToUpgrade']; |
| 2325 |
let pPluginSlugToUpgrade = params['pPluginSlugToUpgrade']; |
| 2326 |
let pWordpressUpgrade = params['pWordpressUpgrade']; |
| 2327 |
let pThemeDone = params['pThemeDone']; |
| 2328 |
let pPluginDone = params['pPluginDone']; |
| 2329 |
let pUpgradeDone = params['pUpgradeDone']; |
| 2330 |
let pErrorMessage = params['pErrorMessage']; |
| 2331 |
let pTransSlugToUpgrade = params['pTransSlugToUpgrade']; |
| 2332 |
let pTransDone = params['pTransDone']; |
| 2333 |
let bulkErrorCode = params['bulkErrorCode']; |
| 2334 |
|
| 2335 |
if (!pThemeDone) { |
| 2336 |
let themeSlugList = globalThis.mainwp_slug_list_to_array(pThemeSlugToUpgrade); |
| 2337 |
|
| 2338 |
const yithSlugList = themeSlugList.filter(slg => slg.startsWith('yith-')); |
| 2339 |
let currentThemeSlug = ''; |
| 2340 |
let remainingThemeSlugs = ''; |
| 2341 |
|
| 2342 |
if (yithSlugList.length > 0) { |
| 2343 |
currentThemeSlug = themeSlugList.shift(); |
| 2344 |
remainingThemeSlugs = themeSlugList.join(','); |
| 2345 |
} else { |
| 2346 |
currentThemeSlug = pThemeSlugToUpgrade; |
| 2347 |
remainingThemeSlugs = ''; |
| 2348 |
} |
| 2349 |
|
| 2350 |
let data = mainwp_secure_data({ |
| 2351 |
action: 'mainwp_upgradeplugintheme', |
| 2352 |
websiteId: pWebsiteId, |
| 2353 |
type: 'theme', |
| 2354 |
slug: currentThemeSlug, |
| 2355 |
bulkUpdate: mainwpVars.websitesTotal > 1 ? 1 : 0 |
| 2356 |
}); |
| 2357 |
|
| 2358 |
jQuery.ajax({ |
| 2359 |
type: "POST", |
| 2360 |
url: ajaxurl, |
| 2361 |
data: data, |
| 2362 |
success: function (pWebsiteId, pSlug, pPluginSlugToUpgrade, pWordpressUpgrade, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { // NOSONAR - compatible. |
| 2363 |
return function (response) { // NOSONAR - complex ok. |
| 2364 |
let slugParts = pSlug.split(','); |
| 2365 |
if (response?.error?.errorCode == 'SUSPENDED_SITE') { |
| 2366 |
let msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '"><i class="pause yellow icon"></i></span>'; |
| 2367 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, false, msgUI); |
| 2368 |
pPluginDone = true; |
| 2369 |
pUpgradeDone = true; |
| 2370 |
pTransDone = true; |
| 2371 |
pThemeDone = true; |
| 2372 |
mainwpVars.errorCount++; |
| 2373 |
} else { |
| 2374 |
for (let sid of slugParts) { |
| 2375 |
let result; |
| 2376 |
let websiteHolder = jQuery('div[theme_slug="' + sid + '"] div[site_id="' + pWebsiteId + '"]'); |
| 2377 |
if (!websiteHolder.exists()) { |
| 2378 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[theme_slug="' + sid + '"]'); |
| 2379 |
} |
| 2380 |
|
| 2381 |
|
| 2382 |
let isError = true; |
| 2383 |
if (response.error) { |
| 2384 |
result = getErrorMessage(response.error); |
| 2385 |
pErrorMessage = result; |
| 2386 |
mainwpVars.errorCount++; |
| 2387 |
} else { |
| 2388 |
let res = response.result; |
| 2389 |
if (mainwp_get_result_entry(res, sid)) { |
| 2390 |
mainwpVars.lastUpdateResultBySite[pWebsiteId] = response.result; |
| 2391 |
websiteHolder.attr('updated', 1); |
| 2392 |
isError = false; |
| 2393 |
} else { |
| 2394 |
result = MainWP.I18n.t('Update failed!'); |
| 2395 |
pErrorMessage = result; |
| 2396 |
} |
| 2397 |
} |
| 2398 |
|
| 2399 |
if (isError) { |
| 2400 |
let res_error = response?.result_error ? response.result_error : ''; |
| 2401 |
if (mainwp_get_result_entry(res_error, sid)) { |
| 2402 |
let _msg = mainwp_get_result_entry(res_error, sid); |
| 2403 |
let roll_error = mainwp_updates_get_rollback_msg(_msg); |
| 2404 |
mainwp_put_actions_errors_msg('updateall', pWebsiteId, (roll_error ? 'roll' : 'default'), roll_error || _msg);// save errors to show later. |
| 2405 |
} |
| 2406 |
} |
| 2407 |
|
| 2408 |
} |
| 2409 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'theme'); |
| 2410 |
} |
| 2411 |
|
| 2412 |
//If all done: continue, else delay 400ms to not stress the server |
| 2413 |
let fnc = function () { |
| 2414 |
let params = { |
| 2415 |
'pWebsiteId': pWebsiteId, |
| 2416 |
'pThemeSlugToUpgrade': remainingThemeSlugs, |
| 2417 |
'pPluginSlugToUpgrade': pPluginSlugToUpgrade, |
| 2418 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2419 |
'pThemeDone': pThemeDone ? true : remainingThemeSlugs === '', |
| 2420 |
'pPluginDone': pPluginDone, |
| 2421 |
'pUpgradeDone': pUpgradeDone, |
| 2422 |
'pErrorMessage': pErrorMessage, |
| 2423 |
'pTransSlugToUpgrade': pTransSlugToUpgrade, |
| 2424 |
'pTransDone': pTransDone, |
| 2425 |
'bulkErrorCode': bulkErrorCode |
| 2426 |
}; |
| 2427 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2428 |
}; |
| 2429 |
|
| 2430 |
if (pPluginDone && pUpgradeDone && pTransDone) |
| 2431 |
fnc(); |
| 2432 |
else |
| 2433 |
setTimeout(fnc, 400); |
| 2434 |
} |
| 2435 |
}(pWebsiteId, currentThemeSlug, pPluginSlugToUpgrade, pWordpressUpgrade, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone), |
| 2436 |
tryCount: 0, |
| 2437 |
retryLimit: 3, |
| 2438 |
endError: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pPluginDone, pUpgradeDone, pTransSlugToUpgrade, pTransDone) { |
| 2439 |
return function () { |
| 2440 |
let remainingThemeSlugs = globalThis.mainwp_slug_list_to_array(pThemeSlugToUpgrade); |
| 2441 |
|
| 2442 |
const yithSlugList = remainingThemeSlugs.filter(slg => slg.startsWith('yith-')); |
| 2443 |
|
| 2444 |
let pThemeDone = true; |
| 2445 |
|
| 2446 |
if (yithSlugList.length > 0) { |
| 2447 |
remainingThemeSlugs.shift(); |
| 2448 |
remainingThemeSlugs = remainingThemeSlugs.join(','); |
| 2449 |
pThemeDone = remainingThemeSlugs === ''; |
| 2450 |
} else { |
| 2451 |
remainingThemeSlugs = pThemeSlugToUpgrade; |
| 2452 |
} |
| 2453 |
|
| 2454 |
|
| 2455 |
let params = { |
| 2456 |
'pWebsiteId': pWebsiteId, |
| 2457 |
'pThemeSlugToUpgrade': remainingThemeSlugs, |
| 2458 |
'pPluginSlugToUpgrade': pPluginSlugToUpgrade, |
| 2459 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2460 |
'pThemeDone': pThemeDone, |
| 2461 |
'pPluginDone': pPluginDone, |
| 2462 |
'pUpgradeDone': pUpgradeDone, |
| 2463 |
'pErrorMessage': 'Error processing request', |
| 2464 |
'pTransSlugToUpgrade': pTransSlugToUpgrade, |
| 2465 |
'pTransDone': pTransDone |
| 2466 |
}; |
| 2467 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2468 |
} |
| 2469 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pPluginDone, pUpgradeDone, pTransSlugToUpgrade, pTransDone), |
| 2470 |
error: function (xhr) { |
| 2471 |
this.tryCount++; |
| 2472 |
if (this.tryCount >= this.retryLimit) { |
| 2473 |
mainwpVars.errorCount++; |
| 2474 |
this.endError(); |
| 2475 |
return; |
| 2476 |
} |
| 2477 |
let pXhr = xhr; |
| 2478 |
setTimeout(() => { |
| 2479 |
if (pXhr.status == 404) { |
| 2480 |
//handle error |
| 2481 |
jQuery.ajax(this); |
| 2482 |
} else if (pXhr.status == 500) { |
| 2483 |
//handle error |
| 2484 |
} else { |
| 2485 |
//handle error |
| 2486 |
} |
| 2487 |
}, 1000); |
| 2488 |
}, |
| 2489 |
dataType: 'json' |
| 2490 |
}); |
| 2491 |
} else if (!pPluginDone) { |
| 2492 |
let pluginSlugList = globalThis.mainwp_slug_list_to_array(pPluginSlugToUpgrade); |
| 2493 |
|
| 2494 |
const yithSlugList = pluginSlugList.filter(slg => slg.startsWith('yith-')); |
| 2495 |
let currentPluginSlug = ''; |
| 2496 |
let remainingPluginSlugs = ''; |
| 2497 |
|
| 2498 |
if (yithSlugList.length > 0) { |
| 2499 |
currentPluginSlug = pluginSlugList.shift(); |
| 2500 |
remainingPluginSlugs = pluginSlugList.join(','); |
| 2501 |
} else { |
| 2502 |
currentPluginSlug = pPluginSlugToUpgrade; |
| 2503 |
remainingPluginSlugs = ''; |
| 2504 |
} |
| 2505 |
|
| 2506 |
let data = mainwp_secure_data({ |
| 2507 |
action: 'mainwp_upgradeplugintheme', |
| 2508 |
websiteId: pWebsiteId, |
| 2509 |
type: 'plugin', |
| 2510 |
slug: currentPluginSlug, |
| 2511 |
bulkUpdate: 1 |
| 2512 |
}); |
| 2513 |
|
| 2514 |
jQuery.ajax({ |
| 2515 |
type: "POST", |
| 2516 |
url: ajaxurl, |
| 2517 |
data: data, |
| 2518 |
success: function (pWebsiteId, pThemeSlugToUpgrade, pSlug, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { // NOSONAR - compatible. |
| 2519 |
return function (response) { // NOSONAR - complex ok. |
| 2520 |
bulkErrorCode = response?.error?.errorCode ?? ''; |
| 2521 |
if (bulkErrorCode == 'SUSPENDED_SITE') { |
| 2522 |
let msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '"><i class="pause yellow icon"></i></span>'; |
| 2523 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, false, msgUI); |
| 2524 |
|
| 2525 |
pThemeDone = true; |
| 2526 |
pUpgradeDone = true; |
| 2527 |
pTransDone = true; |
| 2528 |
pPluginDone = true; |
| 2529 |
|
| 2530 |
mainwpVars.errorCount++; |
| 2531 |
|
| 2532 |
} else { |
| 2533 |
let slugParts = []; |
| 2534 |
if (pSlug.includes(',')) { |
| 2535 |
slugParts = pSlug.split(','); |
| 2536 |
} else { |
| 2537 |
slugParts = [pSlug]; |
| 2538 |
} |
| 2539 |
for (let sid of slugParts) { |
| 2540 |
let result; |
| 2541 |
let websiteHolder = jQuery('div[plugin_slug="' + sid + '"] div[site_id="' + pWebsiteId + '"]'); |
| 2542 |
if (!websiteHolder.exists()) { |
| 2543 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[plugin_slug="' + sid + '"]'); |
| 2544 |
} |
| 2545 |
if (response.error) { |
| 2546 |
result = getErrorMessage(response.error); |
| 2547 |
pErrorMessage = result; |
| 2548 |
mainwpVars.errorCount++; |
| 2549 |
} |
| 2550 |
else { |
| 2551 |
let res = response.result; // result is an object |
| 2552 |
let res_error = response.result_error; |
| 2553 |
if (mainwp_get_result_entry(res, sid)) { |
| 2554 |
mainwpVars.lastUpdateResultBySite[pWebsiteId] = response.result; |
| 2555 |
websiteHolder.attr('updated', 1); |
| 2556 |
} else if (mainwp_get_result_entry(res_error, sid)) { |
| 2557 |
pErrorMessage = mainwp_get_result_entry(res_error, sid); |
| 2558 |
let roll_error = mainwp_updates_get_rollback_msg(pErrorMessage); |
| 2559 |
mainwp_put_actions_errors_msg('updateall', pWebsiteId, roll_error ? 'roll' : 'default', roll_error || pErrorMessage);// save errors to show later. |
| 2560 |
} else { |
| 2561 |
result = MainWP.I18n.t('Update failed!'); |
| 2562 |
pErrorMessage = result; |
| 2563 |
} |
| 2564 |
} |
| 2565 |
} |
| 2566 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'plugin'); |
| 2567 |
} |
| 2568 |
|
| 2569 |
//If all done: continue, else delay 400ms to not stress the server |
| 2570 |
let fnc = function () { |
| 2571 |
let params = { |
| 2572 |
'pWebsiteId': pWebsiteId, |
| 2573 |
'pThemeSlugToUpgrade': pThemeSlugToUpgrade, |
| 2574 |
'pPluginSlugToUpgrade': remainingPluginSlugs, |
| 2575 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2576 |
'pThemeDone': pThemeDone, |
| 2577 |
'pPluginDone': pPluginDone ? true : remainingPluginSlugs === '', |
| 2578 |
'pUpgradeDone': pUpgradeDone, |
| 2579 |
'pErrorMessage': pErrorMessage, |
| 2580 |
'pTransSlugToUpgrade': pTransSlugToUpgrade, |
| 2581 |
'pTransDone': pTransDone, |
| 2582 |
'bulkErrorCode': bulkErrorCode |
| 2583 |
}; |
| 2584 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2585 |
}; |
| 2586 |
|
| 2587 |
if (pThemeDone && pUpgradeDone && pTransDone) |
| 2588 |
fnc(); |
| 2589 |
else |
| 2590 |
setTimeout(fnc, 400); |
| 2591 |
} |
| 2592 |
}(pWebsiteId, pThemeSlugToUpgrade, currentPluginSlug, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone), |
| 2593 |
tryCount: 0, |
| 2594 |
retryLimit: 3, |
| 2595 |
endError: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pTransSlugToUpgrade, pTransDone) { |
| 2596 |
return function () { |
| 2597 |
let remainingPluginSlugs = globalThis.mainwp_slug_list_to_array(pPluginSlugToUpgrade); |
| 2598 |
const yithSlugList = remainingPluginSlugs.filter(slg => slg.startsWith('yith-')); |
| 2599 |
|
| 2600 |
let pPluginDone = true; |
| 2601 |
|
| 2602 |
if (yithSlugList.length > 0) { |
| 2603 |
remainingPluginSlugs.shift(); |
| 2604 |
remainingPluginSlugs = remainingPluginSlugs.join(','); |
| 2605 |
pPluginDone = remainingPluginSlugs === ''; |
| 2606 |
} else { |
| 2607 |
remainingPluginSlugs = pPluginSlugToUpgrade; |
| 2608 |
} |
| 2609 |
|
| 2610 |
let params = { |
| 2611 |
'pWebsiteId': pWebsiteId, |
| 2612 |
'pThemeSlugToUpgrade': pThemeSlugToUpgrade, |
| 2613 |
'pPluginSlugToUpgrade': remainingPluginSlugs, |
| 2614 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2615 |
'pThemeDone': pThemeDone, |
| 2616 |
'pPluginDone': pPluginDone, |
| 2617 |
'pUpgradeDone': pUpgradeDone, |
| 2618 |
'pErrorMessage': 'Error processing request', |
| 2619 |
'pTransSlugToUpgrade': pTransSlugToUpgrade, |
| 2620 |
'pTransDone': pTransDone |
| 2621 |
}; |
| 2622 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2623 |
} |
| 2624 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pTransSlugToUpgrade, pTransDone), |
| 2625 |
error: function (xhr) { |
| 2626 |
this.tryCount++; |
| 2627 |
if (this.tryCount >= this.retryLimit) { |
| 2628 |
mainwpVars.errorCount++; |
| 2629 |
this.endError(); |
| 2630 |
return; |
| 2631 |
} |
| 2632 |
setTimeout(function (pRqst, pXhr) { |
| 2633 |
return function () { |
| 2634 |
if (pXhr.status == 404) { |
| 2635 |
//handle error |
| 2636 |
jQuery.ajax(pRqst); |
| 2637 |
} else if (pXhr.status == 500) { |
| 2638 |
//handle error |
| 2639 |
} else { |
| 2640 |
//handle error |
| 2641 |
} |
| 2642 |
} |
| 2643 |
}(this, xhr), 1000); |
| 2644 |
}, |
| 2645 |
dataType: 'json' |
| 2646 |
}); |
| 2647 |
} else if (!pUpgradeDone) { |
| 2648 |
let data = mainwp_secure_data({ |
| 2649 |
action: 'mainwp_upgradewp', |
| 2650 |
id: pWebsiteId |
| 2651 |
}); |
| 2652 |
|
| 2653 |
jQuery.ajax({ |
| 2654 |
type: "POST", |
| 2655 |
url: ajaxurl, |
| 2656 |
data: data, |
| 2657 |
success: function (WebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { // NOSONAR - compatible. |
| 2658 |
return function (response) { |
| 2659 |
let bulkErrorCode = response?.error?.errorCode ?? ''; |
| 2660 |
if (bulkErrorCode == 'SUSPENDED_SITE') { |
| 2661 |
let msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '"><i class="pause yellow icon"></i></span>'; |
| 2662 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, false, msgUI); |
| 2663 |
|
| 2664 |
pThemeDone = true; |
| 2665 |
pPluginDone = true; |
| 2666 |
pTransDone = true; |
| 2667 |
|
| 2668 |
mainwpVars.errorCount++; |
| 2669 |
|
| 2670 |
} else { |
| 2671 |
let result; |
| 2672 |
let websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"]'); |
| 2673 |
if (response.error) { |
| 2674 |
result = getErrorMessage(response.error); |
| 2675 |
pErrorMessage = result; |
| 2676 |
} else { |
| 2677 |
mainwpVars.lastUpdateResultBySite[pWebsiteId] = response.result; |
| 2678 |
websiteHolder.attr('updated', 1); |
| 2679 |
} |
| 2680 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'wordpress'); |
| 2681 |
|
| 2682 |
} |
| 2683 |
|
| 2684 |
//If all done: continue, else delay 400ms to not stress the server |
| 2685 |
let fnc = function () { |
| 2686 |
let params = { |
| 2687 |
'pWebsiteId': pWebsiteId, |
| 2688 |
'pThemeSlugToUpgrade': pThemeSlugToUpgrade, |
| 2689 |
'pPluginSlugToUpgrade': pPluginSlugToUpgrade, |
| 2690 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2691 |
'pThemeDone': pThemeDone, |
| 2692 |
'pPluginDone': pPluginDone, |
| 2693 |
'pUpgradeDone': true, |
| 2694 |
'pErrorMessage': pErrorMessage, |
| 2695 |
'pTransSlugToUpgrade': pTransSlugToUpgrade, |
| 2696 |
'pTransDone': pTransDone, |
| 2697 |
'bulkErrorCode': bulkErrorCode |
| 2698 |
}; |
| 2699 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2700 |
}; |
| 2701 |
|
| 2702 |
if (pThemeDone && pPluginDone && pTransDone) |
| 2703 |
fnc(); |
| 2704 |
else |
| 2705 |
setTimeout(fnc, 400); |
| 2706 |
} |
| 2707 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pErrorMessage, pTransSlugToUpgrade, pTransDone), |
| 2708 |
tryCount: 0, |
| 2709 |
retryLimit: 3, |
| 2710 |
endError: function (WebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade) { |
| 2711 |
return function () { |
| 2712 |
let params = { |
| 2713 |
'pWebsiteId': WebsiteId, |
| 2714 |
'pThemeSlugToUpgrade': pThemeSlugToUpgrade, |
| 2715 |
'pPluginSlugToUpgrade': pPluginSlugToUpgrade, |
| 2716 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2717 |
'pThemeDone': true, |
| 2718 |
'pPluginDone': true, |
| 2719 |
'pUpgradeDone': true, |
| 2720 |
'pErrorMessage': 'Error processing request', |
| 2721 |
'pTransSlugToUpgrade': pTransSlugToUpgrade, |
| 2722 |
'pTransDone': true |
| 2723 |
}; |
| 2724 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2725 |
} |
| 2726 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade), |
| 2727 |
error: function (xhr) { |
| 2728 |
this.tryCount++; |
| 2729 |
if (this.tryCount >= this.retryLimit) { |
| 2730 |
this.endError(); |
| 2731 |
return; |
| 2732 |
} |
| 2733 |
|
| 2734 |
setTimeout(function (pRqst, pXhr) { |
| 2735 |
return function () { |
| 2736 |
if (pXhr.status == 404) { |
| 2737 |
//handle error |
| 2738 |
jQuery.ajax(pRqst); |
| 2739 |
} else if (pXhr.status == 500) { |
| 2740 |
//handle error |
| 2741 |
} else { |
| 2742 |
//handle error |
| 2743 |
} |
| 2744 |
} |
| 2745 |
}(this, xhr), 1000); |
| 2746 |
}, |
| 2747 |
dataType: 'json' |
| 2748 |
}); |
| 2749 |
} else if (!pTransDone) { // NOSONAR - condition ok. |
| 2750 |
let transSlugList = globalThis.mainwp_slug_list_to_array(pTransSlugToUpgrade); |
| 2751 |
|
| 2752 |
const yithSlugList = transSlugList.filter(slg => slg.startsWith('yith-')); |
| 2753 |
|
| 2754 |
let currentTransSlug = ''; |
| 2755 |
let remainingTransSlugs = ''; |
| 2756 |
|
| 2757 |
if (yithSlugList.length > 0) { |
| 2758 |
currentTransSlug = transSlugList.shift(); |
| 2759 |
remainingTransSlugs = transSlugList.join(','); |
| 2760 |
} else { |
| 2761 |
currentTransSlug = pTransSlugToUpgrade; |
| 2762 |
remainingTransSlugs = ''; |
| 2763 |
} |
| 2764 |
|
| 2765 |
let data = mainwp_secure_data({ |
| 2766 |
action: 'mainwp_upgradeplugintheme', |
| 2767 |
websiteId: pWebsiteId, |
| 2768 |
type: 'translation', |
| 2769 |
slug: currentTransSlug, |
| 2770 |
bulkUpdate: 1 |
| 2771 |
}); |
| 2772 |
|
| 2773 |
jQuery.ajax({ |
| 2774 |
type: "POST", |
| 2775 |
url: ajaxurl, |
| 2776 |
data: data, |
| 2777 |
success: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, pSlug) { // NOSONAR - compatible. |
| 2778 |
return function (response) { // NOSONAR -complex. |
| 2779 |
let bulkErrorCode = response?.error?.errorCode ?? ''; |
| 2780 |
if (bulkErrorCode == 'SUSPENDED_SITE') { |
| 2781 |
let msgUI = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '"><i class="pause yellow icon"></i></span>'; |
| 2782 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, false, msgUI); |
| 2783 |
|
| 2784 |
pThemeDone = true; |
| 2785 |
pPluginDone = true; |
| 2786 |
pUpgradeDone = true; |
| 2787 |
pTransDone = true; |
| 2788 |
|
| 2789 |
mainwpVars.errorCount++; |
| 2790 |
|
| 2791 |
} else { |
| 2792 |
let slugParts = []; |
| 2793 |
if (pSlug.includes(',')) { |
| 2794 |
slugParts = pSlug.split(','); |
| 2795 |
} else { |
| 2796 |
slugParts = [pSlug]; |
| 2797 |
} |
| 2798 |
for (let sid of slugParts) { |
| 2799 |
let result; |
| 2800 |
let websiteHolder = jQuery('div[translation_slug="' + sid + '"] div[site_id="' + pWebsiteId + '"]'); |
| 2801 |
if (!websiteHolder.exists()) { |
| 2802 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[translation_slug="' + sid + '"]'); |
| 2803 |
} |
| 2804 |
if (response.error) { |
| 2805 |
result = getErrorMessage(response.error); |
| 2806 |
pErrorMessage = result; |
| 2807 |
mainwpVars.errorCount++; |
| 2808 |
} else { |
| 2809 |
let res = response.result; |
| 2810 |
if (mainwp_get_result_entry(res, sid)) { |
| 2811 |
mainwpVars.lastUpdateResultBySite[pWebsiteId] = response.result; |
| 2812 |
websiteHolder.attr('updated', 1); |
| 2813 |
} else { |
| 2814 |
result = MainWP.I18n.t('Update failed!'); |
| 2815 |
pErrorMessage = result; |
| 2816 |
} |
| 2817 |
} |
| 2818 |
} |
| 2819 |
|
| 2820 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'translation'); |
| 2821 |
} |
| 2822 |
//If all done: continue, else delay 400ms to not stress the server |
| 2823 |
let fnc = function () { |
| 2824 |
let params = { |
| 2825 |
'pWebsiteId': pWebsiteId, |
| 2826 |
'pThemeSlugToUpgrade': pThemeSlugToUpgrade, |
| 2827 |
'pPluginSlugToUpgrade': pPluginSlugToUpgrade, |
| 2828 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2829 |
'pThemeDone': pThemeDone, |
| 2830 |
'pPluginDone': pPluginDone, |
| 2831 |
'pUpgradeDone': pUpgradeDone, |
| 2832 |
'pErrorMessage': pErrorMessage, |
| 2833 |
'pTransSlugToUpgrade': remainingTransSlugs, |
| 2834 |
'pTransDone': pTransDone ? true : remainingTransSlugs === '', |
| 2835 |
'bulkErrorCode': bulkErrorCode |
| 2836 |
}; |
| 2837 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2838 |
}; |
| 2839 |
|
| 2840 |
if (pThemeDone && pUpgradeDone && pPluginDone) |
| 2841 |
fnc(); |
| 2842 |
else |
| 2843 |
setTimeout(fnc, 400); |
| 2844 |
} |
| 2845 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, currentTransSlug), |
| 2846 |
tryCount: 0, |
| 2847 |
retryLimit: 3, |
| 2848 |
endError: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pUpgradeDone, pTransSlugToUpgrade) { |
| 2849 |
return function () { |
| 2850 |
let remainingTransSlugs = globalThis.mainwp_slug_list_to_array(pTransSlugToUpgrade); |
| 2851 |
|
| 2852 |
const yithSlugList = remainingTransSlugs.filter(slg => slg.startsWith('yith-')); |
| 2853 |
|
| 2854 |
let pTransDone = true; |
| 2855 |
|
| 2856 |
if (yithSlugList.length > 0) { |
| 2857 |
remainingTransSlugs.shift(); |
| 2858 |
remainingTransSlugs = remainingTransSlugs.join(','); |
| 2859 |
pTransDone = remainingTransSlugs === ''; |
| 2860 |
} else { |
| 2861 |
remainingTransSlugs = pTransSlugToUpgrade; |
| 2862 |
} |
| 2863 |
|
| 2864 |
let params = { |
| 2865 |
'pWebsiteId': pWebsiteId, |
| 2866 |
'pThemeSlugToUpgrade': pThemeSlugToUpgrade, |
| 2867 |
'pPluginSlugToUpgrade': pPluginSlugToUpgrade, |
| 2868 |
'pWordpressUpgrade': pWordpressUpgrade, |
| 2869 |
'pThemeDone': pThemeDone, |
| 2870 |
'pPluginDone': pPluginDone, |
| 2871 |
'pUpgradeDone': pUpgradeDone, |
| 2872 |
'pErrorMessage': 'Error processing request', |
| 2873 |
'pTransSlugToUpgrade': remainingTransSlugs, |
| 2874 |
'pTransDone': pTransDone |
| 2875 |
}; |
| 2876 |
updatesoverview_upgrade_int_loop_flow(params); |
| 2877 |
} |
| 2878 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pUpgradeDone, pTransSlugToUpgrade), |
| 2879 |
error: function (xhr) { |
| 2880 |
this.tryCount++; |
| 2881 |
if (this.tryCount >= this.retryLimit) { |
| 2882 |
this.endError(); |
| 2883 |
return; |
| 2884 |
} |
| 2885 |
setTimeout(function (pRqst, pXhr) { |
| 2886 |
return function () { |
| 2887 |
if (pXhr.status == 404) { |
| 2888 |
//handle error |
| 2889 |
jQuery.ajax(pRqst); |
| 2890 |
} else if (pXhr.status == 500) { |
| 2891 |
//handle error |
| 2892 |
} else { |
| 2893 |
//handle error |
| 2894 |
} |
| 2895 |
} |
| 2896 |
}(this, xhr), 1000); |
| 2897 |
}, |
| 2898 |
dataType: 'json' |
| 2899 |
}); |
| 2900 |
} else { |
| 2901 |
if (bulkErrorCode === 'SUSPENDED_SITE') { |
| 2902 |
let _icon = '<i class="pause yellow icon"></i>'; |
| 2903 |
let _error = MainWP.I18n.t('Suspended site.'); |
| 2904 |
updatesoverview_upgrade_all_update_site_status(pWebsiteId, '<span class="mainwp-html-popup" data-position="left center" data-html="">' + _icon + '</span>'); |
| 2905 |
mainwp_init_html_popup('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"] .mainwp-html-popup', _error); |
| 2906 |
} else if ((pErrorMessage != undefined) && (pErrorMessage != '')) { |
| 2907 |
mainwpVars.errorCount++; |
| 2908 |
|
| 2909 |
let rollErrors = mainwp_get_actions_errors_msg('updateall', pWebsiteId, 'roll'); |
| 2910 |
let otherErrors = mainwp_get_actions_errors_msg('updateall', pWebsiteId, 'default'); |
| 2911 |
|
| 2912 |
let _icon = '<i class="red times icon"></i>'; |
| 2913 |
let _error = ''; |
| 2914 |
if (rollErrors) { |
| 2915 |
_icon = mainwpParams.roll_ui_icon; |
| 2916 |
_error = rollErrors + otherErrors; |
| 2917 |
} else { |
| 2918 |
_error = otherErrors |
| 2919 |
} |
| 2920 |
|
| 2921 |
if (_error == '') { |
| 2922 |
_error = MainWP.I18n.t('Update failed. Please try again.'); |
| 2923 |
} |
| 2924 |
|
| 2925 |
updatesoverview_upgrade_all_update_site_status(pWebsiteId, '<span class="mainwp-html-popup" data-position="left center" data-html="">' + _icon + '</span>'); |
| 2926 |
mainwp_init_html_popup('.updatesoverview-upgrade-status-wp[siteid="' + pWebsiteId + '"] .mainwp-html-popup', _error); |
| 2927 |
} else { |
| 2928 |
let lastResult = mainwpVars.lastUpdateResultBySite ? mainwpVars.lastUpdateResultBySite[pWebsiteId] : null; |
| 2929 |
if ( |
| 2930 |
lastResult && |
| 2931 |
typeof mainwp_html_regression !== "undefined" && |
| 2932 |
mainwp_html_regression.use_after_updates === "1" |
| 2933 |
) { |
| 2934 |
let success_icon = '<i class="green check icon"></i>'; |
| 2935 |
let regression_icon_loading = render_html_regression_icon(lastResult, function (regression_final_icon) { |
| 2936 |
updatesoverview_upgrade_all_update_site_status(pWebsiteId, success_icon + ' ' + regression_final_icon); |
| 2937 |
}); |
| 2938 |
updatesoverview_upgrade_all_update_site_status(pWebsiteId, success_icon + ' ' + regression_icon_loading); |
| 2939 |
} else { |
| 2940 |
updatesoverview_upgrade_all_update_site_status(pWebsiteId, '<i class="green check icon"></i>'); |
| 2941 |
} |
| 2942 |
if (mainwpVars.lastUpdateResultBySite) { |
| 2943 |
delete mainwpVars.lastUpdateResultBySite[pWebsiteId]; |
| 2944 |
} |
| 2945 |
} |
| 2946 |
updatesoverview_upgrade_all_update_done(); |
| 2947 |
|
| 2948 |
return false; |
| 2949 |
} |
| 2950 |
}; |
| 2951 |
/* eslint-enable complexity */ |
| 2952 |
|
| 2953 |
let updatesoverview_plugins_dismiss_outdate_detail = function (slug, name, id, obj) { |
| 2954 |
return updatesoverview_dismiss_outdate_plugintheme_by_site('plugin', slug, name, id, obj); |
| 2955 |
}; |
| 2956 |
let updatesoverview_themes_dismiss_outdate_detail = function (slug, name, id, obj) { |
| 2957 |
return updatesoverview_dismiss_outdate_plugintheme_by_site('theme', slug, name, id, obj); |
| 2958 |
}; |
| 2959 |
|
| 2960 |
let updatesoverview_plugins_unignore_abandoned_detail = function (slug, id) { |
| 2961 |
return updatesoverview_unignore_plugintheme_abandoned_by_site('plugin', slug, id); |
| 2962 |
}; |
| 2963 |
let updatesoverview_plugins_unignore_abandoned_detail_all = function () { |
| 2964 |
return updatesoverview_unignore_plugintheme_abandoned_by_site_all('plugin'); |
| 2965 |
}; |
| 2966 |
let updatesoverview_themes_unignore_abandoned_detail = function (slug, id) { |
| 2967 |
return updatesoverview_unignore_plugintheme_abandoned_by_site('theme', slug, id); |
| 2968 |
}; |
| 2969 |
let updatesoverview_themes_unignore_abandoned_detail_all = function () { |
| 2970 |
return updatesoverview_unignore_plugintheme_abandoned_by_site_all('theme'); |
| 2971 |
}; |
| 2972 |
|
| 2973 |
let updatesoverview_dismiss_outdate_plugintheme_by_site = function (what, slug, name, id, pObj) { |
| 2974 |
let data = mainwp_secure_data({ |
| 2975 |
action: 'mainwp_dismissoutdateplugintheme', |
| 2976 |
type: what, |
| 2977 |
id: id, |
| 2978 |
slug: slug, |
| 2979 |
name: name |
| 2980 |
}); |
| 2981 |
let parent = jQuery(pObj).closest('tr'); |
| 2982 |
parent.find('td:last-child').html('<span data-tooltip="Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); |
| 2983 |
jQuery.post(ajaxurl, data, function (response) { |
| 2984 |
if (response.result) { |
| 2985 |
parent.attr('dismissed', '-1'); |
| 2986 |
parent.find('td:last-child').html(MainWP.I18n.t('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>')); |
| 2987 |
|
| 2988 |
} else { |
| 2989 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 2990 |
} |
| 2991 |
}, 'json'); |
| 2992 |
return false; |
| 2993 |
}; |
| 2994 |
|
| 2995 |
// Unignore abandoned Plugin/Theme ignored per site basis |
| 2996 |
let updatesoverview_unignore_plugintheme_abandoned_by_site = function (what, slug, id) { |
| 2997 |
let data = mainwp_secure_data({ |
| 2998 |
action: 'mainwp_unignoreabandonedplugintheme', |
| 2999 |
type: what, |
| 3000 |
id: id, |
| 3001 |
slug: slug |
| 3002 |
}); |
| 3003 |
|
| 3004 |
jQuery.post(ajaxurl, data, function (pWhat, pSlug, pId) { |
| 3005 |
return function (response) { |
| 3006 |
if (response.result) { |
| 3007 |
let siteElement; |
| 3008 |
if (pWhat == 'plugin') { |
| 3009 |
siteElement = jQuery('tr[site-id="' + pId + '"][plugin-slug="' + pSlug + '"]'); |
| 3010 |
} else { |
| 3011 |
siteElement = jQuery('tr[site-id="' + pId + '"][theme-slug="' + pSlug + '"]'); |
| 3012 |
} |
| 3013 |
|
| 3014 |
if (!siteElement.find('div').is(':visible')) { |
| 3015 |
siteElement.remove(); |
| 3016 |
return; |
| 3017 |
} |
| 3018 |
|
| 3019 |
//Check if previous tr is same site.. |
| 3020 |
//Check if next tr is same site.. |
| 3021 |
let siteAfter = siteElement.next(); |
| 3022 |
|
| 3023 |
if (siteAfter.exists() && (siteAfter.attr('site-id') == pId)) { |
| 3024 |
siteAfter.find('div').show(); |
| 3025 |
siteElement.remove(); |
| 3026 |
return; |
| 3027 |
} |
| 3028 |
|
| 3029 |
let parent = siteElement.parent(); |
| 3030 |
|
| 3031 |
siteElement.remove(); |
| 3032 |
|
| 3033 |
if (parent.children('tr').length == 0) { |
| 3034 |
jQuery('#mainwp-unignore-detail-all').addClass('disabled'); |
| 3035 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored abandoned %1s', pWhat) + '</td></tr>'); |
| 3036 |
} |
| 3037 |
} |
| 3038 |
} |
| 3039 |
}(what, slug, id), 'json'); |
| 3040 |
return false; |
| 3041 |
}; |
| 3042 |
|
| 3043 |
// Unignore all per site ignored abandoned Plugins / Themese |
| 3044 |
let updatesoverview_unignore_plugintheme_abandoned_by_site_all = function (what) { |
| 3045 |
let data = mainwp_secure_data({ |
| 3046 |
action: 'mainwp_unignoreabandonedplugintheme', |
| 3047 |
type: what, |
| 3048 |
id: '_ALL_', |
| 3049 |
slug: '_ALL_' |
| 3050 |
}); |
| 3051 |
|
| 3052 |
jQuery.post(ajaxurl, data, function (pWhat) { |
| 3053 |
return function (response) { |
| 3054 |
if (response.result) { |
| 3055 |
let tableElement = jQuery('#ignored-abandoned-' + pWhat + 's-list'); |
| 3056 |
tableElement.find('tr').remove(); |
| 3057 |
tableElement.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored abandoned %1s', pWhat) + '</td></tr>'); |
| 3058 |
jQuery('#mainwp-unignore-detail-all').addClass('disabled'); |
| 3059 |
} |
| 3060 |
} |
| 3061 |
}(what), 'json'); |
| 3062 |
return false; |
| 3063 |
}; |
| 3064 |
|
| 3065 |
let updatesoverview_plugins_abandoned_ignore_all = function (slug, name, pObj) { |
| 3066 |
let parent = jQuery(pObj).closest('tr'); |
| 3067 |
parent.find('td:last-child').html('<span data-tooltip="Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); |
| 3068 |
let data = mainwp_secure_data({ |
| 3069 |
action: 'mainwp_dismissoutdatepluginsthemes', |
| 3070 |
type: 'plugin', |
| 3071 |
slug: slug, |
| 3072 |
name: name |
| 3073 |
}); |
| 3074 |
jQuery.post(ajaxurl, data, function (response) { |
| 3075 |
if (response.result) { |
| 3076 |
parent.find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3077 |
jQuery('.abandoned-plugins-ignore-global[plugin_slug="' + slug + '"]').find('tr td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3078 |
jQuery('.abandoned-plugins-ignore-global[plugin_slug="' + slug + '"]').find('tr[dismissed=0]').attr('dismissed', 1); |
| 3079 |
} else { |
| 3080 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 3081 |
} |
| 3082 |
}, 'json'); |
| 3083 |
return false; |
| 3084 |
}; |
| 3085 |
|
| 3086 |
// Unignore all globally ignored abandoned plugins |
| 3087 |
let updatesoverview_plugins_abandoned_unignore_globally_all = function () { |
| 3088 |
|
| 3089 |
let data = mainwp_secure_data({ |
| 3090 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 3091 |
type: 'plugin', |
| 3092 |
slug: '_ALL_' |
| 3093 |
}); |
| 3094 |
|
| 3095 |
jQuery.post(ajaxurl, data, function (response) { |
| 3096 |
if (response.result) { |
| 3097 |
let tableElement = jQuery('#ignored-globally-abandoned-plugins-list'); |
| 3098 |
tableElement.find('tr').remove(); |
| 3099 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 3100 |
tableElement.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored abandoned plugins.') + '</td></tr>'); |
| 3101 |
} |
| 3102 |
}, 'json'); |
| 3103 |
|
| 3104 |
return false; |
| 3105 |
|
| 3106 |
}; |
| 3107 |
|
| 3108 |
// Unignore globally ignored abandoned plugin |
| 3109 |
let updatesoverview_plugins_abandoned_unignore_globally = function (slug) { |
| 3110 |
|
| 3111 |
let data = mainwp_secure_data({ |
| 3112 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 3113 |
type: 'plugin', |
| 3114 |
slug: slug |
| 3115 |
}); |
| 3116 |
|
| 3117 |
jQuery.post(ajaxurl, data, function (response) { |
| 3118 |
if (response.result) { |
| 3119 |
let ignoreElement = jQuery('#ignored-globally-abandoned-plugins-list tr[plugin-slug="' + slug + '"]'); |
| 3120 |
let parent = ignoreElement.parent(); |
| 3121 |
ignoreElement.remove(); |
| 3122 |
if (parent.children('tr').length == 0) { |
| 3123 |
jQuery('.mainwp-unignore-globally-all').addClass('disabled'); |
| 3124 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored abandoned plugins.') + '</td></tr>'); |
| 3125 |
} |
| 3126 |
} |
| 3127 |
}, 'json'); |
| 3128 |
return false; |
| 3129 |
}; |
| 3130 |
let updatesoverview_themes_abandoned_ignore_all = function (slug, name, pObj) { |
| 3131 |
let parent = jQuery(pObj).closest('tr'); |
| 3132 |
parent.find('td:last-child').html('<span data-tooltip="Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); |
| 3133 |
|
| 3134 |
let data = mainwp_secure_data({ |
| 3135 |
action: 'mainwp_dismissoutdatepluginsthemes', |
| 3136 |
type: 'theme', |
| 3137 |
slug: slug, |
| 3138 |
name: name |
| 3139 |
}); |
| 3140 |
jQuery.post(ajaxurl, data, function (response) { |
| 3141 |
if (response.result) { |
| 3142 |
parent.find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3143 |
jQuery('.abandoned-themes-ignore-global[theme_slug="' + slug + '"]').find('tr td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span> '); |
| 3144 |
jQuery('.abandoned-themes-ignore-global[theme_slug="' + slug + '"]').find('tr[dismissed=0]').attr('dismissed', 1); |
| 3145 |
} else { |
| 3146 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 3147 |
} |
| 3148 |
}, 'json'); |
| 3149 |
return false; |
| 3150 |
}; |
| 3151 |
|
| 3152 |
// Unignore all globablly ignored themes |
| 3153 |
let updatesoverview_themes_abandoned_unignore_globally_all = function () { |
| 3154 |
let data = mainwp_secure_data({ |
| 3155 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 3156 |
type: 'theme', |
| 3157 |
slug: '_ALL_' |
| 3158 |
}); |
| 3159 |
|
| 3160 |
jQuery.post(ajaxurl, data, function (response) { |
| 3161 |
if (response.result) { |
| 3162 |
let tableElement = jQuery('#globally-ignored-themes-list'); |
| 3163 |
tableElement.find('tr').remove(); |
| 3164 |
jQuery('.mainwp-unignore-globally-all').addClass('disabled'); |
| 3165 |
tableElement.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored abandoned themes.') + '</td></tr>'); |
| 3166 |
} |
| 3167 |
}, 'json'); |
| 3168 |
|
| 3169 |
return false; |
| 3170 |
}; |
| 3171 |
|
| 3172 |
// Unignore globally ignored theme |
| 3173 |
let updatesoverview_themes_abandoned_unignore_globally = function (slug) { |
| 3174 |
let data = mainwp_secure_data({ |
| 3175 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 3176 |
type: 'theme', |
| 3177 |
slug: slug |
| 3178 |
}); |
| 3179 |
|
| 3180 |
jQuery.post(ajaxurl, data, function (response) { |
| 3181 |
if (response.result) { |
| 3182 |
let ignoreElement = jQuery('#globally-ignored-themes-list tr[theme-slug="' + slug + '"]'); |
| 3183 |
let parent = ignoreElement.parent(); |
| 3184 |
ignoreElement.remove(); |
| 3185 |
if (parent.children('tr').length == 0) { |
| 3186 |
jQuery('.mainwp-unignore-globally-all').addClass('disabled'); |
| 3187 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored abandoned themes.') + '</td></tr>'); |
| 3188 |
} |
| 3189 |
} |
| 3190 |
}, 'json'); |
| 3191 |
|
| 3192 |
return false; |
| 3193 |
}; |
| 3194 |
|
| 3195 |
let mainwp_siteview_onchange = function (me) { |
| 3196 |
jQuery(me).closest("form").submit(); |
| 3197 |
} |
| 3198 |
|
| 3199 |
jQuery(function () { |
| 3200 |
if (jQuery('#updatesoverview_limit_updates_all').length > 0 && jQuery('#updatesoverview_limit_updates_all').val() > 0) { |
| 3201 |
limitUpdateAll = jQuery('#updatesoverview_limit_updates_all').val(); |
| 3202 |
if (jQuery('.updatesoverview_continue_update_me').length > 0) { |
| 3203 |
continueUpdating = true; |
| 3204 |
jQuery('.updatesoverview_continue_update_me')[0].trigger('click'); |
| 3205 |
} |
| 3206 |
} |
| 3207 |
}); |
| 3208 |
|
| 3209 |
let updatesoverview_recheck_http = function (elem, id) { |
| 3210 |
let data = mainwp_secure_data({ |
| 3211 |
action: 'mainwp_recheck_http', |
| 3212 |
websiteid: id |
| 3213 |
}); |
| 3214 |
jQuery(elem).attr('disabled', 'true'); |
| 3215 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html('<i class="ui active inline loader tiny"></i>'); |
| 3216 |
jQuery.post(ajaxurl, data, function (response) { |
| 3217 |
jQuery(elem).prop("disabled", false); |
| 3218 |
if (response) { |
| 3219 |
let hc = response.httpcode ? response.httpcode : ''; |
| 3220 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html('HTTP ' + hc); |
| 3221 |
if (response.status) { |
| 3222 |
jQuery('#wp_http_response_code_' + id).addClass('http-response-ok'); |
| 3223 |
} else { |
| 3224 |
jQuery('#wp_http_response_code_' + id).removeClass('http-response-ok'); |
| 3225 |
} |
| 3226 |
} else { |
| 3227 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html(MainWP.I18n.t('Undefined error!')); |
| 3228 |
} |
| 3229 |
}, 'json'); |
| 3230 |
return false; |
| 3231 |
}; |
| 3232 |
|
| 3233 |
let updatesoverview_ignore_http_response = function (elem, id) { |
| 3234 |
let data = mainwp_secure_data({ |
| 3235 |
action: 'mainwp_ignore_http_response', |
| 3236 |
websiteid: id |
| 3237 |
}); |
| 3238 |
jQuery(elem).attr('disabled', 'true'); |
| 3239 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html('<i class="ui active inline loader tiny"></i>'); |
| 3240 |
jQuery.post(ajaxurl, data, function (response) { |
| 3241 |
jQuery(elem).prop("disabled", false); |
| 3242 |
if (response?.ok) { |
| 3243 |
jQuery(elem).closest('.mainwp-sub-row').remove(); |
| 3244 |
} |
| 3245 |
}, 'json'); |
| 3246 |
return false; |
| 3247 |
}; |
| 3248 |
|
| 3249 |
let updatesoverview_ignore_plugintheme_by_site = function (what, slug, name, id, pObj, ignore_ver) { |
| 3250 |
let data = mainwp_secure_data({ |
| 3251 |
action: 'mainwp_ignoreplugintheme', |
| 3252 |
type: what, |
| 3253 |
id: id, |
| 3254 |
slug: slug, |
| 3255 |
name: name, |
| 3256 |
ignore_ver: ignore_ver |
| 3257 |
}); |
| 3258 |
|
| 3259 |
jQuery.post(ajaxurl, data, function (response) { |
| 3260 |
let parent = jQuery(pObj).closest('tr'); |
| 3261 |
if (response.result) { |
| 3262 |
jQuery('div[' + what + '_slug="' + slug + '"] div[site_id="' + id + '"]').attr('updated', '-1'); // ok |
| 3263 |
parent.attr('updated', '-1'); |
| 3264 |
parent.find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3265 |
} else { |
| 3266 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 3267 |
} |
| 3268 |
}, 'json'); |
| 3269 |
return false; |
| 3270 |
}; |
| 3271 |
|
| 3272 |
// Unignore Plugin / Themse ignored per site |
| 3273 |
let updatesoverview_unignore_plugintheme_by_site = function (what, slug, id, ver) { |
| 3274 |
let data = mainwp_secure_data({ |
| 3275 |
action: 'mainwp_unignoreplugintheme', |
| 3276 |
type: what, |
| 3277 |
id: id, |
| 3278 |
slug: slug, |
| 3279 |
ignore_ver: ver |
| 3280 |
}); |
| 3281 |
|
| 3282 |
jQuery.post(ajaxurl, data, function (pWhat, pSlug, pId) { |
| 3283 |
return function (response) { |
| 3284 |
if (response.result) { |
| 3285 |
let siteElement; |
| 3286 |
if (pWhat == 'plugin') { |
| 3287 |
siteElement = jQuery('tr[site-id="' + pId + '"][plugin-slug="' + pSlug + '"]'); |
| 3288 |
} else { |
| 3289 |
siteElement = jQuery('tr[site-id="' + pId + '"][theme-slug="' + pSlug + '"]'); |
| 3290 |
} |
| 3291 |
|
| 3292 |
if (!siteElement.find('div').is(':visible')) { |
| 3293 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 3294 |
siteElement.remove(); |
| 3295 |
return; |
| 3296 |
} |
| 3297 |
|
| 3298 |
//Check if previous tr is same site.. |
| 3299 |
//Check if next tr is same site.. |
| 3300 |
let siteAfter = siteElement.next(); |
| 3301 |
if (siteAfter.exists() && (siteAfter.attr('site-id') == pId)) { |
| 3302 |
siteAfter.find('div').show(); |
| 3303 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 3304 |
siteElement.remove(); |
| 3305 |
return; |
| 3306 |
} |
| 3307 |
|
| 3308 |
let parent = siteElement.parent(); |
| 3309 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 3310 |
siteElement.remove(); |
| 3311 |
if (parent.children('tr').length == 0) { |
| 3312 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored %1s', pWhat) + '</td></tr>'); |
| 3313 |
jQuery('.mainwp-unignore-detail-all').addClass('disabled'); |
| 3314 |
} |
| 3315 |
} |
| 3316 |
} |
| 3317 |
}(what, slug, id), 'json'); |
| 3318 |
return false; |
| 3319 |
}; |
| 3320 |
|
| 3321 |
// Unignore all Plugins / Themses ignored per site |
| 3322 |
let updatesoverview_unignore_plugintheme_by_site_all = function (what) { |
| 3323 |
let data = mainwp_secure_data({ |
| 3324 |
action: 'mainwp_unignoreplugintheme', |
| 3325 |
type: what, |
| 3326 |
id: '_ALL_', |
| 3327 |
slug: '_ALL_' |
| 3328 |
}); |
| 3329 |
|
| 3330 |
jQuery.post(ajaxurl, data, function (pWhat) { |
| 3331 |
return function (response) { |
| 3332 |
if (response.result) { |
| 3333 |
let tableElement = jQuery('#ignored-' + pWhat + 's-list'); |
| 3334 |
tableElement.find('tr').remove(); |
| 3335 |
tableElement.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored %1s', pWhat) + '</td></tr>'); |
| 3336 |
jQuery('.mainwp-unignore-detail-all').addClass('disabled'); |
| 3337 |
} |
| 3338 |
} |
| 3339 |
}(what), 'json'); |
| 3340 |
return false; |
| 3341 |
}; |
| 3342 |
|
| 3343 |
/**Plugins part**/ |
| 3344 |
let updatesoverview_plugins_ignore_detail = function (slug, name, id, obj, ignore_ver) { |
| 3345 |
const row = jQuery(obj).closest("tr"); |
| 3346 |
const site_name = jQuery(row).attr("site_name"); |
| 3347 |
let msg = MainWP.I18n.t( |
| 3348 |
"Are you sure you want to ignore %1 plugin updates on %2? The updates will no longer be visible in your MainWP Dashboard.", |
| 3349 |
decodeURIComponent(name), |
| 3350 |
site_name ?? '' |
| 3351 |
); |
| 3352 |
mainwp_confirm( |
| 3353 |
msg, |
| 3354 |
function () { |
| 3355 |
return updatesoverview_ignore_plugintheme_by_site('plugin', slug, name, id, obj, ignore_ver); |
| 3356 |
}, |
| 3357 |
false |
| 3358 |
); |
| 3359 |
return false; |
| 3360 |
}; |
| 3361 |
let updatesoverview_plugins_unignore_detail = function (slug, id, ver) { |
| 3362 |
return updatesoverview_unignore_plugintheme_by_site('plugin', slug, id, ver); |
| 3363 |
}; |
| 3364 |
let updatesoverview_plugins_unignore_detail_all = function () { |
| 3365 |
return updatesoverview_unignore_plugintheme_by_site_all('plugin'); |
| 3366 |
}; |
| 3367 |
let updatesoverview_themes_ignore_detail = function (slug, name, id, obj, ignore_ver) { |
| 3368 |
let msg = MainWP.I18n.t("Are you sure you want to ignore the %1 theme updates? The updates will no longer be visible in your MainWP Dashboard.", name); |
| 3369 |
mainwp_confirm(msg, function () { |
| 3370 |
return updatesoverview_ignore_plugintheme_by_site('theme', slug, name, id, obj, ignore_ver); |
| 3371 |
}, false); |
| 3372 |
return false; |
| 3373 |
}; |
| 3374 |
let updatesoverview_themes_unignore_detail = function (slug, id, ver) { |
| 3375 |
return updatesoverview_unignore_plugintheme_by_site('theme', slug, id, ver); |
| 3376 |
}; |
| 3377 |
let updatesoverview_themes_unignore_detail_all = function () { |
| 3378 |
return updatesoverview_unignore_plugintheme_by_site_all('theme'); |
| 3379 |
}; |
| 3380 |
let updatesoverview_plugins_ignore_all = function (slug, name, obj, ver) { |
| 3381 |
const row = jQuery(obj).closest("tr"); |
| 3382 |
const site_name = jQuery(row).attr("site_name"); |
| 3383 |
let msg = ''; |
| 3384 |
if (site_name === undefined) { |
| 3385 |
msg = MainWP.I18n.t( |
| 3386 |
"Are you sure you want to ignore the %1 plugin updates? The updates will no longer be visible in your MainWP Dashboard.", |
| 3387 |
decodeURIComponent(name) |
| 3388 |
); |
| 3389 |
} else { |
| 3390 |
msg = MainWP.I18n.t( |
| 3391 |
"Are you sure you want to ignore %1 plugin updates on %2 site? The updates will no longer be visible in your MainWP Dashboard.", |
| 3392 |
decodeURIComponent(name), |
| 3393 |
site_name |
| 3394 |
); |
| 3395 |
} |
| 3396 |
mainwp_confirm(msg, function () { |
| 3397 |
let data = mainwp_secure_data({ |
| 3398 |
action: 'mainwp_ignorepluginsthemes', |
| 3399 |
type: 'plugin', |
| 3400 |
slug: slug, |
| 3401 |
name: name, |
| 3402 |
ignore_ver: ver |
| 3403 |
}); |
| 3404 |
let parent = jQuery(obj).closest('tr'); |
| 3405 |
parent.find('td:last-child').html('<span data-tooltip="Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); |
| 3406 |
jQuery.post(ajaxurl, data, function (response) { |
| 3407 |
if (response.result) { |
| 3408 |
if (ver != undefined && ver != '') { // ignore this version. |
| 3409 |
parent.find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3410 |
jQuery('tr[plugin_slug="' + slug + '"][last-version="' + ver + '"]').find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3411 |
jQuery('tr[plugin_slug="' + slug + '"][last-version="' + ver + '"]').attr('updated', '-1'); |
| 3412 |
} else { |
| 3413 |
parent.find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3414 |
jQuery('tr[plugin_slug="' + slug + '"]').find('table tr td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3415 |
jQuery('tr[plugin_slug="' + slug + '"]').find('table tr').attr('updated', '-1'); |
| 3416 |
} |
| 3417 |
} |
| 3418 |
}, 'json'); |
| 3419 |
}, false); |
| 3420 |
return false; |
| 3421 |
}; |
| 3422 |
|
| 3423 |
// Unignore all globally ignored plugins |
| 3424 |
let updatesoverview_plugins_unignore_globally_all = function () { |
| 3425 |
let data = mainwp_secure_data({ |
| 3426 |
action: 'mainwp_unignorepluginsthemes', |
| 3427 |
type: 'plugin', |
| 3428 |
slug: '_ALL_' |
| 3429 |
}); |
| 3430 |
|
| 3431 |
jQuery.post(ajaxurl, data, function (response) { |
| 3432 |
if (response.result) { |
| 3433 |
let tableElement = jQuery('#globally-ignored-plugins-list'); |
| 3434 |
tableElement.find('tr').remove(); |
| 3435 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 3436 |
tableElement.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored plugins.') + '</td></tr>'); |
| 3437 |
} |
| 3438 |
}, 'json'); |
| 3439 |
return false; |
| 3440 |
}; |
| 3441 |
|
| 3442 |
// Unignore globally ignored plugin |
| 3443 |
let updatesoverview_plugins_unignore_globally = function (slug, ver) { |
| 3444 |
let data = mainwp_secure_data({ |
| 3445 |
action: 'mainwp_unignorepluginsthemes', |
| 3446 |
type: 'plugin', |
| 3447 |
slug: slug, |
| 3448 |
ignore_ver: ver |
| 3449 |
}); |
| 3450 |
jQuery.post(ajaxurl, data, function (response) { |
| 3451 |
if (response.result) { |
| 3452 |
let ignoreElement = jQuery('#globally-ignored-plugins-list tr[plugin-slug="' + slug + '"]'); |
| 3453 |
let parent = ignoreElement.parent(); |
| 3454 |
ignoreElement.remove(); |
| 3455 |
if (parent.children('tr').length == 0) { |
| 3456 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 3457 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored plugins.') + '</td></tr>'); |
| 3458 |
} |
| 3459 |
} |
| 3460 |
}, 'json'); |
| 3461 |
return false; |
| 3462 |
}; |
| 3463 |
|
| 3464 |
let updatesoverview_themes_ignore_all = function (slug, name, obj, ver) { |
| 3465 |
let msg = MainWP.I18n.t('Are you sure you want to ignore the %1 theme updates? The updates will no longer be visible in your MainWP Dashboard.', name); |
| 3466 |
mainwp_confirm(msg, function () { |
| 3467 |
|
| 3468 |
let data = mainwp_secure_data({ |
| 3469 |
action: 'mainwp_ignorepluginsthemes', // ignore global or this version global. |
| 3470 |
type: 'theme', |
| 3471 |
slug: slug, |
| 3472 |
name: name, |
| 3473 |
ignore_ver: ver |
| 3474 |
}); |
| 3475 |
let parent = jQuery(obj).closest('tr'); |
| 3476 |
parent.find('td:last-child').html('<span data-tooltip="Please wait..." data-position="left center" data-inverted=""><i class="notched circle loading icon"></i></span>'); |
| 3477 |
jQuery.post(ajaxurl, data, function (response) { |
| 3478 |
if (response.result) { |
| 3479 |
if (ver != undefined && ver != '') { // ignore this version. |
| 3480 |
parent.find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3481 |
jQuery('tr[theme_slug="' + slug + '"][last-version="' + ver + '"]').find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3482 |
jQuery('tr[theme_slug="' + slug + '"][last-version="' + ver + '"]').attr('updated', '-1'); |
| 3483 |
} else { |
| 3484 |
parent.find('td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3485 |
jQuery('tr[theme_slug="' + slug + '"]').find('table tr td:last-child').html('<span data-tooltip="Ignored" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3486 |
jQuery('tr[theme_slug="' + slug + '"]').find('table tr').attr('updated', '-1'); |
| 3487 |
} |
| 3488 |
} |
| 3489 |
}, 'json'); |
| 3490 |
}, false); |
| 3491 |
return false; |
| 3492 |
}; |
| 3493 |
|
| 3494 |
// Unignore all globally ignored themes |
| 3495 |
let updatesoverview_themes_unignore_globally_all = function () { |
| 3496 |
let data = mainwp_secure_data({ |
| 3497 |
action: 'mainwp_unignorepluginsthemes', |
| 3498 |
type: 'theme', |
| 3499 |
slug: '_ALL_' |
| 3500 |
}); |
| 3501 |
|
| 3502 |
jQuery.post(ajaxurl, data, function (response) { |
| 3503 |
if (response.result) { |
| 3504 |
let tableElement = jQuery('#globally-ignored-themes-list'); |
| 3505 |
tableElement.find('tr').remove(); |
| 3506 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 3507 |
tableElement.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored themes.') + '</td></tr>'); |
| 3508 |
} |
| 3509 |
}, 'json'); |
| 3510 |
|
| 3511 |
return false; |
| 3512 |
}; |
| 3513 |
|
| 3514 |
// Unignore globally ignored theme |
| 3515 |
let updatesoverview_themes_unignore_globally = function (slug, ver) { |
| 3516 |
let data = mainwp_secure_data({ |
| 3517 |
action: 'mainwp_unignorepluginsthemes', |
| 3518 |
type: 'theme', |
| 3519 |
slug: slug, |
| 3520 |
ignore_ver: ver |
| 3521 |
}); |
| 3522 |
jQuery.post(ajaxurl, data, function (response) { |
| 3523 |
if (response.result) { |
| 3524 |
let ignoreElement = jQuery('#globally-ignored-themes-list tr[theme-slug="' + slug + '"]'); |
| 3525 |
let parent = ignoreElement.parent(); |
| 3526 |
ignoreElement.remove(); |
| 3527 |
if (parent.children('tr').length == 0) { |
| 3528 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 3529 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored themes.') + '</td></tr>'); |
| 3530 |
} |
| 3531 |
} |
| 3532 |
}, 'json'); |
| 3533 |
return false; |
| 3534 |
}; |
| 3535 |
|
| 3536 |
let manageupdates_ignore_updates = function (what, ignore, slug, name, site_id, ignore_ver, ignored_callback) { |
| 3537 |
let data = mainwp_secure_data({ |
| 3538 |
action: 'mainwp_updates_ignore_upgrades', |
| 3539 |
type: what, |
| 3540 |
ignore: ignore, |
| 3541 |
site_id: site_id, // empty is global ignore. |
| 3542 |
name: name, |
| 3543 |
slug: slug, |
| 3544 |
ignore_ver: ignore_ver |
| 3545 |
}); |
| 3546 |
jQuery.post(ajaxurl, data, function (response) { |
| 3547 |
if (typeof ignored_callback == 'function') { |
| 3548 |
ignored_callback(response); |
| 3549 |
} |
| 3550 |
}, 'json'); |
| 3551 |
return false; |
| 3552 |
}; |
| 3553 |
|
| 3554 |
let updatesoverview_upgrade_ignore = function (site_id, obj, ignore_ver) { |
| 3555 |
let ignored_callback = function () { |
| 3556 |
jQuery(obj).closest('tr').find('td:last-child').html('<span data-tooltip="Ignored this version" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3557 |
}; |
| 3558 |
manageupdates_ignore_updates('wp', 'this_version', 'core', 'WordPress', site_id, ignore_ver, ignored_callback) |
| 3559 |
return false; |
| 3560 |
}; |
| 3561 |
|
| 3562 |
let updatesoverview_upgrade_ignore_this_version_globally = function (ignore_ver) { |
| 3563 |
let ignored_callback = function () { |
| 3564 |
jQuery('tr.mainwp-wordpress-update[last-version="' + ignore_ver + '"]').find('td:last-child').html('<span data-tooltip="Ignored this version globally" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3565 |
jQuery('tr.mainwp-wordpress-update[last-version="' + ignore_ver + '"]').attr('updated', '-1'); |
| 3566 |
}; |
| 3567 |
manageupdates_ignore_updates('wp', 'this_version_global', 'core', 'WordPress', 0, ignore_ver, ignored_callback) |
| 3568 |
return false; |
| 3569 |
}; |
| 3570 |
|
| 3571 |
let updatesoverview_upgrade_ignore_all_version = function (site_id, obj) { |
| 3572 |
let ignored_callback = function () { |
| 3573 |
jQuery(obj).closest('tr').find('td:last-child').html('<span data-tooltip="Ignored this version" data-position="left center" data-inverted=""><i class="check green icon"></i></span>'); |
| 3574 |
}; |
| 3575 |
manageupdates_ignore_updates('wp', 'all_versions', 'core', 'WordPress', site_id, 'all_versions', ignored_callback) |
| 3576 |
return false; |
| 3577 |
}; |
| 3578 |
|
| 3579 |
// Unignore cores per site |
| 3580 |
let updatesoverview_unignore_cores_by_site = function (id, ver) { |
| 3581 |
let data = mainwp_secure_data({ |
| 3582 |
action: 'mainwp_updates_unignore_upgrades', |
| 3583 |
id: id, |
| 3584 |
ignore_ver: ver |
| 3585 |
}); |
| 3586 |
jQuery.post(ajaxurl, data, function (pVer, pId) { |
| 3587 |
return function (response) { |
| 3588 |
if (response.result && 'success' == response.result) { |
| 3589 |
let siteElement = jQuery('tr[site-id="' + pId + '"][ignored-ver="' + pVer + '"]'); |
| 3590 |
|
| 3591 |
if (!siteElement.find('div').is(':visible')) { |
| 3592 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 3593 |
siteElement.remove(); |
| 3594 |
return; |
| 3595 |
} |
| 3596 |
|
| 3597 |
//Check if previous tr is same site.. |
| 3598 |
//Check if next tr is same site.. |
| 3599 |
let siteAfter = siteElement.next(); |
| 3600 |
if (siteAfter.exists() && (siteAfter.attr('site-id') == pId)) { |
| 3601 |
siteAfter.find('div').show(); |
| 3602 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 3603 |
siteElement.remove(); |
| 3604 |
return; |
| 3605 |
} |
| 3606 |
|
| 3607 |
let parent = siteElement.parent(); |
| 3608 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 3609 |
siteElement.remove(); |
| 3610 |
if (parent.children('tr').length == 0) { |
| 3611 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored WordPress') + '</td></tr>'); |
| 3612 |
jQuery('#mainwp-unignore-cores-detail-all').addClass('disabled'); |
| 3613 |
} |
| 3614 |
} |
| 3615 |
} |
| 3616 |
}(ver, id), 'json'); |
| 3617 |
return false; |
| 3618 |
}; |
| 3619 |
|
| 3620 |
// Unignore all Plugins / Themses ignored per site |
| 3621 |
let updatesoverview_unignore_cores_by_site_all = function () { |
| 3622 |
let data = mainwp_secure_data({ |
| 3623 |
action: 'mainwp_updates_unignore_upgrades', |
| 3624 |
id: '_ALL_', |
| 3625 |
}); |
| 3626 |
|
| 3627 |
jQuery.post(ajaxurl, data, function () { |
| 3628 |
return function (response) { |
| 3629 |
if (response.result && 'success' == response.result) { |
| 3630 |
let parent = jQuery('#ignored-cores-list'); |
| 3631 |
parent.find('tr').remove(); |
| 3632 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored WordPress') + '</td></tr>'); |
| 3633 |
jQuery('.mainwp-unignore-detail-all').addClass('disabled'); |
| 3634 |
} |
| 3635 |
} |
| 3636 |
}, 'json'); |
| 3637 |
return false; |
| 3638 |
}; |
| 3639 |
|
| 3640 |
// Unignore globally ignored cores. |
| 3641 |
let updatesoverview_cores_unignore_globally = function (ver) { |
| 3642 |
let data = mainwp_secure_data({ |
| 3643 |
action: 'mainwp_updates_unignore_global_upgrades', |
| 3644 |
ignore_ver: ver |
| 3645 |
}); |
| 3646 |
jQuery.post(ajaxurl, data, function (response) { |
| 3647 |
if (response.result) { |
| 3648 |
let ignoreElement = jQuery('#globally-ignored-cores-list tr[ignored-ver="' + ver + '"]'); |
| 3649 |
let parent = ignoreElement.parent(); |
| 3650 |
ignoreElement.remove(); |
| 3651 |
if (parent.children('tr').length == 0) { |
| 3652 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 3653 |
parent.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored WordPress.') + '</td></tr>'); |
| 3654 |
} |
| 3655 |
} |
| 3656 |
}, 'json'); |
| 3657 |
return false; |
| 3658 |
}; |
| 3659 |
|
| 3660 |
|
| 3661 |
// Unignore all globally ignored cores. |
| 3662 |
let updatesoverview_cores_unignore_globally_all = function () { |
| 3663 |
let data = mainwp_secure_data({ |
| 3664 |
action: 'mainwp_updates_unignore_global_upgrades', |
| 3665 |
slug: '_ALL_' |
| 3666 |
}); |
| 3667 |
|
| 3668 |
jQuery.post(ajaxurl, data, function (response) { |
| 3669 |
if (response.result) { |
| 3670 |
let tableElement = jQuery('#globally-ignored-cores-list'); |
| 3671 |
tableElement.find('tr').remove(); |
| 3672 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 3673 |
tableElement.append('<tr><td colspan="999">' + MainWP.I18n.t('No ignored WordPress.') + '</td></tr>'); |
| 3674 |
} |
| 3675 |
}, 'json'); |
| 3676 |
return false; |
| 3677 |
}; |
| 3678 |
|
| 3679 |
let updatesoverview_upgrade_translation = function (id, slug) { |
| 3680 |
let msg = MainWP.I18n.t('Are you sure you want to update the translation on the selected site?'); |
| 3681 |
mainwp_confirm(msg, function () { |
| 3682 |
return updatesoverview_translations_upgrade_int(slug, id); |
| 3683 |
}, false, 1); |
| 3684 |
}; |
| 3685 |
|
| 3686 |
let updatesoverview_translations_upgrade = function (slug, websiteid) { |
| 3687 |
let msg = MainWP.I18n.t('Are you sure you want to update the translation on the selected site?'); |
| 3688 |
mainwp_confirm(msg, function () { |
| 3689 |
return updatesoverview_translations_upgrade_int(slug, websiteid); |
| 3690 |
}, false, 1); |
| 3691 |
}; |
| 3692 |
|
| 3693 |
let updatesoverview_plugins_upgrade = function (slug, websiteid) { |
| 3694 |
let msg = MainWP.I18n.t('Are you sure you want to update the plugin on the selected site?'); |
| 3695 |
mainwp_confirm(msg, function () { |
| 3696 |
return updatesoverview_plugins_upgrade_int(slug, websiteid); |
| 3697 |
}, false, 1); |
| 3698 |
}; |
| 3699 |
|
| 3700 |
let updatesoverview_themes_upgrade = function (slug, websiteid) { |
| 3701 |
let msg = MainWP.I18n.t('Are you sure you want to update the theme on the selected site?'); |
| 3702 |
mainwp_confirm(msg, function () { |
| 3703 |
return updatesoverview_themes_upgrade_int(slug, websiteid); |
| 3704 |
}, false, 1); |
| 3705 |
}; |
| 3706 |
|
| 3707 |
/** END NEW **/ |
| 3708 |
|
| 3709 |
let updatesoverview_wp_sync = function (websiteid) { |
| 3710 |
let syncIds = []; |
| 3711 |
syncIds.push(websiteid); |
| 3712 |
mainwp_sync_sites_data(syncIds); |
| 3713 |
return false; |
| 3714 |
}; |
| 3715 |
|
| 3716 |
|
| 3717 |
let updatesoverview_group_upgrade_translation = function (id, slug, groupId) { |
| 3718 |
return updatesoverview_upgrade_plugintheme('translation', id, slug, groupId); |
| 3719 |
}; |
| 3720 |
|
| 3721 |
let updatesoverview_upgrade_translation_all = function (id, updatesSelected) { |
| 3722 |
let msg = MainWP.I18n.t('Are you sure you want to update all translations?'); |
| 3723 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3724 |
msg = MainWP.I18n.t('Are you sure you want to update selected translations?'); |
| 3725 |
} |
| 3726 |
mainwp_confirm(msg, function () { |
| 3727 |
return updatesoverview_upgrade_plugintheme_all('translation', id, false, updatesSelected); |
| 3728 |
}, false, 2); |
| 3729 |
return false; |
| 3730 |
}; |
| 3731 |
|
| 3732 |
let updatesoverview_group_upgrade_translation_all = function (id, groupId, updatesSelected) { |
| 3733 |
let msg = MainWP.I18n.t('Are you sure you want to update all translations?'); |
| 3734 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3735 |
msg = MainWP.I18n.t('Are you sure you want to update selected translations?'); |
| 3736 |
} |
| 3737 |
mainwp_confirm(msg, function () { |
| 3738 |
return updatesoverview_group_upgrade_plugintheme_all('translation', id, false, groupId, updatesSelected); |
| 3739 |
}, false, 2); |
| 3740 |
return false; |
| 3741 |
}; |
| 3742 |
|
| 3743 |
let updatesoverview_upgrade_plugin = function (id, slug) { |
| 3744 |
let msg = MainWP.I18n.t('Are you sure you want to update the plugin on the selected site?'); |
| 3745 |
mainwp_confirm(msg, function () { |
| 3746 |
return updatesoverview_upgrade_plugintheme('plugin', id, slug); |
| 3747 |
}, false, 1); |
| 3748 |
}; |
| 3749 |
|
| 3750 |
let updatesoverview_upgrade_plugin_all = function (id, updatesSelected) { |
| 3751 |
let msg = MainWP.I18n.t('Are you sure you want to update all plugins?'); |
| 3752 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3753 |
msg = MainWP.I18n.t('Are you sure you want to update selected plugins?'); |
| 3754 |
} |
| 3755 |
mainwp_confirm(msg, function () { |
| 3756 |
return updatesoverview_upgrade_plugintheme_all('plugin', id, false, updatesSelected); |
| 3757 |
}, false, 2); |
| 3758 |
return false; |
| 3759 |
}; |
| 3760 |
|
| 3761 |
let updatesoverview_group_upgrade_plugin_all = function (id, groupId, updatesSelected) { |
| 3762 |
let msg = MainWP.I18n.t('Are you sure you want to update all plugins?'); |
| 3763 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3764 |
msg = MainWP.I18n.t('Are you sure you want to update selected plugins?'); |
| 3765 |
} |
| 3766 |
mainwp_confirm(msg, function () { |
| 3767 |
return updatesoverview_group_upgrade_plugintheme_all('plugin', id, false, groupId, updatesSelected); |
| 3768 |
}, false, 2); |
| 3769 |
return false; |
| 3770 |
}; |
| 3771 |
|
| 3772 |
let updatesoverview_upgrade_theme = function (id, slug) { |
| 3773 |
let msg = MainWP.I18n.t('Are you sure you want to update the theme on the selected site?'); |
| 3774 |
mainwp_confirm(msg, function () { |
| 3775 |
return updatesoverview_upgrade_plugintheme('theme', id, slug); |
| 3776 |
}, false, 1); |
| 3777 |
}; |
| 3778 |
let updatesoverview_upgrade_theme_all = function (id, updatesSelected) { |
| 3779 |
let msg = MainWP.I18n.t('Are you sure you want to update all themes?'); |
| 3780 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3781 |
msg = MainWP.I18n.t('Are you sure you want to update selected themes?'); |
| 3782 |
} |
| 3783 |
mainwp_confirm(msg, function () { |
| 3784 |
return updatesoverview_upgrade_plugintheme_all('theme', id, false, updatesSelected); |
| 3785 |
}, false, 2); |
| 3786 |
return false; |
| 3787 |
}; |
| 3788 |
|
| 3789 |
let updatesoverview_group_upgrade_theme_all = function (id, groupId, updatesSelected) { |
| 3790 |
let msg = MainWP.I18n.t('Are you sure you want to update all themes?'); |
| 3791 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3792 |
msg = MainWP.I18n.t('Are you sure you want to update selected themes?'); |
| 3793 |
} |
| 3794 |
mainwp_confirm(msg, function () { |
| 3795 |
return updatesoverview_group_upgrade_plugintheme_all('theme', id, false, groupId, updatesSelected); |
| 3796 |
}, false, 2); |
| 3797 |
return false; |
| 3798 |
}; |
| 3799 |
|
| 3800 |
let updatesoverview_upgrade_plugintheme = function (what, id, name, groupId) { |
| 3801 |
updatesoverview_upgrade_plugintheme_list(what, id, [name], false, groupId); |
| 3802 |
return false; |
| 3803 |
}; |
| 3804 |
let updatesoverview_upgrade_plugintheme_all = function (what, id, noCheck, updatesSelected) { |
| 3805 |
|
| 3806 |
// ok: confirmed to do this |
| 3807 |
updatesoverviewContinueAfterBackup = function (pId, pWhat) { |
| 3808 |
return function () { |
| 3809 |
let list = []; |
| 3810 |
let slug_att = pWhat + '_slug'; |
| 3811 |
let slug = ''; |
| 3812 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3813 |
jQuery("#wp_" + pWhat + "_upgrades_" + pId + " tr[updated=0]").each(function () { |
| 3814 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 3815 |
slug = jQuery(this).attr(slug_att); |
| 3816 |
if (slug) { |
| 3817 |
list.push(slug); |
| 3818 |
} |
| 3819 |
} |
| 3820 |
}); |
| 3821 |
if (list.length == 0) { |
| 3822 |
updates_please_select_items_notice(); |
| 3823 |
return false; |
| 3824 |
} |
| 3825 |
} else { |
| 3826 |
jQuery("#wp_" + pWhat + "_upgrades_" + pId + " tr[updated=0]").each(function () { |
| 3827 |
slug = jQuery(this).attr(slug_att); |
| 3828 |
if (slug) { |
| 3829 |
list.push(slug); |
| 3830 |
} |
| 3831 |
|
| 3832 |
}); |
| 3833 |
} |
| 3834 |
let siteName = jQuery("#wp_" + pWhat + "_upgrades_" + pId).attr('site_name'); |
| 3835 |
updatesoverview_upgrade_plugintheme_list_popup(pWhat, pId, siteName, list); |
| 3836 |
} |
| 3837 |
}(id, what); |
| 3838 |
|
| 3839 |
if (noCheck) { |
| 3840 |
updatesoverviewContinueAfterBackup(); |
| 3841 |
return false; |
| 3842 |
} |
| 3843 |
|
| 3844 |
let sitesToUpdate = []; |
| 3845 |
let siteNames = []; |
| 3846 |
|
| 3847 |
sitesToUpdate.push(id); |
| 3848 |
siteNames[id] = jQuery('tbody[site_id="' + id + '"]').attr('site_name'); |
| 3849 |
|
| 3850 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 3851 |
}; |
| 3852 |
|
| 3853 |
let updatesoverview_group_upgrade_plugintheme_all = function (what, id, noCheck, groupId, updatesSelected) { |
| 3854 |
// ok, confirmed to do this |
| 3855 |
updatesoverviewContinueAfterBackup = function (pId, pWhat) { |
| 3856 |
return function () { |
| 3857 |
let list = []; |
| 3858 |
let slug_att = pWhat + '_slug'; |
| 3859 |
jQuery("#wp_" + pWhat + "_upgrades_" + pId + '_group_' + groupId + " tr[updated=0]").each(function () { |
| 3860 |
let slug = jQuery(this).attr(slug_att); |
| 3861 |
if (updatesSelected !== undefined && updatesSelected) { |
| 3862 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked') && slug) { |
| 3863 |
list.push(slug); |
| 3864 |
} |
| 3865 |
if (list.length == 0) { |
| 3866 |
updates_please_select_items_notice(); |
| 3867 |
return false; |
| 3868 |
} |
| 3869 |
} else if (slug) { |
| 3870 |
list.push(slug); |
| 3871 |
} |
| 3872 |
}); |
| 3873 |
|
| 3874 |
// processed by popup |
| 3875 |
//updatesoverview_upgrade_plugintheme_list( what, pId, list, true, groupId ); |
| 3876 |
let siteName = jQuery("#wp_" + pWhat + "_upgrades_" + pId + '_group_' + groupId).attr('site_name'); |
| 3877 |
updatesoverview_upgrade_plugintheme_list_popup(what, pId, siteName, list); |
| 3878 |
} |
| 3879 |
}(id, what); |
| 3880 |
|
| 3881 |
if (noCheck) { |
| 3882 |
updatesoverviewContinueAfterBackup(); |
| 3883 |
return false; |
| 3884 |
} |
| 3885 |
|
| 3886 |
let sitesToUpdate = []; |
| 3887 |
let siteNames = []; |
| 3888 |
|
| 3889 |
sitesToUpdate.push(id); |
| 3890 |
siteNames[id] = jQuery('tbody[site_id="' + id + '"]').attr('site_name'); |
| 3891 |
|
| 3892 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 3893 |
}; |
| 3894 |
|
| 3895 |
let mainwp_render_regression_after_update = function (lastResult, lastSuccessParent) { |
| 3896 |
|
| 3897 |
if ( |
| 3898 |
!lastResult || |
| 3899 |
!lastSuccessParent || |
| 3900 |
typeof mainwp_html_regression === "undefined" || |
| 3901 |
mainwp_html_regression.use_after_updates !== "1" |
| 3902 |
) { |
| 3903 |
return; |
| 3904 |
} |
| 3905 |
|
| 3906 |
const icon_success = |
| 3907 |
'<span data-inverted="" data-position="left center" data-tooltip="' + |
| 3908 |
MainWP.I18n.t('Update successful.', 'mainwp') + |
| 3909 |
'"><i class="green check icon"></i></span>'; |
| 3910 |
|
| 3911 |
const handleFinalIcon = function (regression_icon_final) { |
| 3912 |
const html_final = icon_success + regression_icon_final; |
| 3913 |
lastSuccessParent.find('td:last-child').html(html_final); |
| 3914 |
}; |
| 3915 |
|
| 3916 |
const regression_icon_loading = render_html_regression_icon(lastResult, handleFinalIcon); |
| 3917 |
|
| 3918 |
lastSuccessParent |
| 3919 |
.find('td:last-child') |
| 3920 |
.html(icon_success + regression_icon_loading); |
| 3921 |
} |
| 3922 |
|
| 3923 |
let updatesoverview_upgrade_plugintheme_list = function (what, id, list, noCheck, groupId) { //NOSONAR |
| 3924 |
updatesoverviewContinueAfterBackup = function (pWhat, pId, pList, pGroupId) { //NOSONAR |
| 3925 |
return function () { //NOSONAR |
| 3926 |
let strGroup = ''; |
| 3927 |
if (pGroupId !== undefined) { |
| 3928 |
strGroup = '_group_' + pGroupId; |
| 3929 |
} |
| 3930 |
let newList = []; |
| 3931 |
|
| 3932 |
// Show icon waiting |
| 3933 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 3934 |
let waiting_icon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Updating...', 'mainwp') + '"><i class="notched circle loading icon"></i></span> ' + MainWP.I18n.t('Updating. Please wait...'); |
| 3935 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 3936 |
waiting_icon += regression_waiting_icon; |
| 3937 |
} |
| 3938 |
|
| 3939 |
for (let i = pList.length - 1; i >= 0; i--) { |
| 3940 |
let item = pList[i]; |
| 3941 |
let elem = document.getElementById('wp_upgraded_' + pWhat + '_' + pId + strGroup + '_' + item); |
| 3942 |
if (!elem && typeof item === 'string') { |
| 3943 |
let decoded = mainwp_decode_slug(item); |
| 3944 |
elem = document.getElementById('wp_upgraded_' + pWhat + '_' + pId + strGroup + '_' + decoded); |
| 3945 |
} |
| 3946 |
if (elem?.value == 0) { |
| 3947 |
let parent = jQuery(elem).closest('tr'); |
| 3948 |
parent.find('td:last-child').html(waiting_icon); |
| 3949 |
elem.value = 1; |
| 3950 |
parent.attr('updated', 1); |
| 3951 |
newList.push(item); |
| 3952 |
} |
| 3953 |
} |
| 3954 |
|
| 3955 |
if (newList.length > 0) { |
| 3956 |
let queue = newList.slice(); |
| 3957 |
let lastResult = null; |
| 3958 |
let lastSuccessParent = null; |
| 3959 |
|
| 3960 |
let processNext = function () { |
| 3961 |
if (queue.length === 0) { |
| 3962 |
mainwp_render_regression_after_update(lastResult, lastSuccessParent); |
| 3963 |
return; |
| 3964 |
} |
| 3965 |
|
| 3966 |
let item = queue.shift(); |
| 3967 |
let data = mainwp_secure_data({ |
| 3968 |
action: 'mainwp_upgradeplugintheme', |
| 3969 |
websiteId: pId, |
| 3970 |
type: pWhat, |
| 3971 |
slug: item |
| 3972 |
}); |
| 3973 |
jQuery.post(ajaxurl, data, function (response) { //NOSONAR |
| 3974 |
let extErr = ''; |
| 3975 |
let elem = document.getElementById('wp_upgraded_' + pWhat + '_' + pId + strGroup + '_' + item); |
| 3976 |
if (!elem && typeof item === 'string') { |
| 3977 |
let decoded = mainwp_decode_slug(item); |
| 3978 |
elem = document.getElementById('wp_upgraded_' + pWhat + '_' + pId + strGroup + '_' + decoded); |
| 3979 |
} |
| 3980 |
let parent = jQuery(elem).closest('tr'); |
| 3981 |
|
| 3982 |
if (response.error) { |
| 3983 |
extErr = getErrorMessageInfo(response.error, 'ui'); |
| 3984 |
parent.find('td:last-child').html(extErr); |
| 3985 |
} else { |
| 3986 |
let res = response.result; |
| 3987 |
let res_error = response.result_error; |
| 3988 |
const icon_success = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Update successful.', 'mainwp') + '"><i class="green check icon"></i></span>'; |
| 3989 |
if (mainwp_get_result_entry(res, item)) { |
| 3990 |
parent.find('td:last-child').html(icon_success); |
| 3991 |
lastResult = res; |
| 3992 |
lastSuccessParent = parent; |
| 3993 |
} else if ((what == 'plugin' || what == 'theme') && mainwp_get_result_entry(res_error, item)) { |
| 3994 |
let _error = mainwp_get_result_entry(res_error, item); |
| 3995 |
let _icon = '<i class="red times icon"></i>'; |
| 3996 |
let roll_error = mainwp_updates_get_rollback_msg(_error); |
| 3997 |
if (roll_error) { |
| 3998 |
_error = roll_error; |
| 3999 |
_icon = mainwpParams.roll_ui_icon; |
| 4000 |
} |
| 4001 |
parent.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + _error + '">' + _icon + '</span>'); |
| 4002 |
} else { |
| 4003 |
parent.find('td:last-child').html('<i class="red times icon"></i>'); |
| 4004 |
} |
| 4005 |
} |
| 4006 |
processNext(); |
| 4007 |
}, 'json'); |
| 4008 |
}; |
| 4009 |
processNext(); |
| 4010 |
} |
| 4011 |
|
| 4012 |
updatesoverviewContinueAfterBackup = undefined; |
| 4013 |
} |
| 4014 |
}(what, id, list, groupId); |
| 4015 |
|
| 4016 |
if (noCheck) { |
| 4017 |
updatesoverviewContinueAfterBackup(); |
| 4018 |
return false; |
| 4019 |
} |
| 4020 |
|
| 4021 |
let sitesToUpdate = [id]; |
| 4022 |
let siteNames = []; |
| 4023 |
siteNames[id] = jQuery('tbody[site_id="' + id + '"]').attr('site_name'); |
| 4024 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 4025 |
}; |
| 4026 |
|
| 4027 |
let updatesoverview_upgrade_plugintheme_list_popup = function (what, pId, pSiteName, list) { |
| 4028 |
let updateCount = list.length; |
| 4029 |
if (updateCount == 0) |
| 4030 |
return; |
| 4031 |
|
| 4032 |
let updateWhat = what == 'theme' ? MainWP.I18n.t('themes') : MainWP.I18n.t('translations'); |
| 4033 |
updateWhat = (what == 'plugin') ? MainWP.I18n.t('plugins') : updateWhat; |
| 4034 |
|
| 4035 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 4036 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(mainwp_links_visit_site_and_admin('', pId) + ' ' + updatesmanage_link_to_site(decodeURIComponent(pSiteName), pId) + ' (' + updateCount + ' ' + updateWhat + ')', '<span class="updatesoverview-upgrade-status-wp" siteid="' + pId + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 4037 |
|
| 4038 |
let initData = { |
| 4039 |
title: MainWP.I18n.t('Updating all'), |
| 4040 |
progressMax: 1 |
| 4041 |
}; |
| 4042 |
updatesoverview_update_popup_init(initData); |
| 4043 |
|
| 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 |
|
| 4072 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 4073 |
|
| 4074 |
if (regression_waiting_icon) { |
| 4075 |
statuses.push({ |
| 4076 |
item: 4, |
| 4077 |
icon: regression_waiting_icon, |
| 4078 |
isHidden: true, |
| 4079 |
}); |
| 4080 |
} |
| 4081 |
|
| 4082 |
updatesoverview_plugins_upgrade_all_update_site_status(pId,''); // clear status first. |
| 4083 |
|
| 4084 |
statuses.forEach((status) => { |
| 4085 |
const { item, ...options } = status; |
| 4086 |
upgradeall_update_site_popup_multi_status(pId, item, options); |
| 4087 |
}); |
| 4088 |
|
| 4089 |
let queue = list.slice(); |
| 4090 |
let countError = 0; |
| 4091 |
let lastResult = ''; |
| 4092 |
|
| 4093 |
let processLoop = function (response) { |
| 4094 |
if (queue.length === 0) { |
| 4095 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(1); |
| 4096 |
if ( |
| 4097 |
lastResult && |
| 4098 |
typeof mainwp_html_regression !== "undefined" && |
| 4099 |
mainwp_html_regression.use_after_updates === "1" |
| 4100 |
) { |
| 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 |
}); |
| 4105 |
}); |
| 4106 |
upgradeall_update_site_popup_multi_status(pId, 4, { |
| 4107 |
icon: regression_icon_callback, |
| 4108 |
}); |
| 4109 |
} |
| 4110 |
upgradeall_update_site_popup_multi_status(pId, 1, { |
| 4111 |
isHidden: true // hide spinner. |
| 4112 |
}); |
| 4113 |
|
| 4114 |
if ( countError === 0 ) { |
| 4115 |
setTimeout(function () { |
| 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 |
} |
| 4121 |
}, 3000); |
| 4122 |
} else { |
| 4123 |
mainwpPopup('#mainwp-sync-sites-modal').updateStatusLabel(MainWP.I18n.t('processed')); |
| 4124 |
} |
| 4125 |
return; |
| 4126 |
} |
| 4127 |
|
| 4128 |
let item = queue.shift(); |
| 4129 |
let data = mainwp_secure_data({ |
| 4130 |
action: 'mainwp_upgradeplugintheme', |
| 4131 |
websiteId: pId, |
| 4132 |
type: what, |
| 4133 |
slug: item |
| 4134 |
}); |
| 4135 |
let decoded = mainwp_decode_slug(item, true); |
| 4136 |
jQuery.post(ajaxurl, data, function (response) { // NOSONAR - complex. |
| 4137 |
let res_error = response.result_error; |
| 4138 |
let hasError = false; |
| 4139 |
if (response.error) { |
| 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 |
}); |
| 4147 |
hasError = true; |
| 4148 |
} else if (res_error && mainwp_get_result_entry(res_error, item)) { |
| 4149 |
let new_status = decoded; |
| 4150 |
let _error = mainwp_get_result_entry(res_error, item); |
| 4151 |
let roll_error = mainwp_updates_get_rollback_msg(_error); |
| 4152 |
if (roll_error) { |
| 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 |
}); |
| 4171 |
} |
| 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 |
}); |
| 4192 |
} |
| 4193 |
|
| 4194 |
if( !hasError ){ |
| 4195 |
lastResult = response?.result; |
| 4196 |
} else { |
| 4197 |
++countError; |
| 4198 |
} |
| 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 |
}); |
| 4220 |
}; |
| 4221 |
|
| 4222 |
processLoop(); |
| 4223 |
} |
| 4224 |
|
| 4225 |
// for semantic ui checkboxes |
| 4226 |
jQuery(function () { |
| 4227 |
mainwp_table_check_columns_init(); // call as function to support tables with ajax, may check and call at extensions |
| 4228 |
mainwp_master_checkbox_init(jQuery); |
| 4229 |
}); |
| 4230 |
|
| 4231 |
let mainwp_master_checkbox_init = function ($) { |
| 4232 |
// Master Checkboxes. |
| 4233 |
$('.master-checkbox .master.checkbox').checkbox(); |
| 4234 |
$('.master-checkbox .master.checkbox').on('click', function (e) { |
| 4235 |
if ($(this).checkbox('is checked')) { |
| 4236 |
let $childCheckbox = $(this).closest('.master-checkbox').next('.child-checkbox').find('.checkbox'); |
| 4237 |
$childCheckbox.checkbox('check'); |
| 4238 |
} else { |
| 4239 |
let $childCheckbox = $(this).closest('.master-checkbox').next('.child-checkbox').find('.checkbox'); |
| 4240 |
$childCheckbox.checkbox('uncheck'); |
| 4241 |
} |
| 4242 |
e.stopPropagation(); |
| 4243 |
}); |
| 4244 |
// Child Checkboxes. |
| 4245 |
$('.child-checkbox .child.checkbox') |
| 4246 |
.checkbox( |
| 4247 |
{ |
| 4248 |
// Fire on load to set parent value |
| 4249 |
fireOnInit: true, |
| 4250 |
// Change parent state on each child checkbox change |
| 4251 |
onChange: function () { |
| 4252 |
let $listGroup = $(this).closest('.child-checkbox'), |
| 4253 |
$parentCheckbox = $listGroup.prev('.master-checkbox').find('.checkbox'), |
| 4254 |
$checkbox = $listGroup.find('.checkbox'), |
| 4255 |
allChecked = true, |
| 4256 |
allUnchecked = true |
| 4257 |
; |
| 4258 |
// check to see if all other siblings are checked or unchecked |
| 4259 |
$checkbox.each(function () { |
| 4260 |
if ($(this).checkbox('is checked')) { |
| 4261 |
allUnchecked = false; |
| 4262 |
} |
| 4263 |
else { |
| 4264 |
allChecked = false; |
| 4265 |
} |
| 4266 |
}); |
| 4267 |
// set parent checkbox state, but dont trigger its onChange callback |
| 4268 |
if (allChecked) { |
| 4269 |
$parentCheckbox.checkbox('set checked'); |
| 4270 |
} |
| 4271 |
else if (allUnchecked) { |
| 4272 |
$parentCheckbox.checkbox('set unchecked'); |
| 4273 |
} |
| 4274 |
else { |
| 4275 |
$parentCheckbox.checkbox('set indeterminate'); |
| 4276 |
} |
| 4277 |
} |
| 4278 |
} |
| 4279 |
); |
| 4280 |
|
| 4281 |
// Main Master Checkboxes. |
| 4282 |
// Move label text outside the checkbox div so clicking the text bubbles to th for column sort, |
| 4283 |
// while clicking the checkbox icon (empty label) still handles check/uncheck all behavior. |
| 4284 |
$('.main-master-checkbox .main-master.checkbox').each(function () { |
| 4285 |
let $label = $(this).find('label'); |
| 4286 |
let labelText = $label.text().trim(); |
| 4287 |
if (labelText) { |
| 4288 |
$label.empty(); |
| 4289 |
$(this).after('<span class="mainwp-th-sort-label">' + labelText + '</span>'); |
| 4290 |
} |
| 4291 |
}); |
| 4292 |
$('.main-master-checkbox .main-master.checkbox').checkbox(); |
| 4293 |
$('.main-master-checkbox .main-master.checkbox').on('click', function (e) { |
| 4294 |
if ($(this).checkbox('is checked')) { |
| 4295 |
$(this).closest('.main-master-checkbox').next('.main-child-checkbox').find('.checkbox').checkbox('check'); |
| 4296 |
$(this).closest('.main-master-checkbox').find('.checkbox').checkbox('check'); |
| 4297 |
} else { |
| 4298 |
$(this).closest('.main-master-checkbox').next('.main-child-checkbox').find('.checkbox').checkbox('uncheck'); |
| 4299 |
$(this).closest('.main-master-checkbox').find('.checkbox').checkbox('uncheck'); |
| 4300 |
} |
| 4301 |
e.stopPropagation(); |
| 4302 |
}); |
| 4303 |
|
| 4304 |
} |
| 4305 |
// This function need to update when datatable changed it's style. |
| 4306 |
globalThis.mainwp_table_check_columns_init = function (pTableSelector = 'table') { |
| 4307 |
let tblSelect = pTableSelector; |
| 4308 |
jQuery(document).find(tblSelect + ' th.check-column .checkbox').checkbox({ // table headers. |
| 4309 |
// check all children |
| 4310 |
onChecked: function () { |
| 4311 |
let $table = jQuery(this).closest('table'); |
| 4312 |
if ($table.parent().parent().hasClass('dt-scroll-head') || $table.parent().parent().hasClass('dt-scroll-foot')) { |
| 4313 |
$table = jQuery(this).closest('.dt-scroll'); // to compatible with datatable scroll |
| 4314 |
} |
| 4315 |
|
| 4316 |
if ($table.length > 0) { |
| 4317 |
let $childCheckbox = $table.find('td.check-column .checkbox'); |
| 4318 |
$childCheckbox.checkbox('check'); |
| 4319 |
} |
| 4320 |
}, |
| 4321 |
// uncheck all children |
| 4322 |
onUnchecked: function () { |
| 4323 |
let $table = jQuery(this).closest('table'); |
| 4324 |
if ($table.parent().parent().hasClass('dt-scroll-head') || $table.parent().parent().hasClass('dt-scroll-foot')) { |
| 4325 |
$table = jQuery(this).closest('.dt-scroll'); // to compatible with datatable scroll |
| 4326 |
} |
| 4327 |
if ($table.length > 0) { |
| 4328 |
let $childCheckbox = $table.find('tbody td.check-column .checkbox'); |
| 4329 |
$childCheckbox.checkbox('uncheck'); |
| 4330 |
} |
| 4331 |
} |
| 4332 |
}); |
| 4333 |
|
| 4334 |
jQuery(document).find('td.check-column .checkbox').checkbox({ |
| 4335 |
// Fire on load to set parent value |
| 4336 |
fireOnInit: true, |
| 4337 |
// Change parent state on each child checkbox change |
| 4338 |
onChange: function () { |
| 4339 |
let $table = jQuery(this).closest('table'); |
| 4340 |
|
| 4341 |
if ($table.parent().hasClass('dt-scroll-body')) |
| 4342 |
$table = jQuery(this).closest('.dt-scroll'); // to compatible with datatable scroll |
| 4343 |
|
| 4344 |
let $parentCheckbox = $table.find('th.check-column .checkbox'), |
| 4345 |
$checkbox = $table.find('td.check-column .checkbox'), |
| 4346 |
allChecked = true, |
| 4347 |
allUnchecked = true |
| 4348 |
; |
| 4349 |
|
| 4350 |
$checkbox.each(function () { |
| 4351 |
if (jQuery(this).checkbox('is checked')) { |
| 4352 |
allUnchecked = false; |
| 4353 |
} |
| 4354 |
else { |
| 4355 |
allChecked = false; |
| 4356 |
} |
| 4357 |
}); |
| 4358 |
|
| 4359 |
if (allChecked) { |
| 4360 |
$parentCheckbox.checkbox('set checked'); |
| 4361 |
} |
| 4362 |
else if (allUnchecked) { |
| 4363 |
$parentCheckbox.checkbox('set unchecked'); |
| 4364 |
} |
| 4365 |
} |
| 4366 |
}); |
| 4367 |
} |
| 4368 |
|
| 4369 |
// Sync score icon. |
| 4370 |
const render_html_regression_sync_score_icon = function (score, change_score, website_id) { |
| 4371 |
score = Number(score) || 0; |
| 4372 |
change_score = Number(change_score) || 0; |
| 4373 |
let icon_html = ""; |
| 4374 |
if (score <= change_score) { |
| 4375 |
icon_html = '<i class="check green icon"></i>'; // Minimal change. |
| 4376 |
} else { |
| 4377 |
icon_html = '<i class="fire alternate red icon updates-regression-score-red-flag"></i>'; // Major differences. |
| 4378 |
} |
| 4379 |
|
| 4380 |
if (icon_html !== "" && Number.isInteger(website_id)) { |
| 4381 |
const msg = MainWP.I18n.t('Change score changed. Click to review changes.'); |
| 4382 |
icon_html = `<a href="admin.php?page=ManageSitesHTMLRegression&id=${website_id}" target="_blank" data-tooltip="${msg}" data-inverted="" data-position="left center">${icon_html}</a>`; |
| 4383 |
} |
| 4384 |
|
| 4385 |
return icon_html; |
| 4386 |
}; |
| 4387 |
|
| 4388 |
// Render Icon |
| 4389 |
const render_html_regression_icon = function (result, onDone) { |
| 4390 |
if (typeof mainwp_html_regression === "undefined" || mainwp_html_regression.use_after_updates !== "1") { |
| 4391 |
return ''; |
| 4392 |
} |
| 4393 |
const loading_icon = `<span data-inverted="" data-position="left center" data-tooltip="${MainWP.I18n.t('Regression scan in progress...', 'mainwp')}"><i class="notched circle loading icon"></i></span>`; |
| 4394 |
setTimeout(() => { |
| 4395 |
let _icon = ''; |
| 4396 |
if ( |
| 4397 |
result?.html_regression_max_scope && |
| 4398 |
typeof result.html_regression_max_scope === 'object' && |
| 4399 |
!Array.isArray(result.html_regression_max_scope) && |
| 4400 |
Object.keys(result.html_regression_max_scope).length > 0 |
| 4401 |
) { |
| 4402 |
const regression_scope = result.html_regression_max_scope; |
| 4403 |
_icon = render_html_regression_sync_score_icon( |
| 4404 |
Number.parseInt(regression_scope.change_score_current), |
| 4405 |
Number.parseInt(regression_scope.change_score), |
| 4406 |
regression_scope.website_id |
| 4407 |
); |
| 4408 |
} else { |
| 4409 |
_icon = '<i class="exclamation circle red icon"></i>'; |
| 4410 |
} |
| 4411 |
|
| 4412 |
onDone(_icon); |
| 4413 |
}, 1500); |
| 4414 |
|
| 4415 |
return loading_icon; |
| 4416 |
}; |
| 4417 |
|
| 4418 |
// Render Waiting Icon. |
| 4419 |
const render_html_regression_waiting_icon = function () { |
| 4420 |
if (typeof mainwp_html_regression === "undefined" || mainwp_html_regression.use_after_updates !== "1") { |
| 4421 |
return ''; |
| 4422 |
} |
| 4423 |
|
| 4424 |
return `<span data-inverted="" data-position="left center" data-tooltip="${MainWP.I18n.t('Regression Testing scan will begin after the update is completed.', 'mainwp')}"><i class="hourglass half icon"></i></span>`; |
| 4425 |
} |
| 4426 |
|
| 4427 |
// Render Tooltip Loading Icon. |
| 4428 |
const render_tooltip_loading_icon = function (icon_html) { |
| 4429 |
return `<span data-inverted="" data-position="left center" data-tooltip="${MainWP.I18n.t('Update in progress…', 'mainwp')}">${icon_html}</span>` |
| 4430 |
} |
| 4431 |
|