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