| 1 |
|
| 2 |
/** |
| 3 |
* Backup |
| 4 |
*/ |
| 5 |
let backupDownloadRunning = false; |
| 6 |
let backupError = false; |
| 7 |
let backupContinueRetries = 0; |
| 8 |
let backupContinueRetriesUnique = []; |
| 9 |
|
| 10 |
jQuery(function () { |
| 11 |
jQuery('#backup_btnSubmit').on('click', function () { |
| 12 |
backup(); |
| 13 |
}); |
| 14 |
jQuery('#managesite-backup-status-close').on('click', function () { |
| 15 |
backupDownloadRunning = false; |
| 16 |
mainwpPopup('#managesite-backup-status-box').close(true); |
| 17 |
}); |
| 18 |
|
| 19 |
}); |
| 20 |
let backup = function () { |
| 21 |
backupError = false; |
| 22 |
backupContinueRetries = 0; |
| 23 |
|
| 24 |
jQuery('#backup_loading').show(); |
| 25 |
let remote_destinations = jQuery('#backup_location_remote').hasClass('mainwp_action_down') ? jQuery.map(jQuery('#backup_destination_list').find('input[name="remote_destinations[]"]'), function (el) { |
| 26 |
return { id: jQuery(el).val(), title: jQuery(el).attr('title'), type: jQuery(el).attr('destination_type') }; |
| 27 |
}) : []; |
| 28 |
|
| 29 |
let type = jQuery('#mainwp-backup-type').val(); |
| 30 |
let size = jQuery('#backup_site_' + type + '_size').val(); |
| 31 |
if (type == 'full') { |
| 32 |
size = size * 1024 * 1024 / 2.4; //Guessing how large the zip will be |
| 33 |
} |
| 34 |
let fileName = jQuery('#backup_filename').val(); |
| 35 |
let fileNameUID = mainwp_uid(); |
| 36 |
let loadFilesBeforeZip = jQuery('[name="mainwp_options_loadFilesBeforeZip"]:checked').val(); |
| 37 |
|
| 38 |
let backupPid = Math.round(new Date().getTime() / 1000); |
| 39 |
let data = mainwp_secure_data({ |
| 40 |
action: 'mainwp_backup', |
| 41 |
site_id: jQuery('#backup_site_id').val(), |
| 42 |
pid: backupPid, |
| 43 |
type: type, |
| 44 |
exclude: jQuery('#excluded_folders_list').val(), |
| 45 |
excludebackup: (jQuery('#mainwp-known-backup-locations').attr('checked') ? 1 : 0), |
| 46 |
excludecache: (jQuery('#mainwp-known-cache-locations').attr('checked') ? 1 : 0), |
| 47 |
excludenonwp: (jQuery('#mainwp-non-wordpress-folders').attr('checked') ? 1 : 0), |
| 48 |
excludezip: (jQuery('#mainwp-zip-archives').attr('checked') ? 1 : 0), |
| 49 |
filename: fileName, |
| 50 |
fileNameUID: fileNameUID, |
| 51 |
archiveFormat: jQuery('#mainwp_archiveFormat').val(), |
| 52 |
maximumFileDescriptorsOverride: jQuery('#mainwp_options_maximumFileDescriptorsOverride_override').is(':checked') ? 1 : 0, |
| 53 |
maximumFileDescriptorsAuto: (jQuery('#mainwp_maximumFileDescriptorsAuto').attr('checked') ? 1 : 0), |
| 54 |
maximumFileDescriptors: jQuery('#mainwp_options_maximumFileDescriptors').val(), |
| 55 |
loadFilesBeforeZip: loadFilesBeforeZip, |
| 56 |
subfolder: jQuery('#backup_subfolder').val() |
| 57 |
}, true); |
| 58 |
|
| 59 |
mainwpPopup('#managesite-backup-status-box').getContentEl().html(dateToHMS(new Date()) + ' ' + MainWP.I18n.t('Creating the backup file on the child site, this might take a while depending on the size. Please be patient.') + ' <div id="managesite-createbackup-status-progress" class="ui green progress"><div class="bar"><div class="progress"></div></div></div>'); |
| 60 |
jQuery('#managesite-createbackup-status-progress').progress({ value: 0, total: size }); |
| 61 |
|
| 62 |
mainwpPopup('#managesite-backup-status-box').init({ |
| 63 |
callback: function () { |
| 64 |
if (!backupError) { |
| 65 |
location.reload(); |
| 66 |
} |
| 67 |
} |
| 68 |
}); |
| 69 |
let backsprocessContentEl = mainwpPopup('#managesite-backup-status-box').getContentEl(); |
| 70 |
|
| 71 |
let fnc = function (pSiteId, pType, pFileName, pFileNameUID) { |
| 72 |
return function (pFunction) { |
| 73 |
let data2 = mainwp_secure_data({ |
| 74 |
action: 'mainwp_createbackup_getfilesize', |
| 75 |
siteId: pSiteId, |
| 76 |
type: pType, |
| 77 |
fileName: pFileName, |
| 78 |
fileNameUID: pFileNameUID |
| 79 |
}, false); |
| 80 |
|
| 81 |
jQuery.ajax({ |
| 82 |
url: ajaxurl, |
| 83 |
data: data2, |
| 84 |
method: 'POST', |
| 85 |
success: function (pFunc) { |
| 86 |
return function (response) { |
| 87 |
if (backupCreateRunning && response.error) { |
| 88 |
setTimeout(function () { |
| 89 |
pFunc(pFunc); |
| 90 |
}, 1000); |
| 91 |
return; |
| 92 |
} |
| 93 |
|
| 94 |
if (backupCreateRunning) { |
| 95 |
let progressBar = jQuery('#managesite-createbackup-status-progress'); |
| 96 |
if (progressBar.progress('get value') < progressBar.progress('get total')) { |
| 97 |
progressBar.progress('set progress', response.size); |
| 98 |
} |
| 99 |
|
| 100 |
setTimeout(function () { |
| 101 |
pFunc(pFunc); |
| 102 |
}, 1000); |
| 103 |
} |
| 104 |
} |
| 105 |
}(pFunction), |
| 106 |
error: function (pFunc) { |
| 107 |
return function () { |
| 108 |
if (backupCreateRunning) { |
| 109 |
setTimeout(function () { |
| 110 |
pFunc(pFunc); |
| 111 |
}, 10000); |
| 112 |
} |
| 113 |
} |
| 114 |
}(pFunction), |
| 115 |
dataType: 'json' |
| 116 |
}); |
| 117 |
} |
| 118 |
}(jQuery('#backup_site_id').val(), type, fileName, fileNameUID); |
| 119 |
|
| 120 |
setTimeout(function () { |
| 121 |
fnc(fnc); |
| 122 |
}, 1000); |
| 123 |
|
| 124 |
backupCreateRunning = true; |
| 125 |
jQuery.ajax({ |
| 126 |
url: ajaxurl, |
| 127 |
data: data, |
| 128 |
method: 'POST', |
| 129 |
success: function (pSiteId, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename, pData) { |
| 130 |
return function (response) { |
| 131 |
if (response.error || !response.result) { |
| 132 |
backup_retry_fail(pSiteId, pData, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename, response.error ? response.error : ''); |
| 133 |
} else { |
| 134 |
backupCreateRunning = false; |
| 135 |
|
| 136 |
let progressBar = jQuery('#managesite-createbackup-status-progress'); |
| 137 |
progressBar.progress('set progress', parseFloat(progressBar.progress('get total'))); |
| 138 |
|
| 139 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Backup file on child site created successfully!')); |
| 140 |
|
| 141 |
backup_download_file(pSiteId, pType, response.result.url, response.result.local, response.result.regexfile, response.result.size, response.result.subfolder, pRemoteDestinations); |
| 142 |
} |
| 143 |
} |
| 144 |
}(jQuery('#backup_site_id').val(), remote_destinations, backupPid, type, jQuery('#backup_subfolder').val(), fileName, data), |
| 145 |
error: function (pSiteId, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename, pData) { |
| 146 |
return function () { |
| 147 |
backup_retry_fail(pSiteId, pData, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename); |
| 148 |
} |
| 149 |
}(jQuery('#backup_site_id').val(), remote_destinations, backupPid, type, jQuery('#backup_subfolder').val(), fileName, data), |
| 150 |
dataType: 'json' |
| 151 |
}); |
| 152 |
}; |
| 153 |
|
| 154 |
let backup_retry_fail = function (siteId, pData, remoteDestinations, pid, type, subfolder, filename, responseError) { |
| 155 |
let backsprocessContentEl = mainwpPopup('#managesite-backup-status-box').getContentEl(); |
| 156 |
//we've got the pid file!!!! |
| 157 |
let data = mainwp_secure_data({ |
| 158 |
action: 'mainwp_backup_checkpid', |
| 159 |
site_id: siteId, |
| 160 |
pid: pid, |
| 161 |
type: type, |
| 162 |
subfolder: subfolder, |
| 163 |
filename: filename |
| 164 |
}); |
| 165 |
|
| 166 |
jQuery.ajax({ |
| 167 |
url: ajaxurl, |
| 168 |
data: data, |
| 169 |
method: 'POST', |
| 170 |
success: function (response) { |
| 171 |
if (response.status == 'done') { |
| 172 |
backupCreateRunning = false; |
| 173 |
|
| 174 |
let progressBar = jQuery('#managesite-createbackup-status-progress'); |
| 175 |
progressBar.progress('set progress', parseFloat(progressBar.progress('get total'))); |
| 176 |
|
| 177 |
//download!!! |
| 178 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Backup file on child site created successfully!')); |
| 179 |
|
| 180 |
backup_download_file(siteId, type, response.result.file, response.result.local, response.result.regexfile, response.result.size, response.result.subfolder, remoteDestinations); |
| 181 |
} else if (response.status == 'stalled') { |
| 182 |
backupContinueRetries++; |
| 183 |
|
| 184 |
if (backupContinueRetries > 15) { |
| 185 |
if (responseError != undefined) { |
| 186 |
appendToDiv(backsprocessContentEl, ' <span class="mainwp-red">ERROR: ' + getErrorMessage(responseError) + '</span>'); |
| 187 |
} else { |
| 188 |
appendToDiv(backsprocessContentEl, ' <span class="mainwp-red">ERROR: Backup timed out! (stalled) - <a href="https://mainwp.com/help/docs/mainwp-introduction/resolving-system-requirement-issues/">Please check this help document for more information and possible fixes</a></span>'); // NOSONAR - noopener - open safe. |
| 189 |
} |
| 190 |
} else { |
| 191 |
appendToDiv(backsprocessContentEl, ' Backup stalled, trying to resume from last file...'); |
| 192 |
pData['filename'] = response.result.file; |
| 193 |
pData['append'] = 1; |
| 194 |
pData = mainwp_secure_data(pData, true); //Rescure |
| 195 |
|
| 196 |
jQuery.ajax({ |
| 197 |
url: ajaxurl, |
| 198 |
data: pData, |
| 199 |
method: 'POST', |
| 200 |
success: function (pSiteId, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename, pData) { |
| 201 |
return function (response) { |
| 202 |
if (response.error || !response.result) { |
| 203 |
backup_retry_fail(pSiteId, pData, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename, response.error ? response.error : ''); |
| 204 |
} else { |
| 205 |
backupCreateRunning = false; |
| 206 |
|
| 207 |
let progressBar = jQuery('#managesite-createbackup-status-progress'); |
| 208 |
progressBar.progress('set progress', parseFloat(progressBar.progress('get total'))); |
| 209 |
|
| 210 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Backupfile on child site created successfully.')); |
| 211 |
|
| 212 |
backup_download_file(pSiteId, pType, response.result.url, response.result.local, response.result.regexfile, response.result.size, response.result.subfolder, pRemoteDestinations); |
| 213 |
} |
| 214 |
} |
| 215 |
}(siteId, remoteDestinations, pid, type, subfolder, filename, pData), |
| 216 |
error: function (pSiteId, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename, pData) { |
| 217 |
return function () { |
| 218 |
backup_retry_fail(pSiteId, pData, pRemoteDestinations, pBackupPid, pType, pSubfolder, pFilename); |
| 219 |
} |
| 220 |
}(siteId, remoteDestinations, pid, type, subfolder, filename, pData), |
| 221 |
dataType: 'json' |
| 222 |
}); |
| 223 |
} |
| 224 |
} else if (response.status == 'invalid') { |
| 225 |
backupCreateRunning = false; |
| 226 |
|
| 227 |
if (responseError != undefined) { |
| 228 |
appendToDiv(backsprocessContentEl, ' <span class="mainwp-red">ERROR: ' + getErrorMessage(responseError) + '</span>'); |
| 229 |
} else { |
| 230 |
appendToDiv(backsprocessContentEl, ' <span class="mainwp-red">ERROR: Backup timed out! (invalid) - <a href="https://mainwp.com/help/docs/mainwp-introduction/resolving-system-requirement-issues/">Please check this help document for more information and possible fixes</a></span>'); // NOSONAR - noopener - open safe. |
| 231 |
} |
| 232 |
} else { |
| 233 |
// busy or other. |
| 234 |
//Try again in 5seconds |
| 235 |
setTimeout(function () { |
| 236 |
backup_retry_fail(siteId, pData, remoteDestinations, pid, type, subfolder, filename, responseError); |
| 237 |
}, 10000); |
| 238 |
} |
| 239 |
}, |
| 240 |
error: function () { |
| 241 |
//Try again in 10seconds |
| 242 |
setTimeout(function () { |
| 243 |
backup_retry_fail(siteId, pData, remoteDestinations, pid, type, subfolder, filename, responseError); |
| 244 |
}, 10000); |
| 245 |
}, |
| 246 |
dataType: 'json' |
| 247 |
}); |
| 248 |
}; |
| 249 |
|
| 250 |
backup_download_file = function (pSiteId, type, url, file, regexfile, size, subfolder, remote_destinations) { |
| 251 |
let backsprocessContentEl = mainwpPopup('#managesite-backup-status-box').getContentEl(); |
| 252 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Downloading the file.') + ' <div id="managesite-backup-status-progress" class="ui green progress"><div class="bar"><div class="progress"></div></div></div>'); |
| 253 |
jQuery('#managesite-backup-status-progress').progress({ value: 0, total: size }); |
| 254 |
|
| 255 |
let fnc = function (file) { |
| 256 |
return function (pFunction) { |
| 257 |
let data = mainwp_secure_data({ |
| 258 |
action: 'mainwp_backup_getfilesize', |
| 259 |
local: file |
| 260 |
}); |
| 261 |
jQuery.ajax({ |
| 262 |
url: ajaxurl, |
| 263 |
data: data, |
| 264 |
method: 'POST', |
| 265 |
success: function (pFunc) { |
| 266 |
return function (response) { |
| 267 |
if (backupCreateRunning && response.error) { |
| 268 |
setTimeout(function () { |
| 269 |
pFunc(pFunc); |
| 270 |
}, 5000); |
| 271 |
return; |
| 272 |
} |
| 273 |
|
| 274 |
if (backupDownloadRunning) { |
| 275 |
let progressBar = jQuery('#managesite-backup-status-progress'); |
| 276 |
if (progressBar.progress('get value') < progressBar.progress('get total')) { |
| 277 |
progressBar.progress('set progress', response.result); |
| 278 |
} |
| 279 |
|
| 280 |
setTimeout(function () { |
| 281 |
pFunc(pFunc); |
| 282 |
}, 1000); |
| 283 |
} |
| 284 |
} |
| 285 |
}(pFunction), |
| 286 |
error: function (pFunc) { |
| 287 |
return function () { |
| 288 |
if (backupCreateRunning) { |
| 289 |
setTimeout(function () { |
| 290 |
pFunc(pFunc); |
| 291 |
}, 10000); |
| 292 |
} |
| 293 |
} |
| 294 |
}(pFunction), |
| 295 |
dataType: 'json' |
| 296 |
}); |
| 297 |
} |
| 298 |
}(file); |
| 299 |
|
| 300 |
setTimeout(function () { |
| 301 |
fnc(fnc); |
| 302 |
}, 1000); |
| 303 |
|
| 304 |
let data = mainwp_secure_data({ |
| 305 |
action: 'mainwp_backup_download_file', |
| 306 |
site_id: pSiteId, |
| 307 |
type: type, |
| 308 |
url: url, |
| 309 |
local: file |
| 310 |
}); |
| 311 |
backupDownloadRunning = true; |
| 312 |
|
| 313 |
jQuery.ajax({ |
| 314 |
url: ajaxurl, |
| 315 |
data: data, |
| 316 |
method: 'POST', |
| 317 |
success: function (pSiteId, pFile, pRegexFile, pSubfolder, pRemoteDestinations, pSize, pType, pUrl) { |
| 318 |
return function (response) { |
| 319 |
backupDownloadRunning = false; |
| 320 |
|
| 321 |
if (response.error) { |
| 322 |
appendToDiv(backsprocessContentEl, '<span class="mainwp-red">ERROR: ' + getErrorMessage(response.error) + '</span>'); |
| 323 |
appendToDiv(backsprocessContentEl, '<span class="mainwp-red">' + MainWP.I18n.t('Backup failed!') + '</span>'); |
| 324 |
|
| 325 |
jQuery('#managesite-backup-status-close').prop('value', 'Close'); |
| 326 |
return; |
| 327 |
} |
| 328 |
|
| 329 |
jQuery('#managesite-backup-status-progress').progress('set progress', pSize); |
| 330 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Download from child site completed.')); |
| 331 |
|
| 332 |
let newData = mainwp_secure_data({ |
| 333 |
action: 'mainwp_backup_delete_file', |
| 334 |
site_id: pSiteId, |
| 335 |
file: pUrl |
| 336 |
}); |
| 337 |
jQuery.post(ajaxurl, newData, function () { }, 'json'); |
| 338 |
backup_upload_file(pSiteId, pFile, pRegexFile, pSubfolder, pRemoteDestinations, pType, pSize); |
| 339 |
} |
| 340 |
}(pSiteId, file, regexfile, subfolder, remote_destinations, size, type, url), |
| 341 |
error: function () { |
| 342 |
return function () { |
| 343 |
//Try again in 10seconds |
| 344 |
/*setTimeout(function() { |
| 345 |
download_retry_fail(pSiteId, pData, pFile, pRegexFile, pSubfolder, pRemoteDestinations, pSize, pType, pUrl); |
| 346 |
},10000);*/ |
| 347 |
} |
| 348 |
}(pSiteId, file, regexfile, subfolder, remote_destinations, size, type, url), |
| 349 |
dataType: 'json' |
| 350 |
}); |
| 351 |
}; |
| 352 |
|
| 353 |
let backupUploadRunning = []; |
| 354 |
backup_upload_file = function (pSiteId, pFile, pRegexFile, pSubfolder, pRemoteDestinations, pType, pSize) { |
| 355 |
let backsprocessContentEl = mainwpPopup('#managesite-backup-status-box').getContentEl(); |
| 356 |
if (pRemoteDestinations.length > 0) { |
| 357 |
let remote_destination = pRemoteDestinations[0]; |
| 358 |
//upload.. |
| 359 |
let unique = Date.now(); |
| 360 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Uploading to remote destination: %1 (%2)', remote_destination.title, remote_destination.type) + '<div id="managesite-upload-status-progress-' + unique + '" class="ui green progress"><div class="bar"><div class="progress"></div></div></div>'); |
| 361 |
|
| 362 |
jQuery('#managesite-upload-status-progress-' + unique).progress({ value: 0, total: pSize }); |
| 363 |
|
| 364 |
let fnc = function (pUnique) { |
| 365 |
return function (pFunction) { |
| 366 |
let data2 = mainwp_secure_data({ |
| 367 |
action: 'mainwp_backup_upload_getprogress', |
| 368 |
unique: pUnique |
| 369 |
}, false); |
| 370 |
|
| 371 |
jQuery.ajax({ |
| 372 |
url: ajaxurl, |
| 373 |
data: data2, |
| 374 |
method: 'POST', |
| 375 |
success: function (pFunc) { |
| 376 |
return function (response) { |
| 377 |
if (backupUploadRunning[pUnique] && response.error) { |
| 378 |
setTimeout(function () { |
| 379 |
pFunc(pFunc); |
| 380 |
}, 1000); |
| 381 |
return; |
| 382 |
} |
| 383 |
|
| 384 |
if (backupUploadRunning[pUnique]) { |
| 385 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 386 |
if ((progressBar.length > 0) && (progressBar.progress('get value') < progressBar.progress('get total')) && (progressBar.progress('get value') < Number.parseInt(response.result))) { |
| 387 |
progressBar.progress('set progress', response.result); |
| 388 |
} |
| 389 |
|
| 390 |
setTimeout(function () { |
| 391 |
pFunc(pFunc); |
| 392 |
}, 1000); |
| 393 |
} |
| 394 |
} |
| 395 |
}(pFunction), |
| 396 |
error: function (pFunc) { |
| 397 |
return function () { |
| 398 |
if (backupUploadRunning[pUnique]) { |
| 399 |
setTimeout(function () { |
| 400 |
pFunc(pFunc); |
| 401 |
}, 10000); |
| 402 |
} |
| 403 |
} |
| 404 |
}(pFunction), |
| 405 |
dataType: 'json' |
| 406 |
}); |
| 407 |
} |
| 408 |
}(unique); |
| 409 |
|
| 410 |
setTimeout(function () { |
| 411 |
fnc(fnc); |
| 412 |
}, 1000); |
| 413 |
|
| 414 |
backupUploadRunning[unique] = true; |
| 415 |
|
| 416 |
let data = mainwp_secure_data({ |
| 417 |
action: 'mainwp_backup_upload_file', |
| 418 |
file: pFile, |
| 419 |
siteId: pSiteId, |
| 420 |
regexfile: pRegexFile, |
| 421 |
subfolder: pSubfolder, |
| 422 |
type: pType, |
| 423 |
remote_destination: remote_destination.id, |
| 424 |
unique: unique |
| 425 |
}); |
| 426 |
|
| 427 |
pRemoteDestinations.shift(); |
| 428 |
jQuery.ajax({ |
| 429 |
type: 'POST', |
| 430 |
url: ajaxurl, |
| 431 |
data: data, |
| 432 |
success: function (pSiteId, pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, pData, pUnique, pRemoteDestId) { |
| 433 |
return function (response) { |
| 434 |
if (!response || response.error || !response.result) { |
| 435 |
backup_upload_file_retry_fail(pData, pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, response && response.error ? response.error : ''); |
| 436 |
} else { |
| 437 |
backupUploadRunning[pUnique] = false; |
| 438 |
|
| 439 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 440 |
progressBar.progress('set progress', pSize); |
| 441 |
|
| 442 |
let obj = response.result; |
| 443 |
if (obj.error) { |
| 444 |
backupError = true; |
| 445 |
appendToDiv(backsprocessContentEl, '<span class="mainwp-red">' + MainWP.I18n.t('Upload to %1 (%2) failed:', obj.title, obj.type) + ' ' + obj.error + '</span>'); |
| 446 |
} else { |
| 447 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Upload to %1 (%2) successful!', obj.title, obj.type)); |
| 448 |
} |
| 449 |
|
| 450 |
backup_upload_file(pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 451 |
} |
| 452 |
} |
| 453 |
}(pSiteId, pRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, data, unique, remote_destination.id), |
| 454 |
error: function (pSiteId, pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, pData, pUnique, pRemoteDestId) { |
| 455 |
return function () { |
| 456 |
backup_upload_file_retry_fail(pData, pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId); |
| 457 |
} |
| 458 |
}(pSiteId, pRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, data, unique, remote_destination.id), |
| 459 |
dataType: 'json' |
| 460 |
}); |
| 461 |
} else { |
| 462 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Backup completed!')); |
| 463 |
jQuery('#managesite-backup-status-close').prop('value', 'Close'); |
| 464 |
if (!backupError) { |
| 465 |
setTimeout(function () { |
| 466 |
mainwpPopup('#managesite-backup-status-box').close(true); |
| 467 |
}, 3000); |
| 468 |
} |
| 469 |
return; |
| 470 |
} |
| 471 |
}; |
| 472 |
|
| 473 |
backup_upload_file_retry_fail = function (pData, pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError) { |
| 474 |
let backsprocessContentEl = mainwpPopup('#managesite-backup-status-box').getContentEl(); |
| 475 |
//we've got the pid file!!!! |
| 476 |
let data = mainwp_secure_data({ |
| 477 |
action: 'mainwp_backup_upload_checkstatus', |
| 478 |
unique: pUnique, |
| 479 |
remote_destination: pRemoteDestId |
| 480 |
}); |
| 481 |
|
| 482 |
jQuery.ajax({ |
| 483 |
url: ajaxurl, |
| 484 |
data: data, |
| 485 |
method: 'POST', |
| 486 |
success: function (response) { |
| 487 |
if (response.status == 'done') { |
| 488 |
backupUploadRunning[pUnique] = false; |
| 489 |
|
| 490 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 491 |
progressBar.progress('set progress', pSize); |
| 492 |
|
| 493 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Upload to %1 (%2) successful!', response.info.title, response.info.type)); |
| 494 |
|
| 495 |
backup_upload_file(pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 496 |
} else if (response.status == 'stalled') { |
| 497 |
if (backupContinueRetriesUnique[pUnique] == undefined) { |
| 498 |
backupContinueRetriesUnique[pUnique] = 1; |
| 499 |
} else { |
| 500 |
backupContinueRetriesUnique[pUnique]++; |
| 501 |
} |
| 502 |
|
| 503 |
if (backupContinueRetriesUnique[pUnique] > 10) { |
| 504 |
if (responseError != undefined) { |
| 505 |
backupError = true; |
| 506 |
appendToDiv(backsprocessContentEl, '<span class="mainwp-red">' + MainWP.I18n.t('Upload to %1 (%2) failed:', response.info.title, response.info.type) + ' ' + responseError + '</span>'); |
| 507 |
} else { |
| 508 |
appendToDiv(backsprocessContentEl, ' <span class="mainwp-red">ERROR: Upload timed out! <a href="http://docs.mainwp.com/backup-failed-php-ini-settings/">Please check this help document for more information and possible fixes</a></span>'); |
| 509 |
} |
| 510 |
|
| 511 |
backup_upload_file(pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 512 |
} else { |
| 513 |
appendToDiv(backsprocessContentEl, ' Upload stalled, trying to resume from last position...'); |
| 514 |
|
| 515 |
pData = mainwp_secure_data(pData); //Rescure |
| 516 |
|
| 517 |
jQuery.ajax({ |
| 518 |
url: ajaxurl, |
| 519 |
data: pData, |
| 520 |
method: 'POST', |
| 521 |
success: function (pSiteId, pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, pData, pRemoteDestId) { |
| 522 |
return function (response) { |
| 523 |
if (response.error || !response.result) { |
| 524 |
backup_upload_file_retry_fail(pData, pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, response.error ? response.error : ''); |
| 525 |
} else { |
| 526 |
backupUploadRunning[pUnique] = false; |
| 527 |
|
| 528 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 529 |
progressBar.progress('set progress', pSize); |
| 530 |
|
| 531 |
let obj = response.result; |
| 532 |
if (obj.error) { |
| 533 |
backupError = true; |
| 534 |
appendToDiv(backsprocessContentEl, '<span class="mainwp-red">' + MainWP.I18n.t('Upload to %1 (%2) failed:', obj.title, obj.type) + ' ' + obj.error + '</span>'); |
| 535 |
} else { |
| 536 |
appendToDiv(backsprocessContentEl, MainWP.I18n.t('Upload to %1 (%2) successful!', obj.title, obj.type)); |
| 537 |
} |
| 538 |
|
| 539 |
backup_upload_file(pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 540 |
} |
| 541 |
} |
| 542 |
}(pSiteId, pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, pData, pRemoteDestId), |
| 543 |
error: function (pSiteId, pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, pData, pRemoteDestId) { |
| 544 |
return function () { |
| 545 |
backup_upload_file_retry_fail(pData, pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId); |
| 546 |
} |
| 547 |
}(pSiteId, pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSize, pData, pRemoteDestId), |
| 548 |
dataType: 'json' |
| 549 |
}); |
| 550 |
} |
| 551 |
} else { |
| 552 |
// busy or other. |
| 553 |
//Try again in 5seconds |
| 554 |
setTimeout(function () { |
| 555 |
backup_upload_file_retry_fail(pData, pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError); |
| 556 |
}, 10000); |
| 557 |
} |
| 558 |
}, |
| 559 |
error: function () { |
| 560 |
//Try again in 10seconds |
| 561 |
setTimeout(function () { |
| 562 |
backup_upload_file_retry_fail(pData, pSiteId, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError); |
| 563 |
}, 10000); |
| 564 |
}, |
| 565 |
dataType: 'json' |
| 566 |
}); |
| 567 |
}; |
| 568 |
|
| 569 |
|
| 570 |
/** |
| 571 |
* Manage backups page |
| 572 |
*/ |
| 573 |
jQuery(function () { |
| 574 |
jQuery(document).on('click', '.backup_destination_exclude', function () { |
| 575 |
jQuery(this).parent().parent().animate({ height: 0 }, { |
| 576 |
duration: 'slow', complete: function () { |
| 577 |
jQuery(this).remove(); |
| 578 |
} |
| 579 |
}); |
| 580 |
}); |
| 581 |
jQuery('#mainwp_managebackups_add').on('click', function (event) { |
| 582 |
mainwp_managebackups_add(event); |
| 583 |
}); |
| 584 |
jQuery('#mainwp_managebackups_update').on('click', function (event) { |
| 585 |
mainwp_managebackups_update(event); |
| 586 |
}); |
| 587 |
jQuery(document).on('click', '.backup_run_now', function () { |
| 588 |
managebackups_run_now(jQuery(this)); |
| 589 |
return false; |
| 590 |
}); |
| 591 |
jQuery(document).on('click', '#managebackups-task-status-close', function () { |
| 592 |
backupDownloadRunning = false; |
| 593 |
mainwpPopup('#managebackups-task-status-box').close(true); |
| 594 |
}); |
| 595 |
managebackups_init(); |
| 596 |
|
| 597 |
}); |
| 598 |
managebackups_exclude_folder = function (pElement) { |
| 599 |
let folder = pElement.parent().attr('rel') + "\n"; |
| 600 |
if (jQuery('#excluded_folders_list').val().includes(folder)) |
| 601 |
return; |
| 602 |
|
| 603 |
jQuery('#excluded_folders_list').val(jQuery('#excluded_folders_list').val() + folder); |
| 604 |
}; |
| 605 |
|
| 606 |
let manageBackupsError = false; |
| 607 |
let manageBackupsTaskRemoteDestinations; |
| 608 |
let manageBackupsTaskId; |
| 609 |
let manageBackupsTaskType; |
| 610 |
let manageBackupsTaskError; |
| 611 |
managebackups_run_now = function (el) { |
| 612 |
el = jQuery(el); |
| 613 |
el.hide(); |
| 614 |
el.parent().find('.backup_run_loading').show(); |
| 615 |
mainwpPopup('#managebackups-task-status-box').getContentEl().html(dateToHMS(new Date()) + ' ' + MainWP.I18n.t('Starting the backup task...')); |
| 616 |
jQuery('#managebackups-task-status-close').prop('value', MainWP.I18n.t('Cancel')); |
| 617 |
mainwpPopup('#managebackups-task-status-box').init({ |
| 618 |
title: MainWP.I18n.t('Running task'), callback: function () { |
| 619 |
location.reload(); |
| 620 |
} |
| 621 |
}); |
| 622 |
|
| 623 |
let taskId = el.attr('task_id'); |
| 624 |
let taskType = el.attr('task_type'); |
| 625 |
//Fetch the sites to backup |
| 626 |
let data = mainwp_secure_data({ |
| 627 |
action: 'mainwp_backuptask_get_sites', |
| 628 |
task_id: taskId |
| 629 |
}); |
| 630 |
|
| 631 |
manageBackupsError = false; |
| 632 |
|
| 633 |
jQuery.post(ajaxurl, data, function (pTaskId, pTaskType) { |
| 634 |
return function (response) { |
| 635 |
manageBackupTaskSites = response.result.sites; |
| 636 |
manageBackupsTaskRemoteDestinations = response.result.remoteDestinations; |
| 637 |
manageBackupsTaskId = pTaskId; |
| 638 |
manageBackupsTaskType = pTaskType; |
| 639 |
manageBackupsTaskError = false; |
| 640 |
|
| 641 |
managebackups_run_next(); |
| 642 |
} |
| 643 |
}(taskId, taskType), 'json'); |
| 644 |
}; |
| 645 |
managebackups_run_next = function () { |
| 646 |
let backtaskContentEl = mainwpPopup('#managebackups-task-status-box').getContentEl(); |
| 647 |
if (manageBackupTaskSites.length == 0) { |
| 648 |
appendToDiv(backtaskContentEl, MainWP.I18n.t('Backup task completed') + (manageBackupsTaskError ? ' <span class="mainwp-red">' + MainWP.I18n.t('with errors') + '</span>' : '') + '.'); |
| 649 |
|
| 650 |
jQuery('#managebackups-task-status-close').prop('value', MainWP.I18n.t('Close')); |
| 651 |
if (!manageBackupsError) { |
| 652 |
setTimeout(function () { |
| 653 |
mainwpPopup('#managebackups-task-status-box').close(true); |
| 654 |
}, 3000); |
| 655 |
} |
| 656 |
return; |
| 657 |
} |
| 658 |
|
| 659 |
let siteId = manageBackupTaskSites[0]['id']; |
| 660 |
let siteName = manageBackupTaskSites[0]['name']; |
| 661 |
let size = manageBackupTaskSites[0][manageBackupsTaskType + 'size']; |
| 662 |
let fileNameUID = mainwp_uid(); |
| 663 |
appendToDiv(backtaskContentEl, '[' + siteName + '] ' + MainWP.I18n.t('Creating backup file.') + '<div id="managebackups-task-status-create-progress" siteId="' + siteId + '" class="ui green progress"><div class="bar"><div class="progress"></div></div></div>'); |
| 664 |
|
| 665 |
manageBackupTaskSites.shift(); |
| 666 |
let data = mainwp_secure_data({ |
| 667 |
action: 'mainwp_backuptask_run_site', |
| 668 |
task_id: manageBackupsTaskId, |
| 669 |
site_id: siteId, |
| 670 |
fileNameUID: fileNameUID |
| 671 |
}); |
| 672 |
|
| 673 |
jQuery('#managebackups-task-status-create-progress[siteId="' + siteId + '"]').progress({ value: 0, total: size }); |
| 674 |
let interVal = setInterval(function () { |
| 675 |
let data = mainwp_secure_data({ |
| 676 |
action: 'mainwp_createbackup_getfilesize', |
| 677 |
type: manageBackupsTaskType, |
| 678 |
siteId: siteId, |
| 679 |
fileName: '', |
| 680 |
fileNameUID: fileNameUID |
| 681 |
}); |
| 682 |
jQuery.post(ajaxurl, data, function (pSiteId) { |
| 683 |
return function (response) { |
| 684 |
if (response.error) |
| 685 |
return; |
| 686 |
|
| 687 |
if (backupCreateRunning) { |
| 688 |
let progressBar = jQuery('#managebackups-task-status-create-progress[siteId="' + pSiteId + '"]'); |
| 689 |
if (progressBar.progress('get value') < progressBar.progress('get total')) { |
| 690 |
progressBar.progress('set progress', response.size); |
| 691 |
} |
| 692 |
} |
| 693 |
} |
| 694 |
}(siteId), 'json'); |
| 695 |
}, 1000); |
| 696 |
|
| 697 |
backupCreateRunning = true; |
| 698 |
|
| 699 |
jQuery.ajax({ |
| 700 |
url: ajaxurl, |
| 701 |
data: data, |
| 702 |
method: 'POST', |
| 703 |
success: function (pTaskId, pSiteId, pSiteName, pRemoteDestinations, pInterVal) { |
| 704 |
return function (response) { |
| 705 |
backupCreateRunning = false; |
| 706 |
clearInterval(pInterVal); |
| 707 |
|
| 708 |
let progressBar = jQuery('#managebackups-task-status-create-progress[siteId="' + pSiteId + '"]'); |
| 709 |
progressBar.progress('set progress', parseFloat(progressBar.progress('get total'))); |
| 710 |
|
| 711 |
if (response.error) { |
| 712 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] <span class="mainwp-red">Error: ' + getErrorMessage(response.error) + '</span>'); |
| 713 |
manageBackupsTaskError = true; |
| 714 |
managebackups_run_next(); |
| 715 |
} else { |
| 716 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Backup file created successfully.')); |
| 717 |
|
| 718 |
managebackups_backup_download_file(pSiteId, pSiteName, response.result.type, response.result.url, response.result.local, response.result.regexfile, response.result.size, response.result.subfolder, pRemoteDestinations); |
| 719 |
} |
| 720 |
} |
| 721 |
}(manageBackupsTaskId, siteId, siteName, manageBackupsTaskRemoteDestinations.slice(0), interVal), |
| 722 |
error: function (pInterVal, pSiteName) { |
| 723 |
return function () { |
| 724 |
backupCreateRunning = false; |
| 725 |
clearInterval(pInterVal); |
| 726 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + '<span class="mainwp-red">ERROR: Backup timed out (request) - <a href="https://mainwp.com/help/docs/mainwp-introduction/resolving-system-requirement-issues/">Please check this help document for more information and possible fixes</a></span>'); // NOSONAR - noopener - open safe. |
| 727 |
} |
| 728 |
}(interVal, siteName), dataType: 'json' |
| 729 |
}); |
| 730 |
}; |
| 731 |
|
| 732 |
let managebackups_backup_download_file = function (pSiteId, pSiteName, type, url, file, regexfile, size, subfolder, remote_destinations) { |
| 733 |
let backtaskContentEl = mainwpPopup('#managebackups-task-status-box').getContentEl(); |
| 734 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] Downloading the file. <div id="managebackups-task-status-progress" siteId="' + pSiteId + '" class="ui green progress"><div class="bar"><div class="progress"></div></div></div>'); |
| 735 |
jQuery('#managebackups-task-status-progress[siteId="' + pSiteId + '"]').progress({ value: 0, total: size }); |
| 736 |
let interVal = setInterval(function () { |
| 737 |
let data = mainwp_secure_data({ |
| 738 |
action: 'mainwp_backup_getfilesize', |
| 739 |
local: file |
| 740 |
}); |
| 741 |
jQuery.post(ajaxurl, data, function (pSiteId) { |
| 742 |
return function (response) { |
| 743 |
if (response.error) |
| 744 |
return; |
| 745 |
|
| 746 |
if (backupDownloadRunning) { |
| 747 |
let progressBar = jQuery('#managebackups-task-status-progress[siteId="' + pSiteId + '"]'); |
| 748 |
if (progressBar.progress('get value') < progressBar.progress('get total')) { |
| 749 |
progressBar.progress('set progress', response.result); |
| 750 |
} |
| 751 |
} |
| 752 |
} |
| 753 |
}(pSiteId), 'json'); |
| 754 |
}, 500); |
| 755 |
|
| 756 |
let data = mainwp_secure_data({ |
| 757 |
action: 'mainwp_backup_download_file', |
| 758 |
site_id: pSiteId, |
| 759 |
type: type, |
| 760 |
url: url, |
| 761 |
local: file |
| 762 |
}); |
| 763 |
backupDownloadRunning = true; |
| 764 |
jQuery.post(ajaxurl, data, function (pFile, pRegexFile, pSubfolder, pRemoteDestinations, pSize, pType, pInterVal, pSiteName, pSiteId, pUrl) { |
| 765 |
return function (response) { |
| 766 |
backupDownloadRunning = false; |
| 767 |
clearInterval(pInterVal); |
| 768 |
|
| 769 |
if (response.error) { |
| 770 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] <span class="mainwp-red">ERROR: ' + getErrorMessage(response.error) + '</span>'); |
| 771 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] <span class="mainwp-red">' + MainWP.I18n.t('Backup failed!') + '</span>'); |
| 772 |
|
| 773 |
manageBackupsError = true; |
| 774 |
managebackups_run_next(); |
| 775 |
return; |
| 776 |
} |
| 777 |
|
| 778 |
jQuery('#managebackups-task-status-progress[siteId="' + pSiteId + '"]').progress('set progress', pSize); |
| 779 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Download from child site completed.')); |
| 780 |
|
| 781 |
|
| 782 |
let newData = mainwp_secure_data({ |
| 783 |
action: 'mainwp_backup_delete_file', |
| 784 |
site_id: pSiteId, |
| 785 |
file: pUrl |
| 786 |
}); |
| 787 |
jQuery.post(ajaxurl, newData, function () { }, 'json'); |
| 788 |
|
| 789 |
managebackups_backup_upload_file(pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pRemoteDestinations, pType, pSize); |
| 790 |
} |
| 791 |
}(file, regexfile, subfolder, remote_destinations, size, type, interVal, pSiteName, pSiteId, url), 'json'); |
| 792 |
}; |
| 793 |
|
| 794 |
managebackups_backup_upload_file = function (pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pRemoteDestinations, pType, pSize) { |
| 795 |
let backtaskContentEl = mainwpPopup('#managebackups-task-status-box').getContentEl(); |
| 796 |
if (pRemoteDestinations.length > 0) { |
| 797 |
let remote_destination = pRemoteDestinations[0]; |
| 798 |
//upload.. |
| 799 |
let unique = Date.now(); |
| 800 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Uploading to selected remote destination: %1 (%2)', remote_destination.title, remote_destination.type) + '<div id="managesite-upload-status-progress-' + unique + '" class="ui green progress"><div class="bar"><div class="progress"></div></div></div>'); |
| 801 |
|
| 802 |
jQuery('#managesite-upload-status-progress-' + unique).progress({ value: 0, total: pSize }); |
| 803 |
|
| 804 |
let fnc = function (pUnique) { |
| 805 |
return function (pFunction) { |
| 806 |
let data2 = mainwp_secure_data({ |
| 807 |
action: 'mainwp_backup_upload_getprogress', |
| 808 |
unique: pUnique |
| 809 |
}, false); |
| 810 |
|
| 811 |
jQuery.ajax({ |
| 812 |
url: ajaxurl, |
| 813 |
data: data2, |
| 814 |
method: 'POST', |
| 815 |
success: function (pFunc) { |
| 816 |
return function (response) { |
| 817 |
if (backupUploadRunning[pUnique] && response.error) { |
| 818 |
setTimeout(function () { |
| 819 |
pFunc(pFunc); |
| 820 |
}, 1000); |
| 821 |
return; |
| 822 |
} |
| 823 |
|
| 824 |
if (backupUploadRunning[pUnique]) { |
| 825 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 826 |
if ((progressBar.length > 0) && (progressBar.progress('get value') < progressBar.progress('get total')) && (progressBar.progress('get value') < Number.parseInt(response.result))) { |
| 827 |
progressBar.progress('set progress', response.result); |
| 828 |
} |
| 829 |
|
| 830 |
setTimeout(function () { |
| 831 |
pFunc(pFunc); |
| 832 |
}, 1000); |
| 833 |
} |
| 834 |
} |
| 835 |
}(pFunction), |
| 836 |
error: function (pFunc) { |
| 837 |
return function () { |
| 838 |
if (backupUploadRunning[pUnique]) { |
| 839 |
setTimeout(function () { |
| 840 |
pFunc(pFunc); |
| 841 |
}, 10000); |
| 842 |
} |
| 843 |
} |
| 844 |
}(pFunction), |
| 845 |
dataType: 'json' |
| 846 |
}); |
| 847 |
} |
| 848 |
}(unique); |
| 849 |
|
| 850 |
setTimeout(function () { |
| 851 |
fnc(fnc); |
| 852 |
}, 1000); |
| 853 |
|
| 854 |
backupUploadRunning[unique] = true; |
| 855 |
|
| 856 |
let data = mainwp_secure_data({ |
| 857 |
action: 'mainwp_backup_upload_file', |
| 858 |
file: pFile, |
| 859 |
siteId: pSiteId, |
| 860 |
regexfile: pRegexFile, |
| 861 |
subfolder: pSubfolder, |
| 862 |
type: pType, |
| 863 |
remote_destination: remote_destination.id, |
| 864 |
unique: unique |
| 865 |
}); |
| 866 |
|
| 867 |
pRemoteDestinations.shift(); |
| 868 |
jQuery.ajax({ |
| 869 |
type: 'POST', |
| 870 |
url: ajaxurl, |
| 871 |
data: data, |
| 872 |
success: function (pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, pData, pUnique, pRemoteDestId) { |
| 873 |
return function (response) { |
| 874 |
if (!response || response.error || !response.result) { |
| 875 |
managebackups_backup_upload_file_retry_fail(pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, response.error ? response.error : ''); |
| 876 |
} else { |
| 877 |
backupUploadRunning[pUnique] = false; |
| 878 |
|
| 879 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 880 |
progressBar.progress('set progress', pSize); |
| 881 |
|
| 882 |
let obj = response.result; |
| 883 |
if (obj.error) { |
| 884 |
manageBackupsError = true; |
| 885 |
appendToDiv(backtaskContentEl, '<span class="mainwp-red">[' + pSiteName + '] ' + MainWP.I18n.t('Upload to %1 (%2) failed:', obj.title, obj.type) + ' ' + obj.error + '</span>'); |
| 886 |
} else { |
| 887 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Upload to %1 (%2) successful', obj.title, obj.type)); |
| 888 |
} |
| 889 |
|
| 890 |
managebackups_backup_upload_file(pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 891 |
} |
| 892 |
} |
| 893 |
}(pRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, data, unique, remote_destination.id), |
| 894 |
error: function (pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, pData, pUnique, pRemoteDestId) { |
| 895 |
return function () { |
| 896 |
managebackups_backup_upload_file_retry_fail(pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId); |
| 897 |
} |
| 898 |
}(pRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, data, unique, remote_destination.id), |
| 899 |
dataType: 'json' |
| 900 |
}); |
| 901 |
} else { |
| 902 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Backup completed.')); |
| 903 |
managebackups_run_next(); |
| 904 |
} |
| 905 |
}; |
| 906 |
|
| 907 |
managebackups_backup_upload_file_retry_fail = function (pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError) { |
| 908 |
let backtaskContentEl = mainwpPopup('#managebackups-task-status-box').getContentEl(); |
| 909 |
//we've got the pid file!!!! |
| 910 |
let data = mainwp_secure_data({ |
| 911 |
action: 'mainwp_backup_upload_checkstatus', |
| 912 |
unique: pUnique, |
| 913 |
remote_destination: pRemoteDestId |
| 914 |
}); |
| 915 |
|
| 916 |
jQuery.ajax({ |
| 917 |
url: ajaxurl, |
| 918 |
data: data, |
| 919 |
method: 'POST', |
| 920 |
success: function (response) { |
| 921 |
if (response.status == 'done') { |
| 922 |
backupUploadRunning[pUnique] = false; |
| 923 |
|
| 924 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 925 |
progressBar.progress('set progress', pSize); |
| 926 |
|
| 927 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Upload to %1 (%2) successful', response.info.title, response.info.type)); |
| 928 |
|
| 929 |
managebackups_backup_upload_file(pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 930 |
} else if (response.status == 'busy') { |
| 931 |
//Try again in 10seconds |
| 932 |
setTimeout(function () { |
| 933 |
managebackups_backup_upload_file_retry_fail(pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError); |
| 934 |
}, 10000); |
| 935 |
} else if (response.status == 'stalled') { |
| 936 |
if (backupContinueRetriesUnique[pUnique] == undefined) { |
| 937 |
backupContinueRetriesUnique[pUnique] = 1; |
| 938 |
} else { |
| 939 |
backupContinueRetriesUnique[pUnique]++; |
| 940 |
} |
| 941 |
|
| 942 |
if (backupContinueRetriesUnique[pUnique] > 10) { |
| 943 |
if (responseError != undefined) { |
| 944 |
manageBackupsError = true; |
| 945 |
appendToDiv(backtaskContentEl, '<span class="mainwp-red">[' + pSiteName + '] ' + MainWP.I18n.t('Upload to %1 (%2) failed:', response.info.title, response.info.type) + ' ' + responseError + '</span>'); |
| 946 |
} else { |
| 947 |
appendToDiv(backtaskContentEl, ' <span class="mainwp-red">[' + pSiteName + '] ERROR: Upload timed out - <a href="http://docs.mainwp.com/backup-failed-php-ini-settings/">Please check this help document for more information and possible fixes</a></span>'); |
| 948 |
} |
| 949 |
|
| 950 |
managebackups_backup_upload_file(pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 951 |
} else { |
| 952 |
appendToDiv(backtaskContentEl, ' [' + pSiteName + '] Upload stalled, trying to resume from last position.'); |
| 953 |
|
| 954 |
pData = mainwp_secure_data(pData); //Rescure |
| 955 |
|
| 956 |
jQuery.ajax({ |
| 957 |
url: ajaxurl, |
| 958 |
data: pData, |
| 959 |
method: 'POST', |
| 960 |
success: function (pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, pData, pUnique, pRemoteDestId) { |
| 961 |
return function (response) { |
| 962 |
if (response.error || !response.result) { |
| 963 |
managebackups_backup_upload_file_retry_fail(pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, response.error ? response.error : ''); |
| 964 |
} else { |
| 965 |
backupUploadRunning[pUnique] = false; |
| 966 |
|
| 967 |
let progressBar = jQuery('#managesite-upload-status-progress-' + pUnique); |
| 968 |
progressBar.progress('set progress', pSize); |
| 969 |
|
| 970 |
let obj = response.result; |
| 971 |
if (obj.error) { |
| 972 |
manageBackupsError = true; |
| 973 |
appendToDiv(backtaskContentEl, '<span class="mainwp-red">[' + pSiteName + '] ' + MainWP.I18n.t('Upload to %1 (%2) failed:', obj.title, obj.type) + ' ' + obj.error + '</span>'); |
| 974 |
} else { |
| 975 |
appendToDiv(backtaskContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Upload to %1 (%2) successful', obj.title, obj.type)); |
| 976 |
} |
| 977 |
|
| 978 |
managebackups_backup_upload_file(pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize); |
| 979 |
} |
| 980 |
} |
| 981 |
}(pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, pData, pUnique, pRemoteDestId), |
| 982 |
error: function (pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, pData, pUnique, pRemoteDestId) { |
| 983 |
return function () { |
| 984 |
managebackups_backup_upload_file_retry_fail(pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError); |
| 985 |
} |
| 986 |
}(pNewRemoteDestinations, pFile, pRegexFile, pSubfolder, pType, pSiteName, pSiteId, pSize, pData, pUnique, pRemoteDestId), |
| 987 |
dataType: 'json' |
| 988 |
}); |
| 989 |
} |
| 990 |
} else { |
| 991 |
//Try again in 5seconds |
| 992 |
setTimeout(function () { |
| 993 |
managebackups_backup_upload_file_retry_fail(pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError); |
| 994 |
}, 10000); |
| 995 |
} |
| 996 |
}, |
| 997 |
error: function () { |
| 998 |
//Try again in 10seconds |
| 999 |
setTimeout(function () { |
| 1000 |
managebackups_backup_upload_file_retry_fail(pData, pSiteId, pSiteName, pFile, pRegexFile, pSubfolder, pNewRemoteDestinations, pType, pSize, pUnique, pRemoteDestId, responseError); |
| 1001 |
}, 10000); |
| 1002 |
}, |
| 1003 |
dataType: 'json' |
| 1004 |
}); |
| 1005 |
}; |
| 1006 |
|
| 1007 |
managebackups_init = function () { |
| 1008 |
setVisible('#mainwp_managebackups_add_errors', false); |
| 1009 |
|
| 1010 |
jQuery('#mainwp_managebackups_add_errors').html(); |
| 1011 |
jQuery('#mainwp_managebackups_add_message').html(); |
| 1012 |
}; |
| 1013 |
|
| 1014 |
mainwp_managebackups_update = function () { |
| 1015 |
managebackups_init(); |
| 1016 |
|
| 1017 |
let errors = []; |
| 1018 |
if (jQuery('#mainwp_managebackups_add_name').val() == '') { |
| 1019 |
errors.push(MainWP.I18n.t('Please enter a valid name for your backup task')); |
| 1020 |
} |
| 1021 |
let selected_groups = []; |
| 1022 |
let selected_sites = []; |
| 1023 |
if (jQuery('input[name="select_by"]').val() == 'site') { |
| 1024 |
jQuery("input[name='selected_sites[]']:checked").each(function () { |
| 1025 |
selected_sites.push(jQuery(this).val()); |
| 1026 |
}); |
| 1027 |
if (selected_sites.length == 0) { |
| 1028 |
errors.push(MainWP.I18n.t('Please select websites or groups to add a backup task.')); |
| 1029 |
} |
| 1030 |
} else { |
| 1031 |
jQuery("input[name='selected_groups[]']:checked").each(function () { |
| 1032 |
selected_groups.push(jQuery(this).val()); |
| 1033 |
}); |
| 1034 |
if (selected_groups.length == 0) { |
| 1035 |
errors.push(MainWP.I18n.t('Please select websites or groups to add a backup task.')); |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
if (errors.length > 0) { |
| 1040 |
feedback('mainwp-message-zone', errors.join('<br />'), 'red'); |
| 1041 |
} else { |
| 1042 |
feedback('mainwp-message-zone', MainWP.I18n.t('Adding the task...'), 'green'); |
| 1043 |
|
| 1044 |
jQuery('#mainwp_managebackups_update').attr('disabled', 'true'); //disable button to add.. |
| 1045 |
|
| 1046 |
//let loadFilesBeforeZip = jQuery( '[name="mainwp_options_loadFilesBeforeZip"]:checked' ).val(); |
| 1047 |
let name = jQuery('#mainwp_managebackups_add_name').val(); |
| 1048 |
name = name.replace(/"/g, '"'); |
| 1049 |
let data = mainwp_secure_data({ |
| 1050 |
action: 'mainwp_updatebackup', |
| 1051 |
id: jQuery('#mainwp_managebackups_edit_id').val(), |
| 1052 |
name: name, |
| 1053 |
schedule: jQuery('#mainwp-backup-task-schedule').val(), |
| 1054 |
type: jQuery('#mainwp-backup-type').val(), |
| 1055 |
exclude: (jQuery('#mainwp-backup-type').val() == 'full' ? jQuery('#excluded_folders_list').val() : ''), |
| 1056 |
excludebackup: (jQuery('#mainwp-known-backup-locations').attr('checked') ? 1 : 0), |
| 1057 |
excludecache: (jQuery('#mainwp-known-cache-locations').attr('checked') ? 1 : 0), |
| 1058 |
excludenonwp: (jQuery('#mainwp-non-wordpress-folders').attr('checked') ? 1 : 0), |
| 1059 |
excludezip: (jQuery('#mainwp-zip-archives').attr('checked') ? 1 : 0), |
| 1060 |
'groups[]': selected_groups, |
| 1061 |
'sites[]': selected_sites, |
| 1062 |
subfolder: jQuery('#mainwp_managebackups_add_subfolder').val(), |
| 1063 |
filename: jQuery('#backup_filename').val(), |
| 1064 |
archiveFormat: jQuery('#mainwp_archiveFormat').val(), |
| 1065 |
maximumFileDescriptorsOverride: jQuery('#mainwp_options_maximumFileDescriptorsOverride_override').is(':checked') ? 1 : 0, |
| 1066 |
maximumFileDescriptorsAuto: (jQuery('#mainwp_maximumFileDescriptorsAuto').attr('checked') ? 1 : 0), |
| 1067 |
maximumFileDescriptors: jQuery('#mainwp_options_maximumFileDescriptors').val(), |
| 1068 |
//loadFilesBeforeZip: loadFilesBeforeZip |
| 1069 |
}); |
| 1070 |
jQuery.post(ajaxurl, data, function (response) { |
| 1071 |
managebackups_init(); |
| 1072 |
if (response.error != undefined) { |
| 1073 |
feedback('mainwp-message-zone', response.error, 'red'); |
| 1074 |
} else { |
| 1075 |
//Message the backup task was added |
| 1076 |
feedback('mainwp-message-zone', response.result, 'green'); |
| 1077 |
} |
| 1078 |
|
| 1079 |
jQuery('#mainwp_managebackups_update').prop("disabled", false); //Enable add button |
| 1080 |
}, 'json'); |
| 1081 |
} |
| 1082 |
}; |
| 1083 |
mainwp_managebackups_add = function () { |
| 1084 |
managebackups_init(); |
| 1085 |
|
| 1086 |
let errors = []; |
| 1087 |
if (jQuery('#mainwp_managebackups_add_name').val() == '') { |
| 1088 |
errors.push(MainWP.I18n.t('Please enter a valid name for your backup task')); |
| 1089 |
} |
| 1090 |
let selected_sites = []; |
| 1091 |
let selected_groups = []; |
| 1092 |
if (jQuery('input[name="select_by"]').val() == 'site') { |
| 1093 |
jQuery("input[name='selected_sites[]']:checked").each(function () { |
| 1094 |
selected_sites.push(jQuery(this).val()); |
| 1095 |
}); |
| 1096 |
if (selected_sites.length == 0) { |
| 1097 |
errors.push(MainWP.I18n.t('Please select websites or groups.')); |
| 1098 |
} |
| 1099 |
} else { |
| 1100 |
jQuery("input[name='selected_groups[]']:checked").each(function () { |
| 1101 |
selected_groups.push(jQuery(this).val()); |
| 1102 |
}); |
| 1103 |
if (selected_groups.length == 0) { |
| 1104 |
errors.push(MainWP.I18n.t('Please select websites or groups.')); |
| 1105 |
} |
| 1106 |
} |
| 1107 |
|
| 1108 |
|
| 1109 |
if (errors.length > 0) { |
| 1110 |
feedback('mainwp-message-zone', errors.join('<br />'), 'red'); |
| 1111 |
} else { |
| 1112 |
feedback('mainwp-message-zone', MainWP.I18n.t('Adding the task...'), 'green'); |
| 1113 |
|
| 1114 |
jQuery('#mainwp_managebackups_add').attr('disabled', 'true'); //disable button to add.. |
| 1115 |
|
| 1116 |
jQuery('#mainwp_managesites_add').attr('disabled', 'true'); //Disable add button |
| 1117 |
let loadFilesBeforeZip = jQuery('[name="mainwp_options_loadFilesBeforeZip"]:checked').val(); |
| 1118 |
let name = jQuery('#mainwp_managebackups_add_name').val(); |
| 1119 |
name = name.replace(/"/g, '"'); |
| 1120 |
let data = mainwp_secure_data({ |
| 1121 |
action: 'mainwp_addbackup', |
| 1122 |
name: name, |
| 1123 |
schedule: jQuery('#mainwp-backup-task-schedule').val(), |
| 1124 |
type: jQuery('#mainwp-backup-type').val(), |
| 1125 |
exclude: (jQuery('#mainwp-backup-type').val() == 'full' ? jQuery('#excluded_folders_list').val() : ''), |
| 1126 |
excludebackup: (jQuery('#mainwp-known-backup-locations').attr('checked') ? 1 : 0), |
| 1127 |
excludecache: (jQuery('#mainwp-known-cache-locations').attr('checked') ? 1 : 0), |
| 1128 |
excludenonwp: (jQuery('#mainwp-non-wordpress-folders').attr('checked') ? 1 : 0), |
| 1129 |
excludezip: (jQuery('#mainwp-zip-archives').attr('checked') ? 1 : 0), |
| 1130 |
'groups[]': selected_groups, |
| 1131 |
'sites[]': selected_sites, |
| 1132 |
subfolder: jQuery('#mainwp_managebackups_add_subfolder').val(), |
| 1133 |
filename: jQuery('#backup_filename').val(), |
| 1134 |
archiveFormat: jQuery('#mainwp_archiveFormat').val(), |
| 1135 |
maximumFileDescriptorsOverride: jQuery('#mainwp_options_maximumFileDescriptorsOverride_override').is(':checked') ? 1 : 0, |
| 1136 |
maximumFileDescriptorsAuto: (jQuery('#mainwp_maximumFileDescriptorsAuto').attr('checked') ? 1 : 0), |
| 1137 |
maximumFileDescriptors: jQuery('#mainwp_options_maximumFileDescriptors').val(), |
| 1138 |
loadFilesBeforeZip: loadFilesBeforeZip |
| 1139 |
}); |
| 1140 |
jQuery.post(ajaxurl, data, function (response) { |
| 1141 |
managebackups_init(); |
| 1142 |
if (response.error != undefined) { |
| 1143 |
feedback('mainwp-message-zone', response.error, 'red'); |
| 1144 |
} else { |
| 1145 |
//Message the backup task was added |
| 1146 |
location.href = 'admin.php?page=ManageBackups&a=1'; |
| 1147 |
feedback('mainwp-message-zone', response.result, 'green'); |
| 1148 |
} |
| 1149 |
jQuery('#mainwp_managebackups_add').prop("disabled", false); //Enable add button |
| 1150 |
}, 'json'); |
| 1151 |
} |
| 1152 |
}; |
| 1153 |
managebackups_remove = function (element) { |
| 1154 |
let id = jQuery(element).attr('task_id'); |
| 1155 |
managebackups_init(); |
| 1156 |
|
| 1157 |
let msg = MainWP.I18n.t('Are you sure you want to delete this backup task?'); |
| 1158 |
mainwp_confirm(msg, function () { |
| 1159 |
jQuery('#task-status-' + id).html(MainWP.I18n.t('Removing the task...')); |
| 1160 |
let data = mainwp_secure_data({ |
| 1161 |
action: 'mainwp_removebackup', |
| 1162 |
id: id |
| 1163 |
}); |
| 1164 |
jQuery.post(ajaxurl, data, function (pElement) { |
| 1165 |
return function (response) { |
| 1166 |
managebackups_init(); |
| 1167 |
let result = ''; |
| 1168 |
let error = ''; |
| 1169 |
if (response.error != undefined) { |
| 1170 |
error = response.error; |
| 1171 |
} else if (response.result == 'SUCCESS') { |
| 1172 |
result = MainWP.I18n.t('The task has been removed.'); |
| 1173 |
} else { |
| 1174 |
error = MainWP.I18n.t('An undefined error occurred.'); |
| 1175 |
} |
| 1176 |
|
| 1177 |
if (error != '') { |
| 1178 |
setHtml('#mainwp_managebackups', error); |
| 1179 |
} |
| 1180 |
if (result != '') { |
| 1181 |
setHtml('#mainwp_managebackups_add_message', result); |
| 1182 |
} |
| 1183 |
jQuery('#task-status-' + id).html(''); |
| 1184 |
if (error == '') { |
| 1185 |
jQuery(pElement).closest('tr').remove(); |
| 1186 |
} |
| 1187 |
} |
| 1188 |
}(element), 'json'); |
| 1189 |
}); |
| 1190 |
return false; |
| 1191 |
}; |
| 1192 |
managebackups_resume = function (element) { |
| 1193 |
let id = jQuery(element).attr('task_id'); |
| 1194 |
managebackups_init(); |
| 1195 |
|
| 1196 |
jQuery('#task-status-' + id).html(MainWP.I18n.t('Resuming the task...')); |
| 1197 |
let data = mainwp_secure_data({ |
| 1198 |
action: 'mainwp_resumebackup', |
| 1199 |
id: id |
| 1200 |
}); |
| 1201 |
jQuery.post(ajaxurl, data, function (pElement, pId) { |
| 1202 |
return function (response) { |
| 1203 |
managebackups_init(); |
| 1204 |
let result = ''; |
| 1205 |
let error = ''; |
| 1206 |
if (response.error != undefined) { |
| 1207 |
error = response.error; |
| 1208 |
} else if (response.result == 'SUCCESS') { |
| 1209 |
result = MainWP.I18n.t('The task has been resumed.'); |
| 1210 |
} else { |
| 1211 |
error = MainWP.I18n.t('An undefined error occurred.'); |
| 1212 |
} |
| 1213 |
|
| 1214 |
if (error != '') { |
| 1215 |
setHtml('#mainwp_managebackups', error); |
| 1216 |
} |
| 1217 |
if (result != '') { |
| 1218 |
setHtml('#mainwp_managebackups_add_message', result); |
| 1219 |
} |
| 1220 |
jQuery('#task-status-' + id).html(''); |
| 1221 |
|
| 1222 |
if (error == '') { |
| 1223 |
jQuery(pElement).after('<a href="#" task_id="' + pId + '" onClick="return managebackups_pause(this)">' + MainWP.I18n.t('Pause') + '</a>'); |
| 1224 |
jQuery(pElement).remove(); |
| 1225 |
} |
| 1226 |
} |
| 1227 |
}(element, id), 'json'); |
| 1228 |
|
| 1229 |
return false; |
| 1230 |
}; |
| 1231 |
managebackups_pause = function (element) { |
| 1232 |
let id = jQuery(element).attr('task_id'); |
| 1233 |
managebackups_init(); |
| 1234 |
|
| 1235 |
jQuery('#task-status-' + id).html(MainWP.I18n.t('Pausing the task...')); |
| 1236 |
let data = mainwp_secure_data({ |
| 1237 |
action: 'mainwp_pausebackup', |
| 1238 |
id: id |
| 1239 |
}); |
| 1240 |
jQuery.post(ajaxurl, data, function (pElement, pId) { |
| 1241 |
return function (response) { |
| 1242 |
managebackups_init(); |
| 1243 |
let result = ''; |
| 1244 |
let error = ''; |
| 1245 |
if (response.error != undefined) { |
| 1246 |
error = response.error; |
| 1247 |
} else if (response.result == 'SUCCESS') { |
| 1248 |
result = MainWP.I18n.t('The task has been paused.'); |
| 1249 |
} else { |
| 1250 |
error = MainWP.I18n.t('An undefined error occurred.'); |
| 1251 |
} |
| 1252 |
|
| 1253 |
if (error != '') { |
| 1254 |
setHtml('#mainwp_managebackups', error); |
| 1255 |
} |
| 1256 |
if (result != '') { |
| 1257 |
setHtml('#mainwp_managebackups_add_message', result); |
| 1258 |
} |
| 1259 |
jQuery('#task-status-' + id).html(''); |
| 1260 |
if (error == '') { |
| 1261 |
jQuery(pElement).after('<a href="#" task_id="' + pId + '" onClick="return managebackups_resume(this)">' + MainWP.I18n.t('Resume') + '</a>'); |
| 1262 |
jQuery(pElement).remove(); |
| 1263 |
} |
| 1264 |
} |
| 1265 |
}(element, id), 'json'); |
| 1266 |
|
| 1267 |
return false; |
| 1268 |
}; |
| 1269 |
|
| 1270 |
|
| 1271 |
jQuery(document).on('click', '#updatesoverview-backup-ignore', function () { |
| 1272 |
if (updatesoverviewContinueAfterBackup != undefined) { |
| 1273 |
mainwpPopup('#updatesoverview-backup-box').close(); |
| 1274 |
updatesoverviewContinueAfterBackup(); |
| 1275 |
updatesoverviewContinueAfterBackup = undefined; |
| 1276 |
} |
| 1277 |
}); |
| 1278 |
|
| 1279 |
let updatesoverviewShowBusyFunction; |
| 1280 |
let updatesoverviewShowBusyTimeout; |
| 1281 |
mainwp_updatesoverview_checkBackups = function (sitesToUpdate, siteNames) { |
| 1282 |
if (mainwpParams['disable_checkBackupBeforeUpgrade']) { |
| 1283 |
if (updatesoverviewContinueAfterBackup != undefined) { |
| 1284 |
updatesoverviewContinueAfterBackup(); |
| 1285 |
} |
| 1286 |
return false; |
| 1287 |
} |
| 1288 |
|
| 1289 |
updatesoverviewShowBusyFunction = function () { |
| 1290 |
|
| 1291 |
let output = MainWP.I18n.t('Checking if a backup is required for the selected updates...'); |
| 1292 |
mainwpPopup('#updatesoverview-backup-box').getContentEl().html(output); |
| 1293 |
jQuery('#updatesoverview-backup-all').hide(); |
| 1294 |
jQuery('#updatesoverview-backup-ignore').hide(); |
| 1295 |
|
| 1296 |
mainwpPopup('#updatesoverview-backup-box').init({ |
| 1297 |
title: MainWP.I18n.t("Checking backup settings..."), callback: function () { |
| 1298 |
window.location.href = location.href |
| 1299 |
} |
| 1300 |
}); |
| 1301 |
}; |
| 1302 |
|
| 1303 |
updatesoverviewShowBusyTimeout = setTimeout(updatesoverviewShowBusyFunction, 300); |
| 1304 |
|
| 1305 |
//Step 2: Check if backups are ok. |
| 1306 |
let data = mainwp_secure_data({ |
| 1307 |
action: 'mainwp_checkbackups', |
| 1308 |
sites: sitesToUpdate |
| 1309 |
}); |
| 1310 |
|
| 1311 |
jQuery.ajax({ |
| 1312 |
type: "POST", |
| 1313 |
url: ajaxurl, |
| 1314 |
data: data, |
| 1315 |
success: function (pSiteNames) { |
| 1316 |
return function (response) { |
| 1317 |
clearTimeout(updatesoverviewShowBusyTimeout); |
| 1318 |
|
| 1319 |
mainwpPopup('#updatesoverview-backup-box').close(); |
| 1320 |
|
| 1321 |
let siteFeedback = undefined; |
| 1322 |
|
| 1323 |
if (response['result'] && response['result']['sites'] != undefined) { |
| 1324 |
siteFeedback = []; |
| 1325 |
for (let currSiteId in response['result']['sites']) { |
| 1326 |
if (!response['result']['sites'][currSiteId]) { |
| 1327 |
siteFeedback.push(currSiteId); |
| 1328 |
} |
| 1329 |
} |
| 1330 |
if (siteFeedback.length == 0) |
| 1331 |
siteFeedback = undefined; |
| 1332 |
} |
| 1333 |
|
| 1334 |
if (siteFeedback != undefined) { |
| 1335 |
let backupPrimary = ''; |
| 1336 |
if (response['result']['primary_backup'] && response['result']['primary_backup'] != undefined) |
| 1337 |
backupPrimary = response['result']['primary_backup']; |
| 1338 |
|
| 1339 |
if (backupPrimary == '') { |
| 1340 |
jQuery('#updatesoverview-backup-all').show(); |
| 1341 |
jQuery('#updatesoverview-backup-ignore').show(); |
| 1342 |
} else { |
| 1343 |
let backupLink = mainwp_get_primaryBackup_link(backupPrimary); |
| 1344 |
jQuery('#updatesoverview-backup-now').attr('href', backupLink).show(); |
| 1345 |
jQuery('#updatesoverview-backup-ignore').val(MainWP.I18n.t('Proceed with Updates')).show(); |
| 1346 |
} |
| 1347 |
|
| 1348 |
let output = '<span class="mainwp-red">' + MainWP.I18n.t('A full backup has not been taken in the last days for the following sites:') + '</span><br /><br />'; |
| 1349 |
|
| 1350 |
if (backupPrimary == '') { // default backup feature |
| 1351 |
for (let id of siteFeedback) { |
| 1352 |
output += '<span class="updatesoverview-backup-site" siteid="' + id + '">' + decodeURIComponent(pSiteNames[id]) + '</span><br />'; |
| 1353 |
} |
| 1354 |
} else { |
| 1355 |
for (let id of siteFeedback) { |
| 1356 |
output += '<span>' + decodeURIComponent(pSiteNames[id]) + '</span><br />'; |
| 1357 |
} |
| 1358 |
} |
| 1359 |
|
| 1360 |
mainwpPopup('#updatesoverview-backup-box').getContentEl().html(output); |
| 1361 |
|
| 1362 |
mainwpPopup('#updatesoverview-backup-box').init({ |
| 1363 |
title: MainWP.I18n.t("Full backup required!"), callback: function () { |
| 1364 |
if (updatesoverviewContinueAfterBackup != undefined) { |
| 1365 |
updatesoverviewContinueAfterBackup = undefined; |
| 1366 |
} |
| 1367 |
window.location.href = location.href |
| 1368 |
} |
| 1369 |
}); |
| 1370 |
return false; |
| 1371 |
} |
| 1372 |
|
| 1373 |
if (updatesoverviewContinueAfterBackup != undefined) { |
| 1374 |
updatesoverviewContinueAfterBackup(); |
| 1375 |
} |
| 1376 |
} |
| 1377 |
}(siteNames), |
| 1378 |
error: function () { |
| 1379 |
|
| 1380 |
mainwpPopup('#updatesoverview-backup-box').close(true); |
| 1381 |
}, |
| 1382 |
dataType: 'json' |
| 1383 |
}); |
| 1384 |
|
| 1385 |
return false; |
| 1386 |
}; |
| 1387 |
|
| 1388 |
|
| 1389 |
jQuery(document).on('click', '#updatesoverview-backupnow-close', function () { |
| 1390 |
if (jQuery(this).prop('cancel') == '1') { |
| 1391 |
updatesoverviewBackupSites = []; |
| 1392 |
updatesoverviewBackupError = false; |
| 1393 |
updatesoverviewBackupDownloadRunning = false; |
| 1394 |
mainwpPopup('#updatesoverview-backup-box').close(true); |
| 1395 |
} else { |
| 1396 |
mainwpPopup('#updatesoverview-backup-box').close(); |
| 1397 |
if (updatesoverviewContinueAfterBackup != undefined) |
| 1398 |
updatesoverviewContinueAfterBackup(); |
| 1399 |
} |
| 1400 |
}); |
| 1401 |
jQuery(document).on('click', '#updatesoverview-backup-all', function () { |
| 1402 |
|
| 1403 |
// change action buttons |
| 1404 |
mainwpPopup('#updatesoverview-backup-box').setActionButtons('<input id="updatesoverview-backupnow-close" type="button" name="Ignore" value="' + MainWP.I18n.t('Cancel') + '" class="button"/>'); |
| 1405 |
mainwpPopup('#updatesoverview-backup-box').init({ |
| 1406 |
title: MainWP.I18n.t("Full backup"), callback: function () { |
| 1407 |
updatesoverviewContinueAfterBackup = undefined; |
| 1408 |
window.location.href = location.href |
| 1409 |
} |
| 1410 |
}); |
| 1411 |
|
| 1412 |
let sitesToBackup = jQuery('.updatesoverview-backup-site'); |
| 1413 |
updatesoverviewBackupSites = []; |
| 1414 |
for (let id of sitesToBackup) { |
| 1415 |
let currentSite = []; |
| 1416 |
currentSite['id'] = jQuery(id).attr('siteid'); |
| 1417 |
currentSite['name'] = jQuery(id).text(); |
| 1418 |
updatesoverviewBackupSites.push(currentSite); |
| 1419 |
} |
| 1420 |
updatesoverview_backup_run(); |
| 1421 |
}); |
| 1422 |
|
| 1423 |
let updatesoverviewBackupSites; |
| 1424 |
let updatesoverviewBackupError; |
| 1425 |
let updatesoverviewBackupDownloadRunning; |
| 1426 |
|
| 1427 |
updatesoverview_backup_run = function () { |
| 1428 |
mainwpPopup('#updatesoverview-backup-box').getContentEl().html(dateToHMS(new Date()) + ' ' + MainWP.I18n.t('Starting required backup(s)...')); |
| 1429 |
jQuery('#updatesoverview-backupnow-close').prop('value', MainWP.I18n.t('Cancel')); |
| 1430 |
jQuery('#updatesoverview-backupnow-close').prop('cancel', '1'); |
| 1431 |
updatesoverview_backup_run_next(); |
| 1432 |
}; |
| 1433 |
|
| 1434 |
updatesoverview_backup_run_next = function () { |
| 1435 |
let backupContentEl = mainwpPopup('#updatesoverview-backup-box').getContentEl(); |
| 1436 |
if (updatesoverviewBackupSites.length == 0) { |
| 1437 |
appendToDiv(backupContentEl, MainWP.I18n.t('Required backup(s) completed') + (updatesoverviewBackupError ? ' <span class="mainwp-red">' + MainWP.I18n.t('with errors') + '</span>' : '') + '.'); |
| 1438 |
|
| 1439 |
jQuery('#updatesoverview-backupnow-close').prop('cancel', '0'); |
| 1440 |
if (updatesoverviewBackupError) { |
| 1441 |
jQuery('#updatesoverview-backupnow-close').prop('value', MainWP.I18n.t('Continue update anyway')); |
| 1442 |
} else { |
| 1443 |
jQuery('#updatesoverview-backupnow-close').prop('value', MainWP.I18n.t('Continue update')); |
| 1444 |
} |
| 1445 |
return; |
| 1446 |
} |
| 1447 |
|
| 1448 |
let siteName = updatesoverviewBackupSites[0]['name']; |
| 1449 |
appendToDiv(backupContentEl, '[' + siteName + '] ' + MainWP.I18n.t('Creating backup file...')); |
| 1450 |
|
| 1451 |
let siteId = updatesoverviewBackupSites[0]['id']; |
| 1452 |
updatesoverviewBackupSites.shift(); |
| 1453 |
let data = mainwp_secure_data({ |
| 1454 |
action: 'mainwp_backup_run_site', |
| 1455 |
site_id: siteId |
| 1456 |
}); |
| 1457 |
|
| 1458 |
jQuery.post(ajaxurl, data, function (pSiteId, pSiteName) { |
| 1459 |
return function (response) { |
| 1460 |
if (response.error) { |
| 1461 |
appendToDiv(backupContentEl, '[' + pSiteName + '] <span class="mainwp-red">ERROR: ' + getErrorMessage(response.error) + '</span>'); |
| 1462 |
updatesoverviewBackupError = true; |
| 1463 |
updatesoverview_backup_run_next(); |
| 1464 |
} else { |
| 1465 |
appendToDiv(backupContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Backup file created successfully!')); |
| 1466 |
|
| 1467 |
updatesoverview_backupnow_download_file(pSiteId, pSiteName, response.result.type, response.result.url, response.result.local, response.result.regexfile, response.result.size, response.result.subfolder); |
| 1468 |
} |
| 1469 |
|
| 1470 |
} |
| 1471 |
}(siteId, siteName), 'json'); |
| 1472 |
}; |
| 1473 |
updatesoverview_backupnow_download_file = function (pSiteId, pSiteName, type, url, file, regexfile, size, subfolder) { |
| 1474 |
let backupContentEl = mainwpPopup('#updatesoverview-backup-box').getContentEl(); |
| 1475 |
appendToDiv(backupContentEl, '[' + pSiteName + '] Downloading the file... <div id="updatesoverview-backupnow-status-progress" siteId="' + pSiteId + '" class="ui green progress"><div class="bar"><div class="progress"></div></div>'); |
| 1476 |
jQuery('#updatesoverview-backupnow-status-progress[siteId="' + pSiteId + '"]').progress({ value: 0, total: size }); |
| 1477 |
let interVal = setInterval(function () { |
| 1478 |
let data = mainwp_secure_data({ |
| 1479 |
action: 'mainwp_backup_getfilesize', |
| 1480 |
local: file |
| 1481 |
}); |
| 1482 |
jQuery.post(ajaxurl, data, function (pSiteId) { |
| 1483 |
return function (response) { |
| 1484 |
if (response.error) |
| 1485 |
return; |
| 1486 |
|
| 1487 |
if (updatesoverviewBackupDownloadRunning) { |
| 1488 |
let progressBar = jQuery('#updatesoverview-backupnow-status-progress[siteId="' + pSiteId + '"]'); |
| 1489 |
if (progressBar.progress('get value') < progressBar.progress('get total')) { |
| 1490 |
progressBar.progress('set progress', response.result); |
| 1491 |
} |
| 1492 |
} |
| 1493 |
} |
| 1494 |
}(pSiteId), 'json'); |
| 1495 |
}, 500); |
| 1496 |
|
| 1497 |
let data = mainwp_secure_data({ |
| 1498 |
action: 'mainwp_backup_download_file', |
| 1499 |
site_id: pSiteId, |
| 1500 |
type: type, |
| 1501 |
url: url, |
| 1502 |
local: file |
| 1503 |
}); |
| 1504 |
updatesoverviewBackupDownloadRunning = true; |
| 1505 |
jQuery.post(ajaxurl, data, function (pFile, pRegexFile, pSubfolder, pSize, pType, pInterVal, pSiteName, pSiteId, pUrl) { |
| 1506 |
return function (response) { |
| 1507 |
updatesoverviewBackupDownloadRunning = false; |
| 1508 |
clearInterval(pInterVal); |
| 1509 |
|
| 1510 |
if (response.error) { |
| 1511 |
appendToDiv(backupContentEl, '[' + pSiteName + '] <span class="mainwp-red">ERROR: ' + getErrorMessage(response.error) + '</span>'); |
| 1512 |
appendToDiv(backupContentEl, '[' + pSiteName + '] <span class="mainwp-red">' + MainWP.I18n.t('Backup failed!') + '</span>'); |
| 1513 |
|
| 1514 |
updatesoverviewBackupError = true; |
| 1515 |
updatesoverview_backup_run_next(); |
| 1516 |
return; |
| 1517 |
} |
| 1518 |
|
| 1519 |
jQuery('#updatesoverview-backupnow-status-progress[siteId="' + pSiteId + '"]').progress('set progress', pSize); |
| 1520 |
appendToDiv(backupContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Download from the child site completed.')); |
| 1521 |
appendToDiv(backupContentEl, '[' + pSiteName + '] ' + MainWP.I18n.t('Backup completed.')); |
| 1522 |
|
| 1523 |
let newData = mainwp_secure_data({ |
| 1524 |
action: 'mainwp_backup_delete_file', |
| 1525 |
site_id: pSiteId, |
| 1526 |
file: pUrl |
| 1527 |
}); |
| 1528 |
jQuery.post(ajaxurl, newData, function () { }, 'json'); |
| 1529 |
|
| 1530 |
updatesoverview_backup_run_next(); |
| 1531 |
} |
| 1532 |
}(file, regexfile, subfolder, size, type, interVal, pSiteName, pSiteId, url), 'json'); |
| 1533 |
}; |
| 1534 |
|