| 1 |
|
| 2 |
globalThis.mainwpVars = globalThis.mainwpVars || {}; |
| 3 |
|
| 4 |
// Trigger Manage Sites Bulk Actions |
| 5 |
jQuery(document).on('click', '#mainwp-do-sites-bulk-actions', function () { |
| 6 |
let action = jQuery("#mainwp-sites-bulk-actions-menu").dropdown("get value"); |
| 7 |
if (action) { |
| 8 |
mainwp_managesites_doaction(action); |
| 9 |
} |
| 10 |
return false; |
| 11 |
}); |
| 12 |
|
| 13 |
jQuery(document).on('click', '#mainwp-manage-sites-filter-toggle-button', function () { |
| 14 |
jQuery('#mainwp-sites-filters-row').toggle(300); |
| 15 |
return false; |
| 16 |
}); |
| 17 |
|
| 18 |
|
| 19 |
// Manage Sites Bulk Actions |
| 20 |
/* eslint-disable complexity */ |
| 21 |
let mainwp_managesites_doaction = function (action) { // NOSONAR - complex. |
| 22 |
|
| 23 |
if (action == 'delete' || action == 'test_connection' || action == 'sync' || action == 'reconnect' || action == 'update_plugins' || action == 'update_themes' || action == 'update_wpcore' || action == 'update_translations' || action == 'refresh_favico' || action == 'checknow' || action == 'update_everything' || action == 'check_abandoned_plugin' || action == 'check_abandoned_theme' || action == 'suspend' || action == 'unsuspend') { |
| 24 |
|
| 25 |
if (mainwpVars.bulkManageSitesTaskRunning) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
let confirmMsg = ''; |
| 30 |
let _selection_cancelled = false; |
| 31 |
|
| 32 |
if (action == 'delete' || action == 'update_plugins' || action == 'update_themes' || action == 'update_wpcore' || action == 'update_translations' || action == 'update_everything' || action == 'check_abandoned_plugin' || action == 'check_abandoned_theme' || action == 'suspend') { |
| 33 |
|
| 34 |
switch (action) { |
| 35 |
case 'delete': |
| 36 |
confirmMsg = MainWP.I18n.t("You are about to remove the selected sites from your MainWP Dashboard?"); |
| 37 |
break; |
| 38 |
case 'update_plugins': |
| 39 |
confirmMsg = MainWP.I18n.t("You are about to update plugins on the selected sites?"); |
| 40 |
_selection_cancelled = true; |
| 41 |
break; |
| 42 |
case 'update_themes': |
| 43 |
confirmMsg = MainWP.I18n.t("You are about to update themes on the selected sites?"); |
| 44 |
_selection_cancelled = true; |
| 45 |
break; |
| 46 |
case 'update_wpcore': |
| 47 |
confirmMsg = MainWP.I18n.t("You are about to update WordPress core files on the selected sites?"); |
| 48 |
_selection_cancelled = true; |
| 49 |
break; |
| 50 |
case 'update_translations': |
| 51 |
confirmMsg = MainWP.I18n.t("You are about to update translations on the selected sites?"); |
| 52 |
_selection_cancelled = true; |
| 53 |
break; |
| 54 |
case 'update_everything': |
| 55 |
confirmMsg = MainWP.I18n.t("You are about to update everything on the selected sites?"); |
| 56 |
_selection_cancelled = true; |
| 57 |
break; |
| 58 |
case 'check_abandoned_plugin': |
| 59 |
confirmMsg = MainWP.I18n.t("You are about to check abandoned plugin on the selected sites?"); |
| 60 |
_selection_cancelled = true; |
| 61 |
break; |
| 62 |
case 'check_abandoned_theme': |
| 63 |
confirmMsg = MainWP.I18n.t("You are about to check abandoned theme on the selected sites?"); |
| 64 |
_selection_cancelled = true; |
| 65 |
break; |
| 66 |
case 'suspend': |
| 67 |
confirmMsg = MainWP.I18n.t("You are about to suspend the selected sites?"); |
| 68 |
_selection_cancelled = true; |
| 69 |
break; |
| 70 |
} |
| 71 |
|
| 72 |
if (confirmMsg == '') { |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
let _cancelled_callback = null; |
| 77 |
if (_selection_cancelled) { |
| 78 |
_cancelled_callback = function () { |
| 79 |
jQuery('#mainwp-sites-bulk-actions-menu').dropdown("set selected", "sync"); |
| 80 |
}; |
| 81 |
} |
| 82 |
|
| 83 |
let updateType; // undefined |
| 84 |
|
| 85 |
if (action == 'update_plugins' || action == 'update_themes' || action == 'update_translations' || action == 'update_everything') { |
| 86 |
updateType = 2; // multi update |
| 87 |
} |
| 88 |
|
| 89 |
mainwp_confirm(confirmMsg, function () { mainwp_managesites_doaction_process(action); }, _cancelled_callback, updateType); |
| 90 |
|
| 91 |
return; // return those case |
| 92 |
} |
| 93 |
mainwp_managesites_doaction_process(action); // other case callback |
| 94 |
} |
| 95 |
|
| 96 |
mainwp_managesites_doaction_open(action); |
| 97 |
|
| 98 |
}; |
| 99 |
/* eslint-enable complexity */ |
| 100 |
|
| 101 |
let mainwp_managesites_doaction_open = function (action) { |
| 102 |
jQuery('#mainwp-manage-sites-body-table .check-column INPUT:checkbox:checked').each(function () { |
| 103 |
let row = jQuery(this).closest('tr'); |
| 104 |
let url = ''; |
| 105 |
if (action === 'open_wpadmin') { |
| 106 |
url = row.find('a.open_newwindow_wpadmin').attr('href'); |
| 107 |
window.open(url, '_blank'); |
| 108 |
} else if (action === 'open_frontpage') { |
| 109 |
url = row.find('a.open_site_url').attr('href'); |
| 110 |
window.open(url, '_blank'); |
| 111 |
} |
| 112 |
}); |
| 113 |
} |
| 114 |
|
| 115 |
globalThis.managesites_reset_bulk_actions_params = function () { |
| 116 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 117 |
mainwpVars.bulkManageSitesCurrentThreads = 0; |
| 118 |
mainwpVars.bulkManageSitesFinished = 0; |
| 119 |
mainwpVars.bulkManageSitesTotal = 0; |
| 120 |
}; |
| 121 |
|
| 122 |
let mainwp_managesites_doaction_process = function (action) { |
| 123 |
|
| 124 |
managesites_bulk_init(false); |
| 125 |
|
| 126 |
bulkManageSitesTotal = jQuery('#mainwp-manage-sites-body-table .check-column INPUT:checkbox:checked[status="queue"]').length; |
| 127 |
mainwpVars.bulkManageSitesTaskRunning = true; |
| 128 |
|
| 129 |
let selectedIds = jQuery.map(jQuery('#mainwp-manage-sites-body-table .check-column INPUT:checkbox:checked'), function (el) { |
| 130 |
return jQuery(el).val(); |
| 131 |
}); |
| 132 |
|
| 133 |
|
| 134 |
if (action == 'delete') { |
| 135 |
mainwp_managesites_bulk_remove_next(); |
| 136 |
return false; |
| 137 |
} else if (action == 'sync') { |
| 138 |
mainwp_sync_sites_data(selectedIds); |
| 139 |
} else if (action == 'reconnect') { |
| 140 |
mainwp_managesites_bulk_reconnect_next(); |
| 141 |
} else if (action == 'update_plugins') { |
| 142 |
mainwp_update_pluginsthemes('plugin', selectedIds); |
| 143 |
} else if (action == 'update_themes') { |
| 144 |
mainwp_update_pluginsthemes('theme', selectedIds); |
| 145 |
} else if (action == 'update_wpcore') { |
| 146 |
managesites_wordpress_global_upgrade_all(selectedIds, false); |
| 147 |
} else if (action == 'update_translations') { |
| 148 |
mainwp_update_pluginsthemes('translation', selectedIds); |
| 149 |
} else if (action == 'update_everything') { |
| 150 |
jQuery('#sync_selected_site_ids').val(selectedIds.join(',')); |
| 151 |
managesites_wordpress_global_upgrade_all(selectedIds, true); // Update everything, start update wpcore first. |
| 152 |
} else if (action == 'refresh_favico') { |
| 153 |
mainwp_managesites_bulk_refresh_favico(selectedIds); |
| 154 |
} else if (action == 'checknow') { |
| 155 |
mainwp_sync_sites_data(selectedIds, 'checknow'); |
| 156 |
} else if (action == 'check_abandoned_plugin') { |
| 157 |
mainwp_managesites_bulk_check_abandoned(selectedIds, 'plugin'); |
| 158 |
} else if (action == 'check_abandoned_theme') { |
| 159 |
mainwp_managesites_bulk_check_abandoned(selectedIds, 'theme'); |
| 160 |
} else if (action == 'suspend' || action == 'unsuspend') { |
| 161 |
mainwp_managesites_bulk_suspend_status(selectedIds, action); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
jQuery(document).on('click', '.managesites_syncdata', function () { |
| 167 |
let syncIds = []; |
| 168 |
let row = jQuery(this).closest('tr'); |
| 169 |
let sid = 0; |
| 170 |
if (jQuery(row).hasClass('child')) { |
| 171 |
row = jQuery(row).prev(); |
| 172 |
sid = row.attr('siteid'); |
| 173 |
} else { |
| 174 |
sid = row.attr('siteid'); |
| 175 |
} |
| 176 |
if (sid) { |
| 177 |
syncIds.push(row.attr('siteid')); |
| 178 |
} |
| 179 |
mainwp_sync_sites_data(syncIds); |
| 180 |
return false; |
| 181 |
}); |
| 182 |
|
| 183 |
jQuery(document).on('click', '.managesites_checknow', function () { |
| 184 |
let row = jQuery(this).closest('.menu'); |
| 185 |
let syncIds = []; |
| 186 |
syncIds.push(row.attr('siteid')); |
| 187 |
mainwp_sync_sites_data(syncIds, 'checknow'); |
| 188 |
return false; |
| 189 |
}); |
| 190 |
|
| 191 |
jQuery(document).on('change', '#mainwp-add-new-button', function () { |
| 192 |
let url = jQuery('#mainwp-add-new-button :selected').attr('item-url'); |
| 193 |
if ( url !== undefined && url != '') |
| 194 |
mainwp_forceReload(url); |
| 195 |
return false; |
| 196 |
}); |
| 197 |
|
| 198 |
let mainwp_managesites_bulk_reconnect_next = function () { |
| 199 |
while ((checkedBox = jQuery('#mainwp-manage-sites-body-table .check-column INPUT:checkbox:checked[status="queue"]:first')) && (checkedBox.length > 0) && (bulkManageSitesCurrentThreads < bulkManageSitesMaxThreads)) { // NOSONAR -- modified out side the function. |
| 200 |
mainwp_managesites_bulk_reconnect_specific(checkedBox); |
| 201 |
} |
| 202 |
if ((bulkManageSitesTotal > 0) && (bulkManageSitesFinished == bulkManageSitesTotal)) { |
| 203 |
setHtml('#mainwp-message-zone', MainWP.I18n.t("Process completed. Reloading page...")); |
| 204 |
setTimeout(function () { |
| 205 |
mainwp_forceReload(); |
| 206 |
}, 3000); |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
let mainwp_managesites_bulk_reconnect_specific = function (pCheckedBox) { |
| 211 |
|
| 212 |
pCheckedBox.attr('status', 'running'); |
| 213 |
let rowObj = pCheckedBox.closest('tr'); |
| 214 |
let siteUrl = rowObj.attr('site-url'); |
| 215 |
let siteId = rowObj.attr('siteid'); |
| 216 |
|
| 217 |
// skip reconnect sites without sync error |
| 218 |
if ( ! ( rowObj.hasClass('child-site') && rowObj.hasClass('error') ) ) { |
| 219 |
bulkManageSitesFinished++; |
| 220 |
mainwp_managesites_bulk_reconnect_next(); |
| 221 |
return; |
| 222 |
} |
| 223 |
|
| 224 |
bulkManageSitesCurrentThreads++; |
| 225 |
|
| 226 |
|
| 227 |
rowObj.html('<td colspan="999"><i class="notched circle loading icon"></i> ' + 'Trying to reconnect. Please wait...' + '</td>'); |
| 228 |
|
| 229 |
let data = mainwp_secure_data({ |
| 230 |
action: 'mainwp_reconnectwp', |
| 231 |
siteid: siteId |
| 232 |
}); |
| 233 |
|
| 234 |
jQuery.post(ajaxurl, data, function (response) { |
| 235 |
bulkManageSitesCurrentThreads--; |
| 236 |
bulkManageSitesFinished++; |
| 237 |
rowObj.html('<td colspan="999"></td>'); |
| 238 |
|
| 239 |
response = response.trim(); |
| 240 |
let msg = '', error = ''; |
| 241 |
if (response.substring(0, 5) == 'ERROR') { |
| 242 |
if (response.length == 5) { |
| 243 |
error = MainWP.I18n.t('Undefined error occurred. Please try again.'); |
| 244 |
error = siteUrl + ' - ' + error; |
| 245 |
} else { |
| 246 |
error = response.substring(6); |
| 247 |
let err = mainwp_js_get_error_not_detected_connect(error, 'html_msg', false, true); |
| 248 |
if (true !== err && '' != err) { |
| 249 |
error = err; // decoded error. |
| 250 |
} |
| 251 |
} |
| 252 |
} else { |
| 253 |
msg = siteUrl + ' - ' + mainwp_get_reconnect_error(response, siteId); |
| 254 |
} |
| 255 |
|
| 256 |
if (msg != '') { |
| 257 |
rowObj.removeClass('error'); |
| 258 |
rowObj.addClass('positive'); |
| 259 |
rowObj.html('<td colspan="999"><i class="green check icon"></i>' + msg + '</td>'); |
| 260 |
} else if (error != '') { |
| 261 |
rowObj.html('<td colspan="999"><i class="red times icon"></i>' + error + '</td>'); |
| 262 |
} |
| 263 |
mainwp_managesites_bulk_reconnect_next(); |
| 264 |
}); |
| 265 |
}; |
| 266 |
|
| 267 |
|
| 268 |
let mainwp_managesites_bulk_remove_next = function () { |
| 269 |
while ((checkedBox = jQuery('#mainwp-manage-sites-body-table .check-column INPUT:checkbox:checked[status="queue"]:first')) && (checkedBox.length > 0) && (bulkManageSitesCurrentThreads < bulkManageSitesMaxThreads)) { // NOSONAR -- modified out side the function. |
| 270 |
mainwp_managesites_bulk_remove_specific(checkedBox); |
| 271 |
} |
| 272 |
if ((bulkManageSitesTotal > 0) && (bulkManageSitesFinished == bulkManageSitesTotal)) { // NOSONAR - modified outside the function. |
| 273 |
setHtml('#mainwp-message-zone', MainWP.I18n.t("Process completed. Reloading page...")); |
| 274 |
setTimeout(function () { |
| 275 |
mainwp_forceReload(); |
| 276 |
}, 3000); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
let mainwp_managesites_bulk_remove_specific = function (pCheckedBox) { |
| 281 |
pCheckedBox.attr('status', 'running'); |
| 282 |
let rowObj = pCheckedBox.closest('tr'); |
| 283 |
bulkManageSitesCurrentThreads++; |
| 284 |
|
| 285 |
let id = rowObj.attr('siteid'); |
| 286 |
|
| 287 |
rowObj.html('<td colspan="999"><i class="notched circle loading icon"></i> ' + 'Removing and deactivating the MainWP Child plugin...' + '</td>'); |
| 288 |
|
| 289 |
let data = mainwp_secure_data({ |
| 290 |
action: 'mainwp_removesite', |
| 291 |
id: id |
| 292 |
}); |
| 293 |
jQuery.post(ajaxurl, data, function (response) { |
| 294 |
bulkManageSitesCurrentThreads--; |
| 295 |
bulkManageSitesFinished++; |
| 296 |
rowObj.html('<td colspan="999"></td>'); |
| 297 |
let result = ''; |
| 298 |
let error = ''; |
| 299 |
if (response.error != undefined) { |
| 300 |
error = response.error; |
| 301 |
} else if (response.result == 'SUCCESS') { |
| 302 |
result = MainWP.I18n.t('The site has been removed and the MainWP Child plugin has been disabled.'); |
| 303 |
} else if (response.result == 'NOSITE') { |
| 304 |
error = MainWP.I18n.t('Site not found. Please try again.'); |
| 305 |
} else { |
| 306 |
result = MainWP.I18n.t('The site has been removed but the MainWP Child plugin could not be disabled.'); |
| 307 |
} |
| 308 |
|
| 309 |
if (error != '') { |
| 310 |
rowObj.html('<td colspan="999"><i class="red times icon"></i>' + error + '</td>'); |
| 311 |
} |
| 312 |
|
| 313 |
rowObj.html('<td colspan="999"><i class="green check icon"></i>' + result + '</td>'); |
| 314 |
setTimeout(function () { |
| 315 |
jQuery('tr[siteid=' + id + ']').fadeOut(1000); |
| 316 |
}, 3000); |
| 317 |
|
| 318 |
mainwp_managesites_bulk_remove_next(); |
| 319 |
}, 'json'); |
| 320 |
}; |
| 321 |
|
| 322 |
|
| 323 |
let bulkManageSitesMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests']; |
| 324 |
let bulkManageSitesCurrentThreads = 0; |
| 325 |
let bulkManageSitesTotal = 0; |
| 326 |
let bulkManageSitesFinished = 0; |
| 327 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 328 |
|
| 329 |
|
| 330 |
let managesites_bulk_init = function (isMonitorsBulk) { |
| 331 |
mainwp_set_message_zone('#mainwp-message-zone-client'); |
| 332 |
if (!mainwpVars.bulkManageSitesTaskRunning) { |
| 333 |
bulkManageSitesCurrentThreads = 0; |
| 334 |
bulkManageSitesTotal = 0; |
| 335 |
bulkManageSitesFinished = 0; |
| 336 |
|
| 337 |
if (isMonitorsBulk) { |
| 338 |
bulkManageSitesMaxThreads = mainwpParams?.maximumUptimeMonitoringRequests ? mainwpParams.maximumUptimeMonitoringRequests : 10; |
| 339 |
jQuery('#mainwp-manage-sites-body-table .check-column INPUT:checkbox:not(.sub-pages-checkbox)').each(function () { |
| 340 |
jQuery(this).attr('status', 'queue') |
| 341 |
}); |
| 342 |
} else { |
| 343 |
bulkManageSitesMaxThreads = mainwpParams['maximumInstallUpdateRequests'] == undefined ? 3 : mainwpParams['maximumInstallUpdateRequests']; |
| 344 |
jQuery('#mainwp-manage-sites-body-table .check-column INPUT:checkbox').each(function () { |
| 345 |
jQuery(this).attr('status', 'queue') |
| 346 |
}); |
| 347 |
} |
| 348 |
|
| 349 |
} |
| 350 |
}; |
| 351 |
|
| 352 |
|
| 353 |
let mainwp_managesites_bulk_refresh_favico = function (siteIds) { |
| 354 |
let allWebsiteIds = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { |
| 355 |
return jQuery(el).val(); |
| 356 |
}); |
| 357 |
|
| 358 |
let selectedIds = [], excludeIds = []; |
| 359 |
if (Array.isArray(siteIds)) { |
| 360 |
jQuery.grep(allWebsiteIds, function (el) { |
| 361 |
if (jQuery.inArray(el, siteIds) > -1) { |
| 362 |
selectedIds.push(el); |
| 363 |
} else { |
| 364 |
excludeIds.push(el); |
| 365 |
} |
| 366 |
}); |
| 367 |
for (let id of excludeIds) { |
| 368 |
dashboard_update_site_hide(id); |
| 369 |
} |
| 370 |
allWebsiteIds = selectedIds; |
| 371 |
} |
| 372 |
|
| 373 |
let nrOfWebsites = allWebsiteIds.length; |
| 374 |
|
| 375 |
if (nrOfWebsites == 0) { |
| 376 |
managesites_reset_bulk_actions_params(); |
| 377 |
return; |
| 378 |
} |
| 379 |
|
| 380 |
let siteNames = {}; |
| 381 |
|
| 382 |
for (let id of allWebsiteIds) { |
| 383 |
dashboard_update_site_status(id, '<i class="clock outline icon"></i>'); |
| 384 |
siteNames[id] = jQuery('.sync-site-status[siteid="' + id + '"]').attr('niceurl'); |
| 385 |
} |
| 386 |
let initData = { |
| 387 |
progressMax: nrOfWebsites, |
| 388 |
title: 'Refresh Favicon', |
| 389 |
statusText: MainWP.I18n.t('updated'), |
| 390 |
callback: function () { |
| 391 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 392 |
mainwp_forceReload(); |
| 393 |
} |
| 394 |
}; |
| 395 |
mainwpPopup('#mainwp-sync-sites-modal').init(initData); |
| 396 |
|
| 397 |
mainwp_managesites_refresh_favico_all_int(allWebsiteIds); |
| 398 |
}; |
| 399 |
|
| 400 |
let mainwp_managesites_refresh_favico_all_int = function (websiteIds) { |
| 401 |
mainwpVars.websitesToUpgrade = websiteIds; |
| 402 |
mainwpVars.currentWebsite = 0; |
| 403 |
mainwpVars.websitesDone = 0; |
| 404 |
mainwpVars.websitesTotal = mainwpVars.websitesToUpgrade.length; |
| 405 |
mainwpVars.websitesLeft = mainwpVars.websitesToUpgrade.length; |
| 406 |
|
| 407 |
mainwpVars.bulkTaskRunning = true; |
| 408 |
mainwp_managesites_refresh_favico_all_loop_next(); |
| 409 |
}; |
| 410 |
|
| 411 |
let mainwp_managesites_refresh_favico_all_loop_next = function () { |
| 412 |
while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxThreads) && (mainwpVars.websitesLeft > 0)) { |
| 413 |
mainwp_managesites_refresh_favico_all_upgrade_next(); |
| 414 |
} |
| 415 |
}; |
| 416 |
|
| 417 |
let mainwp_managesites_refresh_favico_all_upgrade_next = function () { |
| 418 |
mainwpVars.currentThreads++; |
| 419 |
mainwpVars.websitesLeft--; |
| 420 |
|
| 421 |
let websiteId = mainwpVars.websitesToUpgrade[mainwpVars.currentWebsite++]; |
| 422 |
dashboard_update_site_status(websiteId, '<i class="sync alternate loading icon"></i>'); |
| 423 |
|
| 424 |
mainwp_managesites_refresh_favico_int(websiteId); |
| 425 |
}; |
| 426 |
|
| 427 |
let mainwp_managesites_refresh_favico_int = function (siteid) { |
| 428 |
|
| 429 |
let data = mainwp_secure_data({ |
| 430 |
action: 'mainwp_get_site_icon', |
| 431 |
siteId: siteid |
| 432 |
}); |
| 433 |
|
| 434 |
jQuery.ajax({ |
| 435 |
type: 'POST', |
| 436 |
url: ajaxurl, |
| 437 |
data: data, |
| 438 |
success: function (pSiteid) { |
| 439 |
return function (response) { |
| 440 |
mainwpVars.currentThreads--; |
| 441 |
mainwpVars.websitesDone++; |
| 442 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 443 |
if (response.error != undefined) { |
| 444 |
dashboard_update_site_status(pSiteid, '<i class="red times icon"></i>'); |
| 445 |
} else if (response.result && response.result == 'success') { |
| 446 |
dashboard_update_site_status(pSiteid, '<i class="green check icon"></i>', true); |
| 447 |
} else { |
| 448 |
dashboard_update_site_status(pSiteid, '<i class="red times icon"></i>'); |
| 449 |
} |
| 450 |
mainwp_managesites_refresh_favico_all_loop_next(); |
| 451 |
} |
| 452 |
}(siteid), |
| 453 |
dataType: 'json' |
| 454 |
}); |
| 455 |
return false; |
| 456 |
}; |
| 457 |
|
| 458 |
|
| 459 |
/* Suspend sites */ |
| 460 |
let mainwp_managesites_bulk_suspend_status = function (siteIds, status) { |
| 461 |
|
| 462 |
let allWebsiteIds = jQuery('.dashboard_wp_id[error-status=0]').map(function (indx, el) { |
| 463 |
return jQuery(el).val(); |
| 464 |
}); |
| 465 |
let selectedIds = [], excludeIds = []; |
| 466 |
if (Array.isArray(siteIds)) { |
| 467 |
jQuery.grep(allWebsiteIds, function (el) { |
| 468 |
if (jQuery.inArray(el, siteIds) > -1) { |
| 469 |
selectedIds.push(el); |
| 470 |
} else { |
| 471 |
excludeIds.push(el); |
| 472 |
} |
| 473 |
}); |
| 474 |
for (let id of excludeIds) { |
| 475 |
dashboard_update_site_hide(id); |
| 476 |
} |
| 477 |
allWebsiteIds = selectedIds; |
| 478 |
} |
| 479 |
|
| 480 |
let nrOfWebsites = allWebsiteIds.length; |
| 481 |
|
| 482 |
if (nrOfWebsites == 0) { |
| 483 |
managesites_reset_bulk_actions_params(); |
| 484 |
return; |
| 485 |
} |
| 486 |
|
| 487 |
let siteNames = {}; |
| 488 |
|
| 489 |
for (let id of allWebsiteIds) { |
| 490 |
dashboard_update_site_status(id, '<i class="clock outline icon"></i>'); |
| 491 |
siteNames[id] = jQuery('.sync-site-status[siteid="' + id + '"]').attr('niceurl'); |
| 492 |
} |
| 493 |
let initData = { |
| 494 |
progressMax: nrOfWebsites, |
| 495 |
title: 'Suspend Site', |
| 496 |
statusText: MainWP.I18n.t('suspended'), |
| 497 |
callback: function () { |
| 498 |
mainwpVars.bulkManageSitesTaskRunning = false; |
| 499 |
mainwp_forceReload(); |
| 500 |
} |
| 501 |
}; |
| 502 |
mainwpPopup('#mainwp-sync-sites-modal').init(initData); |
| 503 |
|
| 504 |
mainwp_managesites_suspend_status_all_int(allWebsiteIds, status); |
| 505 |
}; |
| 506 |
|
| 507 |
let mainwp_managesites_suspend_status_all_int = function (websiteIds, status) { |
| 508 |
mainwpVars.websitesToUpgrade = websiteIds; |
| 509 |
mainwpVars.currentWebsite = 0; |
| 510 |
mainwpVars.websitesDone = 0; |
| 511 |
mainwpVars.websitesTotal = mainwpVars.websitesToUpgrade.length; |
| 512 |
mainwpVars.websitesLeft = mainwpVars.websitesToUpgrade.length; |
| 513 |
|
| 514 |
mainwpVars.bulkTaskRunning = true; |
| 515 |
mainwp_managesites_suspend_status_all_loop_next(status); |
| 516 |
}; |
| 517 |
|
| 518 |
let mainwp_managesites_suspend_status_all_loop_next = function (status) { |
| 519 |
while (mainwpVars.bulkTaskRunning && (mainwpVars.currentThreads < mainwpVars.maxThreads) && (mainwpVars.websitesLeft > 0)) { |
| 520 |
mainwp_managesites_suspend_status_all_upgrade_next(status); |
| 521 |
} |
| 522 |
}; |
| 523 |
let mainwp_managesites_suspend_status_all_upgrade_next = function (status) { |
| 524 |
mainwpVars.currentThreads++; |
| 525 |
mainwpVars.websitesLeft--; |
| 526 |
|
| 527 |
let websiteId = mainwpVars.websitesToUpgrade[mainwpVars.currentWebsite++]; |
| 528 |
dashboard_update_site_status(websiteId, '<i class="sync alternate loading icon"></i>'); |
| 529 |
|
| 530 |
mainwp_managesites_suspend_status_int(websiteId, status); |
| 531 |
}; |
| 532 |
|
| 533 |
let mainwp_managesites_suspend_status_int = function (siteid, status) { |
| 534 |
let data = mainwp_secure_data({ |
| 535 |
action: 'mainwp_manage_sites_suspend_site', |
| 536 |
suspended: (status == 'suspend') ? 1 : 0, |
| 537 |
siteid: siteid, |
| 538 |
}); |
| 539 |
|
| 540 |
jQuery.ajax({ |
| 541 |
type: 'POST', |
| 542 |
url: ajaxurl, |
| 543 |
data: data, |
| 544 |
success: function (pSiteid) { |
| 545 |
return function (response) { |
| 546 |
mainwpVars.currentThreads--; |
| 547 |
mainwpVars.websitesDone++; |
| 548 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(mainwpVars.websitesDone); |
| 549 |
if (response.error != undefined) { |
| 550 |
dashboard_update_site_status(pSiteid, '<span data-inverted="" data-position="left center" data-tooltip="' + response.error + '"><i class="times red icon"></i></span>'); |
| 551 |
} else if (response.result && response.result == 'success') { |
| 552 |
dashboard_update_site_status(pSiteid, '<i class="green check icon"></i>', true); |
| 553 |
} else { |
| 554 |
dashboard_update_site_status(pSiteid, '<i class="red times icon"></i>'); |
| 555 |
} |
| 556 |
mainwp_managesites_suspend_status_all_loop_next(status); |
| 557 |
} |
| 558 |
}(siteid), |
| 559 |
dataType: 'json' |
| 560 |
}); |
| 561 |
return false; |
| 562 |
}; |
| 563 |
|