| 1 |
/* eslint complexity: ["error", 100] */ |
| 2 |
// current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 3 |
|
| 4 |
// Init Per Group data |
| 5 |
updatesoverview_updates_init_group_view = function () { |
| 6 |
jQuery('.element_ui_view_values').each(function () { |
| 7 |
var parent = jQuery(this).parent(); |
| 8 |
var uid = jQuery(this).attr('elem-uid'); |
| 9 |
var total = jQuery(this).attr('total'); |
| 10 |
var can_update = jQuery(this).attr('can-update'); |
| 11 |
|
| 12 |
if (total == 0) { |
| 13 |
// carefully remove this, or it will causing error with display or according sorting |
| 14 |
jQuery(parent).find("[row-uid='" + uid + "']").next().remove(); // remove content according part |
| 15 |
jQuery(parent).find("[row-uid='" + uid + "']").remove(); // remove title according part |
| 16 |
} else { |
| 17 |
jQuery(parent).find("[total-uid='" + uid + "']").html(total + ' ' + (total == 1 ? __('Update') : __('Updates'))); |
| 18 |
jQuery(parent).find("[total-uid='" + uid + "']").attr('sort-value', total); |
| 19 |
} |
| 20 |
|
| 21 |
if (can_update) { |
| 22 |
jQuery(parent).find("[btn-all-uid='" + uid + "']").text(total == 1 ? __('Update') : __('Update All')).show(); |
| 23 |
} |
| 24 |
}); |
| 25 |
} |
| 26 |
|
| 27 |
// Update individual WP |
| 28 |
updatesoverview_upgrade = function (id, obj) { |
| 29 |
|
| 30 |
var parent = jQuery(obj).closest('.mainwp-wordpress-update'); |
| 31 |
var upgradeElement = jQuery(parent).find('#wp-updated-' + id); |
| 32 |
|
| 33 |
if (upgradeElement.val() != 0) |
| 34 |
return false; |
| 35 |
|
| 36 |
|
| 37 |
updatesoverviewContinueAfterBackup = function (pId, pUpgradeElement) { |
| 38 |
return function () { |
| 39 |
jQuery('.mainwp-wordpress-update[site_id="' + pId + '"] > td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Updating...', 'mainwp') + '"><i class="notched circle loading icon"></i></span> ' + __('Updating. Please wait...')); |
| 40 |
pUpgradeElement.val(1); |
| 41 |
var data = mainwp_secure_data({ |
| 42 |
action: 'mainwp_upgradewp', |
| 43 |
id: pId |
| 44 |
}); |
| 45 |
|
| 46 |
jQuery.post(ajaxurl, data, function (response) { |
| 47 |
if (response.error) { |
| 48 |
var err_msg = ''; |
| 49 |
if (response.error.extra) { |
| 50 |
err_msg = response.error.extra + ' '; |
| 51 |
} |
| 52 |
jQuery('.mainwp-wordpress-update[site_id="' + pId + '"] > td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + err_msg + '"><i class="red times icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', pId)); |
| 53 |
} else { |
| 54 |
jQuery('.mainwp-wordpress-update[site_id="' + pId + '"] > td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', pId)); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
}, 'json'); |
| 59 |
} |
| 60 |
}(id, upgradeElement); |
| 61 |
|
| 62 |
var sitesToUpdate = [id]; |
| 63 |
var siteNames = []; |
| 64 |
|
| 65 |
siteNames[id] = jQuery('.mainwp-wordpress-update[site_id="' + id + '"]').attr('site_name'); |
| 66 |
|
| 67 |
var msg = __('Are you sure you want to update the Wordpress core files on the selected site?'); |
| 68 |
mainwp_confirm(msg, function () { |
| 69 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 70 |
}, false, 1); |
| 71 |
}; |
| 72 |
|
| 73 |
/** Update bulk **/ |
| 74 |
|
| 75 |
var websitesToUpgrade = []; |
| 76 |
var updatesoverviewContinueAfterBackup = undefined; |
| 77 |
var limitUpdateAll = 0; |
| 78 |
var continueUpdatesAll = '', continueUpdatesSlug = ''; |
| 79 |
var continueUpdating = false; |
| 80 |
|
| 81 |
updatesoverview_update_popup_init = function (data) { |
| 82 |
data = data || {}; |
| 83 |
data.callback = function () { |
| 84 |
bulkTaskRunning = false; |
| 85 |
window.location.href = location.href; |
| 86 |
}; |
| 87 |
data.statusText = __('updated'); |
| 88 |
mainwpPopup('#mainwp-sync-sites-modal').init(data); |
| 89 |
} |
| 90 |
|
| 91 |
// Update Group |
| 92 |
updatesoverview_wordpress_global_upgrade_all = function (groupId, updatesSelected) { |
| 93 |
if (bulkTaskRunning) |
| 94 |
return false; |
| 95 |
|
| 96 |
//Step 1: build form |
| 97 |
var sitesToUpdate = []; |
| 98 |
var siteNames = {}; |
| 99 |
var foundChildren = []; |
| 100 |
|
| 101 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 102 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 103 |
jQuery('#update_wrapper_wp_upgrades_group_' + groupId).find('tr.mainwp-wordpress-update[updated="0"]').each( |
| 104 |
function () { |
| 105 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 106 |
foundChildren.push(this); |
| 107 |
} |
| 108 |
} |
| 109 |
); |
| 110 |
} else { |
| 111 |
jQuery('tr.mainwp-wordpress-update[updated="0"]').each( |
| 112 |
function () { |
| 113 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 114 |
foundChildren.push(this); |
| 115 |
} |
| 116 |
} |
| 117 |
); |
| 118 |
} |
| 119 |
if (foundChildren.length == 0) { |
| 120 |
updates_please_select_items_notice(); |
| 121 |
return false; |
| 122 |
} |
| 123 |
} else { |
| 124 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 125 |
// groups selector is only one for each screen. |
| 126 |
foundChildren = jQuery('#update_wrapper_wp_upgrades_group_' + groupId).find('tr.mainwp-wordpress-update[updated="0"]'); |
| 127 |
} else { |
| 128 |
// childs selector is only one for each screen. |
| 129 |
foundChildren = jQuery('tr.mainwp-wordpress-update[updated="0"]'); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if (foundChildren.length == 0) |
| 134 |
return false; |
| 135 |
|
| 136 |
var sitesCount = 0; |
| 137 |
|
| 138 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 139 |
|
| 140 |
for (var i = 0; i < foundChildren.length; i++) { |
| 141 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && typeof groupId === 'undefined') { |
| 142 |
continueUpdatesAll = 'wpcore_global_upgrade_all'; |
| 143 |
break; |
| 144 |
} |
| 145 |
|
| 146 |
var child = foundChildren[i]; |
| 147 |
var siteId = jQuery(child).attr('site_id'); |
| 148 |
var siteName = jQuery(child).attr('site_name'); |
| 149 |
|
| 150 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 151 |
sitesCount++; |
| 152 |
sitesToUpdate.push(siteId); |
| 153 |
siteNames[siteId] = siteName; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
var _callback = function () { |
| 158 |
|
| 159 |
for (var j = 0; j < sitesToUpdate.length; j++) { |
| 160 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteNames[sitesToUpdate[j]]) + ' (WordPress update)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + sitesToUpdate[j] + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 161 |
} |
| 162 |
|
| 163 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate) { |
| 164 |
return function () { |
| 165 |
var initData = { |
| 166 |
title: __('Updating All'), |
| 167 |
progressMax: pSitesCount, |
| 168 |
}; |
| 169 |
|
| 170 |
updatesoverview_update_popup_init(initData); |
| 171 |
//Step 3: start updates |
| 172 |
updatesoverview_wordpress_upgrade_all_int(pSitesToUpdate); |
| 173 |
|
| 174 |
updatesoverviewContinueAfterBackup = undefined; |
| 175 |
} |
| 176 |
}(sitesCount, sitesToUpdate); |
| 177 |
|
| 178 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 179 |
}; |
| 180 |
|
| 181 |
// new confirm message |
| 182 |
if (!continueUpdating) { |
| 183 |
if (jQuery(siteNames).length > 0) { |
| 184 |
var sitesList = []; |
| 185 |
jQuery.each(siteNames, function (index, value) { |
| 186 |
if (value) { // to fix |
| 187 |
sitesList.push(decodeURIComponent(value)); |
| 188 |
} |
| 189 |
}); |
| 190 |
var confirmMsg = __('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>', __('WordPress Core'), sitesList.join('<br />')); |
| 191 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 192 |
} |
| 193 |
return false; |
| 194 |
} |
| 195 |
_callback(); |
| 196 |
return false; |
| 197 |
}; |
| 198 |
|
| 199 |
updatesoverview_wordpress_upgrade_all_int = function (websiteIds) { |
| 200 |
websitesToUpgrade = websiteIds; |
| 201 |
currentWebsite = 0; |
| 202 |
websitesDone = 0; |
| 203 |
websitesTotal = websitesLeft = websitesToUpgrade.length; |
| 204 |
|
| 205 |
bulkTaskRunning = true; |
| 206 |
updatesoverview_wordpress_upgrade_all_loop_next(); |
| 207 |
}; |
| 208 |
updatesoverview_wordpress_upgrade_all_loop_next = function () { |
| 209 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 210 |
updatesoverview_wordpress_upgrade_all_upgrade_next(); |
| 211 |
} |
| 212 |
}; |
| 213 |
updatesoverview_wordpress_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 214 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 215 |
}; |
| 216 |
updatesoverview_wordpress_upgrade_all_upgrade_next = function () { |
| 217 |
currentThreads++; |
| 218 |
websitesLeft--; |
| 219 |
|
| 220 |
var websiteId = websitesToUpgrade[currentWebsite++]; |
| 221 |
updatesoverview_wordpress_upgrade_all_update_site_status(websiteId, __('<i class="notched circle loading icon"></i>')); |
| 222 |
|
| 223 |
updatesoverview_wordpress_upgrade_int(websiteId, true); |
| 224 |
}; |
| 225 |
updatesoverview_wordpress_upgrade_all_update_done = function () { |
| 226 |
currentThreads--; |
| 227 |
if (!bulkTaskRunning) |
| 228 |
return; |
| 229 |
websitesDone++; |
| 230 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 231 |
|
| 232 |
if (websitesDone == websitesTotal) { |
| 233 |
//updatesoverview_check_to_continue_updates(); |
| 234 |
return; |
| 235 |
} |
| 236 |
updatesoverview_wordpress_upgrade_all_loop_next(); |
| 237 |
}; |
| 238 |
updatesoverview_wordpress_upgrade_int = function (websiteId, bulkMode) { |
| 239 |
|
| 240 |
var data = mainwp_secure_data({ |
| 241 |
action: 'mainwp_upgradewp', |
| 242 |
id: websiteId |
| 243 |
}); |
| 244 |
jQuery.post(ajaxurl, data, function (pWebsiteId, pBulkMode) { |
| 245 |
return function (response) { |
| 246 |
var error = ''; |
| 247 |
var success = false; |
| 248 |
|
| 249 |
if (response.error) { |
| 250 |
var err_msg = ''; |
| 251 |
if (response.error.extra) { |
| 252 |
err_msg = response.error.extra + ' '; |
| 253 |
} |
| 254 |
error = err_msg; |
| 255 |
if (pBulkMode) |
| 256 |
updatesoverview_wordpress_upgrade_all_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + err_msg + '"><i class="red times icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId)); |
| 257 |
} else { |
| 258 |
result = response.result; |
| 259 |
success = true; |
| 260 |
if (pBulkMode) |
| 261 |
updatesoverview_wordpress_upgrade_all_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId)); |
| 262 |
} |
| 263 |
updatesoverview_wordpress_upgrade_all_update_done(); |
| 264 |
} |
| 265 |
}(websiteId, bulkMode), 'json'); |
| 266 |
|
| 267 |
return false; |
| 268 |
}; |
| 269 |
|
| 270 |
var currentTranslationSlugToUpgrade = undefined; |
| 271 |
var websitesTranslationSlugsToUpgrade = undefined; |
| 272 |
updatesoverview_translations_global_upgrade_all = function (groupId, updatesSelected) { |
| 273 |
if (bulkTaskRunning) |
| 274 |
return false; |
| 275 |
|
| 276 |
//Step 1: build form |
| 277 |
var sitesToUpdate = []; |
| 278 |
var siteNames = {}; |
| 279 |
var sitesTranslationSlugs = {}; |
| 280 |
var foundChildren = []; |
| 281 |
|
| 282 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 283 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 284 |
jQuery('#update_wrapper_translation_upgrades_group_' + groupId).find('tr.mainwp-translation-update[updated="0"]').each( |
| 285 |
function () { |
| 286 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 287 |
foundChildren.push(this); |
| 288 |
} |
| 289 |
} |
| 290 |
); |
| 291 |
} else { |
| 292 |
jQuery('#translations-updates-global').find('table tr[updated="0"]').each( |
| 293 |
function () { |
| 294 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 295 |
foundChildren.push(this); |
| 296 |
} |
| 297 |
} |
| 298 |
); |
| 299 |
} |
| 300 |
if (foundChildren.length == 0) { |
| 301 |
updates_please_select_items_notice(); |
| 302 |
return false; |
| 303 |
} |
| 304 |
} else { |
| 305 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 306 |
foundChildren = jQuery('#update_wrapper_translation_upgrades_group_' + groupId).find('tr.mainwp-translation-update[updated="0"]'); |
| 307 |
} else { |
| 308 |
foundChildren = jQuery('#translations-updates-global').find('table tr[updated="0"]'); |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
if (foundChildren.length == 0) |
| 313 |
return false; |
| 314 |
var sitesCount = 0; |
| 315 |
|
| 316 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 317 |
|
| 318 |
for (var i = 0; i < foundChildren.length; i++) { |
| 319 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && typeof groupId === 'undefined') { |
| 320 |
continueUpdatesAll = 'translations_global_upgrade_all'; |
| 321 |
break; |
| 322 |
} |
| 323 |
var child = jQuery(foundChildren[i]); |
| 324 |
var parent = child.parent(); // to fix |
| 325 |
|
| 326 |
var siteElement; |
| 327 |
var translationElement; |
| 328 |
|
| 329 |
var checkAttr = child.attr('site_id'); |
| 330 |
if ((typeof checkAttr !== 'undefined') && (checkAttr !== false)) { |
| 331 |
siteElement = child; |
| 332 |
translationElement = parent; |
| 333 |
} else { |
| 334 |
siteElement = parent; |
| 335 |
translationElement = child; |
| 336 |
} |
| 337 |
|
| 338 |
var siteId = siteElement.attr('site_id'); |
| 339 |
var siteName = siteElement.attr('site_name'); |
| 340 |
var translationSlug = translationElement.attr('translation_slug'); |
| 341 |
|
| 342 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 343 |
sitesCount++; |
| 344 |
sitesToUpdate.push(siteId); |
| 345 |
siteNames[siteId] = siteName; |
| 346 |
} |
| 347 |
if (sitesTranslationSlugs[siteId] == undefined) { |
| 348 |
sitesTranslationSlugs[siteId] = translationSlug; |
| 349 |
} else { |
| 350 |
sitesTranslationSlugs[siteId] += ',' + translationSlug; |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
var _callback = function () { |
| 355 |
for (var i = 0; i < sitesToUpdate.length; i++) { |
| 356 |
var updateCount = sitesTranslationSlugs[sitesToUpdate[i]].match(/,/g); |
| 357 |
if (updateCount == null) |
| 358 |
updateCount = 1; |
| 359 |
else |
| 360 |
updateCount = updateCount.length + 1; |
| 361 |
|
| 362 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteNames[sitesToUpdate[i]]) + ' (' + updateCount + ' translations)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + sitesToUpdate[i] + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 363 |
} |
| 364 |
|
| 365 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate, pSitesTranslationSlugs) { |
| 366 |
return function () { |
| 367 |
|
| 368 |
var initData = { |
| 369 |
title: __('Updating all...'), |
| 370 |
progressMax: pSitesCount |
| 371 |
}; |
| 372 |
updatesoverview_update_popup_init(initData); |
| 373 |
|
| 374 |
//Step 3: start updates |
| 375 |
updatesoverview_translations_upgrade_all_int(undefined, pSitesToUpdate, pSitesTranslationSlugs); |
| 376 |
|
| 377 |
updatesoverviewContinueAfterBackup = undefined; |
| 378 |
} |
| 379 |
}(sitesCount, sitesToUpdate, sitesTranslationSlugs); |
| 380 |
|
| 381 |
|
| 382 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
// new confirm message |
| 387 |
if (!continueUpdating) { |
| 388 |
if (jQuery(siteNames).length > 0) { |
| 389 |
var sitesList = []; |
| 390 |
jQuery.each(siteNames, function (index, value) { |
| 391 |
if (value) { // to fix |
| 392 |
sitesList.push(decodeURIComponent(value)); |
| 393 |
} |
| 394 |
}); |
| 395 |
var confirmMsg = __('You are about to update %1 on the following site(s):\n%2?', 'translations', sitesList.join(', ')); |
| 396 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 397 |
} |
| 398 |
return false; |
| 399 |
} |
| 400 |
_callback(); |
| 401 |
return false; |
| 402 |
}; |
| 403 |
updatesoverview_translations_upgrade_all = function (slug, translationName) { |
| 404 |
if (bulkTaskRunning) |
| 405 |
return false; |
| 406 |
//Step 1: build form |
| 407 |
var sitesToUpdate = []; |
| 408 |
var siteNames = []; |
| 409 |
// var foundChildren = jQuery( 'div[translation_slug="' + slug + '"]' ).children( 'div[updated="0"]' ); |
| 410 |
var foundChildren = jQuery('.translations-bulk-updates[translation_slug="' + slug + '"]').find('tr[updated="0"]'); |
| 411 |
|
| 412 |
if (foundChildren.length == 0) |
| 413 |
return false; |
| 414 |
|
| 415 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 416 |
|
| 417 |
for (var i = 0; i < foundChildren.length; i++) { |
| 418 |
if (limitUpdateAll > 0 && i >= limitUpdateAll) { |
| 419 |
continueUpdatesAll = 'translations_upgrade_all'; |
| 420 |
continueUpdatesSlug = slug; |
| 421 |
break; |
| 422 |
} |
| 423 |
var child = foundChildren[i]; |
| 424 |
var siteId = jQuery(child).attr('site_id'); |
| 425 |
var siteName = jQuery(child).attr('site_name'); |
| 426 |
siteNames[siteId] = siteName; |
| 427 |
sitesToUpdate.push(siteId); |
| 428 |
} |
| 429 |
|
| 430 |
translationName = decodeURIComponent(translationName); |
| 431 |
translationName = translationName.replace(/\+/g, ' '); |
| 432 |
|
| 433 |
var _callback = function () { |
| 434 |
|
| 435 |
for (var i = 0; i < sitesToUpdate.length; i++) { |
| 436 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteNames[sitesToUpdate[i]]), '<span class="updatesoverview-upgrade-status-wp" siteid="' + sitesToUpdate[i] + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 437 |
} |
| 438 |
|
| 439 |
var sitesCount = sitesToUpdate.length; |
| 440 |
|
| 441 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSlug, pSitesToUpdate) { |
| 442 |
return function () { |
| 443 |
|
| 444 |
// init and show popup |
| 445 |
|
| 446 |
var initData = { |
| 447 |
title: __('Updating %1', decodeURIComponent(translationName)), |
| 448 |
progressMax: pSitesCount |
| 449 |
}; |
| 450 |
updatesoverview_update_popup_init(initData); |
| 451 |
//Step 3: start updates |
| 452 |
updatesoverview_translations_upgrade_all_int(pSlug, pSitesToUpdate); |
| 453 |
|
| 454 |
updatesoverviewContinueAfterBackup = undefined; |
| 455 |
} |
| 456 |
}(sitesCount, slug, sitesToUpdate); |
| 457 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 458 |
} |
| 459 |
|
| 460 |
// new confirm message |
| 461 |
if (!continueUpdating) { |
| 462 |
if (jQuery(siteNames).length > 0) { |
| 463 |
var sitesList = []; |
| 464 |
jQuery.each(siteNames, function (index, value) { |
| 465 |
if (value) { // to fix |
| 466 |
sitesList.push(decodeURIComponent(value)); |
| 467 |
} |
| 468 |
}); |
| 469 |
var confirmMsg = __('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 />')); |
| 470 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 471 |
} |
| 472 |
return false; |
| 473 |
} |
| 474 |
|
| 475 |
_callback(); |
| 476 |
return false; |
| 477 |
}; |
| 478 |
updatesoverview_translations_upgrade_all_int = function (slug, websiteIds, sitesTranslationSlugs) { |
| 479 |
currentTranslationSlugToUpgrade = slug; |
| 480 |
websitesTranslationSlugsToUpgrade = sitesTranslationSlugs; |
| 481 |
websitesToUpdateTranslations = websiteIds; |
| 482 |
currentWebsite = 0; |
| 483 |
websitesDone = 0; |
| 484 |
websitesTotal = websitesLeft = websitesToUpdateTranslations.length; |
| 485 |
|
| 486 |
bulkTaskRunning = true; |
| 487 |
updatesoverview_translations_upgrade_all_loop_next(); |
| 488 |
}; |
| 489 |
updatesoverview_translations_upgrade_all_loop_next = function () { |
| 490 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 491 |
updatesoverview_translations_upgrade_all_upgrade_next(); |
| 492 |
} |
| 493 |
}; |
| 494 |
updatesoverview_translations_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 495 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 496 |
}; |
| 497 |
updatesoverview_translations_upgrade_all_upgrade_next = function () { |
| 498 |
currentThreads++; |
| 499 |
websitesLeft--; |
| 500 |
|
| 501 |
var websiteId = websitesToUpdateTranslations[currentWebsite++]; |
| 502 |
updatesoverview_translations_upgrade_all_update_site_status(websiteId, '<i class="notched circle loading icon"></i>'); |
| 503 |
|
| 504 |
var slugToUpgrade = currentTranslationSlugToUpgrade; |
| 505 |
if (slugToUpgrade == undefined) |
| 506 |
slugToUpgrade = websitesTranslationSlugsToUpgrade[websiteId]; |
| 507 |
updatesoverview_translations_upgrade_int(slugToUpgrade, websiteId, true, true); |
| 508 |
}; |
| 509 |
|
| 510 |
updatesoverview_translations_upgrade_all_update_done = function () { |
| 511 |
currentThreads--; |
| 512 |
if (!bulkTaskRunning) |
| 513 |
return; |
| 514 |
websitesDone++; |
| 515 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 516 |
|
| 517 |
if (websitesDone == websitesTotal) { |
| 518 |
updatesoverview_check_to_continue_updates(); |
| 519 |
return; |
| 520 |
} |
| 521 |
|
| 522 |
updatesoverview_translations_upgrade_all_loop_next(); |
| 523 |
}; |
| 524 |
updatesoverview_translations_upgrade_int = function (slug, websiteId, bulkMode, noCheck) { |
| 525 |
updatesoverviewContinueAfterBackup = function (pSlug, pWebsiteId, pBulkMode) { |
| 526 |
return function () { |
| 527 |
var slugParts = pSlug.split(','); |
| 528 |
for (var i = 0; i < slugParts.length; i++) { |
| 529 |
var websiteHolder = jQuery('.translations-bulk-updates[translation_slug="' + slugParts[i] + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 530 |
if (!websiteHolder.exists()) { |
| 531 |
websiteHolder = jQuery('.translations-bulk-updates[site_id="' + pWebsiteId + '"] tr[translation_slug="' + slugParts[i] + '"]'); |
| 532 |
} |
| 533 |
|
| 534 |
websiteHolder.find('td:last-child').html('<i class="notched circle loading icon"></i> ' + __('Updating. Please wait...')); |
| 535 |
} |
| 536 |
|
| 537 |
var data = mainwp_secure_data({ |
| 538 |
action: 'mainwp_upgradeplugintheme', |
| 539 |
websiteId: pWebsiteId, |
| 540 |
type: 'translation', |
| 541 |
slug: pSlug |
| 542 |
}); |
| 543 |
jQuery.ajax({ |
| 544 |
type: "POST", |
| 545 |
url: ajaxurl, |
| 546 |
data: data, |
| 547 |
success: function (pSlug, pWebsiteId, pBulkMode) { |
| 548 |
return function (response) { |
| 549 |
var slugParts = pSlug.split(','); |
| 550 |
var done = false; |
| 551 |
var success = false; |
| 552 |
var error = ''; |
| 553 |
for (var i = 0; i < slugParts.length; i++) { |
| 554 |
var websiteHolder = jQuery('.translations-bulk-updates[translation_slug="' + slugParts[i] + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 555 |
if (!websiteHolder.exists()) { |
| 556 |
websiteHolder = jQuery('.translations-bulk-updates[site_id="' + pWebsiteId + '"] tr[translation_slug="' + slugParts[i] + '"]'); |
| 557 |
} |
| 558 |
|
| 559 |
if (response.error) { |
| 560 |
if (!done && pBulkMode) |
| 561 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 562 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 563 |
error = response.error; |
| 564 |
} else { |
| 565 |
var res = response.result; |
| 566 |
if (res[slugParts[i]]) { |
| 567 |
if (!done && pBulkMode) |
| 568 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, '<i class="green check icon"></i>'); |
| 569 |
websiteHolder.attr('updated', 1); |
| 570 |
websiteHolder.find('td:last-child').html('<i class="green check icon"></i>'); |
| 571 |
success = true; |
| 572 |
} else { |
| 573 |
if (!done && pBulkMode) |
| 574 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 575 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 576 |
error = __('Undefined error.'); |
| 577 |
} |
| 578 |
} |
| 579 |
if (!done && pBulkMode) { |
| 580 |
updatesoverview_translations_upgrade_all_update_done(); |
| 581 |
done = true; |
| 582 |
} |
| 583 |
} |
| 584 |
} |
| 585 |
}(pSlug, pWebsiteId, pBulkMode), |
| 586 |
tryCount: 0, |
| 587 |
retryLimit: 3, |
| 588 |
endError: function (pSlug, pWebsiteId, pBulkMode) { |
| 589 |
return function () { |
| 590 |
var slugParts = pSlug.split(','); |
| 591 |
var done = false; |
| 592 |
for (var i = 0; i < slugParts.length; i++) { |
| 593 |
var result; |
| 594 |
var websiteHolder = jQuery('.translations-bulk-updates[translation_slug="' + slugParts[i] + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 595 |
if (!websiteHolder.exists()) { |
| 596 |
websiteHolder = jQuery('.translations-bulk-updates[site_id="' + pWebsiteId + '"] tr[translation_slug="' + slugParts[i] + '"]'); |
| 597 |
} |
| 598 |
|
| 599 |
result = __('FAILED'); |
| 600 |
if (!done && pBulkMode) { |
| 601 |
updatesoverview_translations_upgrade_all_update_site_status(pWebsiteId, '<span class="mainwp-red"><i class="exclamation icon"></i> ' + __('FAILED') + '</span>'); |
| 602 |
updatesoverview_translations_upgrade_all_update_done(); |
| 603 |
done = true; |
| 604 |
} |
| 605 |
|
| 606 |
websiteHolder.find('td:last-child').html(result); |
| 607 |
} |
| 608 |
} |
| 609 |
}(pSlug, pWebsiteId, pBulkMode), |
| 610 |
error: function (xhr) { |
| 611 |
this.tryCount++; |
| 612 |
if (this.tryCount >= this.retryLimit) { |
| 613 |
this.endError(); |
| 614 |
return; |
| 615 |
} |
| 616 |
|
| 617 |
var fnc = function (pRqst, pXhr) { |
| 618 |
return function () { |
| 619 |
if (pXhr.status == 404) { |
| 620 |
//handle error |
| 621 |
jQuery.ajax(pRqst); |
| 622 |
} else if (pXhr.status == 500) { |
| 623 |
//handle error |
| 624 |
} else { |
| 625 |
//handle error |
| 626 |
} |
| 627 |
} |
| 628 |
}(this, xhr); |
| 629 |
setTimeout(fnc, 500); |
| 630 |
}, |
| 631 |
dataType: 'json' |
| 632 |
}); |
| 633 |
|
| 634 |
updatesoverviewContinueAfterBackup = undefined; |
| 635 |
} |
| 636 |
}(slug, websiteId, bulkMode); |
| 637 |
|
| 638 |
if (noCheck) { |
| 639 |
updatesoverviewContinueAfterBackup(); |
| 640 |
return false; |
| 641 |
} |
| 642 |
|
| 643 |
var sitesToUpdate = [websiteId]; |
| 644 |
var siteNames = []; |
| 645 |
siteNames[websiteId] = jQuery('div[site_id="' + websiteId + '"]').attr('site_name'); |
| 646 |
|
| 647 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 648 |
}; |
| 649 |
var currentPluginSlugToUpgrade = undefined; |
| 650 |
var websitesPluginSlugsToUpgrade = undefined; |
| 651 |
updatesoverview_plugins_global_upgrade_all = function (groupId, updatesSelected) { |
| 652 |
if (bulkTaskRunning) |
| 653 |
return false; |
| 654 |
|
| 655 |
//Step 1: build form |
| 656 |
var sitesToUpdate = []; |
| 657 |
var siteNames = {}; |
| 658 |
var sitesPluginSlugs = {}; |
| 659 |
var foundChildren = []; |
| 660 |
|
| 661 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 662 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 663 |
jQuery('#update_wrapper_plugin_upgrades_group_' + groupId).find('tr.mainwp-plugin-update[updated="0"]').each( |
| 664 |
function () { |
| 665 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 666 |
foundChildren.push(this); |
| 667 |
} |
| 668 |
} |
| 669 |
); |
| 670 |
} else { |
| 671 |
jQuery('#plugins-updates-global').find('table tr[updated="0"]').each( |
| 672 |
function () { |
| 673 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 674 |
foundChildren.push(this); |
| 675 |
} |
| 676 |
} |
| 677 |
); |
| 678 |
} |
| 679 |
if (foundChildren.length == 0) { |
| 680 |
updates_please_select_items_notice(); |
| 681 |
return false; |
| 682 |
} |
| 683 |
} else { |
| 684 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 685 |
foundChildren = jQuery('#update_wrapper_plugin_upgrades_group_' + groupId).find('tr.mainwp-plugin-update[updated="0"]'); |
| 686 |
} else { |
| 687 |
foundChildren = jQuery('#plugins-updates-global').find('table tr[updated="0"]'); |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
if (foundChildren.length == 0) |
| 692 |
return false; |
| 693 |
var sitesCount = 0; |
| 694 |
|
| 695 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 696 |
|
| 697 |
for (var i = 0; i < foundChildren.length; i++) { |
| 698 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && typeof groupId === 'undefined') { |
| 699 |
continueUpdatesAll = 'plugins_global_upgrade_all'; |
| 700 |
break; |
| 701 |
} |
| 702 |
var child = jQuery(foundChildren[i]); |
| 703 |
var parent = child.parent(); // to fix |
| 704 |
|
| 705 |
var siteElement; |
| 706 |
var pluginElement; |
| 707 |
|
| 708 |
var checkAttr = child.attr('site_id'); |
| 709 |
if ((typeof checkAttr !== 'undefined') && (checkAttr !== false)) { |
| 710 |
siteElement = child; |
| 711 |
pluginElement = parent; |
| 712 |
} else { |
| 713 |
siteElement = parent; |
| 714 |
pluginElement = child; |
| 715 |
} |
| 716 |
|
| 717 |
var siteId = siteElement.attr('site_id'); |
| 718 |
var siteName = siteElement.attr('site_name'); |
| 719 |
var pluginSlug = pluginElement.attr('plugin_slug'); |
| 720 |
|
| 721 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 722 |
sitesCount++; |
| 723 |
sitesToUpdate.push(siteId); |
| 724 |
siteNames[siteId] = siteName; |
| 725 |
} |
| 726 |
if (sitesPluginSlugs[siteId] == undefined) { |
| 727 |
sitesPluginSlugs[siteId] = pluginSlug; |
| 728 |
} else { |
| 729 |
sitesPluginSlugs[siteId] += ',' + pluginSlug; |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
var _callback = function () { |
| 734 |
|
| 735 |
for (var i = 0; i < sitesToUpdate.length; i++) { |
| 736 |
var updateCount = sitesPluginSlugs[sitesToUpdate[i]].match(/,/g); |
| 737 |
if (updateCount == null) |
| 738 |
updateCount = 1; |
| 739 |
else |
| 740 |
updateCount = updateCount.length + 1; |
| 741 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteNames[sitesToUpdate[i]]) + ' (' + updateCount + ' plugins)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + sitesToUpdate[i] + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 742 |
} |
| 743 |
|
| 744 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate, pSitesPluginSlugs) { |
| 745 |
return function () { |
| 746 |
|
| 747 |
var initData = { |
| 748 |
title: __('Updating all'), |
| 749 |
progressMax: pSitesCount |
| 750 |
}; |
| 751 |
updatesoverview_update_popup_init(initData); |
| 752 |
|
| 753 |
//Step 3: start updates |
| 754 |
updatesoverview_plugins_upgrade_all_int(undefined, pSitesToUpdate, pSitesPluginSlugs); |
| 755 |
|
| 756 |
updatesoverviewContinueAfterBackup = undefined; |
| 757 |
} |
| 758 |
}(sitesCount, sitesToUpdate, sitesPluginSlugs); |
| 759 |
|
| 760 |
|
| 761 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 762 |
} |
| 763 |
|
| 764 |
// new confirm message |
| 765 |
if (!continueUpdating) { |
| 766 |
if (jQuery(siteNames).length > 0) { |
| 767 |
var sitesList = []; |
| 768 |
jQuery.each(siteNames, function (index, value) { |
| 769 |
if (value) { // to fix |
| 770 |
sitesList.push(decodeURIComponent(value)); |
| 771 |
} |
| 772 |
}); |
| 773 |
var confirmMsg = __('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>', __('plugins'), sitesList.join('<br />')); |
| 774 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 775 |
} |
| 776 |
return false; |
| 777 |
} |
| 778 |
_callback(); |
| 779 |
return false; |
| 780 |
}; |
| 781 |
updatesoverview_plugins_upgrade_all = function (slug, pluginName, updatesSelected) { |
| 782 |
if (bulkTaskRunning) |
| 783 |
return false; |
| 784 |
|
| 785 |
//Step 1: build form |
| 786 |
var sitesToUpdate = []; |
| 787 |
var siteNames = []; |
| 788 |
var foundChildren = []; |
| 789 |
|
| 790 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 791 |
jQuery('tr[plugin_slug="' + slug + '"]').find('table tr[updated="0"]').each( |
| 792 |
function () { |
| 793 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 794 |
foundChildren.push(this); |
| 795 |
} |
| 796 |
} |
| 797 |
); |
| 798 |
if (foundChildren.length == 0) { |
| 799 |
updates_please_select_items_notice(); |
| 800 |
return false; |
| 801 |
} |
| 802 |
} else { |
| 803 |
foundChildren = jQuery('tr[plugin_slug="' + slug + '"]').find('table tr[updated="0"]'); |
| 804 |
} |
| 805 |
|
| 806 |
if (foundChildren.length == 0) |
| 807 |
return false; |
| 808 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 809 |
|
| 810 |
for (var i = 0; i < foundChildren.length; i++) { |
| 811 |
if (limitUpdateAll > 0 && i >= limitUpdateAll) { |
| 812 |
continueUpdatesAll = 'plugins_upgrade_all'; |
| 813 |
continueUpdatesSlug = slug; |
| 814 |
break; |
| 815 |
} |
| 816 |
var child = foundChildren[i]; |
| 817 |
var siteId = jQuery(child).attr('site_id'); |
| 818 |
var siteName = jQuery(child).attr('site_name'); |
| 819 |
siteNames[siteId] = siteName; |
| 820 |
sitesToUpdate.push(siteId); |
| 821 |
} |
| 822 |
|
| 823 |
pluginName = decodeURIComponent(pluginName); |
| 824 |
pluginName = pluginName.replace(/\+/g, ' '); |
| 825 |
|
| 826 |
var _callback = function () { |
| 827 |
|
| 828 |
for (var i = 0; i < sitesToUpdate.length; i++) { |
| 829 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteNames[sitesToUpdate[i]]), '<span class="updatesoverview-upgrade-status-wp" siteid="' + sitesToUpdate[i] + '">' + '<span data-inverted="" data-position="left center" data-tooltip="' + __('Pending', 'mainwp') + '"><i class="clock outline icon"></i></span> ' + '</span>'); |
| 830 |
} |
| 831 |
|
| 832 |
var sitesCount = sitesToUpdate.length; |
| 833 |
|
| 834 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSlug, pSitesToUpdate) { |
| 835 |
return function () { |
| 836 |
|
| 837 |
var initData = { |
| 838 |
title: __('Updating %1', decodeURIComponent(pluginName)), |
| 839 |
progressMax: pSitesCount |
| 840 |
}; |
| 841 |
updatesoverview_update_popup_init(initData); |
| 842 |
|
| 843 |
//Step 3: start updates |
| 844 |
updatesoverview_plugins_upgrade_all_int(pSlug, pSitesToUpdate); |
| 845 |
|
| 846 |
updatesoverviewContinueAfterBackup = undefined; |
| 847 |
} |
| 848 |
}(sitesCount, slug, sitesToUpdate); |
| 849 |
|
| 850 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 851 |
} |
| 852 |
|
| 853 |
// new confirm message |
| 854 |
if (!continueUpdating) { |
| 855 |
if (siteNames.length > 0) { |
| 856 |
var sitesList = []; |
| 857 |
jQuery.each(siteNames, function (index, value) { |
| 858 |
if (value) { // to fix |
| 859 |
sitesList.push(decodeURIComponent(value)); |
| 860 |
} |
| 861 |
}); |
| 862 |
var confirmMsg = __('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 />')); |
| 863 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 864 |
} |
| 865 |
return false; |
| 866 |
} |
| 867 |
_callback(); |
| 868 |
return false; |
| 869 |
|
| 870 |
}; |
| 871 |
updatesoverview_plugins_upgrade_all_int = function (slug, websiteIds, sitesPluginSlugs) { |
| 872 |
currentPluginSlugToUpgrade = slug; |
| 873 |
websitesPluginSlugsToUpgrade = sitesPluginSlugs; |
| 874 |
websitesToUpdatePlugins = websiteIds; |
| 875 |
currentWebsite = 0; |
| 876 |
websitesDone = 0; |
| 877 |
websitesTotal = websitesLeft = websitesToUpdatePlugins.length; |
| 878 |
|
| 879 |
bulkTaskRunning = true; |
| 880 |
updatesoverview_plugins_upgrade_all_loop_next(); |
| 881 |
}; |
| 882 |
updatesoverview_plugins_upgrade_all_loop_next = function () { |
| 883 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 884 |
updatesoverview_plugins_upgrade_all_upgrade_next(); |
| 885 |
} |
| 886 |
}; |
| 887 |
updatesoverview_plugins_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 888 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 889 |
}; |
| 890 |
updatesoverview_plugins_upgrade_all_upgrade_next = function () { |
| 891 |
currentThreads++; |
| 892 |
websitesLeft--; |
| 893 |
|
| 894 |
var websiteId = websitesToUpdatePlugins[currentWebsite++]; |
| 895 |
|
| 896 |
updatesoverview_plugins_upgrade_all_update_site_status(websiteId, '<i class="notched circle loading icon"></i>'); |
| 897 |
|
| 898 |
var slugToUpgrade = currentPluginSlugToUpgrade; |
| 899 |
if (slugToUpgrade == undefined) |
| 900 |
slugToUpgrade = websitesPluginSlugsToUpgrade[websiteId]; |
| 901 |
updatesoverview_plugins_upgrade_int(slugToUpgrade, websiteId, true, true); |
| 902 |
}; |
| 903 |
|
| 904 |
updatesoverview_check_to_continue_updates = function () { |
| 905 |
var loc_href = location.href; |
| 906 |
if (limitUpdateAll > 0 && continueUpdatesAll != '') { |
| 907 |
if (loc_href.indexOf("&continue_update=") == -1) { |
| 908 |
var loc_href = loc_href + '&continue_update=' + continueUpdatesAll; |
| 909 |
if (continueUpdatesAll == 'plugins_upgrade_all' || continueUpdatesAll == 'themes_upgrade_all' || continueUpdatesAll == 'translations_upgrade_all') { |
| 910 |
loc_href += '&slug=' + continueUpdatesSlug; |
| 911 |
} |
| 912 |
} |
| 913 |
} else { |
| 914 |
if (loc_href.indexOf("page=mainwp_tab") != -1) { |
| 915 |
loc_href = 'admin.php?page=mainwp_tab'; |
| 916 |
} else { |
| 917 |
loc_href = 'admin.php?page=UpdatesManage'; |
| 918 |
} |
| 919 |
} |
| 920 |
setTimeout(function () { |
| 921 |
bulkTaskRunning = false; |
| 922 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 923 |
}, 3000); |
| 924 |
return false; |
| 925 |
} |
| 926 |
|
| 927 |
updatesoverview_plugins_upgrade_all_update_done = function () { |
| 928 |
currentThreads--; |
| 929 |
if (!bulkTaskRunning) |
| 930 |
return; |
| 931 |
websitesDone++; |
| 932 |
|
| 933 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 934 |
|
| 935 |
if (websitesDone == websitesTotal) { |
| 936 |
updatesoverview_check_to_continue_updates(); |
| 937 |
return; |
| 938 |
} |
| 939 |
|
| 940 |
updatesoverview_plugins_upgrade_all_loop_next(); |
| 941 |
}; |
| 942 |
updatesoverview_plugins_upgrade_int = function (slug, websiteId, bulkMode, noCheck) { |
| 943 |
updatesoverviewContinueAfterBackup = function (pSlug, pWebsiteId, pBulkMode) { |
| 944 |
return function () { |
| 945 |
var slugParts = pSlug.split(','); |
| 946 |
for (var i = 0; i < slugParts.length; i++) { |
| 947 |
var websiteHolder = jQuery('.plugins-bulk-updates[plugin_slug="' + slugParts[i] + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 948 |
if (!websiteHolder.exists()) { |
| 949 |
websiteHolder = jQuery('.plugins-bulk-updates[site_id="' + pWebsiteId + '"] tr[plugin_slug="' + slugParts[i] + '"]'); |
| 950 |
} |
| 951 |
websiteHolder.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Updating...', 'mainwp') + '"><i class="notched circle loading icon"></i></span> ' + __('Updating. Please wait...')); |
| 952 |
} |
| 953 |
|
| 954 |
var data = mainwp_secure_data({ |
| 955 |
action: 'mainwp_upgradeplugintheme', |
| 956 |
websiteId: pWebsiteId, |
| 957 |
type: 'plugin', |
| 958 |
slug: pSlug |
| 959 |
}); |
| 960 |
jQuery.ajax({ |
| 961 |
type: "POST", |
| 962 |
url: ajaxurl, |
| 963 |
data: data, |
| 964 |
success: function (pSlug, pWebsiteId, pBulkMode) { |
| 965 |
return function (response) { |
| 966 |
var slugParts = pSlug.split(','); |
| 967 |
var done = false; |
| 968 |
var success = false; |
| 969 |
var error = ''; |
| 970 |
for (var i = 0; i < slugParts.length; i++) { |
| 971 |
var websiteHolder = jQuery('.plugins-bulk-updates[plugin_slug="' + slugParts[i] + '"] tr[site_id="' + pWebsiteId + '"]'); |
| 972 |
if (!websiteHolder.exists()) { |
| 973 |
websiteHolder = jQuery('.plugins-bulk-updates[site_id="' + pWebsiteId + '"] tr[plugin_slug="' + slugParts[i] + '"]'); |
| 974 |
} |
| 975 |
|
| 976 |
if (response.error || response.notices) { |
| 977 |
var extErr = getErrorMessageInfo(response.error, 'ui') |
| 978 |
if (!done && pBulkMode) |
| 979 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, extErr); |
| 980 |
websiteHolder.find('td:last-child').html(extErr); |
| 981 |
if (response.error) { |
| 982 |
error = response.error; |
| 983 |
} |
| 984 |
} else { |
| 985 |
var res = response.result; |
| 986 |
var res_error = response.result_error; |
| 987 |
if (res[slugParts[i]]) { |
| 988 |
if (!done && pBulkMode) |
| 989 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId)); |
| 990 |
websiteHolder.attr('updated', 1); |
| 991 |
websiteHolder.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', pWebsiteId)); |
| 992 |
success = true; |
| 993 |
} else if (res_error[slugParts[i]]) { |
| 994 |
if (!done && pBulkMode) |
| 995 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + res_error[slugParts[i]] + '"><i class="red times icon"></i></span>'); |
| 996 |
websiteHolder.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + res_error[slugParts[i]] + '"><i class="red times icon"></i></span>'); |
| 997 |
error = res_error[slugParts[i]]; |
| 998 |
} else { |
| 999 |
if (!done && pBulkMode) |
| 1000 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 1001 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 1002 |
error = _('Undefined error'); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
if (!done && pBulkMode) { |
| 1006 |
updatesoverview_plugins_upgrade_all_update_done(); |
| 1007 |
done = true; |
| 1008 |
} |
| 1009 |
} |
| 1010 |
} |
| 1011 |
}(pSlug, pWebsiteId, pBulkMode), |
| 1012 |
tryCount: 0, |
| 1013 |
retryLimit: 3, |
| 1014 |
endError: function (pSlug, pWebsiteId, pBulkMode) { |
| 1015 |
return function () { |
| 1016 |
var slugParts = pSlug.split(','); |
| 1017 |
var done = false; |
| 1018 |
for (var i = 0; i < slugParts.length; i++) { |
| 1019 |
//Siteview |
| 1020 |
var websiteHolder = jQuery('div[plugin_slug="' + slugParts[i] + '"] div[site_id="' + pWebsiteId + '"]'); |
| 1021 |
if (!websiteHolder.exists()) { |
| 1022 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[plugin_slug="' + slugParts[i] + '"]'); |
| 1023 |
} |
| 1024 |
|
| 1025 |
if (!done && pBulkMode) { |
| 1026 |
updatesoverview_plugins_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 1027 |
updatesoverview_plugins_upgrade_all_update_done(); |
| 1028 |
done = true; |
| 1029 |
} |
| 1030 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
}(pSlug, pWebsiteId, pBulkMode), |
| 1034 |
error: function (xhr) { |
| 1035 |
this.tryCount++; |
| 1036 |
if (this.tryCount >= this.retryLimit) { |
| 1037 |
this.endError(); |
| 1038 |
return; |
| 1039 |
} |
| 1040 |
|
| 1041 |
var fnc = function (pRqst, pXhr) { |
| 1042 |
return function () { |
| 1043 |
if (pXhr.status == 404) { |
| 1044 |
//handle error |
| 1045 |
jQuery.ajax(pRqst); |
| 1046 |
} else if (pXhr.status == 500) { |
| 1047 |
//handle error |
| 1048 |
} else { |
| 1049 |
//handle error |
| 1050 |
} |
| 1051 |
} |
| 1052 |
}(this, xhr); |
| 1053 |
setTimeout(fnc, 500); |
| 1054 |
}, |
| 1055 |
dataType: 'json' |
| 1056 |
}); |
| 1057 |
|
| 1058 |
updatesoverviewContinueAfterBackup = undefined; |
| 1059 |
} |
| 1060 |
}(slug, websiteId, bulkMode); |
| 1061 |
|
| 1062 |
if (noCheck) { |
| 1063 |
updatesoverviewContinueAfterBackup(); |
| 1064 |
return false; |
| 1065 |
} |
| 1066 |
|
| 1067 |
var sitesToUpdate = [websiteId]; |
| 1068 |
var siteNames = []; |
| 1069 |
siteNames[websiteId] = jQuery('div[site_id="' + websiteId + '"]').attr('site_name'); |
| 1070 |
|
| 1071 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1072 |
}; |
| 1073 |
|
| 1074 |
var currentThemeSlugToUpgrade = undefined; |
| 1075 |
var websitesThemeSlugsToUpgrade = undefined; |
| 1076 |
updatesoverview_themes_global_upgrade_all = function (groupId, updatesSelected) { |
| 1077 |
if (bulkTaskRunning) |
| 1078 |
return false; |
| 1079 |
|
| 1080 |
//Step 1: build form |
| 1081 |
var sitesToUpdate = []; |
| 1082 |
var siteNames = {}; |
| 1083 |
var sitesPluginSlugs = {}; |
| 1084 |
var foundChildren = []; |
| 1085 |
|
| 1086 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 1087 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 1088 |
jQuery('#update_wrapper_theme_upgrades_group_' + groupId).find('tr.mainwp-theme-update[updated="0"]').each( |
| 1089 |
function () { |
| 1090 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 1091 |
foundChildren.push(this); |
| 1092 |
} |
| 1093 |
} |
| 1094 |
); |
| 1095 |
} else { |
| 1096 |
jQuery('#themes-updates-global').find('table tr[updated="0"]').each( |
| 1097 |
function () { |
| 1098 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 1099 |
foundChildren.push(this); |
| 1100 |
} |
| 1101 |
} |
| 1102 |
); |
| 1103 |
} |
| 1104 |
if (foundChildren.length == 0) { |
| 1105 |
updates_please_select_items_notice(); |
| 1106 |
return false; |
| 1107 |
} |
| 1108 |
} else { |
| 1109 |
if (typeof groupId !== 'undefined' && false !== groupId) { |
| 1110 |
foundChildren = jQuery('#update_wrapper_theme_upgrades_group_' + groupId).find('tr.mainwp-theme-update[updated="0"]'); |
| 1111 |
} else { |
| 1112 |
foundChildren = jQuery('#themes-updates-global').find('table tr[updated="0"]'); |
| 1113 |
} |
| 1114 |
} |
| 1115 |
|
| 1116 |
if (foundChildren.length == 0) |
| 1117 |
return false; |
| 1118 |
var sitesCount = 0; |
| 1119 |
|
| 1120 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 1121 |
|
| 1122 |
for (var i = 0; i < foundChildren.length; i++) { |
| 1123 |
if (limitUpdateAll > 0 && i >= limitUpdateAll && typeof groupId === 'undefined') { |
| 1124 |
continueUpdatesAll = 'themes_global_upgrade_all'; |
| 1125 |
break; |
| 1126 |
} |
| 1127 |
var child = jQuery(foundChildren[i]); |
| 1128 |
var parent = child.parent(); // to fix |
| 1129 |
|
| 1130 |
var siteElement; |
| 1131 |
var themeElement; |
| 1132 |
|
| 1133 |
var checkAttr = child.attr('site_id'); |
| 1134 |
if ((typeof checkAttr !== 'undefined') && (checkAttr !== false)) { |
| 1135 |
siteElement = child; |
| 1136 |
themeElement = parent; |
| 1137 |
} else { |
| 1138 |
siteElement = parent; |
| 1139 |
themeElement = child; |
| 1140 |
} |
| 1141 |
|
| 1142 |
var siteId = siteElement.attr('site_id'); |
| 1143 |
var siteName = siteElement.attr('site_name'); |
| 1144 |
var themeSlug = themeElement.attr('theme_slug'); |
| 1145 |
|
| 1146 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 1147 |
sitesCount++; |
| 1148 |
sitesToUpdate.push(siteId); |
| 1149 |
siteNames[siteId] = siteName; |
| 1150 |
} |
| 1151 |
if (sitesPluginSlugs[siteId] == undefined) { |
| 1152 |
sitesPluginSlugs[siteId] = themeSlug; |
| 1153 |
} else { |
| 1154 |
sitesPluginSlugs[siteId] += ',' + themeSlug; |
| 1155 |
} |
| 1156 |
} |
| 1157 |
|
| 1158 |
var _callback = function () { |
| 1159 |
|
| 1160 |
for (var i = 0; i < sitesToUpdate.length; i++) { |
| 1161 |
var updateCount = sitesPluginSlugs[sitesToUpdate[i]].match(/,/g); |
| 1162 |
if (updateCount == null) |
| 1163 |
updateCount = 1; |
| 1164 |
else |
| 1165 |
updateCount = updateCount.length + 1; |
| 1166 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteNames[sitesToUpdate[i]]) + ' (' + updateCount + ' themes)', '<span class="updatesoverview-upgrade-status-wp" siteid="' + sitesToUpdate[i] + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 1167 |
} |
| 1168 |
|
| 1169 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate, pSitesPluginSlugs) { |
| 1170 |
return function () { |
| 1171 |
|
| 1172 |
var initData = { |
| 1173 |
title: __('Updating all...'), |
| 1174 |
progressMax: pSitesCount |
| 1175 |
}; |
| 1176 |
updatesoverview_update_popup_init(initData); |
| 1177 |
|
| 1178 |
//Step 3: start updates |
| 1179 |
updatesoverview_themes_upgrade_all_int(undefined, pSitesToUpdate, pSitesPluginSlugs); |
| 1180 |
|
| 1181 |
updatesoverviewContinueAfterBackup = undefined; |
| 1182 |
} |
| 1183 |
}(sitesCount, sitesToUpdate, sitesPluginSlugs); |
| 1184 |
|
| 1185 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1186 |
} |
| 1187 |
|
| 1188 |
// new confirm message |
| 1189 |
if (!continueUpdating) { |
| 1190 |
if (jQuery(siteNames).length > 0) { |
| 1191 |
var sitesList = []; |
| 1192 |
jQuery.each(siteNames, function (index, value) { |
| 1193 |
if (value) { // to fix |
| 1194 |
sitesList.push(decodeURIComponent(value)); |
| 1195 |
} |
| 1196 |
}); |
| 1197 |
var confirmMsg = __('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>', __('themes'), sitesList.join('<br />')); |
| 1198 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 1199 |
} |
| 1200 |
return false; |
| 1201 |
} |
| 1202 |
_callback(); |
| 1203 |
return false; |
| 1204 |
}; |
| 1205 |
|
| 1206 |
updates_please_select_items_notice = function () { |
| 1207 |
var msg = __('Please, select items to update.'); |
| 1208 |
jQuery('#mainwp-modal-confirm-select .content-massage').html(msg); |
| 1209 |
jQuery('#mainwp-modal-confirm-select').modal('show'); |
| 1210 |
return false; |
| 1211 |
} |
| 1212 |
|
| 1213 |
updatesoverview_themes_upgrade_all = function (slug, themeName, updatesSelected) { |
| 1214 |
if (bulkTaskRunning) |
| 1215 |
return false; |
| 1216 |
|
| 1217 |
//Step 1: build form |
| 1218 |
var sitesToUpdate = []; |
| 1219 |
var siteNames = []; |
| 1220 |
var foundChildren = []; |
| 1221 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 1222 |
jQuery('tr[theme_slug="' + slug + '"]').find('table tr[updated="0"]').each( |
| 1223 |
function () { |
| 1224 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 1225 |
foundChildren.push(this); |
| 1226 |
} |
| 1227 |
} |
| 1228 |
); |
| 1229 |
if (foundChildren.length == 0) { |
| 1230 |
updates_please_select_items_notice(); |
| 1231 |
return false; |
| 1232 |
} |
| 1233 |
} else { |
| 1234 |
foundChildren = jQuery('tr[theme_slug="' + slug + '"]').find('table tr[updated="0"]'); |
| 1235 |
} |
| 1236 |
|
| 1237 |
if (foundChildren.length == 0) |
| 1238 |
return false; |
| 1239 |
|
| 1240 |
|
| 1241 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 1242 |
|
| 1243 |
for (var i = 0; i < foundChildren.length; i++) { |
| 1244 |
if (limitUpdateAll > 0 && i >= limitUpdateAll) { |
| 1245 |
continueUpdatesAll = 'themes_upgrade_all'; |
| 1246 |
continueUpdatesSlug = slug; |
| 1247 |
break; |
| 1248 |
} |
| 1249 |
var child = foundChildren[i]; |
| 1250 |
var siteId = jQuery(child).attr('site_id'); |
| 1251 |
var siteName = jQuery(child).attr('site_name'); |
| 1252 |
siteNames[siteId] = siteName; |
| 1253 |
sitesToUpdate.push(siteId); |
| 1254 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteName), '<span class="updatesoverview-upgrade-status-wp" siteid="' + siteId + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 1255 |
} |
| 1256 |
|
| 1257 |
themeName = decodeURIComponent(themeName); |
| 1258 |
themeName = themeName.replace(/\+/g, ' '); |
| 1259 |
|
| 1260 |
var _callback = function () { |
| 1261 |
|
| 1262 |
var sitesCount = sitesToUpdate.length; |
| 1263 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSlug, pSitesToUpdate) { |
| 1264 |
return function () { |
| 1265 |
//Step 2: show form |
| 1266 |
|
| 1267 |
var initData = { |
| 1268 |
title: __('Updating %1', decodeURIComponent(themeName)), |
| 1269 |
progressMax: pSitesCount |
| 1270 |
}; |
| 1271 |
updatesoverview_update_popup_init(initData); |
| 1272 |
|
| 1273 |
//Step 3: start updates |
| 1274 |
updatesoverview_themes_upgrade_all_int(pSlug, pSitesToUpdate); |
| 1275 |
|
| 1276 |
updatesoverviewContinueAfterBackup = undefined; |
| 1277 |
} |
| 1278 |
}(sitesCount, slug, sitesToUpdate); |
| 1279 |
|
| 1280 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1281 |
} |
| 1282 |
|
| 1283 |
// new confirm message |
| 1284 |
if (!continueUpdating) { |
| 1285 |
if (jQuery(siteNames).length > 0) { |
| 1286 |
var sitesList = []; |
| 1287 |
jQuery.each(siteNames, function (index, value) { |
| 1288 |
if (value) { // to fix |
| 1289 |
sitesList.push(decodeURIComponent(value)); |
| 1290 |
} |
| 1291 |
}); |
| 1292 |
var confirmMsg = __('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 />')); |
| 1293 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 1294 |
} |
| 1295 |
return false; |
| 1296 |
} |
| 1297 |
_callback(); |
| 1298 |
return false; |
| 1299 |
}; |
| 1300 |
updatesoverview_themes_upgrade_all_int = function (slug, websiteIds, sitesThemeSlugs) { |
| 1301 |
currentThemeSlugToUpgrade = slug; |
| 1302 |
websitesThemeSlugsToUpgrade = sitesThemeSlugs; |
| 1303 |
websitesToUpdate = websiteIds; |
| 1304 |
currentWebsite = 0; |
| 1305 |
websitesDone = 0; |
| 1306 |
websitesTotal = websitesLeft = websitesToUpdate.length; |
| 1307 |
|
| 1308 |
bulkTaskRunning = true; |
| 1309 |
updatesoverview_themes_upgrade_all_loop_next(); |
| 1310 |
}; |
| 1311 |
updatesoverview_themes_upgrade_all_loop_next = function () { |
| 1312 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 1313 |
updatesoverview_themes_upgrade_all_upgrade_next(); |
| 1314 |
} |
| 1315 |
}; |
| 1316 |
updatesoverview_themes_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 1317 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 1318 |
}; |
| 1319 |
updatesoverview_themes_upgrade_all_upgrade_next = function () { |
| 1320 |
currentThreads++; |
| 1321 |
websitesLeft--; |
| 1322 |
|
| 1323 |
var websiteId = websitesToUpdate[currentWebsite++]; |
| 1324 |
updatesoverview_themes_upgrade_all_update_site_status(websiteId, '<i class="notched circle loading icon"></i>'); |
| 1325 |
|
| 1326 |
var slugToUpgrade = currentThemeSlugToUpgrade; |
| 1327 |
if (slugToUpgrade == undefined) |
| 1328 |
slugToUpgrade = websitesThemeSlugsToUpgrade[websiteId]; |
| 1329 |
updatesoverview_themes_upgrade_int(slugToUpgrade, websiteId, true); |
| 1330 |
}; |
| 1331 |
updatesoverview_themes_upgrade_all_update_done = function () { |
| 1332 |
currentThreads--; |
| 1333 |
if (!bulkTaskRunning) |
| 1334 |
return; |
| 1335 |
websitesDone++; |
| 1336 |
|
| 1337 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 1338 |
|
| 1339 |
if (websitesDone == websitesTotal) { |
| 1340 |
updatesoverview_check_to_continue_updates(); |
| 1341 |
return; |
| 1342 |
} |
| 1343 |
|
| 1344 |
updatesoverview_themes_upgrade_all_loop_next(); |
| 1345 |
}; |
| 1346 |
updatesoverview_themes_upgrade_int = function (slug, websiteId, bulkMode) { |
| 1347 |
var slugParts = slug.split(','); |
| 1348 |
for (var i = 0; i < slugParts.length; i++) { |
| 1349 |
var websiteHolder = jQuery('.themes-bulk-updates[theme_slug="' + slugParts[i] + '"] tr[site_id="' + websiteId + '"]'); |
| 1350 |
if (!websiteHolder.exists()) { |
| 1351 |
websiteHolder = jQuery('.themes-bulk-updates[site_id="' + websiteId + '"] tr[theme_slug="' + slugParts[i] + '"]'); |
| 1352 |
} |
| 1353 |
websiteHolder.find('td:last-child').html('<i class="notched circle loading icon"></i> ' + __('Updating. Please wait...')); |
| 1354 |
|
| 1355 |
} |
| 1356 |
|
| 1357 |
var data = mainwp_secure_data({ |
| 1358 |
action: 'mainwp_upgradeplugintheme', |
| 1359 |
websiteId: websiteId, |
| 1360 |
type: 'theme', |
| 1361 |
slug: slug |
| 1362 |
}); |
| 1363 |
jQuery.ajax({ |
| 1364 |
type: "POST", |
| 1365 |
url: ajaxurl, |
| 1366 |
data: data, |
| 1367 |
success: function (pSlug, pWebsiteId, pBulkMode) { |
| 1368 |
return function (response) { |
| 1369 |
var slugParts = pSlug.split(','); |
| 1370 |
var done = false; |
| 1371 |
var success = false; |
| 1372 |
var error = ''; |
| 1373 |
for (var i = 0; i < slugParts.length; i++) { |
| 1374 |
var websiteHolder = jQuery('.themes-bulk-updates[theme_slug="' + slugParts[i] + '"] tr[site_id="' + websiteId + '"]'); |
| 1375 |
if (!websiteHolder.exists()) { |
| 1376 |
websiteHolder = jQuery('.themes-bulk-updates[site_id="' + websiteId + '"] tr[theme_slug="' + slugParts[i] + '"]'); |
| 1377 |
} |
| 1378 |
|
| 1379 |
if (response.error) { |
| 1380 |
var extErr = getErrorMessageInfo(response.error, 'ui') |
| 1381 |
if (!done && pBulkMode) |
| 1382 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, extErr); |
| 1383 |
websiteHolder.find('td:last-child').html(extErr); |
| 1384 |
error = getErrorMessageInfo(response.error); |
| 1385 |
} else { |
| 1386 |
var res = response.result; |
| 1387 |
|
| 1388 |
if (res[slugParts[i]]) { |
| 1389 |
if (!done && pBulkMode) |
| 1390 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, '<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', websiteId)); |
| 1391 |
websiteHolder.attr('updated', 1); |
| 1392 |
websiteHolder.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful', 'mainwp') + '"><i class="green check icon"></i></span>' + ' ' + mainwp_links_visit_site_and_admin('', websiteId)); |
| 1393 |
success = true; |
| 1394 |
} else { |
| 1395 |
if (!done && pBulkMode) |
| 1396 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 1397 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 1398 |
error = __('Undefined error'); |
| 1399 |
|
| 1400 |
} |
| 1401 |
|
| 1402 |
} |
| 1403 |
if (!done && pBulkMode) { |
| 1404 |
updatesoverview_themes_upgrade_all_update_done(); |
| 1405 |
done = true; |
| 1406 |
} |
| 1407 |
} |
| 1408 |
} |
| 1409 |
}(slug, websiteId, bulkMode), |
| 1410 |
tryCount: 0, |
| 1411 |
retryLimit: 3, |
| 1412 |
endError: function (pSlug, pWebsiteId, pBulkMode) { |
| 1413 |
return function () { |
| 1414 |
var slugParts = pSlug.split(','); |
| 1415 |
var done = false; |
| 1416 |
for (var i = 0; i < slugParts.length; i++) { |
| 1417 |
var websiteHolder = jQuery('div[theme_slug="' + slugParts[i] + '"] div[site_id="' + pWebsiteId + '"]'); |
| 1418 |
if (!websiteHolder.exists()) { |
| 1419 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[theme_slug="' + slugParts[i] + '"]'); |
| 1420 |
} |
| 1421 |
|
| 1422 |
if (!done && pBulkMode) { |
| 1423 |
updatesoverview_themes_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 1424 |
updatesoverview_themes_upgrade_all_update_done(); |
| 1425 |
done = true; |
| 1426 |
} |
| 1427 |
websiteHolder.find('td:last-child').html('<i class="red times icon"></i>'); |
| 1428 |
} |
| 1429 |
} |
| 1430 |
}(slug, websiteId, bulkMode), |
| 1431 |
error: function (xhr) { |
| 1432 |
this.tryCount++; |
| 1433 |
if (this.tryCount >= this.retryLimit) { |
| 1434 |
this.endError(); |
| 1435 |
return; |
| 1436 |
} |
| 1437 |
|
| 1438 |
var fnc = function (pRqst, pXhr) { |
| 1439 |
return function () { |
| 1440 |
if (pXhr.status == 404) { |
| 1441 |
//handle error |
| 1442 |
jQuery.ajax(pRqst); |
| 1443 |
} else if (pXhr.status == 500) { |
| 1444 |
//handle error |
| 1445 |
} else { |
| 1446 |
//handle error |
| 1447 |
} |
| 1448 |
} |
| 1449 |
}(this, xhr); |
| 1450 |
setTimeout(fnc, 500); |
| 1451 |
}, |
| 1452 |
dataType: 'json' |
| 1453 |
}); |
| 1454 |
|
| 1455 |
return false; |
| 1456 |
}; |
| 1457 |
|
| 1458 |
|
| 1459 |
/* eslint-disable complexity */ |
| 1460 |
updatesoverview_global_upgrade_all = function (which) { |
| 1461 |
|
| 1462 |
if (bulkTaskRunning) |
| 1463 |
return false; |
| 1464 |
|
| 1465 |
//Step 1: build form |
| 1466 |
var sitesToUpdate = []; |
| 1467 |
var sitesToUpgrade = []; |
| 1468 |
var sitesPluginSlugs = {}; |
| 1469 |
var sitesThemeSlugs = {}; |
| 1470 |
var sitesTranslationSlugs = {}; |
| 1471 |
var siteNames = {}; |
| 1472 |
|
| 1473 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 1474 |
|
| 1475 |
var sitesCount = 0; |
| 1476 |
var foundChildren = undefined; |
| 1477 |
|
| 1478 |
if (which == 'all' || which == 'wp') { |
| 1479 |
//Find wordpress to update |
| 1480 |
foundChildren = jQuery('#wp_upgrades').find('div[updated="0"]'); |
| 1481 |
if (foundChildren.length != 0) { |
| 1482 |
for (var i = 0; i < foundChildren.length; i++) { |
| 1483 |
var child = jQuery(foundChildren[i]); |
| 1484 |
var siteId = child.attr('site_id'); |
| 1485 |
var siteName = child.attr('site_name'); |
| 1486 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 1487 |
sitesCount++; |
| 1488 |
sitesToUpdate.push(siteId); |
| 1489 |
siteNames[siteId] = siteName; |
| 1490 |
} |
| 1491 |
if (sitesToUpgrade.indexOf(siteId) == -1) |
| 1492 |
sitesToUpgrade.push(siteId); |
| 1493 |
} |
| 1494 |
} |
| 1495 |
} |
| 1496 |
|
| 1497 |
if (which == 'all' || which == 'plugin') { |
| 1498 |
//Find plugins to update |
| 1499 |
foundChildren = jQuery('#wp_plugin_upgrades').find('div[updated="0"]'); |
| 1500 |
if (foundChildren.length != 0) { |
| 1501 |
for (var i = 0; i < foundChildren.length; i++) { |
| 1502 |
var child = jQuery(foundChildren[i]); |
| 1503 |
siteElement = child; |
| 1504 |
|
| 1505 |
var siteId = siteElement.attr('site_id'); |
| 1506 |
var siteName = siteElement.attr('site_name'); |
| 1507 |
var pluginSlug = siteElement.attr('plugin_slug'); |
| 1508 |
|
| 1509 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 1510 |
sitesCount++; |
| 1511 |
sitesToUpdate.push(siteId); |
| 1512 |
siteNames[siteId] = siteName; |
| 1513 |
} |
| 1514 |
|
| 1515 |
if (sitesPluginSlugs[siteId] == undefined) { |
| 1516 |
sitesPluginSlugs[siteId] = pluginSlug; |
| 1517 |
} else { |
| 1518 |
sitesPluginSlugs[siteId] += ',' + pluginSlug; |
| 1519 |
} |
| 1520 |
} |
| 1521 |
} |
| 1522 |
} |
| 1523 |
|
| 1524 |
if (which == 'all' || which == 'theme') { |
| 1525 |
//Find themes to update |
| 1526 |
foundChildren = jQuery('#wp_theme_upgrades').find('div[updated="0"]'); |
| 1527 |
if (foundChildren.length != 0) { |
| 1528 |
for (var i = 0; i < foundChildren.length; i++) { |
| 1529 |
var child = jQuery(foundChildren[i]); |
| 1530 |
var siteElement = child; |
| 1531 |
|
| 1532 |
var siteId = siteElement.attr('site_id'); |
| 1533 |
var siteName = siteElement.attr('site_name'); |
| 1534 |
var themeSlug = siteElement.attr('theme_slug'); |
| 1535 |
|
| 1536 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 1537 |
sitesCount++; |
| 1538 |
sitesToUpdate.push(siteId); |
| 1539 |
siteNames[siteId] = siteName; |
| 1540 |
} |
| 1541 |
|
| 1542 |
if (sitesThemeSlugs[siteId] == undefined) { |
| 1543 |
sitesThemeSlugs[siteId] = themeSlug; |
| 1544 |
} else { |
| 1545 |
sitesThemeSlugs[siteId] += ',' + themeSlug; |
| 1546 |
} |
| 1547 |
} |
| 1548 |
} |
| 1549 |
} |
| 1550 |
|
| 1551 |
if (which == 'all' || which == 'translation') { |
| 1552 |
//Find translation to update |
| 1553 |
foundChildren = jQuery('#wp_translation_upgrades').find('div[updated="0"]'); |
| 1554 |
if (foundChildren.length != 0) { |
| 1555 |
for (var i = 0; i < foundChildren.length; i++) { |
| 1556 |
var child = jQuery(foundChildren[i]); |
| 1557 |
var siteElement = child; |
| 1558 |
|
| 1559 |
var siteId = siteElement.attr('site_id'); |
| 1560 |
var siteName = siteElement.attr('site_name'); |
| 1561 |
var transSlug = siteElement.attr('translation_slug'); |
| 1562 |
|
| 1563 |
if (sitesToUpdate.indexOf(siteId) == -1) { |
| 1564 |
sitesCount++; |
| 1565 |
sitesToUpdate.push(siteId); |
| 1566 |
siteNames[siteId] = siteName; |
| 1567 |
} |
| 1568 |
|
| 1569 |
if (sitesTranslationSlugs[siteId] == undefined) { |
| 1570 |
sitesTranslationSlugs[siteId] = transSlug; |
| 1571 |
} else { |
| 1572 |
sitesTranslationSlugs[siteId] += ',' + transSlug; |
| 1573 |
} |
| 1574 |
} |
| 1575 |
} |
| 1576 |
} |
| 1577 |
|
| 1578 |
var _callback = function () { |
| 1579 |
//Build form |
| 1580 |
for (var j = 0; j < sitesToUpdate.length; j++) { |
| 1581 |
var siteId = sitesToUpdate[j]; |
| 1582 |
|
| 1583 |
var whatToUpgrade = ''; |
| 1584 |
|
| 1585 |
if (sitesToUpgrade.indexOf(siteId) != -1) |
| 1586 |
whatToUpgrade = '<span class="wordpress">WordPress core files</span>'; |
| 1587 |
|
| 1588 |
if (sitesPluginSlugs[siteId] != undefined) { |
| 1589 |
var updateCount = sitesPluginSlugs[siteId].match(/,/g); |
| 1590 |
if (updateCount == null) |
| 1591 |
updateCount = 1; |
| 1592 |
else |
| 1593 |
updateCount = updateCount.length + 1; |
| 1594 |
|
| 1595 |
if (whatToUpgrade != '') |
| 1596 |
whatToUpgrade += ', '; |
| 1597 |
|
| 1598 |
whatToUpgrade += '<span class="plugin">' + updateCount + ' plugin' + (updateCount > 1 ? 's' : '') + '</span>'; |
| 1599 |
} |
| 1600 |
|
| 1601 |
if (sitesThemeSlugs[siteId] != undefined) { |
| 1602 |
var updateCount = sitesThemeSlugs[siteId].match(/,/g); |
| 1603 |
if (updateCount == null) |
| 1604 |
updateCount = 1; |
| 1605 |
else |
| 1606 |
updateCount = updateCount.length + 1; |
| 1607 |
|
| 1608 |
if (whatToUpgrade != '') |
| 1609 |
whatToUpgrade += ', '; |
| 1610 |
|
| 1611 |
whatToUpgrade += '<span class="theme">' + updateCount + ' theme' + (updateCount > 1 ? 's' : '') + '</span>'; |
| 1612 |
} |
| 1613 |
|
| 1614 |
|
| 1615 |
if (sitesTranslationSlugs[siteId] != undefined) { |
| 1616 |
var updateCount = sitesTranslationSlugs[siteId].match(/,/g); |
| 1617 |
if (updateCount == null) |
| 1618 |
updateCount = 1; |
| 1619 |
else |
| 1620 |
updateCount = updateCount.length + 1; |
| 1621 |
|
| 1622 |
if (whatToUpgrade != '') |
| 1623 |
whatToUpgrade += ', '; |
| 1624 |
|
| 1625 |
whatToUpgrade += '<span class="translation">' + updateCount + ' translation' + (updateCount > 1 ? 's' : '') + '</span>'; |
| 1626 |
} |
| 1627 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(siteNames[siteId]) + ' (' + whatToUpgrade + ')', '<span class="updatesoverview-upgrade-status-wp" siteid="' + siteId + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 1628 |
} |
| 1629 |
|
| 1630 |
updatesoverviewContinueAfterBackup = function (pSitesCount, pSitesToUpdate, pSitesToUpgrade, pSitesPluginSlugs, pSitesThemeSlugs, psitesTranslationSlugs) { |
| 1631 |
return function () { |
| 1632 |
//Step 2: show form |
| 1633 |
|
| 1634 |
var initData = { |
| 1635 |
title: __('Updating All'), |
| 1636 |
progressMax: pSitesCount |
| 1637 |
}; |
| 1638 |
updatesoverview_update_popup_init(initData); |
| 1639 |
|
| 1640 |
//Step 3: start updates |
| 1641 |
updatesoverview_upgrade_all_int(pSitesToUpdate, pSitesToUpgrade, pSitesPluginSlugs, pSitesThemeSlugs, psitesTranslationSlugs); |
| 1642 |
|
| 1643 |
updatesoverviewContinueAfterBackup = undefined; |
| 1644 |
}; |
| 1645 |
}(sitesCount, sitesToUpdate, sitesToUpgrade, sitesPluginSlugs, sitesThemeSlugs, sitesTranslationSlugs); |
| 1646 |
|
| 1647 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 1648 |
} // end _callback() |
| 1649 |
|
| 1650 |
// new confirm message |
| 1651 |
if (jQuery(siteNames).length > 0) { |
| 1652 |
var sitesList = []; |
| 1653 |
jQuery.each(siteNames, function (index, value) { |
| 1654 |
if (value) { // to fix |
| 1655 |
sitesList.push(decodeURIComponent(value)); |
| 1656 |
} |
| 1657 |
}); |
| 1658 |
|
| 1659 |
var whichUpdates = __('WordPress core files, plugins, themes and translations'); |
| 1660 |
if (which == 'wp') { |
| 1661 |
whichUpdates = __('WordPress core files'); |
| 1662 |
} else if (which == 'plugin') { |
| 1663 |
whichUpdates = __('plugins'); |
| 1664 |
} else if (which == 'theme') { |
| 1665 |
whichUpdates = __('themes'); |
| 1666 |
} else if (which == 'translation') { |
| 1667 |
whichUpdates = __('translations'); |
| 1668 |
} |
| 1669 |
|
| 1670 |
var confirmMsg = __('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 />')); |
| 1671 |
|
| 1672 |
mainwp_confirm(confirmMsg, _callback, false, 2); |
| 1673 |
return false; |
| 1674 |
} else { |
| 1675 |
return false; |
| 1676 |
} |
| 1677 |
|
| 1678 |
}; |
| 1679 |
/* eslint-enable complexity */ |
| 1680 |
|
| 1681 |
updatesoverview_upgrade_all_int = function (pSitesToUpdate, pSitesToUpgrade, pSitesPluginSlugs, pSitesThemeSlugs, psitesTranslationSlugs) { |
| 1682 |
websitesToUpdate = pSitesToUpdate; |
| 1683 |
|
| 1684 |
websitesToUpgrade = pSitesToUpgrade; |
| 1685 |
|
| 1686 |
websitesPluginSlugsToUpgrade = pSitesPluginSlugs; |
| 1687 |
currentPluginSlugToUpgrade = undefined; |
| 1688 |
|
| 1689 |
websitesThemeSlugsToUpgrade = pSitesThemeSlugs; |
| 1690 |
currentThemeSlugToUpgrade = undefined; |
| 1691 |
|
| 1692 |
websitesTransSlugsToUpgrade = psitesTranslationSlugs; |
| 1693 |
currentTransSlugToUpgrade = undefined; |
| 1694 |
|
| 1695 |
currentWebsite = 0; |
| 1696 |
websitesDone = 0; |
| 1697 |
websitesTotal = websitesLeft = websitesToUpdate.length; |
| 1698 |
|
| 1699 |
bulkTaskRunning = true; |
| 1700 |
|
| 1701 |
updatesoverview_upgrade_all_loop_next(); |
| 1702 |
}; |
| 1703 |
|
| 1704 |
updatesoverview_upgrade_all_loop_next = function () { |
| 1705 |
while (bulkTaskRunning && (currentThreads < maxThreads) && (websitesLeft > 0)) { |
| 1706 |
updatesoverview_upgrade_all_upgrade_next(); |
| 1707 |
} |
| 1708 |
}; |
| 1709 |
updatesoverview_upgrade_all_update_site_status = function (siteId, newStatus) { |
| 1710 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').html(newStatus); |
| 1711 |
}; |
| 1712 |
updatesoverview_upgrade_all_update_site_bold = function (siteId, sub) { |
| 1713 |
jQuery('.updatesoverview-upgrade-status-wp[siteid="' + siteId + '"]').parent().parent().find('.' + sub).css('font-weight', 'bold'); |
| 1714 |
}; |
| 1715 |
updatesoverview_upgrade_all_upgrade_next = function () { |
| 1716 |
currentThreads++; |
| 1717 |
websitesLeft--; |
| 1718 |
|
| 1719 |
var websiteId = websitesToUpdate[currentWebsite++]; |
| 1720 |
updatesoverview_upgrade_all_update_site_status(websiteId, '<i class="notched circle loading icon"></i>'); |
| 1721 |
|
| 1722 |
var themeSlugToUpgrade = websitesThemeSlugsToUpgrade[websiteId]; |
| 1723 |
var pluginSlugToUpgrade = websitesPluginSlugsToUpgrade[websiteId]; |
| 1724 |
var transSlugToUpgrade = websitesTransSlugsToUpgrade[websiteId]; |
| 1725 |
var wordpressUpgrade = (websitesToUpgrade.indexOf(websiteId) != -1); |
| 1726 |
|
| 1727 |
updatesoverview_upgrade_int(websiteId, themeSlugToUpgrade, pluginSlugToUpgrade, wordpressUpgrade, transSlugToUpgrade); |
| 1728 |
}; |
| 1729 |
|
| 1730 |
updatesoverview_upgrade_int = function (websiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade) { |
| 1731 |
updatesoverview_upgrade_int_flow(websiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, (pThemeSlugToUpgrade == undefined), (pPluginSlugToUpgrade == undefined), !pWordpressUpgrade, undefined, pTransSlugToUpgrade, (pTransSlugToUpgrade == undefined)); |
| 1732 |
return false; |
| 1733 |
}; |
| 1734 |
|
| 1735 |
updatesoverview_upgrade_int_loop_flow = function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { |
| 1736 |
updatesoverview_upgrade_int_flow(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone); |
| 1737 |
return false; |
| 1738 |
}; |
| 1739 |
|
| 1740 |
updatesoverview_upgrade_all_update_done = function () { |
| 1741 |
currentThreads--; |
| 1742 |
if (!bulkTaskRunning) |
| 1743 |
return; |
| 1744 |
websitesDone++; |
| 1745 |
|
| 1746 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(websitesDone); |
| 1747 |
|
| 1748 |
if (websitesDone == websitesTotal) { |
| 1749 |
setTimeout(function () { |
| 1750 |
bulkTaskRunning = false; |
| 1751 |
// close and refresh page |
| 1752 |
mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 1753 |
|
| 1754 |
}, 3000); |
| 1755 |
return; |
| 1756 |
} |
| 1757 |
|
| 1758 |
updatesoverview_upgrade_all_loop_next(); |
| 1759 |
}; |
| 1760 |
|
| 1761 |
updatesoverview_upgrade_int_flow = function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { |
| 1762 |
if (!pThemeDone) { |
| 1763 |
var data = mainwp_secure_data({ |
| 1764 |
action: 'mainwp_upgradeplugintheme', |
| 1765 |
websiteId: pWebsiteId, |
| 1766 |
type: 'theme', |
| 1767 |
slug: pThemeSlugToUpgrade |
| 1768 |
}); |
| 1769 |
|
| 1770 |
jQuery.ajax({ |
| 1771 |
type: "POST", |
| 1772 |
url: ajaxurl, |
| 1773 |
data: data, |
| 1774 |
success: function (pWebsiteId, pSlug, pPluginSlugToUpgrade, pWordpressUpgrade, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { |
| 1775 |
return function (response) { |
| 1776 |
var slugParts = pSlug.split(','); |
| 1777 |
var success = false; |
| 1778 |
for (var i = 0; i < slugParts.length; i++) { |
| 1779 |
var result; |
| 1780 |
success = false; |
| 1781 |
var websiteHolder = jQuery('div[theme_slug="' + slugParts[i] + '"] div[site_id="' + pWebsiteId + '"]'); |
| 1782 |
if (!websiteHolder.exists()) { |
| 1783 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[theme_slug="' + slugParts[i] + '"]'); |
| 1784 |
} |
| 1785 |
if (response.error) { |
| 1786 |
result = getErrorMessage(response.error); |
| 1787 |
pErrorMessage = result; |
| 1788 |
} else { |
| 1789 |
var res = response.result; |
| 1790 |
|
| 1791 |
if (res[slugParts[i]]) { |
| 1792 |
websiteHolder.attr('updated', 1); |
| 1793 |
success = true; |
| 1794 |
} else { |
| 1795 |
result = __('Update failed!'); |
| 1796 |
pErrorMessage = result; |
| 1797 |
} |
| 1798 |
} |
| 1799 |
|
| 1800 |
} |
| 1801 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'theme'); |
| 1802 |
|
| 1803 |
//If all done: continue, else delay 400ms to not stress the server |
| 1804 |
var fnc = function () { |
| 1805 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pSlug, pPluginSlugToUpgrade, pWordpressUpgrade, true, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone); |
| 1806 |
}; |
| 1807 |
|
| 1808 |
if (pPluginDone && pUpgradeDone && pTransDone) |
| 1809 |
fnc(); |
| 1810 |
else |
| 1811 |
setTimeout(fnc, 400); |
| 1812 |
} |
| 1813 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pPluginDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone), |
| 1814 |
tryCount: 0, |
| 1815 |
retryLimit: 3, |
| 1816 |
endError: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade) { |
| 1817 |
return function () { |
| 1818 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, true, true, true, 'Error processing request', pTransSlugToUpgrade, true); |
| 1819 |
} |
| 1820 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade), |
| 1821 |
error: function (xhr) { |
| 1822 |
this.tryCount++; |
| 1823 |
if (this.tryCount >= this.retryLimit) { |
| 1824 |
this.endError(); |
| 1825 |
return; |
| 1826 |
} |
| 1827 |
|
| 1828 |
var fnc = function (pRqst, pXhr) { |
| 1829 |
return function () { |
| 1830 |
if (pXhr.status == 404) { |
| 1831 |
//handle error |
| 1832 |
jQuery.ajax(pRqst); |
| 1833 |
} else if (pXhr.status == 500) { |
| 1834 |
//handle error |
| 1835 |
} else { |
| 1836 |
//handle error |
| 1837 |
} |
| 1838 |
} |
| 1839 |
}(this, xhr); |
| 1840 |
setTimeout(fnc, 1000); |
| 1841 |
}, |
| 1842 |
dataType: 'json' |
| 1843 |
}); |
| 1844 |
} else if (!pPluginDone) { |
| 1845 |
var data = mainwp_secure_data({ |
| 1846 |
action: 'mainwp_upgradeplugintheme', |
| 1847 |
websiteId: pWebsiteId, |
| 1848 |
type: 'plugin', |
| 1849 |
slug: pPluginSlugToUpgrade |
| 1850 |
}); |
| 1851 |
|
| 1852 |
jQuery.ajax({ |
| 1853 |
type: "POST", |
| 1854 |
url: ajaxurl, |
| 1855 |
data: data, |
| 1856 |
success: function (pWebsiteId, pThemeSlugToUpgrade, pSlug, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { |
| 1857 |
return function (response) { |
| 1858 |
var slugParts = pSlug.split(','); |
| 1859 |
var success = false; |
| 1860 |
for (var i = 0; i < slugParts.length; i++) { |
| 1861 |
var result; |
| 1862 |
success = false; |
| 1863 |
var websiteHolder = jQuery('div[theme_slug="' + slugParts[i] + '"] div[site_id="' + pWebsiteId + '"]'); |
| 1864 |
if (!websiteHolder.exists()) { |
| 1865 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[theme_slug="' + slugParts[i] + '"]'); |
| 1866 |
} |
| 1867 |
if (response.error) { |
| 1868 |
result = getErrorMessage(response.error); |
| 1869 |
pErrorMessage = result; |
| 1870 |
} |
| 1871 |
else { |
| 1872 |
var res = response.result; // result is an object |
| 1873 |
var res_error = response.result_error; |
| 1874 |
if (res[encodeURIComponent(slugParts[i])]) { |
| 1875 |
websiteHolder.attr('updated', 1); |
| 1876 |
success = true; |
| 1877 |
} else if (res_error[encodeURIComponent(slugParts[i])]) { |
| 1878 |
pErrorMessage = res_error[encodeURIComponent(slugParts[i])]; |
| 1879 |
} else { |
| 1880 |
result = __('Update failed!'); |
| 1881 |
pErrorMessage = result; |
| 1882 |
} |
| 1883 |
} |
| 1884 |
} |
| 1885 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'plugin'); |
| 1886 |
|
| 1887 |
//If all done: continue, else delay 400ms to not stress the server |
| 1888 |
var fnc = function () { |
| 1889 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pThemeSlugToUpgrade, pSlug, pWordpressUpgrade, pThemeDone, true, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone); |
| 1890 |
}; |
| 1891 |
|
| 1892 |
if (pThemeDone && pUpgradeDone && pTransDone) |
| 1893 |
fnc(); |
| 1894 |
else |
| 1895 |
setTimeout(fnc, 400); |
| 1896 |
} |
| 1897 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade, pTransDone), |
| 1898 |
tryCount: 0, |
| 1899 |
retryLimit: 3, |
| 1900 |
endError: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade) { |
| 1901 |
return function () { |
| 1902 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, true, true, true, 'Error processing request', pTransSlugToUpgrade, true); |
| 1903 |
} |
| 1904 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade), |
| 1905 |
error: function (xhr) { |
| 1906 |
this.tryCount++; |
| 1907 |
if (this.tryCount >= this.retryLimit) { |
| 1908 |
this.endError(); |
| 1909 |
return; |
| 1910 |
} |
| 1911 |
|
| 1912 |
var fnc = function (pRqst, pXhr) { |
| 1913 |
return function () { |
| 1914 |
if (pXhr.status == 404) { |
| 1915 |
//handle error |
| 1916 |
jQuery.ajax(pRqst); |
| 1917 |
} else if (pXhr.status == 500) { |
| 1918 |
//handle error |
| 1919 |
} else { |
| 1920 |
//handle error |
| 1921 |
} |
| 1922 |
} |
| 1923 |
}(this, xhr); |
| 1924 |
setTimeout(fnc, 1000); |
| 1925 |
}, |
| 1926 |
dataType: 'json' |
| 1927 |
}); |
| 1928 |
} else if (!pUpgradeDone) { |
| 1929 |
var data = mainwp_secure_data({ |
| 1930 |
action: 'mainwp_upgradewp', |
| 1931 |
id: pWebsiteId |
| 1932 |
}); |
| 1933 |
|
| 1934 |
jQuery.ajax({ |
| 1935 |
type: "POST", |
| 1936 |
url: ajaxurl, |
| 1937 |
data: data, |
| 1938 |
success: function (WebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pErrorMessage, pTransSlugToUpgrade, pTransDone) { |
| 1939 |
return function (response) { |
| 1940 |
var result; |
| 1941 |
var websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"]'); |
| 1942 |
var success = false; |
| 1943 |
if (response.error) { |
| 1944 |
result = getErrorMessage(response.error); |
| 1945 |
pErrorMessage = result; |
| 1946 |
} else { |
| 1947 |
result = response.result; |
| 1948 |
websiteHolder.attr('updated', 1); |
| 1949 |
success = true; |
| 1950 |
} |
| 1951 |
|
| 1952 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'wordpress'); |
| 1953 |
|
| 1954 |
//If all done: continue, else delay 400ms to not stress the server |
| 1955 |
var fnc = function () { |
| 1956 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, true, pErrorMessage, pTransSlugToUpgrade, pTransDone); |
| 1957 |
}; |
| 1958 |
|
| 1959 |
if (pThemeDone && pPluginDone && pTransDone) |
| 1960 |
fnc(); |
| 1961 |
else |
| 1962 |
setTimeout(fnc, 400); |
| 1963 |
} |
| 1964 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pErrorMessage, pTransSlugToUpgrade, pTransDone), |
| 1965 |
tryCount: 0, |
| 1966 |
retryLimit: 3, |
| 1967 |
endError: function (WebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade) { |
| 1968 |
return function () { |
| 1969 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, true, true, true, 'Error processing request', pTransSlugToUpgrade, true); |
| 1970 |
} |
| 1971 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade), |
| 1972 |
error: function (xhr) { |
| 1973 |
this.tryCount++; |
| 1974 |
if (this.tryCount >= this.retryLimit) { |
| 1975 |
this.endError(); |
| 1976 |
return; |
| 1977 |
} |
| 1978 |
|
| 1979 |
var fnc = function (pRqst, pXhr) { |
| 1980 |
return function () { |
| 1981 |
if (pXhr.status == 404) { |
| 1982 |
//handle error |
| 1983 |
jQuery.ajax(pRqst); |
| 1984 |
} else if (pXhr.status == 500) { |
| 1985 |
//handle error |
| 1986 |
} else { |
| 1987 |
//handle error |
| 1988 |
} |
| 1989 |
} |
| 1990 |
}(this, xhr); |
| 1991 |
setTimeout(fnc, 1000); |
| 1992 |
}, |
| 1993 |
dataType: 'json' |
| 1994 |
}); |
| 1995 |
} else if (!pTransDone) { |
| 1996 |
var data = mainwp_secure_data({ |
| 1997 |
action: 'mainwp_upgradeplugintheme', |
| 1998 |
websiteId: pWebsiteId, |
| 1999 |
type: 'translation', |
| 2000 |
slug: pTransSlugToUpgrade |
| 2001 |
}); |
| 2002 |
|
| 2003 |
jQuery.ajax({ |
| 2004 |
type: "POST", |
| 2005 |
url: ajaxurl, |
| 2006 |
data: data, |
| 2007 |
success: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, pSlug) { |
| 2008 |
return function (response) { |
| 2009 |
var slugParts = pSlug.split(','); |
| 2010 |
var success; |
| 2011 |
for (var i = 0; i < slugParts.length; i++) { |
| 2012 |
var result; |
| 2013 |
success = false; |
| 2014 |
var websiteHolder = jQuery('div[translation_slug="' + slugParts[i] + '"] div[site_id="' + pWebsiteId + '"]'); |
| 2015 |
if (!websiteHolder.exists()) { |
| 2016 |
websiteHolder = jQuery('div[site_id="' + pWebsiteId + '"] div[translation_slug="' + slugParts[i] + '"]'); |
| 2017 |
} |
| 2018 |
if (response.error) { |
| 2019 |
result = getErrorMessage(response.error); |
| 2020 |
pErrorMessage = result; |
| 2021 |
} else { |
| 2022 |
var res = response.result; |
| 2023 |
if (res[slugParts[i]]) { |
| 2024 |
websiteHolder.attr('updated', 1); |
| 2025 |
success = true; |
| 2026 |
} else { |
| 2027 |
result = __('Update failed!'); |
| 2028 |
pErrorMessage = result; |
| 2029 |
} |
| 2030 |
|
| 2031 |
} |
| 2032 |
} |
| 2033 |
|
| 2034 |
updatesoverview_upgrade_all_update_site_bold(pWebsiteId, 'translation'); |
| 2035 |
|
| 2036 |
//If all done: continue, else delay 400ms to not stress the server |
| 2037 |
var fnc = function () { |
| 2038 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pPluginDone, pUpgradeDone, pErrorMessage, pSlug, true); |
| 2039 |
}; |
| 2040 |
|
| 2041 |
if (pThemeDone && pUpgradeDone && pPluginDone) |
| 2042 |
fnc(); |
| 2043 |
else |
| 2044 |
setTimeout(fnc, 400); |
| 2045 |
} |
| 2046 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pThemeDone, pUpgradeDone, pErrorMessage, pTransSlugToUpgrade), |
| 2047 |
tryCount: 0, |
| 2048 |
retryLimit: 3, |
| 2049 |
endError: function (pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade) { |
| 2050 |
return function () { |
| 2051 |
updatesoverview_upgrade_int_loop_flow(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, true, true, true, 'Error processing request', pTransSlugToUpgrade, true); |
| 2052 |
} |
| 2053 |
}(pWebsiteId, pThemeSlugToUpgrade, pPluginSlugToUpgrade, pWordpressUpgrade, pTransSlugToUpgrade), |
| 2054 |
error: function (xhr) { |
| 2055 |
this.tryCount++; |
| 2056 |
if (this.tryCount >= this.retryLimit) { |
| 2057 |
this.endError(); |
| 2058 |
return; |
| 2059 |
} |
| 2060 |
|
| 2061 |
var fnc = function (pRqst, pXhr) { |
| 2062 |
return function () { |
| 2063 |
if (pXhr.status == 404) { |
| 2064 |
//handle error |
| 2065 |
jQuery.ajax(pRqst); |
| 2066 |
} else if (pXhr.status == 500) { |
| 2067 |
//handle error |
| 2068 |
} else { |
| 2069 |
//handle error |
| 2070 |
} |
| 2071 |
} |
| 2072 |
}(this, xhr); |
| 2073 |
setTimeout(fnc, 1000); |
| 2074 |
}, |
| 2075 |
dataType: 'json' |
| 2076 |
}); |
| 2077 |
} else { |
| 2078 |
if ((pErrorMessage != undefined) && (pErrorMessage != '')) { |
| 2079 |
updatesoverview_upgrade_all_update_site_status(pWebsiteId, '<i class="red times icon"></i>'); |
| 2080 |
} else { |
| 2081 |
updatesoverview_upgrade_all_update_site_status(pWebsiteId, '<i class="green check icon"></i>'); |
| 2082 |
} |
| 2083 |
updatesoverview_upgrade_all_update_done(); |
| 2084 |
|
| 2085 |
return false; |
| 2086 |
} |
| 2087 |
}; |
| 2088 |
|
| 2089 |
updatesoverview_plugins_dismiss_outdate_detail = function (slug, name, id, obj) { |
| 2090 |
return updatesoverview_dismiss_outdate_plugintheme_by_site('plugin', slug, name, id, obj); |
| 2091 |
}; |
| 2092 |
updatesoverview_themes_dismiss_outdate_detail = function (slug, name, id, obj) { |
| 2093 |
return updatesoverview_dismiss_outdate_plugintheme_by_site('theme', slug, name, id, obj); |
| 2094 |
}; |
| 2095 |
|
| 2096 |
updatesoverview_plugins_unignore_abandoned_detail = function (slug, id) { |
| 2097 |
return updatesoverview_unignore_plugintheme_abandoned_by_site('plugin', slug, id); |
| 2098 |
}; |
| 2099 |
updatesoverview_plugins_unignore_abandoned_detail_all = function () { |
| 2100 |
return updatesoverview_unignore_plugintheme_abandoned_by_site_all('plugin'); |
| 2101 |
}; |
| 2102 |
updatesoverview_themes_unignore_abandoned_detail = function (slug, id) { |
| 2103 |
return updatesoverview_unignore_plugintheme_abandoned_by_site('theme', slug, id); |
| 2104 |
}; |
| 2105 |
updatesoverview_themes_unignore_abandoned_detail_all = function () { |
| 2106 |
return updatesoverview_unignore_plugintheme_abandoned_by_site_all('theme'); |
| 2107 |
}; |
| 2108 |
|
| 2109 |
updatesoverview_dismiss_outdate_plugintheme_by_site = function (what, slug, name, id, pObj) { |
| 2110 |
var data = mainwp_secure_data({ |
| 2111 |
action: 'mainwp_dismissoutdateplugintheme', |
| 2112 |
type: what, |
| 2113 |
id: id, |
| 2114 |
slug: slug, |
| 2115 |
name: name |
| 2116 |
}); |
| 2117 |
var parent = jQuery(pObj).closest('tr'); |
| 2118 |
parent.find('td:last-child').html(__('Ignoring...')); |
| 2119 |
jQuery.post(ajaxurl, data, function (response) { |
| 2120 |
if (response.result) { |
| 2121 |
parent.attr('dismissed', '-1'); |
| 2122 |
parent.find('td:last-child').html(__('Ignored!')); |
| 2123 |
|
| 2124 |
} else { |
| 2125 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 2126 |
} |
| 2127 |
}, 'json'); |
| 2128 |
return false; |
| 2129 |
}; |
| 2130 |
|
| 2131 |
// Unignore abandoned Plugin/Theme ignored per site basis |
| 2132 |
updatesoverview_unignore_plugintheme_abandoned_by_site = function (what, slug, id) { |
| 2133 |
var data = mainwp_secure_data({ |
| 2134 |
action: 'mainwp_unignoreabandonedplugintheme', |
| 2135 |
type: what, |
| 2136 |
id: id, |
| 2137 |
slug: slug |
| 2138 |
}); |
| 2139 |
|
| 2140 |
jQuery.post(ajaxurl, data, function (pWhat, pSlug, pId) { |
| 2141 |
return function (response) { |
| 2142 |
if (response.result) { |
| 2143 |
var siteElement; |
| 2144 |
if (pWhat == 'plugin') { |
| 2145 |
siteElement = jQuery('tr[site-id="' + pId + '"][plugin-slug="' + pSlug + '"]'); |
| 2146 |
} else { |
| 2147 |
siteElement = jQuery('tr[site-id="' + pId + '"][theme-slug="' + pSlug + '"]'); |
| 2148 |
} |
| 2149 |
|
| 2150 |
if (!siteElement.find('div').is(':visible')) { |
| 2151 |
siteElement.remove(); |
| 2152 |
return; |
| 2153 |
} |
| 2154 |
|
| 2155 |
//Check if previous tr is same site.. |
| 2156 |
//Check if next tr is same site.. |
| 2157 |
var siteAfter = siteElement.next(); |
| 2158 |
|
| 2159 |
if (siteAfter.exists() && (siteAfter.attr('site-id') == pId)) { |
| 2160 |
siteAfter.find('div').show(); |
| 2161 |
siteElement.remove(); |
| 2162 |
return; |
| 2163 |
} |
| 2164 |
|
| 2165 |
var parent = siteElement.parent(); |
| 2166 |
|
| 2167 |
siteElement.remove(); |
| 2168 |
|
| 2169 |
if (parent.children('tr').length == 0) { |
| 2170 |
jQuery('#mainwp-unignore-detail-all').addClass('disabled'); |
| 2171 |
parent.append('<tr><td colspan="999">' + __('No ignored abandoned %1s', pWhat) + '</td></tr>'); |
| 2172 |
} |
| 2173 |
} |
| 2174 |
} |
| 2175 |
}(what, slug, id), 'json'); |
| 2176 |
return false; |
| 2177 |
}; |
| 2178 |
|
| 2179 |
// Unignore all per site ignored abandoned Plugins / Themese |
| 2180 |
updatesoverview_unignore_plugintheme_abandoned_by_site_all = function (what) { |
| 2181 |
var data = mainwp_secure_data({ |
| 2182 |
action: 'mainwp_unignoreabandonedplugintheme', |
| 2183 |
type: what, |
| 2184 |
id: '_ALL_', |
| 2185 |
slug: '_ALL_' |
| 2186 |
}); |
| 2187 |
|
| 2188 |
jQuery.post(ajaxurl, data, function (pWhat) { |
| 2189 |
return function (response) { |
| 2190 |
if (response.result) { |
| 2191 |
var tableElement = jQuery('#ignored-abandoned-' + pWhat + 's-list'); |
| 2192 |
tableElement.find('tr').remove(); |
| 2193 |
tableElement.append('<tr><td colspan="999">' + __('No ignored abandoned %1s', pWhat) + '</td></tr>'); |
| 2194 |
jQuery('#mainwp-unignore-detail-all').addClass('disabled'); |
| 2195 |
} |
| 2196 |
} |
| 2197 |
}(what), 'json'); |
| 2198 |
return false; |
| 2199 |
}; |
| 2200 |
|
| 2201 |
updatesoverview_plugins_abandoned_ignore_all = function (slug, name, pObj) { |
| 2202 |
var parent = jQuery(pObj).closest('tr'); |
| 2203 |
parent.find('td:last-child').html(__('Ignoring...')); |
| 2204 |
var data = mainwp_secure_data({ |
| 2205 |
action: 'mainwp_dismissoutdatepluginsthemes', |
| 2206 |
type: 'plugin', |
| 2207 |
slug: slug, |
| 2208 |
name: name |
| 2209 |
}); |
| 2210 |
jQuery.post(ajaxurl, data, function (response) { |
| 2211 |
if (response.result) { |
| 2212 |
parent.find('td:last-child').html(__('Ignored!')); |
| 2213 |
jQuery('.abandoned-plugins-ignore-global[plugin_slug="' + slug + '"]').find('tr td:last-child').html(__('Ignored!')); |
| 2214 |
jQuery('.abandoned-plugins-ignore-global[plugin_slug="' + slug + '"]').find('tr[dismissed=0]').attr('dismissed', 1); |
| 2215 |
} else { |
| 2216 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 2217 |
} |
| 2218 |
}, 'json'); |
| 2219 |
return false; |
| 2220 |
}; |
| 2221 |
|
| 2222 |
// Unignore all globally ignored abandoned plugins |
| 2223 |
updatesoverview_plugins_abandoned_unignore_globally_all = function () { |
| 2224 |
|
| 2225 |
var data = mainwp_secure_data({ |
| 2226 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 2227 |
type: 'plugin', |
| 2228 |
slug: '_ALL_' |
| 2229 |
}); |
| 2230 |
|
| 2231 |
jQuery.post(ajaxurl, data, function (response) { |
| 2232 |
if (response.result) { |
| 2233 |
var tableElement = jQuery('#ignored-globally-abandoned-plugins-list'); |
| 2234 |
tableElement.find('tr').remove(); |
| 2235 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 2236 |
tableElement.append('<tr><td colspan="999">' + __('No ignored abandoned plugins.') + '</td></tr>'); |
| 2237 |
} |
| 2238 |
}, 'json'); |
| 2239 |
|
| 2240 |
return false; |
| 2241 |
|
| 2242 |
}; |
| 2243 |
|
| 2244 |
// Unignore globally ignored abandoned plugin |
| 2245 |
updatesoverview_plugins_abandoned_unignore_globally = function (slug) { |
| 2246 |
|
| 2247 |
var data = mainwp_secure_data({ |
| 2248 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 2249 |
type: 'plugin', |
| 2250 |
slug: slug |
| 2251 |
}); |
| 2252 |
|
| 2253 |
jQuery.post(ajaxurl, data, function (response) { |
| 2254 |
if (response.result) { |
| 2255 |
var ignoreElement = jQuery('#ignored-globally-abandoned-plugins-list tr[plugin-slug="' + slug + '"]'); |
| 2256 |
var parent = ignoreElement.parent(); |
| 2257 |
ignoreElement.remove(); |
| 2258 |
if (parent.children('tr').length == 0) { |
| 2259 |
jQuery('.mainwp-unignore-globally-all').addClass('disabled'); |
| 2260 |
parent.append('<tr><td colspan="999">' + __('No ignored abandoned plugins.') + '</td></tr>'); |
| 2261 |
} |
| 2262 |
} |
| 2263 |
}, 'json'); |
| 2264 |
return false; |
| 2265 |
}; |
| 2266 |
updatesoverview_themes_abandoned_ignore_all = function (slug, name, pObj) { |
| 2267 |
var parent = jQuery(pObj).closest('tr'); |
| 2268 |
parent.find('td:last-child').html(__('Ignoring...')); |
| 2269 |
|
| 2270 |
var data = mainwp_secure_data({ |
| 2271 |
action: 'mainwp_dismissoutdatepluginsthemes', |
| 2272 |
type: 'theme', |
| 2273 |
slug: slug, |
| 2274 |
name: name |
| 2275 |
}); |
| 2276 |
jQuery.post(ajaxurl, data, function (response) { |
| 2277 |
if (response.result) { |
| 2278 |
parent.find('td:last-child').html(__('Ignored!')); |
| 2279 |
jQuery('.abandoned-themes-ignore-global[theme_slug="' + slug + '"]').find('tr td:last-child').html(__('Ignored!')); |
| 2280 |
jQuery('.abandoned-themes-ignore-global[theme_slug="' + slug + '"]').find('tr[dismissed=0]').attr('dismissed', 1); |
| 2281 |
} else { |
| 2282 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 2283 |
} |
| 2284 |
}, 'json'); |
| 2285 |
return false; |
| 2286 |
}; |
| 2287 |
|
| 2288 |
// Unignore all globablly ignored themes |
| 2289 |
updatesoverview_themes_abandoned_unignore_globally_all = function () { |
| 2290 |
var data = mainwp_secure_data({ |
| 2291 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 2292 |
type: 'theme', |
| 2293 |
slug: '_ALL_' |
| 2294 |
}); |
| 2295 |
|
| 2296 |
jQuery.post(ajaxurl, data, function (response) { |
| 2297 |
if (response.result) { |
| 2298 |
var tableElement = jQuery('#globally-ignored-themes-list'); |
| 2299 |
tableElement.find('tr').remove(); |
| 2300 |
jQuery('.mainwp-unignore-globally-all').addClass('disabled'); |
| 2301 |
tableElement.append('<tr><td colspan="999">' + __('No ignored abandoned themes.') + '</td></tr>'); |
| 2302 |
} |
| 2303 |
}, 'json'); |
| 2304 |
|
| 2305 |
return false; |
| 2306 |
}; |
| 2307 |
|
| 2308 |
// Unignore globally ignored theme |
| 2309 |
updatesoverview_themes_abandoned_unignore_globally = function (slug) { |
| 2310 |
var data = mainwp_secure_data({ |
| 2311 |
action: 'mainwp_unignoreabandonedpluginsthemes', |
| 2312 |
type: 'theme', |
| 2313 |
slug: slug |
| 2314 |
}); |
| 2315 |
|
| 2316 |
jQuery.post(ajaxurl, data, function (response) { |
| 2317 |
if (response.result) { |
| 2318 |
var ignoreElement = jQuery('#globally-ignored-themes-list tr[theme-slug="' + slug + '"]'); |
| 2319 |
var parent = ignoreElement.parent(); |
| 2320 |
ignoreElement.remove(); |
| 2321 |
if (parent.children('tr').length == 0) { |
| 2322 |
jQuery('.mainwp-unignore-globally-all').addClass('disabled'); |
| 2323 |
parent.append('<tr><td colspan="999">' + __('No ignored abandoned themes.') + '</td></tr>'); |
| 2324 |
} |
| 2325 |
} |
| 2326 |
}, 'json'); |
| 2327 |
|
| 2328 |
return false; |
| 2329 |
}; |
| 2330 |
|
| 2331 |
mainwp_siteview_onchange = function (me) { |
| 2332 |
jQuery(me).closest("form").submit(); |
| 2333 |
} |
| 2334 |
|
| 2335 |
jQuery(document).ready(function () { |
| 2336 |
if (jQuery('#updatesoverview_limit_updates_all').length > 0 && jQuery('#updatesoverview_limit_updates_all').val() > 0) { |
| 2337 |
limitUpdateAll = jQuery('#updatesoverview_limit_updates_all').val(); |
| 2338 |
if (jQuery('.updatesoverview_continue_update_me').length > 0) { |
| 2339 |
continueUpdating = true; |
| 2340 |
jQuery('.updatesoverview_continue_update_me')[0].trigger('click'); |
| 2341 |
} |
| 2342 |
} |
| 2343 |
}); |
| 2344 |
|
| 2345 |
updatesoverview_recheck_http = function (elem, id) { |
| 2346 |
var data = mainwp_secure_data({ |
| 2347 |
action: 'mainwp_recheck_http', |
| 2348 |
websiteid: id |
| 2349 |
}); |
| 2350 |
jQuery(elem).attr('disabled', 'true'); |
| 2351 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html('<i class="ui active inline loader tiny"></i>'); |
| 2352 |
jQuery.post(ajaxurl, data, function (response) { |
| 2353 |
jQuery(elem).prop("disabled", false); |
| 2354 |
if (response) { |
| 2355 |
var hc = (response && response.httpcode) ? response.httpcode : ''; |
| 2356 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html('HTTP ' + hc); |
| 2357 |
if (response.status) { |
| 2358 |
jQuery('#wp_http_response_code_' + id).addClass('http-response-ok'); |
| 2359 |
} else { |
| 2360 |
jQuery('#wp_http_response_code_' + id).removeClass('http-response-ok'); |
| 2361 |
} |
| 2362 |
} else { |
| 2363 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html(__('Undefined error!')); |
| 2364 |
} |
| 2365 |
}, 'json'); |
| 2366 |
return false; |
| 2367 |
}; |
| 2368 |
|
| 2369 |
updatesoverview_ignore_http_response = function (elem, id) { |
| 2370 |
var data = mainwp_secure_data({ |
| 2371 |
action: 'mainwp_ignore_http_response', |
| 2372 |
websiteid: id |
| 2373 |
}); |
| 2374 |
jQuery(elem).attr('disabled', 'true'); |
| 2375 |
jQuery('#wp_http_response_code_' + id + ' .http-code').html('<i class="ui active inline loader tiny"></i>'); |
| 2376 |
jQuery.post(ajaxurl, data, function (response) { |
| 2377 |
jQuery(elem).prop("disabled", false); |
| 2378 |
if (response && response.ok) { |
| 2379 |
jQuery(elem).closest('.mainwp-sub-row').remove(); |
| 2380 |
} |
| 2381 |
}, 'json'); |
| 2382 |
return false; |
| 2383 |
}; |
| 2384 |
|
| 2385 |
updatesoverview_ignore_plugintheme_by_site = function (what, slug, name, id, pObj) { |
| 2386 |
var data = mainwp_secure_data({ |
| 2387 |
action: 'mainwp_ignoreplugintheme', |
| 2388 |
type: what, |
| 2389 |
id: id, |
| 2390 |
slug: slug, |
| 2391 |
name: name |
| 2392 |
}); |
| 2393 |
|
| 2394 |
jQuery.post(ajaxurl, data, function (response) { |
| 2395 |
var parent = jQuery(pObj).closest('tr'); |
| 2396 |
if (response.result) { |
| 2397 |
jQuery('div[' + what + '_slug="' + slug + '"] div[site_id="' + id + '"]').attr('updated', '-1'); // ok |
| 2398 |
parent.attr('updated', '-1'); |
| 2399 |
parent.find('td:last-child').html(__('Ignored')); |
| 2400 |
} else { |
| 2401 |
parent.find('td:last-child').html(getErrorMessage(response.error)); |
| 2402 |
} |
| 2403 |
}, 'json'); |
| 2404 |
return false; |
| 2405 |
}; |
| 2406 |
|
| 2407 |
// Unignore Plugin / Themse ignored per site |
| 2408 |
updatesoverview_unignore_plugintheme_by_site = function (what, slug, id) { |
| 2409 |
var data = mainwp_secure_data({ |
| 2410 |
action: 'mainwp_unignoreplugintheme', |
| 2411 |
type: what, |
| 2412 |
id: id, |
| 2413 |
slug: slug |
| 2414 |
}); |
| 2415 |
|
| 2416 |
jQuery.post(ajaxurl, data, function (pWhat, pSlug, pId) { |
| 2417 |
return function (response) { |
| 2418 |
if (response.result) { |
| 2419 |
var siteElement; |
| 2420 |
if (pWhat == 'plugin') { |
| 2421 |
siteElement = jQuery('tr[site-id="' + pId + '"][plugin-slug="' + pSlug + '"]'); |
| 2422 |
} else { |
| 2423 |
siteElement = jQuery('tr[site-id="' + pId + '"][theme-slug="' + pSlug + '"]'); |
| 2424 |
} |
| 2425 |
|
| 2426 |
if (!siteElement.find('div').is(':visible')) { |
| 2427 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 2428 |
siteElement.remove(); |
| 2429 |
return; |
| 2430 |
} |
| 2431 |
|
| 2432 |
//Check if previous tr is same site.. |
| 2433 |
//Check if next tr is same site.. |
| 2434 |
var siteAfter = siteElement.next(); |
| 2435 |
if (siteAfter.exists() && (siteAfter.attr('site-id') == pId)) { |
| 2436 |
siteAfter.find('div').show(); |
| 2437 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 2438 |
siteElement.remove(); |
| 2439 |
return; |
| 2440 |
} |
| 2441 |
|
| 2442 |
var parent = siteElement.parent(); |
| 2443 |
mainwp_responsive_fix_remove_child_row(siteElement); |
| 2444 |
siteElement.remove(); |
| 2445 |
if (parent.children('tr').length == 0) { |
| 2446 |
parent.append('<tr><td colspan="999">' + __('No ignored %1s', pWhat) + '</td></tr>'); |
| 2447 |
jQuery('.mainwp-unignore-detail-all').addClass('disabled'); |
| 2448 |
} |
| 2449 |
} |
| 2450 |
} |
| 2451 |
}(what, slug, id), 'json'); |
| 2452 |
return false; |
| 2453 |
}; |
| 2454 |
|
| 2455 |
|
| 2456 |
// Unignore all Plugins / Themses ignored per site |
| 2457 |
updatesoverview_unignore_plugintheme_by_site_all = function (what) { |
| 2458 |
var data = mainwp_secure_data({ |
| 2459 |
action: 'mainwp_unignoreplugintheme', |
| 2460 |
type: what, |
| 2461 |
id: '_ALL_', |
| 2462 |
slug: '_ALL_' |
| 2463 |
}); |
| 2464 |
|
| 2465 |
jQuery.post(ajaxurl, data, function (pWhat) { |
| 2466 |
return function (response) { |
| 2467 |
if (response.result) { |
| 2468 |
var tableElement = jQuery('#ignored-' + pWhat + 's-list'); |
| 2469 |
tableElement.find('tr').remove(); |
| 2470 |
tableElement.append('<tr><td colspan="999">' + __('No ignored %1s', pWhat) + '</td></tr>'); |
| 2471 |
jQuery('.mainwp-unignore-detail-all').addClass('disabled'); |
| 2472 |
} |
| 2473 |
} |
| 2474 |
}(what), 'json'); |
| 2475 |
return false; |
| 2476 |
}; |
| 2477 |
|
| 2478 |
/**Plugins part**/ |
| 2479 |
updatesoverview_translations_detail = function (slug) { |
| 2480 |
jQuery('div[translation_slug="' + slug + '"]').toggle(100, 'linear'); |
| 2481 |
return false; |
| 2482 |
}; |
| 2483 |
|
| 2484 |
updatesoverview_plugins_ignore_detail = function (slug, name, id, obj) { |
| 2485 |
var msg = __('Are you sure you want to ignore the %1 plugin updates? The updates will no longer be visible in your MainWP Dashboard.', name); |
| 2486 |
mainwp_confirm(msg, function () { |
| 2487 |
return updatesoverview_ignore_plugintheme_by_site('plugin', slug, name, id, obj); |
| 2488 |
}, false, 1); |
| 2489 |
return false; |
| 2490 |
}; |
| 2491 |
updatesoverview_plugins_unignore_detail = function (slug, id) { |
| 2492 |
return updatesoverview_unignore_plugintheme_by_site('plugin', slug, id); |
| 2493 |
}; |
| 2494 |
updatesoverview_plugins_unignore_detail_all = function () { |
| 2495 |
return updatesoverview_unignore_plugintheme_by_site_all('plugin'); |
| 2496 |
}; |
| 2497 |
updatesoverview_themes_ignore_detail = function (slug, name, id, obj) { |
| 2498 |
var msg = __('Are you sure you want to ignore the %1 theme updates? The updates will no longer be visible in your MainWP Dashboard.', name); |
| 2499 |
mainwp_confirm(msg, function () { |
| 2500 |
return updatesoverview_ignore_plugintheme_by_site('theme', slug, name, id, obj); |
| 2501 |
}, false, 1); |
| 2502 |
return false; |
| 2503 |
}; |
| 2504 |
updatesoverview_themes_unignore_detail = function (slug, id) { |
| 2505 |
return updatesoverview_unignore_plugintheme_by_site('theme', slug, id); |
| 2506 |
}; |
| 2507 |
updatesoverview_themes_unignore_detail_all = function () { |
| 2508 |
return updatesoverview_unignore_plugintheme_by_site_all('theme'); |
| 2509 |
}; |
| 2510 |
updatesoverview_plugins_ignore_all = function (slug, name, obj) { |
| 2511 |
var msg = __('Are you sure you want to ignore the %1 plugin updates? The updates will no longer be visible in your MainWP Dashboard.', name); |
| 2512 |
mainwp_confirm(msg, function () { |
| 2513 |
var data = mainwp_secure_data({ |
| 2514 |
action: 'mainwp_ignorepluginsthemes', |
| 2515 |
type: 'plugin', |
| 2516 |
slug: slug, |
| 2517 |
name: name |
| 2518 |
}); |
| 2519 |
var parent = jQuery(obj).closest('tr'); |
| 2520 |
parent.find('td:last-child').html(__('Ignoring...')); |
| 2521 |
jQuery.post(ajaxurl, data, function (response) { |
| 2522 |
if (response.result) { |
| 2523 |
parent.find('td:last-child').html(__('Ignored')); |
| 2524 |
jQuery('tr[plugin_slug="' + slug + '"]').find('table tr td:last-child').html(__('Ignored')); |
| 2525 |
jQuery('tr[plugin_slug="' + slug + '"]').find('table tr').attr('updated', '-1'); |
| 2526 |
} |
| 2527 |
}, 'json'); |
| 2528 |
}, false, 1); |
| 2529 |
return false; |
| 2530 |
}; |
| 2531 |
|
| 2532 |
// Unignore all globally ignored plugins |
| 2533 |
updatesoverview_plugins_unignore_globally_all = function () { |
| 2534 |
var data = mainwp_secure_data({ |
| 2535 |
action: 'mainwp_unignorepluginsthemes', |
| 2536 |
type: 'plugin', |
| 2537 |
slug: '_ALL_' |
| 2538 |
}); |
| 2539 |
|
| 2540 |
jQuery.post(ajaxurl, data, function (response) { |
| 2541 |
if (response.result) { |
| 2542 |
var tableElement = jQuery('#globally-ignored-plugins-list'); |
| 2543 |
tableElement.find('tr').remove(); |
| 2544 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 2545 |
tableElement.append('<tr><td colspan="999">' + __('No ignored plugins.') + '</td></tr>'); |
| 2546 |
} |
| 2547 |
}, 'json'); |
| 2548 |
return false; |
| 2549 |
}; |
| 2550 |
|
| 2551 |
// Unignore globally ignored plugin |
| 2552 |
updatesoverview_plugins_unignore_globally = function (slug) { |
| 2553 |
var data = mainwp_secure_data({ |
| 2554 |
action: 'mainwp_unignorepluginsthemes', |
| 2555 |
type: 'plugin', |
| 2556 |
slug: slug |
| 2557 |
}); |
| 2558 |
jQuery.post(ajaxurl, data, function (response) { |
| 2559 |
if (response.result) { |
| 2560 |
var ignoreElement = jQuery('#globally-ignored-plugins-list tr[plugin-slug="' + slug + '"]'); |
| 2561 |
var parent = ignoreElement.parent(); |
| 2562 |
ignoreElement.remove(); |
| 2563 |
if (parent.children('tr').length == 0) { |
| 2564 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 2565 |
parent.append('<tr><td colspan="999">' + __('No ignored plugins.') + '</td></tr>'); |
| 2566 |
} |
| 2567 |
} |
| 2568 |
}, 'json'); |
| 2569 |
return false; |
| 2570 |
}; |
| 2571 |
|
| 2572 |
updatesoverview_themes_ignore_all = function (slug, name, obj) { |
| 2573 |
var msg = __('Are you sure you want to ignore the %1 theme updates? The updates will no longer be visible in your MainWP Dashboard.', name); |
| 2574 |
mainwp_confirm(msg, function () { |
| 2575 |
|
| 2576 |
var data = mainwp_secure_data({ |
| 2577 |
action: 'mainwp_ignorepluginsthemes', |
| 2578 |
type: 'theme', |
| 2579 |
slug: slug, |
| 2580 |
name: name |
| 2581 |
}); |
| 2582 |
var parent = jQuery(obj).closest('tr'); |
| 2583 |
parent.find('td:last-child').html(__('Ignoring...')); |
| 2584 |
jQuery.post(ajaxurl, data, function (response) { |
| 2585 |
if (response.result) { |
| 2586 |
parent.find('td:last-child').html(__('Ignored')); |
| 2587 |
jQuery('tr[theme_slug="' + slug + '"]').find('table tr td:last-child').html(__('Ignored')); |
| 2588 |
jQuery('tr[theme_slug="' + slug + '"]').find('table tr').attr('updated', '-1'); |
| 2589 |
} |
| 2590 |
}, 'json'); |
| 2591 |
}, false, 1); |
| 2592 |
return false; |
| 2593 |
}; |
| 2594 |
|
| 2595 |
// Unignore all globally ignored themes |
| 2596 |
updatesoverview_themes_unignore_globally_all = function () { |
| 2597 |
var data = mainwp_secure_data({ |
| 2598 |
action: 'mainwp_unignorepluginsthemes', |
| 2599 |
type: 'theme', |
| 2600 |
slug: '_ALL_' |
| 2601 |
}); |
| 2602 |
|
| 2603 |
jQuery.post(ajaxurl, data, function (response) { |
| 2604 |
if (response.result) { |
| 2605 |
var tableElement = jQuery('#globally-ignored-themes-list'); |
| 2606 |
tableElement.find('tr').remove(); |
| 2607 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 2608 |
tableElement.append('<tr><td colspan="999">' + __('No ignored themes.') + '</td></tr>'); |
| 2609 |
} |
| 2610 |
}, 'json'); |
| 2611 |
|
| 2612 |
return false; |
| 2613 |
}; |
| 2614 |
|
| 2615 |
// Unignore globally ignored theme |
| 2616 |
updatesoverview_themes_unignore_globally = function (slug) { |
| 2617 |
var data = mainwp_secure_data({ |
| 2618 |
action: 'mainwp_unignorepluginsthemes', |
| 2619 |
type: 'theme', |
| 2620 |
slug: slug |
| 2621 |
}); |
| 2622 |
jQuery.post(ajaxurl, data, function (response) { |
| 2623 |
if (response.result) { |
| 2624 |
var ignoreElement = jQuery('#globally-ignored-themes-list tr[theme-slug="' + slug + '"]'); |
| 2625 |
var parent = ignoreElement.parent(); |
| 2626 |
ignoreElement.remove(); |
| 2627 |
if (parent.children('tr').length == 0) { |
| 2628 |
jQuery('#mainwp-unignore-globally-all').addClass('disabled'); |
| 2629 |
parent.append('<tr><td colspan="999">' + __('No ignored themes.') + '</td></tr>'); |
| 2630 |
} |
| 2631 |
} |
| 2632 |
}, 'json'); |
| 2633 |
return false; |
| 2634 |
}; |
| 2635 |
|
| 2636 |
updatesoverview_upgrade_translation = function (id, slug) { |
| 2637 |
var msg = __('Are you sure you want to update the translation on the selected site?'); |
| 2638 |
mainwp_confirm(msg, function () { |
| 2639 |
return updatesoverview_translations_upgrade_int(slug, id); |
| 2640 |
}, false, 1); |
| 2641 |
}; |
| 2642 |
|
| 2643 |
updatesoverview_translations_upgrade = function (slug, websiteid) { |
| 2644 |
var msg = __('Are you sure you want to update the translation on the selected site?'); |
| 2645 |
mainwp_confirm(msg, function () { |
| 2646 |
return updatesoverview_translations_upgrade_int(slug, websiteid); |
| 2647 |
}, false, 1); |
| 2648 |
}; |
| 2649 |
|
| 2650 |
updatesoverview_plugins_upgrade = function (slug, websiteid) { |
| 2651 |
var msg = __('Are you sure you want to update the plugin on the selected site?'); |
| 2652 |
mainwp_confirm(msg, function () { |
| 2653 |
return updatesoverview_plugins_upgrade_int(slug, websiteid); |
| 2654 |
}, false, 1); |
| 2655 |
}; |
| 2656 |
|
| 2657 |
updatesoverview_themes_upgrade = function (slug, websiteid) { |
| 2658 |
var msg = __('Are you sure you want to update the theme on the selected site?'); |
| 2659 |
mainwp_confirm(msg, function () { |
| 2660 |
return updatesoverview_themes_upgrade_int(slug, websiteid); |
| 2661 |
}, false, 1); |
| 2662 |
}; |
| 2663 |
|
| 2664 |
/** END NEW **/ |
| 2665 |
|
| 2666 |
updatesoverview_wp_sync = function (websiteid) { |
| 2667 |
var syncIds = []; |
| 2668 |
syncIds.push(websiteid); |
| 2669 |
mainwp_sync_sites_data(syncIds); |
| 2670 |
return false; |
| 2671 |
}; |
| 2672 |
|
| 2673 |
|
| 2674 |
updatesoverview_group_upgrade_translation = function (id, slug, groupId) { |
| 2675 |
return updatesoverview_upgrade_plugintheme('translation', id, slug, groupId); |
| 2676 |
}; |
| 2677 |
|
| 2678 |
updatesoverview_upgrade_translation_all = function (id, updatesSelected) { |
| 2679 |
var msg = __('Are you sure you want to update all translations?'); |
| 2680 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2681 |
msg = __('Are you sure you want to update selected translations?'); |
| 2682 |
} |
| 2683 |
mainwp_confirm(msg, function () { |
| 2684 |
return updatesoverview_upgrade_plugintheme_all('translation', id, false, updatesSelected); |
| 2685 |
}, false, 2); |
| 2686 |
return false; |
| 2687 |
}; |
| 2688 |
|
| 2689 |
updatesoverview_group_upgrade_translation_all = function (id, groupId, updatesSelected) { |
| 2690 |
var msg = __('Are you sure you want to update all translations?'); |
| 2691 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2692 |
msg = __('Are you sure you want to update selected translations?'); |
| 2693 |
} |
| 2694 |
mainwp_confirm(msg, function () { |
| 2695 |
return updatesoverview_group_upgrade_plugintheme_all('translation', id, false, groupId, updatesSelected); |
| 2696 |
}, false, 2); |
| 2697 |
return false; |
| 2698 |
}; |
| 2699 |
|
| 2700 |
updatesoverview_upgrade_plugin = function (id, slug) { |
| 2701 |
var msg = __('Are you sure you want to update the plugin on the selected site?'); |
| 2702 |
mainwp_confirm(msg, function () { |
| 2703 |
return updatesoverview_upgrade_plugintheme('plugin', id, slug); |
| 2704 |
}, false, 1); |
| 2705 |
}; |
| 2706 |
|
| 2707 |
updatesoverview_group_upgrade_plugin = function (id, slug, groupId) { |
| 2708 |
return updatesoverview_upgrade_plugintheme('plugin', id, slug, groupId); |
| 2709 |
}; |
| 2710 |
|
| 2711 |
updatesoverview_upgrade_plugin_all = function (id, updatesSelected) { |
| 2712 |
var msg = __('Are you sure you want to update all plugins?'); |
| 2713 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2714 |
msg = __('Are you sure you want to update selected plugins?'); |
| 2715 |
} |
| 2716 |
mainwp_confirm(msg, function () { |
| 2717 |
return updatesoverview_upgrade_plugintheme_all('plugin', id, false, updatesSelected); |
| 2718 |
}, false, 2); |
| 2719 |
return false; |
| 2720 |
}; |
| 2721 |
|
| 2722 |
updatesoverview_group_upgrade_plugin_all = function (id, groupId, updatesSelected) { |
| 2723 |
var msg = __('Are you sure you want to update all plugins?'); |
| 2724 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2725 |
msg = __('Are you sure you want to update selected plugins?'); |
| 2726 |
} |
| 2727 |
mainwp_confirm(msg, function () { |
| 2728 |
return updatesoverview_group_upgrade_plugintheme_all('plugin', id, false, groupId, updatesSelected); |
| 2729 |
}, false, 2); |
| 2730 |
return false; |
| 2731 |
}; |
| 2732 |
|
| 2733 |
updatesoverview_upgrade_theme = function (id, slug) { |
| 2734 |
var msg = __('Are you sure you want to update the theme on the selected site?'); |
| 2735 |
mainwp_confirm(msg, function () { |
| 2736 |
return updatesoverview_upgrade_plugintheme('theme', id, slug); |
| 2737 |
}, false, 1); |
| 2738 |
}; |
| 2739 |
updatesoverview_group_upgrade_theme = function (id, slug, groupId) { |
| 2740 |
return updatesoverview_upgrade_plugintheme('theme', id, slug, groupId); |
| 2741 |
}; |
| 2742 |
|
| 2743 |
updatesoverview_upgrade_theme_all = function (id, updatesSelected) { |
| 2744 |
var msg = __('Are you sure you want to update all themes?'); |
| 2745 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2746 |
msg = __('Are you sure you want to update selected themes?'); |
| 2747 |
} |
| 2748 |
mainwp_confirm(msg, function () { |
| 2749 |
return updatesoverview_upgrade_plugintheme_all('theme', id, false, updatesSelected); |
| 2750 |
}, false, 2); |
| 2751 |
return false; |
| 2752 |
}; |
| 2753 |
|
| 2754 |
updatesoverview_group_upgrade_theme_all = function (id, groupId, updatesSelected) { |
| 2755 |
var msg = __('Are you sure you want to update all themes?'); |
| 2756 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2757 |
msg = __('Are you sure you want to update selected themes?'); |
| 2758 |
} |
| 2759 |
mainwp_confirm(msg, function () { |
| 2760 |
return updatesoverview_group_upgrade_plugintheme_all('theme', id, false, groupId, updatesSelected); |
| 2761 |
}, false, 2); |
| 2762 |
return false; |
| 2763 |
}; |
| 2764 |
|
| 2765 |
updatesoverview_upgrade_plugintheme = function (what, id, name, groupId) { |
| 2766 |
updatesoverview_upgrade_plugintheme_list(what, id, [name], false, groupId); |
| 2767 |
return false; |
| 2768 |
}; |
| 2769 |
updatesoverview_upgrade_plugintheme_all = function (what, id, noCheck, updatesSelected) { |
| 2770 |
|
| 2771 |
// ok: confirmed to do this |
| 2772 |
updatesoverviewContinueAfterBackup = function (pId, pWhat) { |
| 2773 |
return function () { |
| 2774 |
var list = []; |
| 2775 |
var slug_att = pWhat + '_slug'; |
| 2776 |
var slug = ''; |
| 2777 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2778 |
jQuery("#wp_" + pWhat + "_upgrades_" + pId + " tr[updated=0]").each(function () { |
| 2779 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 2780 |
slug = jQuery(this).attr(slug_att); |
| 2781 |
if (slug) { |
| 2782 |
list.push(slug); |
| 2783 |
} |
| 2784 |
} |
| 2785 |
}); |
| 2786 |
if (list.length == 0) { |
| 2787 |
updates_please_select_items_notice(); |
| 2788 |
return false; |
| 2789 |
} |
| 2790 |
} else { |
| 2791 |
jQuery("#wp_" + pWhat + "_upgrades_" + pId + " tr[updated=0]").each(function () { |
| 2792 |
slug = jQuery(this).attr(slug_att); |
| 2793 |
if (slug) { |
| 2794 |
list.push(slug); |
| 2795 |
} |
| 2796 |
|
| 2797 |
}); |
| 2798 |
} |
| 2799 |
var siteName = jQuery("#wp_" + pWhat + "_upgrades_" + pId).attr('site_name'); |
| 2800 |
updatesoverview_upgrade_plugintheme_list_popup(pWhat, pId, siteName, list); |
| 2801 |
} |
| 2802 |
}(id, what); |
| 2803 |
|
| 2804 |
if (noCheck) { |
| 2805 |
updatesoverviewContinueAfterBackup(); |
| 2806 |
return false; |
| 2807 |
} |
| 2808 |
|
| 2809 |
var sitesToUpdate = []; |
| 2810 |
var siteNames = []; |
| 2811 |
|
| 2812 |
sitesToUpdate.push(id); |
| 2813 |
siteNames[id] = jQuery('tbody[site_id="' + id + '"]').attr('site_name'); |
| 2814 |
|
| 2815 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 2816 |
}; |
| 2817 |
|
| 2818 |
updatesoverview_group_upgrade_plugintheme_all = function (what, id, noCheck, groupId, updatesSelected) { |
| 2819 |
// ok, confirmed to do this |
| 2820 |
updatesoverviewContinueAfterBackup = function (pId, pWhat) { |
| 2821 |
return function () { |
| 2822 |
var list = []; |
| 2823 |
var slug_att = pWhat + '_slug'; |
| 2824 |
jQuery("#wp_" + pWhat + "_upgrades_" + pId + '_group_' + groupId + " tr[updated=0]").each(function () { |
| 2825 |
var slug = jQuery(this).attr(slug_att); |
| 2826 |
if (typeof updatesSelected !== 'undefined' && updatesSelected) { |
| 2827 |
if (jQuery(this).find('.child.checkbox').checkbox('is checked')) { |
| 2828 |
if (slug) { |
| 2829 |
list.push(slug); |
| 2830 |
} |
| 2831 |
} |
| 2832 |
if (list.length == 0) { |
| 2833 |
updates_please_select_items_notice(); |
| 2834 |
return false; |
| 2835 |
} |
| 2836 |
} else { |
| 2837 |
if (slug) { |
| 2838 |
list.push(slug); |
| 2839 |
} |
| 2840 |
} |
| 2841 |
}); |
| 2842 |
|
| 2843 |
// proccessed by popup |
| 2844 |
//updatesoverview_upgrade_plugintheme_list( what, pId, list, true, groupId ); |
| 2845 |
var siteName = jQuery("#wp_" + pWhat + "_upgrades_" + pId + '_group_' + groupId).attr('site_name'); |
| 2846 |
updatesoverview_upgrade_plugintheme_list_popup(what, pId, siteName, list); |
| 2847 |
} |
| 2848 |
}(id, what); |
| 2849 |
|
| 2850 |
if (noCheck) { |
| 2851 |
updatesoverviewContinueAfterBackup(); |
| 2852 |
return false; |
| 2853 |
} |
| 2854 |
|
| 2855 |
var sitesToUpdate = []; |
| 2856 |
var siteNames = []; |
| 2857 |
|
| 2858 |
sitesToUpdate.push(id); |
| 2859 |
siteNames[id] = jQuery('tbody[site_id="' + id + '"]').attr('site_name'); |
| 2860 |
|
| 2861 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 2862 |
}; |
| 2863 |
|
| 2864 |
updatesoverview_upgrade_plugintheme_list = function (what, id, list, noCheck, groupId) { |
| 2865 |
updatesoverviewContinueAfterBackup = function (pWhat, pId, pList, pGroupId) { |
| 2866 |
return function () { |
| 2867 |
var strGroup = ''; |
| 2868 |
if (typeof pGroupId !== 'undefined') { |
| 2869 |
strGroup = '_group_' + pGroupId; |
| 2870 |
} |
| 2871 |
var newList = []; |
| 2872 |
|
| 2873 |
for (var i = pList.length - 1; i >= 0; i--) { |
| 2874 |
var item = pList[i]; |
| 2875 |
var elem = document.getElementById('wp_upgraded_' + pWhat + '_' + pId + strGroup + '_' + item); |
| 2876 |
if (elem && elem.value == 0) { |
| 2877 |
var parent = jQuery(elem).closest('tr'); |
| 2878 |
parent.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Updating...', 'mainwp') + '"><i class="notched circle loading icon"></i></span> ' + __('Updating. Please wait...')); |
| 2879 |
elem.value = 1; |
| 2880 |
parent.attr('updated', 1); |
| 2881 |
newList.push(item); |
| 2882 |
} |
| 2883 |
} |
| 2884 |
|
| 2885 |
if (newList.length > 0) { |
| 2886 |
var data = mainwp_secure_data({ |
| 2887 |
action: 'mainwp_upgradeplugintheme', |
| 2888 |
websiteId: pId, |
| 2889 |
type: pWhat, |
| 2890 |
slug: newList.join(',') |
| 2891 |
}); |
| 2892 |
jQuery.post(ajaxurl, data, function (response) { |
| 2893 |
var success = false; |
| 2894 |
var extErr = ''; |
| 2895 |
if (response.error) { |
| 2896 |
extErr = getErrorMessageInfo(response.error, 'ui') |
| 2897 |
} |
| 2898 |
else { |
| 2899 |
var res = response.result; |
| 2900 |
var res_error = response.result_error; |
| 2901 |
|
| 2902 |
for (var i = 0; i < newList.length; i++) { |
| 2903 |
var item = newList[i]; |
| 2904 |
|
| 2905 |
var elem = document.getElementById('wp_upgraded_' + pWhat + '_' + pId + strGroup + '_' + item); |
| 2906 |
var parent = jQuery(elem).closest('tr'); |
| 2907 |
if (res[item]) { |
| 2908 |
parent.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + __('Update successful.', 'mainwp') + '"><i class="green check icon"></i></span>'); |
| 2909 |
} else if (what == 'plugin' && res_error[item]) { |
| 2910 |
parent.find('td:last-child').html('<span data-inverted="" data-position="left center" data-tooltip="' + res_error[item] + '"><i class="red times icon"></i></span>'); |
| 2911 |
} else { |
| 2912 |
parent.find('td:last-child').html('<i class="red times icon"></i>'); |
| 2913 |
} |
| 2914 |
} |
| 2915 |
success = true; |
| 2916 |
} |
| 2917 |
if (!success) { |
| 2918 |
for (var i = 0; i < newList.length; i++) { |
| 2919 |
var item = newList[i]; |
| 2920 |
var elem = document.getElementById('wp_upgraded_' + pWhat + '_' + pId + strGroup + '_' + item); |
| 2921 |
var parent = jQuery(elem).closest('tr'); |
| 2922 |
parent.find('td:last-child').html(extErr); |
| 2923 |
} |
| 2924 |
} |
| 2925 |
}, 'json'); |
| 2926 |
|
| 2927 |
} |
| 2928 |
|
| 2929 |
updatesoverviewContinueAfterBackup = undefined; |
| 2930 |
} |
| 2931 |
}(what, id, list, groupId); |
| 2932 |
|
| 2933 |
if (noCheck) { |
| 2934 |
updatesoverviewContinueAfterBackup(); |
| 2935 |
return false; |
| 2936 |
} |
| 2937 |
|
| 2938 |
var sitesToUpdate = [id]; |
| 2939 |
var siteNames = []; |
| 2940 |
siteNames[id] = jQuery('tbody[site_id="' + id + '"]').attr('site_name'); |
| 2941 |
return mainwp_updatesoverview_checkBackups(sitesToUpdate, siteNames); |
| 2942 |
}; |
| 2943 |
|
| 2944 |
updatesoverview_upgrade_plugintheme_list_popup = function (what, pId, pSiteName, list) { |
| 2945 |
var updateCount = list.length; |
| 2946 |
if (updateCount == 0) |
| 2947 |
return; |
| 2948 |
|
| 2949 |
var updateWhat = (what == 'plugin') ? __('plugins') : (what == 'theme' ? __('themes') : __('translations')); |
| 2950 |
|
| 2951 |
mainwpPopup('#mainwp-sync-sites-modal').clearList(); |
| 2952 |
mainwpPopup('#mainwp-sync-sites-modal').appendItemsList(decodeURIComponent(pSiteName) + ' (' + updateCount + ' ' + updateWhat + ')', '<span class="updatesoverview-upgrade-status-wp" siteid="' + pId + '">' + '<i class="clock outline icon"></i> ' + '</span>'); |
| 2953 |
|
| 2954 |
var type = ''; |
| 2955 |
var info_type = ''; |
| 2956 |
if ('plugin' === what || 'theme' === what) { |
| 2957 |
type = what; |
| 2958 |
info_type = type + 's'; |
| 2959 |
} else if ('translation' === what) { |
| 2960 |
type = 'trans'; |
| 2961 |
info_type = type; |
| 2962 |
} |
| 2963 |
|
| 2964 |
var initData = { |
| 2965 |
title: __('Updating all'), |
| 2966 |
progressMax: 1 |
| 2967 |
}; |
| 2968 |
updatesoverview_update_popup_init(initData); |
| 2969 |
var data = mainwp_secure_data({ |
| 2970 |
action: 'mainwp_upgradeplugintheme', |
| 2971 |
websiteId: pId, |
| 2972 |
type: what, |
| 2973 |
slug: list.join(',') |
| 2974 |
}); |
| 2975 |
|
| 2976 |
updatesoverview_plugins_upgrade_all_update_site_status(pId, '<i class="notched circle loading icon"></i>'); |
| 2977 |
|
| 2978 |
jQuery.post(ajaxurl, data, function (response) { |
| 2979 |
var success = false; |
| 2980 |
var error = ''; |
| 2981 |
if (response.error) { |
| 2982 |
var extErr = getErrorMessageInfo(response.error, 'ui'); |
| 2983 |
updatesoverview_plugins_upgrade_all_update_site_status(pId, extErr); |
| 2984 |
error = getErrorMessageInfo(response.error); |
| 2985 |
} |
| 2986 |
else { |
| 2987 |
success = true; |
| 2988 |
updatesoverview_plugins_upgrade_all_update_site_status(pId, '<i class="green check icon"></i>' + ' ' + mainwp_links_visit_site_and_admin('', pId)); |
| 2989 |
} |
| 2990 |
|
| 2991 |
mainwpPopup('#mainwp-sync-sites-modal').setProgressSite(1); |
| 2992 |
setTimeout(function () { |
| 2993 |
//mainwpPopup('#mainwp-sync-sites-modal').close(true); |
| 2994 |
}, 3000); |
| 2995 |
}); |
| 2996 |
} |
| 2997 |
|
| 2998 |
// for semantic ui checkboxes |
| 2999 |
jQuery(document).ready(function () { |
| 3000 |
mainwp_table_check_columns_init(); // call as function to support tables with ajax, may check and call at extensions |
| 3001 |
mainwp_master_checkbox_init(jQuery); |
| 3002 |
}); |
| 3003 |
|
| 3004 |
mainwp_master_checkbox_init = function ($) { |
| 3005 |
// Master Checkboxes. |
| 3006 |
$('.master-checkbox .master.checkbox').checkbox(); |
| 3007 |
$('.master-checkbox .master.checkbox').on('click', function (e) { |
| 3008 |
if ($(this).checkbox('is checked')) { |
| 3009 |
var |
| 3010 |
$childCheckbox = $(this).closest('.master-checkbox').next('.child-checkbox').find('.checkbox') |
| 3011 |
; |
| 3012 |
$childCheckbox.checkbox('check'); |
| 3013 |
} else { |
| 3014 |
var |
| 3015 |
$childCheckbox = $(this).closest('.master-checkbox').next('.child-checkbox').find('.checkbox') |
| 3016 |
; |
| 3017 |
$childCheckbox.checkbox('uncheck'); |
| 3018 |
} |
| 3019 |
e.stopPropagation(); |
| 3020 |
}); |
| 3021 |
// Child Checkboxes. |
| 3022 |
$('.child-checkbox .child.checkbox') |
| 3023 |
.checkbox( |
| 3024 |
{ |
| 3025 |
// Fire on load to set parent value |
| 3026 |
fireOnInit: true, |
| 3027 |
// Change parent state on each child checkbox change |
| 3028 |
onChange: function () { |
| 3029 |
var |
| 3030 |
$listGroup = $(this).closest('.child-checkbox'), |
| 3031 |
$parentCheckbox = $listGroup.prev('.master-checkbox').find('.checkbox'), |
| 3032 |
$checkbox = $listGroup.find('.checkbox'), |
| 3033 |
allChecked = true, |
| 3034 |
allUnchecked = true |
| 3035 |
; |
| 3036 |
// check to see if all other siblings are checked or unchecked |
| 3037 |
$checkbox.each(function () { |
| 3038 |
if ($(this).checkbox('is checked')) { |
| 3039 |
allUnchecked = false; |
| 3040 |
} |
| 3041 |
else { |
| 3042 |
allChecked = false; |
| 3043 |
} |
| 3044 |
}); |
| 3045 |
// set parent checkbox state, but dont trigger its onChange callback |
| 3046 |
if (allChecked) { |
| 3047 |
$parentCheckbox.checkbox('set checked'); |
| 3048 |
} |
| 3049 |
else if (allUnchecked) { |
| 3050 |
$parentCheckbox.checkbox('set unchecked'); |
| 3051 |
} |
| 3052 |
else { |
| 3053 |
$parentCheckbox.checkbox('set indeterminate'); |
| 3054 |
} |
| 3055 |
} |
| 3056 |
} |
| 3057 |
); |
| 3058 |
|
| 3059 |
// Main Master Checkboxes. |
| 3060 |
$('.main-master-checkbox .main-master.checkbox').checkbox(); |
| 3061 |
$('.main-master-checkbox .main-master.checkbox').on('click', function (e) { |
| 3062 |
console.log('main-master click'); |
| 3063 |
if ($(this).checkbox('is checked')) { |
| 3064 |
$(this).closest('.main-master-checkbox').next('.main-child-checkbox').find('.checkbox').checkbox('check'); |
| 3065 |
$(this).closest('.main-master-checkbox').find('.checkbox').checkbox('check'); |
| 3066 |
} else { |
| 3067 |
$(this).closest('.main-master-checkbox').next('.main-child-checkbox').find('.checkbox').checkbox('uncheck'); |
| 3068 |
$(this).closest('.main-master-checkbox').find('.checkbox').checkbox('uncheck'); |
| 3069 |
} |
| 3070 |
e.stopPropagation(); |
| 3071 |
}); |
| 3072 |
|
| 3073 |
} |
| 3074 |
|
| 3075 |
mainwp_table_check_columns_init = function () { |
| 3076 |
jQuery(document).find('table th.check-column .checkbox').checkbox({ |
| 3077 |
// check all children |
| 3078 |
onChecked: function () { |
| 3079 |
var $table = jQuery(this).closest('table'); |
| 3080 |
if ($table.parent().hasClass('dataTables_scrollHeadInner')) { |
| 3081 |
$table = jQuery(this).closest('.dataTables_scroll'); // to compatible with datatable scroll |
| 3082 |
} |
| 3083 |
|
| 3084 |
if ($table.length > 0) { |
| 3085 |
var $childCheckbox = $table.find('td.check-column .checkbox'); |
| 3086 |
$childCheckbox.checkbox('check'); |
| 3087 |
} |
| 3088 |
}, |
| 3089 |
// uncheck all children |
| 3090 |
onUnchecked: function () { |
| 3091 |
var $table = jQuery(this).closest('table'); |
| 3092 |
|
| 3093 |
if ($table.parent().hasClass('dataTables_scrollHeadInner')) |
| 3094 |
$table = jQuery(this).closest('.dataTables_scroll'); // to compatible with datatable scroll |
| 3095 |
|
| 3096 |
|
| 3097 |
if ($table.length > 0) { |
| 3098 |
var $childCheckbox = $table.find('td.check-column .checkbox'); |
| 3099 |
$childCheckbox.checkbox('uncheck'); |
| 3100 |
} |
| 3101 |
} |
| 3102 |
}); |
| 3103 |
|
| 3104 |
jQuery(document).find('td.check-column .checkbox').checkbox({ |
| 3105 |
// Fire on load to set parent value |
| 3106 |
fireOnInit: true, |
| 3107 |
// Change parent state on each child checkbox change |
| 3108 |
onChange: function () { |
| 3109 |
|
| 3110 |
var $table = jQuery(this).closest('table'); |
| 3111 |
|
| 3112 |
if ($table.parent().hasClass('dataTables_scrollBody')) |
| 3113 |
$table = jQuery(this).closest('.dataTables_scroll'); // to compatible with datatable scroll |
| 3114 |
|
| 3115 |
var $parentCheckbox = $table.find('th.check-column .checkbox'), |
| 3116 |
$checkbox = $table.find('td.check-column .checkbox'), |
| 3117 |
allChecked = true, |
| 3118 |
allUnchecked = true |
| 3119 |
; |
| 3120 |
|
| 3121 |
$checkbox.each(function () { |
| 3122 |
if (jQuery(this).checkbox('is checked')) { |
| 3123 |
allUnchecked = false; |
| 3124 |
} |
| 3125 |
else { |
| 3126 |
allChecked = false; |
| 3127 |
} |
| 3128 |
}); |
| 3129 |
|
| 3130 |
if (allChecked) { |
| 3131 |
$parentCheckbox.checkbox('set checked'); |
| 3132 |
} |
| 3133 |
else if (allUnchecked) { |
| 3134 |
$parentCheckbox.checkbox('set unchecked'); |
| 3135 |
} |
| 3136 |
} |
| 3137 |
}); |
| 3138 |
} |
| 3139 |
|
| 3140 |
|