| 1 |
/* eslint-disable complexity */ |
| 2 |
// current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 3 |
globalThis.mainwpVars = globalThis.mainwpVars || {}; |
| 4 |
|
| 5 |
|
| 6 |
let ugradingWebsiteAll = false; |
| 7 |
let ignoredBackupBeforeUpdate = false; |
| 8 |
let ugradingAllCurrentStep = ''; |
| 9 |
let managesitesContinueAfterBackup; |
| 10 |
|
| 11 |
let managesitesBackupSites; |
| 12 |
let managesitesBackupError; |
| 13 |
let managesitesBackupDownloadRunning; |
| 14 |
|
| 15 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 16 |
|
| 17 |
let managesites_update_all_next_step = function () { |
| 18 |
let next = ''; |
| 19 |
if ('wpcore' == ugradingAllCurrentStep) { |
| 20 |
next = 'plugin'; |
| 21 |
} else if ('plugin' == ugradingAllCurrentStep) { |
| 22 |
next = 'theme'; |
| 23 |
} else if ('theme' == ugradingAllCurrentStep) { |
| 24 |
next = 'translation'; |
| 25 |
} |
| 26 |
ugradingAllCurrentStep = next; |
| 27 |
return ugradingAllCurrentStep; |
| 28 |
} |
| 29 |
|
| 30 |
let mainwp_update_get_selected_sitesids = function (selectedSitesIds, allSitesIds) { |
| 31 |
let selectedIds = [], excludeIds = []; |
| 32 |
if (Array.isArray(selectedSitesIds)) { |
| 33 |
jQuery.grep(allSitesIds, function (el) { |
| 34 |
if (jQuery.inArray(el, selectedSitesIds) > -1) { |
| 35 |
selectedIds.push(el); |
| 36 |
} else { |
| 37 |
excludeIds.push(el); |
| 38 |
} |
| 39 |
}); |
| 40 |
for (let id of excludeIds) { |
| 41 |
dashboard_update_site_hide(id); |
| 42 |
} |
| 43 |
allSitesIds = selectedIds; |
| 44 |
} |
| 45 |
return allSitesIds; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
// global variable. |
| 50 |
globalThis.mainwp_update_pluginsthemes = function (updateType, updateSiteIds) { |
| 51 |
let allWebsiteIds = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { |
| 52 |
return jQuery(el).val(); |
| 53 |
}); |
| 54 |
allWebsiteIds = mainwp_update_get_selected_sitesids(updateSiteIds, allWebsiteIds); |
| 55 |
let nrOfWebsites = allWebsiteIds.length; |
| 56 |
|
| 57 |
if (nrOfWebsites == 0) { |
| 58 |
managesites_reset_bulk_actions_params(); |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
let siteNames = {}; |
| 63 |
|
| 64 |
for (let id of allWebsiteIds) { |
| 65 |
dashboard_update_site_status(id, '<i class="clock outline icon"></i> ' + MainWP.I18n.t('PENDING')); |
| 66 |
siteNames[id] = jQuery('.sync-site-status[siteid="' + id + '"]').attr('niceurl'); |
| 67 |
} |
| 68 |
|
| 69 |
managesitesContinueAfterBackup = function (pType, sitesCount, pAllWebsiteIds) { |
| 70 |
return function () { |
| 71 |
let title = ''; |
| 72 |
if (ugradingWebsiteAll) { |
| 73 |
if (pType == 'plugin') |
| 74 |
title = MainWP.I18n.t("Updating everything: Plugins..."); |
| 75 |
else if (pType == 'theme') { |
| 76 |
title = MainWP.I18n.t("Updating everything: Themes..."); |
| 77 |
} else if (pType == 'translation') { |
| 78 |
title = MainWP.I18n.t("Updating everything: Translations..."); |
| 79 |
} |
| 80 |
mainwpPopup('#mainwp-sync-sites-modal').setTitle(title); // popup displayed. |
| 81 |
mainwpPopup('#mainwp-sync-sites-modal').setStatusText('0 / ' + nrOfWebsites + ' ' + MainWP.I18n.t('updated')); // popup displayed. |
| 82 |
|
| 83 |
|
| 84 |
} else { |
| 85 |
if (pType == 'plugin') |
| 86 |
title = MainWP.I18n.t("Updating plugins..."); |
| 87 |
else if (pType == 'theme') { |
| 88 |
title = MainWP.I18n.t("Updating themes..."); |
| 89 |
} else if (pType == 'translation') { |
| 90 |
title = MainWP.I18n.t("Updating translations..."); |
| 91 |
} |
| 92 |
let initData = { |
| 93 |
progressMax: sitesCount, |
| 94 |
statusText: MainWP.I18n.t('updated'), |
| 95 |
callback: function () { |
| 96 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 97 |
}, |
| 98 |
allowMultiple: true |
| 99 |
}; |
| 100 |
if (title != '') |
| 101 |
initData.title = title; |
| 102 |
|
| 103 |
mainwpPopup('#mainwp-sync-sites-modal').init(initData); |
| 104 |
} |
| 105 |
|
| 106 |
managesites_update_pluginsthemes(pType, pAllWebsiteIds); |
| 107 |
managesitesContinueAfterBackup = undefined; |
| 108 |
} |
| 109 |
}(updateType, nrOfWebsites, allWebsiteIds); |
| 110 |
|
| 111 |
if (!ignoredBackupBeforeUpdate) { |
| 112 |
mainwp_managesites_checkBackups(allWebsiteIds, siteNames); |
| 113 |
} else if (managesitesContinueAfterBackup != undefined) { |
| 114 |
managesitesContinueAfterBackup(); |
| 115 |
} |
| 116 |
|
| 117 |
}; |
| 118 |
|
| 119 |
let websitesUpdateError = 0; |
| 120 |
let websitesEveryError; |
| 121 |
|
| 122 |
let managesites_update_pluginsthemes = function (pType, websiteIds) { |
| 123 |
mainwpVars.websitesToUpdate = websiteIds; |
| 124 |
mainwpVars.currentWebsite = 0; |
| 125 |
mainwpVars.websitesDone = 0; |
| 126 |
websitesUpdateError = 0; |
| 127 |
websitesEveryError = 0; |
| 128 |
|
| 129 |
mainwpVars.websitesTotal = mainwpVars.websitesToUpdate.length; |
| 130 |
mainwpVars.websitesLeft = mainwpVars.websitesToUpdate.length; |
| 131 |
|
| 132 |
mainwpVars.bulkManageSitesTaskRunning = true; |
| 133 |
|
| 134 |
if (mainwpVars.websitesTotal == 0) { |
| 135 |
managesites_update_pluginsthemes_done(pType); |
| 136 |
} else { |
| 137 |
managesites_loop_pluginsthemes_next(pType); |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
let managesites_loop_pluginsthemes_next = function (pType) { |
| 142 |
while (mainwpVars.bulkManageSitesTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxThreads) && (mainwpVars.websitesLeft > 0)) { |
| 143 |
managesites_update_pluginsthemes_next(pType); |
| 144 |
} |
| 145 |
}; |
| 146 |
|
| 147 |
let managesites_update_pluginsthemes_done = function (pType) { |
| 148 |
mainwpVars.currentThreads--; |
| 149 |
if (!mainwpVars.bulkManageSitesTaskRunning) |
| 150 |
return; |
| 151 |
mainwpVars.websitesDone++; |
| 152 |
if (mainwpVars.websitesDone > mainwpVars.websitesTotal) |
| 153 |
mainwpVars.websitesDone = mainwpVars.websitesTotal; |
| 154 |
|
| 155 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 156 |
|
| 157 |
if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { |
| 158 |
setTimeout(function () { |
| 159 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 160 |
|
| 161 |
if (ugradingWebsiteAll) { |
| 162 |
// get next updating everything step. |
| 163 |
let nextStep = managesites_update_all_next_step(); |
| 164 |
if ('' != nextStep) { |
| 165 |
websitesEveryError += websitesUpdateError; |
| 166 |
let selectedIds = jQuery('#sync_selected_site_ids').val().split(','); |
| 167 |
setTimeout(function () { |
| 168 |
// start next update step. |
| 169 |
mainwp_update_pluginsthemes(nextStep, selectedIds); |
| 170 |
}, 1000); |
| 171 |
return; // do not close the popup. |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
if (websitesUpdateError <= 0 && websitesEveryError <= 0 && mainwpVars.errorCount <= 0) { |
| 176 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 177 |
} else { |
| 178 |
let message = websitesUpdateError + ' Site' + (websitesUpdateError > 1 ? 's' : '') + ' Timed / Errored out. <br/><span class="mainwp-small">(There was an error syncing some of your sites. <a href="https://docs.mainwp.com/troubleshooting/potential-issues">Please check this help doc for possible solutions.</a>)</span>'; // NOSONAR - noopener - open safe. |
| 179 |
mainwpPopup('#mainwp-sync-sites-modal').getContentEl().prepend('<span class="mainwp-red"><strong>' + message + '</strong></span><br /><br />'); |
| 180 |
} |
| 181 |
}, 2000); |
| 182 |
return; |
| 183 |
} |
| 184 |
|
| 185 |
managesites_loop_pluginsthemes_next(pType); |
| 186 |
}; |
| 187 |
|
| 188 |
let _tempVal = 0; |
| 189 |
|
| 190 |
let managesites_update_pluginsthemes_next_int = function (websiteId, data, errors) { |
| 191 |
// to enable chunk update, for manage sites page only |
| 192 |
data['chunk_support'] = 1; |
| 193 |
|
| 194 |
jQuery.ajax({ |
| 195 |
type: 'POST', |
| 196 |
url: ajaxurl, |
| 197 |
data: data, |
| 198 |
success: function (pWebsiteId, pData, pErrors) { |
| 199 |
return function (response) { // NOSONAR - complex ok. |
| 200 |
if (response.error) { |
| 201 |
mainwpVars.errorCount++; |
| 202 |
dashboard_update_site_status(pWebsiteId, getErrorMessageInfo(response.error, 'ui')); |
| 203 |
websitesUpdateError++; |
| 204 |
} else { |
| 205 |
let res_error = response?.result_error; |
| 206 |
let isError = false; |
| 207 |
if (res_error) { |
| 208 |
|
| 209 |
let _error = ''; |
| 210 |
let has_roll_error = false; |
| 211 |
for (let e in res_error) { |
| 212 |
let ro_error = mainwp_updates_get_rollback_msg(res_error[e]); |
| 213 |
if (ro_error) { |
| 214 |
_error += ro_error + '<br/>'; |
| 215 |
has_roll_error = true; |
| 216 |
} else { |
| 217 |
_error += res_error[e] + '<br/>'; |
| 218 |
} |
| 219 |
mainwpVars.errorCount++; |
| 220 |
} |
| 221 |
|
| 222 |
if (_error) { |
| 223 |
isError = true; |
| 224 |
let _icon = '<i class="red times icon"></i>'; |
| 225 |
if (has_roll_error) { |
| 226 |
_icon = mainwpParams.roll_ui_icon; |
| 227 |
} |
| 228 |
dashboard_update_site_status(pWebsiteId, '<span class="mainwp-html-popup" data-position="left center" data-html="">' + _icon + '</span>', false); |
| 229 |
mainwp_init_html_popup('.sync-site-status[siteid="' + pWebsiteId + '"] .mainwp-html-popup', _error); |
| 230 |
} |
| 231 |
|
| 232 |
} else if (response.chunk_slugs) { // to support reduce update plugins/themes |
| 233 |
let msg = '<i class="sync alternate loading icon"></i>'; |
| 234 |
_tempVal++; |
| 235 |
if (_tempVal % 2) |
| 236 |
msg = '<i class="fa fa-refresh fa-spin"></i>'; |
| 237 |
dashboard_update_site_status(pWebsiteId, msg); |
| 238 |
pData['chunk_slugs'] = response.chunk_slugs; |
| 239 |
managesites_update_pluginsthemes_next_int(pWebsiteId, pData, pErrors); |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
if (!isError) { |
| 244 |
dashboard_update_site_status(pWebsiteId, '<i class="green check icon"></i>', true); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
managesites_update_pluginsthemes_done(pData['type']); |
| 249 |
} |
| 250 |
}(websiteId, data, errors), |
| 251 |
error: function (pWebsiteId, pData, pErrors) { |
| 252 |
return function () { |
| 253 |
if (pErrors > 5) { |
| 254 |
dashboard_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 255 |
websitesUpdateError++; |
| 256 |
managesites_update_pluginsthemes_done(pData['type']); |
| 257 |
} else { |
| 258 |
pErrors++; |
| 259 |
managesites_update_pluginsthemes_next_int(pWebsiteId, pData, pErrors); |
| 260 |
} |
| 261 |
} |
| 262 |
}(websiteId, data, errors), |
| 263 |
dataType: 'json' |
| 264 |
}); |
| 265 |
}; |
| 266 |
|
| 267 |
|
| 268 |
let managesites_update_pluginsthemes_next = function (pType) { |
| 269 |
mainwpVars.currentThreads++; |
| 270 |
mainwpVars.websitesLeft--; |
| 271 |
let websiteId = mainwpVars.websitesToUpdate[mainwpVars.currentWebsite++]; |
| 272 |
dashboard_update_site_status(websiteId, MainWP.I18n.t('<i class="sync alternate loading icon"></i>')); |
| 273 |
let data = mainwp_secure_data({ |
| 274 |
action: 'mainwp_upgradeplugintheme', |
| 275 |
websiteId: websiteId, |
| 276 |
type: pType, |
| 277 |
bulkUpdate: mainwpVars.websitesTotal > 1 ? 1 : 0 |
| 278 |
}); |
| 279 |
managesites_update_pluginsthemes_next_int(websiteId, data, 0); |
| 280 |
}; |
| 281 |
|
| 282 |
|
| 283 |
jQuery(document).on('click', '#managesites-backup-ignore', function () { |
| 284 |
if (managesitesContinueAfterBackup != undefined) { |
| 285 |
ignoredBackupBeforeUpdate = true; |
| 286 |
mainwpPopup('#managesites-backup-box').close(); |
| 287 |
managesitesContinueAfterBackup(); |
| 288 |
managesitesContinueAfterBackup = undefined; |
| 289 |
} |
| 290 |
}); |
| 291 |
|
| 292 |
let mainwp_managesites_checkBackups = function (sitesToUpdate, siteNames) { |
| 293 |
if (!mainwpParams['backup_before_upgrade']) { |
| 294 |
if (managesitesContinueAfterBackup != undefined) |
| 295 |
managesitesContinueAfterBackup(); |
| 296 |
return; |
| 297 |
} |
| 298 |
let managesitesShowBusyFunction = function () { |
| 299 |
let output = MainWP.I18n.t('Checking if a backup is required for the selected updates...'); |
| 300 |
mainwpPopup('#managesites-backup-box').getContentEl().html(output); |
| 301 |
jQuery('#managesites-backup-all').hide(); |
| 302 |
jQuery('#managesites-backup-ignore').hide(); |
| 303 |
mainwpPopup('#managesites-backup-box').init({ |
| 304 |
title: MainWP.I18n.t("Checking backup settings..."), callback: function () { |
| 305 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 306 |
}, |
| 307 |
allowMultiple: true |
| 308 |
}); |
| 309 |
|
| 310 |
}; |
| 311 |
|
| 312 |
let managesitesShowBusyTimeout = setTimeout(managesitesShowBusyFunction, 300); |
| 313 |
|
| 314 |
//Step 2: Check if backups are ok. |
| 315 |
let data = mainwp_secure_data({ |
| 316 |
action: 'mainwp_checkbackups', |
| 317 |
sites: sitesToUpdate |
| 318 |
}); |
| 319 |
|
| 320 |
jQuery.ajax({ |
| 321 |
type: "POST", |
| 322 |
url: ajaxurl, |
| 323 |
data: data, |
| 324 |
success: function (pSiteNames) { |
| 325 |
return function (response) { |
| 326 |
clearTimeout(managesitesShowBusyTimeout); |
| 327 |
|
| 328 |
mainwpPopup('#managesites-backup-box').close(); |
| 329 |
let siteFeedback; |
| 330 |
|
| 331 |
if (response?.result?.sites) { |
| 332 |
siteFeedback = []; |
| 333 |
for (let currSiteId in response['result']['sites']) { |
| 334 |
if (!response['result']['sites'][currSiteId]) { |
| 335 |
siteFeedback.push(currSiteId); |
| 336 |
} |
| 337 |
} |
| 338 |
if (siteFeedback.length == 0) |
| 339 |
siteFeedback = undefined; |
| 340 |
} |
| 341 |
|
| 342 |
if (siteFeedback != undefined) { |
| 343 |
mainwp_managesites_prepare_backup_popup(response, pSiteNames, siteFeedback); |
| 344 |
mainwpPopup('#managesites-backup-box').init({ |
| 345 |
title: MainWP.I18n.t("Full backup required!"), callback: function () { |
| 346 |
managesitesContinueAfterBackup = undefined; |
| 347 |
}, |
| 348 |
allowMultiple: true |
| 349 |
}); |
| 350 |
|
| 351 |
return; |
| 352 |
} |
| 353 |
if (managesitesContinueAfterBackup != undefined) |
| 354 |
managesitesContinueAfterBackup(); |
| 355 |
} |
| 356 |
}(siteNames), |
| 357 |
error: function () { |
| 358 |
mainwpPopup('#managesites-backup-box').close(true); |
| 359 |
}, |
| 360 |
dataType: 'json' |
| 361 |
}); |
| 362 |
}; |
| 363 |
|
| 364 |
let mainwp_get_primaryBackup_link = function (what) { |
| 365 |
let slug = ''; |
| 366 |
switch (what) { |
| 367 |
case 'backupbuddy': |
| 368 |
slug = 'Extensions-Mainwp-Buddy-Extension&subpage=backup'; |
| 369 |
break; |
| 370 |
case 'backwpup': |
| 371 |
slug = 'Extensions-Mainwp-Backwpup-Extension'; |
| 372 |
break; |
| 373 |
case 'updraftplus': |
| 374 |
slug = 'Extensions-Mainwp-Updraftplus-Extension'; |
| 375 |
break; |
| 376 |
default: |
| 377 |
} |
| 378 |
|
| 379 |
let pageSlug = ''; |
| 380 |
|
| 381 |
if (slug != '') |
| 382 |
pageSlug = 'admin.php?page=' + slug; |
| 383 |
|
| 384 |
return pageSlug; |
| 385 |
} |
| 386 |
jQuery(document).on('click', '#managesites-backupnow-close', function () { |
| 387 |
if (jQuery(this).prop('cancel') == '1') { |
| 388 |
managesitesBackupSites = []; |
| 389 |
managesitesBackupError = false; |
| 390 |
managesitesBackupDownloadRunning = false; |
| 391 |
mainwpPopup('#managesites-backup-box').close(true); |
| 392 |
} else { |
| 393 |
mainwpPopup('#managesites-backup-box').close(); |
| 394 |
if (managesitesContinueAfterBackup != undefined) |
| 395 |
managesitesContinueAfterBackup(); |
| 396 |
} |
| 397 |
}); |
| 398 |
jQuery(document).on('click', '#managesites-backup-all', function () { |
| 399 |
mainwpPopup('#managesites-backup-box').close(); |
| 400 |
// change action buttons |
| 401 |
mainwpPopup('#managesites-backup-box').setActionButtons('<input id="managesites-backupnow-close" type="button" name="Ignore" value="' + MainWP.I18n.t('Cancel') + '" class="button"/>'); |
| 402 |
mainwpPopup('#managesites-backup-box').init({ |
| 403 |
title: MainWP.I18n.t("Full backup"), callback: function () { |
| 404 |
managesitesContinueAfterBackup = undefined; |
| 405 |
mainwp_forceReload(); |
| 406 |
} |
| 407 |
}); |
| 408 |
let sitesToBackup = mainwpPopup('#managesites-backup-box').getContentEl().find('.managesites-backup-site'); |
| 409 |
managesitesBackupSites = []; |
| 410 |
for (let id of sitesToBackup) { |
| 411 |
let currentSite = { 'id': jQuery(id).attr('siteid'), 'name': jQuery(id).text() }; |
| 412 |
managesitesBackupSites.push(currentSite); |
| 413 |
} |
| 414 |
managesites_backup_run(); |
| 415 |
}); |
| 416 |
|
| 417 |
|
| 418 |
let managesites_backup_run = function () { |
| 419 |
mainwpPopup('#managesites-backup-box').getContentEl().html(dateToHMS(new Date()) + ' ' + MainWP.I18n.t('Starting required backup(s)...')); |
| 420 |
jQuery('#managesites-backupnow-close').prop('value', MainWP.I18n.t('Cancel')); |
| 421 |
jQuery('#managesites-backupnow-close').prop('cancel', '1'); |
| 422 |
managesites_backup_run_next(); |
| 423 |
}; |
| 424 |
|
| 425 |
let managesites_backup_run_next = function () { |
| 426 |
let backupContentEl = mainwpPopup('#managesites-backup-box').getContentEl(); |
| 427 |
if (managesitesBackupSites.length == 0) { |
| 428 |
appendToDiv(backupContentEl, MainWP.I18n.t('Required backup(s) completed') + (managesitesBackupError ? ' <span class="mainwp-red">' + MainWP.I18n.t('with errors') + '</span>' : '') + '.'); |
| 429 |
|
| 430 |
jQuery('#managesites-backupnow-close').prop('cancel', '0'); |
| 431 |
if (managesitesBackupError) { |
| 432 |
//Error... |
| 433 |
jQuery('#managesites-backupnow-close').prop('value', MainWP.I18n.t('Continue update anyway')); |
| 434 |
} else { |
| 435 |
jQuery('#managesites-backupnow-close').prop('value', MainWP.I18n.t('Continue update')); |
| 436 |
} |
| 437 |
return; |
| 438 |
} |
| 439 |
|
| 440 |
let siteName = managesitesBackupSites[0]['name']; |
| 441 |
appendToDiv(backupContentEl, '[' + siteName + '] ' + MainWP.I18n.t('Creating backup file...')); |
| 442 |
|
| 443 |
let siteId = managesitesBackupSites[0]['id']; |
| 444 |
managesitesBackupSites.shift(); |
| 445 |
let data = mainwp_secure_data({ |
| 446 |
action: 'mainwp_backup_run_site', |
| 447 |
site_id: siteId |
| 448 |
}); |
| 449 |
|
| 450 |
jQuery.post(ajaxurl, data, function (pSiteId, pSiteName) { |
| 451 |
return function (response) { |
| 452 |
if (response.error) { |
| 453 |
appendToDiv(backupContentEl, '[' + pSiteName + '] <span class="mainwp-red">Error: ' + getErrorMessage(response.error) + '</span>'); |
| 454 |
managesitesBackupError = true; |
| 455 |
managesites_backup_run_next(); |
| 456 |
} else { |
| 457 |
appendToDiv(backupContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Backup file created successfully!')); |
| 458 |
|
| 459 |
managesites_backupnow_download_file({ 'id': pSiteId, 'name': pSiteName }, response.result.type, response.result.url, response.result.local, response.result.size); |
| 460 |
} |
| 461 |
|
| 462 |
} |
| 463 |
}(siteId, siteName), 'json'); |
| 464 |
}; |
| 465 |
|
| 466 |
let managesites_backupnow_download_file = function (siteInfo, type, url, file, size) { |
| 467 |
let pSiteId = siteInfo['id']; |
| 468 |
let pSiteName = siteInfo['name']; |
| 469 |
let backupContentEl = mainwpPopup('#managesites-backup-box').getContentEl(); |
| 470 |
appendToDiv(backupContentEl, '[' + pSiteName + '] Downloading the file. <div id="managesites-backupnow-status-progress" siteId="' + pSiteId + '" class="ui green progress"><div class="bar"><div class="progress"></div></div></div>'); |
| 471 |
jQuery('#managesites-backupnow-status-progress[siteId="' + pSiteId + '"]').progress({ value: 0, total: size }); |
| 472 |
let interVal = setInterval(function () { |
| 473 |
let data = mainwp_secure_data({ |
| 474 |
action: 'mainwp_backup_getfilesize', |
| 475 |
local: file |
| 476 |
}); |
| 477 |
jQuery.post(ajaxurl, data, function (pSiteId) { |
| 478 |
return function (response) { |
| 479 |
if (response.error) |
| 480 |
return; |
| 481 |
|
| 482 |
if (managesitesBackupDownloadRunning) { |
| 483 |
let progressBar = jQuery('#managesites-backupnow-status-progress[siteId="' + pSiteId + '"]'); |
| 484 |
if (progressBar.progress('get value') < progressBar.progress('get total')) { |
| 485 |
progressBar.progress('set progress', response.result); |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
}(pSiteId), 'json'); |
| 490 |
}, 500); |
| 491 |
|
| 492 |
let data = mainwp_secure_data({ |
| 493 |
action: 'mainwp_backup_download_file', |
| 494 |
site_id: pSiteId, |
| 495 |
type: type, |
| 496 |
url: url, |
| 497 |
local: file |
| 498 |
}); |
| 499 |
managesitesBackupDownloadRunning = true; |
| 500 |
jQuery.post(ajaxurl, data, function (pSize, pInterVal, pSiteName, pSiteId, pUrl) { |
| 501 |
return function (response) { |
| 502 |
managesitesBackupDownloadRunning = false; |
| 503 |
clearInterval(pInterVal); |
| 504 |
|
| 505 |
if (response.error) { |
| 506 |
appendToDiv(backupContentEl, '[' + pSiteName + '] <span class="error">' + getErrorMessage(response.error) + '</span>'); |
| 507 |
appendToDiv(backupContentEl, '[' + pSiteName + '] <span class="error">' + MainWP.I18n.t('Backup failed') + '</span>'); |
| 508 |
|
| 509 |
managesitesBackupError = true; |
| 510 |
managesites_backup_run_next(); |
| 511 |
return; |
| 512 |
} |
| 513 |
|
| 514 |
jQuery('#managesites-backupnow-status-progress[siteId="' + pSiteId + '"]').progress('set progress', pSize); |
| 515 |
appendToDiv(backupContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Download from the child site completed.')); |
| 516 |
appendToDiv(backupContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Backup completed.')); |
| 517 |
|
| 518 |
let newData = mainwp_secure_data({ |
| 519 |
action: 'mainwp_backup_delete_file', |
| 520 |
site_id: pSiteId, |
| 521 |
file: pUrl |
| 522 |
}); |
| 523 |
jQuery.post(ajaxurl, newData, function () { }, 'json'); |
| 524 |
|
| 525 |
managesites_backup_run_next(); |
| 526 |
} |
| 527 |
}(size, interVal, pSiteName, pSiteId, url), 'json'); |
| 528 |
}; |
| 529 |
|
| 530 |
globalThis.managesites_wordpress_global_upgrade_all = function (updateSiteIds, updateEverything) { |
| 531 |
let allWebsiteIds = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { |
| 532 |
return jQuery(el).val(); |
| 533 |
}); |
| 534 |
allWebsiteIds = mainwp_update_get_selected_sitesids(updateSiteIds, allWebsiteIds); |
| 535 |
|
| 536 |
let nrOfWebsites = allWebsiteIds.length; |
| 537 |
|
| 538 |
if (nrOfWebsites == 0) { |
| 539 |
managesites_reset_bulk_actions_params(); |
| 540 |
return; |
| 541 |
} |
| 542 |
|
| 543 |
let progressLen = nrOfWebsites; |
| 544 |
let title = MainWP.I18n.t("Updating WordPress"); |
| 545 |
|
| 546 |
|
| 547 |
if (updateEverything) { |
| 548 |
ugradingWebsiteAll = true; |
| 549 |
ugradingAllCurrentStep = 'wpcore'; // to get next step. |
| 550 |
title = MainWP.I18n.t("Updating everything: WordPress"); |
| 551 |
progressLen = nrOfWebsites * 4; // 4 looping on number of sites. |
| 552 |
} |
| 553 |
|
| 554 |
let siteNames = {}; |
| 555 |
|
| 556 |
for (let id of allWebsiteIds) { |
| 557 |
dashboard_update_site_status(id, '<i class="clock outline icon"></i> ' + MainWP.I18n.t('PENDING')); |
| 558 |
siteNames[id] = jQuery('.sync-site-status[siteid="' + id + '"]').attr('niceurl'); |
| 559 |
} |
| 560 |
|
| 561 |
managesitesContinueAfterBackup = function (sitesCount, pAllWebsiteIds) { |
| 562 |
return function () { |
| 563 |
mainwpPopup('#mainwp-sync-sites-modal').init({ |
| 564 |
title: title, |
| 565 |
progressMax: progressLen, |
| 566 |
totalSites: nrOfWebsites, |
| 567 |
allowMultiple: true, |
| 568 |
statusText: MainWP.I18n.t('updated'), |
| 569 |
callback: function () { |
| 570 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 571 |
}, |
| 572 |
}); |
| 573 |
managesites_wordpress_upgrade_all_int(pAllWebsiteIds); |
| 574 |
managesites_wordpress_upgrade_all_loop_next(); |
| 575 |
managesitesContinueAfterBackup = undefined; |
| 576 |
} |
| 577 |
|
| 578 |
}(nrOfWebsites, allWebsiteIds); |
| 579 |
mainwp_managesites_checkBackups(allWebsiteIds, siteNames); |
| 580 |
}; |
| 581 |
|
| 582 |
let managesites_wordpress_upgrade_all_int = function (websiteIds) { |
| 583 |
mainwpVars.websitesToUpgrade = websiteIds; |
| 584 |
mainwpVars.currentWebsite = 0; |
| 585 |
mainwpVars.websitesDone = 0; |
| 586 |
mainwpVars.websitesTotal = mainwpVars.websitesToUpgrade.length; |
| 587 |
mainwpVars.websitesLeft = mainwpVars.websitesToUpgrade.length; |
| 588 |
|
| 589 |
mainwpVars.bulkManageSitesTaskRunning = true; |
| 590 |
}; |
| 591 |
let managesites_wordpress_upgrade_all_loop_next = function () { |
| 592 |
while (mainwpVars.bulkManageSitesTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxThreads) && (mainwpVars.websitesLeft > 0)) { |
| 593 |
managesites_wordpress_upgrade_all_upgrade_next(); |
| 594 |
} |
| 595 |
}; |
| 596 |
let managesites_wordpress_upgrade_all_upgrade_next = function () { |
| 597 |
mainwpVars.currentThreads++; |
| 598 |
mainwpVars.websitesLeft--; |
| 599 |
const regression_waiting_icon = render_html_regression_waiting_icon(); |
| 600 |
let waiting_icon = '<i class="sync alternate loading icon"></i>'; |
| 601 |
if (regression_waiting_icon && "" !== regression_waiting_icon) { |
| 602 |
waiting_icon += regression_waiting_icon; |
| 603 |
} |
| 604 |
|
| 605 |
let websiteId = mainwpVars.websitesToUpgrade[mainwpVars.currentWebsite++]; |
| 606 |
dashboard_update_site_status(websiteId, waiting_icon); |
| 607 |
|
| 608 |
managesites_wordpress_upgrade_int(websiteId); |
| 609 |
}; |
| 610 |
let managesites_wordpress_upgrade_all_update_done = function () { |
| 611 |
mainwpVars.currentThreads--; |
| 612 |
if (!mainwpVars.bulkManageSitesTaskRunning) |
| 613 |
return; |
| 614 |
mainwpVars.websitesDone++; |
| 615 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 616 |
|
| 617 |
if (mainwpVars.websitesDone == mainwpVars.websitesTotal) { |
| 618 |
if (ugradingWebsiteAll) { |
| 619 |
// get next updating everything step. |
| 620 |
let nextStep = managesites_update_all_next_step(); |
| 621 |
let selectedIds = jQuery('#sync_selected_site_ids').val().split(','); |
| 622 |
setTimeout(function () { |
| 623 |
// start next update step. |
| 624 |
mainwp_update_pluginsthemes(nextStep, selectedIds); |
| 625 |
}, 1000); |
| 626 |
return; // do not close the popup. |
| 627 |
} |
| 628 |
|
| 629 |
setTimeout(function () { |
| 630 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 631 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 632 |
}, 3000); |
| 633 |
return; |
| 634 |
} |
| 635 |
|
| 636 |
managesites_wordpress_upgrade_all_loop_next(); |
| 637 |
}; |
| 638 |
|
| 639 |
let managesites_wordpress_upgrade_int = function (websiteId) { |
| 640 |
let data = mainwp_secure_data({ |
| 641 |
action: 'mainwp_upgradewp', |
| 642 |
id: websiteId |
| 643 |
}); |
| 644 |
jQuery.post(ajaxurl, data, function (pWebsiteId) { |
| 645 |
return function (response) { |
| 646 |
if (response.error) { |
| 647 |
websitesUpdateError++; |
| 648 |
let errIcon = '<i class="red times icon"></i>'; |
| 649 |
if (response?.error?.errorCode == 'SUSPENDED_SITE') { |
| 650 |
errIcon = '<span data-inverted="" data-position="left center" data-tooltip="' + MainWP.I18n.t('Suspended site.') + '"><i class="pause yellow icon"></i></span>'; |
| 651 |
} |
| 652 |
dashboard_update_site_status(pWebsiteId, errIcon + ' ' + mainwp_links_visit_site_and_admin('', websiteId), true); |
| 653 |
} else { |
| 654 |
dashboard_update_site_status(pWebsiteId, '<i class="green check icon"></i>' + ' ' + mainwp_links_visit_site_and_admin('', websiteId)); |
| 655 |
} |
| 656 |
|
| 657 |
managesites_wordpress_upgrade_all_update_done(); |
| 658 |
} |
| 659 |
}(websiteId), 'json'); |
| 660 |
|
| 661 |
return false; |
| 662 |
}; |
| 663 |
|
| 664 |
globalThis.mainwp_managesites_prepare_backup_popup = function (response, pSiteNames, siteFeedback) { |
| 665 |
let backupPrimary = ''; |
| 666 |
if (response['result']['primary_backup'] && response['result']['primary_backup'] != undefined) |
| 667 |
backupPrimary = response['result']['primary_backup']; |
| 668 |
|
| 669 |
if (backupPrimary == '') { |
| 670 |
jQuery('#managesites-backup-all').show(); |
| 671 |
jQuery('#managesites-backup-ignore').show(); |
| 672 |
} else { |
| 673 |
let backupLink = mainwp_get_primaryBackup_link(backupPrimary); |
| 674 |
jQuery('#managesites-backup-now').attr('href', backupLink).show(); |
| 675 |
jQuery('#managesites-backup-ignore').val(MainWP.I18n.t('Proceed with Updates')).show(); |
| 676 |
} |
| 677 |
|
| 678 |
let output = '<span class="mainwp-red">' + MainWP.I18n.t('A full backup has not been taken in the last days for the following sites:') + '</span><br /><br />'; |
| 679 |
if (backupPrimary == '') { // default backup feature |
| 680 |
for (let id of siteFeedback) { |
| 681 |
output += '<span class="managesites-backup-site" siteid="' + id + '">' + decodeURIComponent(pSiteNames[id]) + '</span><br />'; |
| 682 |
} |
| 683 |
} else { |
| 684 |
for (let id of siteFeedback) { |
| 685 |
output += '<span>' + decodeURIComponent(pSiteNames[id]) + '</span><br />'; |
| 686 |
} |
| 687 |
} |
| 688 |
mainwpPopup('#managesites-backup-box').getContentEl().html(output); |
| 689 |
} |
| 690 |
|