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