transferito.js
3198 lines
| 1 | (function($) { |
| 2 | |
| 3 | $(document).ready(function(){ |
| 4 | |
| 5 | function Transferito() { |
| 6 | this.mappedStatus = null; |
| 7 | this.validated = { |
| 8 | ftp: false, |
| 9 | database: false |
| 10 | }; |
| 11 | this.ftpPath = ''; |
| 12 | this.localUploadComplete = { |
| 13 | database: false, |
| 14 | codebase: false |
| 15 | }; |
| 16 | this.transferMethodOptions = { |
| 17 | method: '', |
| 18 | cPanelAllowed: false, |
| 19 | }; |
| 20 | this.currentStatus = 'backup.completed'; |
| 21 | this.backupSize = 0; |
| 22 | this.backupPercentage = { |
| 23 | codebase: 0, |
| 24 | codebaseIncrement: 0, |
| 25 | database: 0, |
| 26 | databaseIncrement: 0, |
| 27 | }; |
| 28 | this.utilities = { |
| 29 | tempMigrationDetails: { |
| 30 | key: '', |
| 31 | details: {} |
| 32 | }, |
| 33 | selector: $('#transferitoTemplate'), |
| 34 | modalSelector: $('#transferitoModalTemplate'), |
| 35 | migrationSteps: { |
| 36 | amount: 0, |
| 37 | currentStep: -1, |
| 38 | stepSplit: 0 |
| 39 | }, |
| 40 | removeTrailingSlashes: function(url) { |
| 41 | return url.replace(/\/+$/, ''); |
| 42 | }, |
| 43 | removeProtocols: function(host) { |
| 44 | return host.replace(/sftp:\/\/|ftp:\/\//, ''); |
| 45 | }, |
| 46 | getFormValues: function(object, item) { |
| 47 | if (item.name.indexOf('[]') !== -1) { |
| 48 | var key = item.name.replace('[]', ''); |
| 49 | var value = item.value; |
| 50 | (!object[key]) ? object[key] = [value] : object[key].push(value); |
| 51 | } else { |
| 52 | object[item.name] = (item.value === 'on') ? true : item.value; |
| 53 | } |
| 54 | return object; |
| 55 | }, |
| 56 | validateFormFields: function() { |
| 57 | var errorCount = 0; |
| 58 | $('.transferito__field-required:visible').each(function (index, formElement) { |
| 59 | var formSelector = $(formElement); |
| 60 | |
| 61 | /** |
| 62 | * If the field is empty |
| 63 | * Show the error |
| 64 | */ |
| 65 | if (!formSelector.val()) { |
| 66 | errorCount += 1; |
| 67 | } |
| 68 | }); |
| 69 | return errorCount === 0; |
| 70 | }, |
| 71 | validateURL: function() { |
| 72 | var cleanedURL = this.selector.find('#domain').val().trim().replace(/\/$/, ""); |
| 73 | var domain = cleanedURL.split('//'); |
| 74 | return domain.length === 2 && ['http:', 'https:'].indexOf(domain[0]) !== -1; |
| 75 | }, |
| 76 | changeTemplate: function(action, nonce, extraData = {}, clearTemplate = false, callback) { |
| 77 | var self = this; |
| 78 | var data = { |
| 79 | action: action, |
| 80 | actionKey: nonce, |
| 81 | data: extraData |
| 82 | }; |
| 83 | |
| 84 | if (clearTemplate) { |
| 85 | this.setTemplate(''); |
| 86 | } |
| 87 | |
| 88 | var templateChange = $.post(ajaxurl, data, function(response) { |
| 89 | var theResponse = response.data; |
| 90 | var hasAdditionalData = theResponse.hasOwnProperty('additionalData'); |
| 91 | var template = theResponse.hasOwnProperty('htmlTemplate') |
| 92 | ? theResponse.htmlTemplate |
| 93 | : ''; |
| 94 | self.setTemplate(template); |
| 95 | |
| 96 | /** |
| 97 | * |
| 98 | */ |
| 99 | if (callback) { |
| 100 | callback(theResponse); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Show the legend message |
| 105 | */ |
| 106 | if (hasAdditionalData) { |
| 107 | self.displayHeaderLegend(null, theResponse.additionalData.mainMessage); |
| 108 | } |
| 109 | |
| 110 | }); |
| 111 | templateChange.fail(function(data) { |
| 112 | self.setTemplate('Something has gone wrong - Please refresh the page and try again'); |
| 113 | }); |
| 114 | }, |
| 115 | setTemplate: function(template, elementSelector = false, fadeInTime = 1500, customContent = false) { |
| 116 | /** |
| 117 | * If the selector isn't present |
| 118 | * Default to replace the whole screen |
| 119 | */ |
| 120 | if (!elementSelector) { |
| 121 | this.selector.html(template).fadeIn(1500); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Replace the HTML in the specified selector |
| 126 | */ |
| 127 | if (elementSelector) { |
| 128 | elementSelector.html(template).fadeIn(fadeInTime); |
| 129 | |
| 130 | /** |
| 131 | * If the customContent argument has been provided |
| 132 | * Update the modal content & the relevant selector |
| 133 | */ |
| 134 | if (customContent) { |
| 135 | elementSelector.find(customContent.selector).html(customContent.content); |
| 136 | } |
| 137 | } |
| 138 | }, |
| 139 | loadingOnlyHTML: function() { |
| 140 | var template = '<div class="transferito__one-column-container transferito__one-column-container--no-width transferito-loader">'; |
| 141 | template += '<div class="transferito-loader__icon transferito-loader__icon--no-bottom-margin"></div>'; |
| 142 | template += '</div>'; |
| 143 | return template; |
| 144 | }, |
| 145 | loadingScreenHTML: function(message, subMessage) { |
| 146 | var template = '<div class="transferito__one-column">'; |
| 147 | template += '<div class="transferito__one-column-container transferito-loader">'; |
| 148 | template += '<div class="transferito-loader__icon"></div>'; |
| 149 | template += '<div class="transferito-loader__text transferito-text__p1--semi-bold">'; |
| 150 | template += message; |
| 151 | template += '</div>'; |
| 152 | |
| 153 | if (subMessage) { |
| 154 | template += '<div class="transferito-loader__text transferito-text__p1--regular">'; |
| 155 | template += subMessage; |
| 156 | template += '</div>'; |
| 157 | } |
| 158 | |
| 159 | template += '</div>'; |
| 160 | template += '</div>'; |
| 161 | return template; |
| 162 | }, |
| 163 | showLoadingScreen: function(message = 'Loading...', subMessage) { |
| 164 | this.selector.html(this.loadingScreenHTML(message, subMessage)); |
| 165 | }, |
| 166 | buildPayload: function () { |
| 167 | var self = this; |
| 168 | var formElements = []; |
| 169 | |
| 170 | /** |
| 171 | * Create array of form elements that aren't hidden |
| 172 | * Include check for hidden form elements |
| 173 | */ |
| 174 | $('.transferito-form-element').each(function(index, formElement) { |
| 175 | var formSelector = $(formElement), |
| 176 | isVisible = formSelector.closest('table').css('display'); |
| 177 | |
| 178 | if (isVisible === 'table' || isVisible === undefined) { |
| 179 | formElements.push(formElement); |
| 180 | } |
| 181 | }); |
| 182 | |
| 183 | /** |
| 184 | * Turn array of form elements |
| 185 | * Into object with input names as properties & input values as value |
| 186 | */ |
| 187 | return $(formElements) |
| 188 | .serializeArray() |
| 189 | .reduce(function(object, item) { |
| 190 | return self.getFormValues(object, item) |
| 191 | }, {}); |
| 192 | }, |
| 193 | filterPayload: function(payload, allowedProperties = []) { |
| 194 | /** |
| 195 | * Check if there are keys to filter |
| 196 | */ |
| 197 | if (allowedProperties.length === 0) { |
| 198 | return payload; |
| 199 | } |
| 200 | |
| 201 | for (var property in payload) { |
| 202 | if (payload.hasOwnProperty(property) && !allowedProperties.includes(property)) { |
| 203 | delete payload[property]; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return payload; |
| 208 | }, |
| 209 | setTransferMethodOptions: function (method, cPanelAllowed) { |
| 210 | transferito.transferMethodOptions.method = method; |
| 211 | transferito.transferMethodOptions.cPanelAllowed = cPanelAllowed; |
| 212 | }, |
| 213 | checkMigrationProgressSteps: function () { |
| 214 | this.migrationSteps.amount = $('.transferito-migration-progress__step').not(':hidden').length - 1; |
| 215 | this.migrationSteps.stepSplit = Math.round(100 / this.migrationSteps.amount); |
| 216 | }, |
| 217 | updateCurrentMigrationProgressStep: function() { |
| 218 | this.migrationSteps.currentStep = this.migrationSteps.currentStep + 1; |
| 219 | this.updateMigrationOverviewProgressPercentage( |
| 220 | this.migrationSteps.currentStep * this.migrationSteps.stepSplit |
| 221 | ); |
| 222 | }, |
| 223 | calculateOverviewProgressPercentage: function (percentage) { |
| 224 | var percentageAsDecimal = (percentage / 100); |
| 225 | var stepPercentage = Math.round(this.migrationSteps.stepSplit * percentageAsDecimal); |
| 226 | var currentOverviewPercentage = this.migrationSteps.currentStep * this.migrationSteps.stepSplit; |
| 227 | var total = currentOverviewPercentage + stepPercentage; |
| 228 | |
| 229 | return (total > 99) ? 100 : total; |
| 230 | }, |
| 231 | updateMigrationOverviewProgressPercentage: function(percentage) { |
| 232 | $('#progressOverviewPercentage').html(percentage); |
| 233 | $('.transferito-migration-progress__bar--value').css('width', percentage + '%'); |
| 234 | }, |
| 235 | updateProgressStep: function(status, selector, statusChanged) { |
| 236 | /** |
| 237 | * If the status doesn't equal one of the allowed |
| 238 | */ |
| 239 | if (status !== 'completed' && status !== 'active') { |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | var elementID = selector.attr('id'); |
| 244 | var hiddenElementClass = 'transferito__hide-element'; |
| 245 | var disabledStepClass = 'transferito-migration-progress__disabled-text'; |
| 246 | |
| 247 | selector.removeClass(disabledStepClass); |
| 248 | |
| 249 | /** |
| 250 | * If it's active only add the class |
| 251 | */ |
| 252 | if (status === 'active') { |
| 253 | /** |
| 254 | * Move the counter to the next migration step when a step has been initialised |
| 255 | */ |
| 256 | if (statusChanged) { |
| 257 | /** |
| 258 | * Log event |
| 259 | */ |
| 260 | this.logEvent('migrationStatus', { |
| 261 | status: elementID |
| 262 | }); |
| 263 | |
| 264 | this.updateCurrentMigrationProgressStep(); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Change the static image to a spinner on this step |
| 269 | */ |
| 270 | if (elementID === 'progress__finalizingWPInstall') { |
| 271 | selector |
| 272 | .find('.transferito-migration-progress__step-percent > .transferito-migration-progress__final-step') |
| 273 | .removeClass('transferito-migration-progress__final-step--static') |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * If it's completed remove the active and add the completed |
| 279 | */ |
| 280 | if (status === 'completed') { |
| 281 | /** |
| 282 | * Update the overview % to 100% |
| 283 | */ |
| 284 | if (elementID === 'progress__finalizingWPInstall') { |
| 285 | this.updateMigrationOverviewProgressPercentage(100); |
| 286 | } |
| 287 | |
| 288 | selector.find('.transferito-migration-progress__step-icon').removeClass(hiddenElementClass); |
| 289 | selector.find('.transferito-migration-progress__step-percent').addClass(hiddenElementClass); |
| 290 | } |
| 291 | }, |
| 292 | updateProgressPercentage: function(percentage, selector) { |
| 293 | /** |
| 294 | * If percentage is null |
| 295 | */ |
| 296 | if (!percentage) { |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Calc the overview moving percentage |
| 302 | * Then update it |
| 303 | */ |
| 304 | this.updateMigrationOverviewProgressPercentage( |
| 305 | this.calculateOverviewProgressPercentage(percentage) |
| 306 | ); |
| 307 | |
| 308 | /** |
| 309 | * Update the percentage for the progress bar |
| 310 | */ |
| 311 | selector.html(percentage); |
| 312 | }, |
| 313 | hideProgressPercentage: function(selector) { |
| 314 | /** |
| 315 | * Update the percentage for the progress bar |
| 316 | */ |
| 317 | selector.closest('.transferito-migration-progress__step-percent').addClass('transferito__hide-element'); |
| 318 | }, |
| 319 | round: function(value, precision) { |
| 320 | var multiplier = Math.pow(10, precision || 0); |
| 321 | return Math.round(value * multiplier) / multiplier; |
| 322 | }, |
| 323 | saveBackupPercentage: function(key, options) { |
| 324 | transferito.backupPercentage[key] = options.percentage; |
| 325 | transferito.backupPercentage[key + 'Increment'] = this.round(options.increment); |
| 326 | }, |
| 327 | updateTheBackupProgress: function(type) { |
| 328 | transferito.backupSize += transferito.backupPercentage[type + 'Increment']; |
| 329 | var archiveSize = this.round(transferito.backupSize); |
| 330 | var usedArchiveSize = archiveSize > 99 ? 99 : archiveSize; |
| 331 | this.updateProgressPercentage(usedArchiveSize, $('#backupInstallationProgressPercentage')); |
| 332 | }, |
| 333 | updateTheExecBackupProgress: function(amount, initialAmount) { |
| 334 | /** |
| 335 | * If the amount is truthy |
| 336 | * & it is greater than the initialAmount then & only then my friend should we proceed |
| 337 | */ |
| 338 | if (amount && amount > initialAmount) { |
| 339 | /** |
| 340 | * If the amount is greater than the backup size |
| 341 | * Then we continue - |
| 342 | * The percentage should never decrease |
| 343 | */ |
| 344 | if (amount > transferito.backupSize) { |
| 345 | transferito.backupSize = amount; |
| 346 | var archiveSize = this.round(transferito.backupSize); |
| 347 | var usedArchiveSize = archiveSize > 99 ? 99 : archiveSize; |
| 348 | this.updateProgressPercentage(usedArchiveSize, $('#backupInstallationProgressPercentage')); |
| 349 | } |
| 350 | } |
| 351 | }, |
| 352 | changeProgressStep: function (migrationStatus, responseData, statusChanged) { |
| 353 | /** |
| 354 | * Move the status of the step |
| 355 | */ |
| 356 | this.updateProgressStep(migrationStatus.status, migrationStatus.selector, statusChanged); |
| 357 | |
| 358 | /** |
| 359 | * Check that the progress property exists and that the response data is there |
| 360 | */ |
| 361 | if (migrationStatus.hasOwnProperty('progress') && responseData) { |
| 362 | var percentage = responseData.hasOwnProperty('metadata') && responseData.metadata && responseData.metadata.hasOwnProperty('value') |
| 363 | ? responseData.metadata.value |
| 364 | : null; |
| 365 | |
| 366 | /** |
| 367 | * Update the progress |
| 368 | */ |
| 369 | this.updateProgressPercentage(percentage, migrationStatus.progressSelector); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * If progress completion property exists |
| 374 | */ |
| 375 | if (migrationStatus.hasOwnProperty('progressComplete')) { |
| 376 | this.hideProgressPercentage(migrationStatus.progressSelector); |
| 377 | } |
| 378 | }, |
| 379 | displayModal: function(modalName, customModalContent) { |
| 380 | /** |
| 381 | * Log event |
| 382 | */ |
| 383 | this.logEvent('modalOpened', { |
| 384 | modalName: modalName |
| 385 | }); |
| 386 | |
| 387 | /** |
| 388 | * Get the HTML for the modal |
| 389 | */ |
| 390 | var modalHTML = $('#' + modalName).html(); |
| 391 | |
| 392 | /** |
| 393 | * Remove the style attribute |
| 394 | */ |
| 395 | this.modalSelector.removeAttr('style'); |
| 396 | |
| 397 | /** |
| 398 | * Remove the hidden element |
| 399 | */ |
| 400 | this.modalSelector.removeClass('transferito__hide-element'); |
| 401 | |
| 402 | /** |
| 403 | * Move the HTML into the modal DIV |
| 404 | */ |
| 405 | this.setTemplate(modalHTML, this.modalSelector, 500, customModalContent); |
| 406 | }, |
| 407 | displayFormGuideModal: function(modalName, relatedGuideName) { |
| 408 | this.displayModal(modalName); |
| 409 | $('#hostingGuideName').val(relatedGuideName); |
| 410 | }, |
| 411 | closeModal: function() { |
| 412 | /** |
| 413 | * Modal Selector |
| 414 | */ |
| 415 | var modalTemplate = $('#transferitoModalTemplate'); |
| 416 | |
| 417 | /** |
| 418 | * Remove the hidden element |
| 419 | */ |
| 420 | modalTemplate.addClass('transferito__hide-element'); |
| 421 | |
| 422 | /** |
| 423 | * Add the loading smaller loading indicator |
| 424 | */ |
| 425 | this.setTemplate('', modalTemplate); |
| 426 | |
| 427 | /** |
| 428 | * Remove the style attribute |
| 429 | */ |
| 430 | modalTemplate.removeAttr('style'); |
| 431 | }, |
| 432 | displayMigrationProgressFailure: function (selector, message) { |
| 433 | |
| 434 | var elementID = selector.attr('id'); |
| 435 | var hiddenElementClass = 'transferito__hide-element'; |
| 436 | |
| 437 | /** |
| 438 | * Change the title |
| 439 | */ |
| 440 | $('#migrationProgressTitle').html('Migration Failed'); |
| 441 | |
| 442 | /** |
| 443 | * Change the colour to red |
| 444 | */ |
| 445 | $('#overviewProgressPercentageBar').addClass('transferito-migration-progress__bar--red'); |
| 446 | |
| 447 | /** |
| 448 | * Add the left align class |
| 449 | */ |
| 450 | selector.addClass('transferito-migration-progress__step--left-align'); |
| 451 | |
| 452 | /** |
| 453 | * Display the main icon |
| 454 | * Hide the progress percentage |
| 455 | * Display the warning error icon |
| 456 | */ |
| 457 | selector.find('.transferito-migration-progress__step-icon') |
| 458 | .html('<div class="transferito-icon transferito-icon--exclamation-mark"></div>') |
| 459 | .addClass('transferito-migration-progress__step-icon--extended'); |
| 460 | selector.find('.transferito-migration-progress__step-percent').addClass(hiddenElementClass); |
| 461 | selector.find('.transferito-migration-progress__step-icon').removeClass(hiddenElementClass); |
| 462 | |
| 463 | /** |
| 464 | * Display the error container |
| 465 | * & Add the message into the error container |
| 466 | */ |
| 467 | selector.find('.transferito-migration-progress__step-title > .transferito-migration-progress__error-container') |
| 468 | .removeClass(hiddenElementClass) |
| 469 | .html(message); |
| 470 | }, |
| 471 | buildMappedStatus: function() { |
| 472 | return { |
| 473 | 'download.backup.started': { |
| 474 | progress: true, |
| 475 | progressSelector: $('#downloadBackupProgressPercentage'), |
| 476 | previous: [], |
| 477 | status: 'active', |
| 478 | selector: $('#progress__downloadingBackup') |
| 479 | }, |
| 480 | 'download.backup.completed': { |
| 481 | progressComplete: true, |
| 482 | progressSelector: $('#downloadBackupProgressPercentage'), |
| 483 | previous: [], |
| 484 | status: 'completed', |
| 485 | selector: $('#progress__downloadingBackup') |
| 486 | }, |
| 487 | 'extract.backup.started': { |
| 488 | progress: true, |
| 489 | progressSelector: $('#extractingBackupProgressPercentage'), |
| 490 | previous: ['download.backup.completed'], |
| 491 | status: 'active', |
| 492 | selector: $('#progress__extractingBackup') |
| 493 | }, |
| 494 | 'extract.backup.completed': { |
| 495 | progressComplete: true, |
| 496 | progressSelector: $('#extractingBackupProgressPercentage'), |
| 497 | previous: [ |
| 498 | 'download.backup.completed', |
| 499 | 'extract.backup.started', |
| 500 | ], |
| 501 | status: 'completed', |
| 502 | selector: $('#progress__extractingBackup') |
| 503 | }, |
| 504 | 'import.database.started': { |
| 505 | progress: true, |
| 506 | progressSelector: $('#installDatabaseProgressPercentage'), |
| 507 | previous: [ |
| 508 | 'download.backup.completed', |
| 509 | 'extract.backup.started', |
| 510 | 'extract.backup.completed' |
| 511 | ], |
| 512 | status: 'active', |
| 513 | selector: $('#progress__installingWordPress') |
| 514 | }, |
| 515 | 'import.database.completed': { |
| 516 | progressComplete: true, |
| 517 | progressSelector: $('#installDatabaseProgressPercentage'), |
| 518 | previous: [ |
| 519 | 'download.backup.completed', |
| 520 | 'extract.backup.started', |
| 521 | 'extract.backup.completed', |
| 522 | 'import.database.started' |
| 523 | ], |
| 524 | status: 'completed', |
| 525 | selector: $('#progress__installingWordPress') |
| 526 | }, |
| 527 | 'finalize.install': { |
| 528 | progressComplete: true, |
| 529 | progressSelector: $('#installDatabaseProgressPercentage'), |
| 530 | previous: [ |
| 531 | 'download.backup.completed', |
| 532 | 'extract.backup.started', |
| 533 | 'extract.backup.completed', |
| 534 | 'import.database.started', |
| 535 | 'import.database.completed' |
| 536 | ], |
| 537 | status: 'active', |
| 538 | selector: $('#progress__finalizingWPInstall') |
| 539 | }, |
| 540 | 'completed': { |
| 541 | previous: [ |
| 542 | 'download.backup.completed', |
| 543 | 'extract.backup.started', |
| 544 | 'extract.backup.completed', |
| 545 | 'import.database.started', |
| 546 | 'import.database.completed', |
| 547 | 'finalize.install' |
| 548 | ], |
| 549 | status: 'completed', |
| 550 | selector: $('#progress__finalizingWPInstall') |
| 551 | }, |
| 552 | 'completed.with.errors': { |
| 553 | previous: [ |
| 554 | 'download.backup.completed', |
| 555 | 'extract.backup.started', |
| 556 | 'extract.backup.completed', |
| 557 | 'import.database.started', |
| 558 | 'import.database.completed', |
| 559 | 'finalize.install' |
| 560 | ], |
| 561 | status: 'completed.with.errors', |
| 562 | selector: $('#progress__finalizingWPInstall') |
| 563 | } |
| 564 | }; |
| 565 | }, |
| 566 | displayHeaderLegend: function(state, message) { |
| 567 | var legendSelector = $('#transferitoHeaderLegend'); |
| 568 | var legendState = { |
| 569 | error: 'transferito-legend--error', |
| 570 | warning: 'transferito-legend--warning', |
| 571 | success: 'transferito-legend--success' |
| 572 | }; |
| 573 | var mappedLegendState = (!state) ? '' : legendState[state]; |
| 574 | |
| 575 | /** |
| 576 | * Remove all classes |
| 577 | */ |
| 578 | legendSelector.removeClass(); |
| 579 | |
| 580 | /** |
| 581 | * Add the initial legend class back |
| 582 | */ |
| 583 | legendSelector.addClass('transferito-legend'); |
| 584 | |
| 585 | /** |
| 586 | * Add the correct class on the element - if the state exists |
| 587 | */ |
| 588 | if (mappedLegendState) { |
| 589 | legendSelector.addClass(mappedLegendState); |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Add the message to the legend |
| 594 | */ |
| 595 | legendSelector.html(message); |
| 596 | }, |
| 597 | hideHeaderLegend: function() { |
| 598 | $('#transferitoHeaderLegend').addClass('transferito__hide-element') |
| 599 | }, |
| 600 | logEvent: function(event, eventProperties) { |
| 601 | $.post(ajaxurl, { |
| 602 | action: 'log_transferito_event', |
| 603 | securityKey: $('#logEventNonce').val(), |
| 604 | event, |
| 605 | eventProperties, |
| 606 | }); |
| 607 | }, |
| 608 | saveTempMigrationDetails: function(details, key) { |
| 609 | this.tempMigrationDetails.details = details; |
| 610 | this.tempMigrationDetails.key = key; |
| 611 | }, |
| 612 | clearTempMigrationDetails: function() { |
| 613 | this.tempMigrationDetails.details = {}; |
| 614 | this.tempMigrationDetails.key = ''; |
| 615 | } |
| 616 | }; |
| 617 | |
| 618 | /** |
| 619 | * Check the site |
| 620 | */ |
| 621 | this.checkSite = function() { |
| 622 | this.utilities.changeTemplate( |
| 623 | 'check_current_site', |
| 624 | $('#nonce').val(), |
| 625 | {}, |
| 626 | false, |
| 627 | function (response) { |
| 628 | if (!response?.hideWelcomeScreen) { |
| 629 | transferito.utilities.displayModal('firstMigrationInformation'); |
| 630 | } |
| 631 | } |
| 632 | ); |
| 633 | }; |
| 634 | |
| 635 | /** |
| 636 | * Get the migration status |
| 637 | * |
| 638 | * @param token |
| 639 | */ |
| 640 | this.getStatus = function (token) { |
| 641 | var self = this; |
| 642 | this.mappedStatus = this.utilities.buildMappedStatus(); |
| 643 | $.post(ajaxurl, { |
| 644 | action: 'status_check', |
| 645 | token: token, |
| 646 | securityKey: $('#statusCheckNonce').val() |
| 647 | }, function(response) { |
| 648 | |
| 649 | /** |
| 650 | * If the status is false or null |
| 651 | * Retry the status check |
| 652 | * |
| 653 | * If not process the status as normal |
| 654 | */ |
| 655 | if (!response.data) { |
| 656 | self.getStatus(token); |
| 657 | } else { |
| 658 | |
| 659 | console.log(response.data); |
| 660 | |
| 661 | /** |
| 662 | * Check the status has the properties to not fails |
| 663 | */ |
| 664 | if (response.hasOwnProperty('data') && response.data.hasOwnProperty('completed')) { |
| 665 | |
| 666 | /** |
| 667 | * Check the object has the status property |
| 668 | */ |
| 669 | if (response.data.hasOwnProperty('status')) { |
| 670 | |
| 671 | /** |
| 672 | * Check if the status has changed |
| 673 | */ |
| 674 | var statusChanged = self.currentStatus !== response.data.status; |
| 675 | |
| 676 | /** |
| 677 | * Assign the status to the current status |
| 678 | */ |
| 679 | self.currentStatus = response.data.status; |
| 680 | |
| 681 | /** |
| 682 | * Check that the status exists |
| 683 | */ |
| 684 | var migrationStatus = self.mappedStatus.hasOwnProperty(response.data.status) |
| 685 | ? self.mappedStatus[response.data.status] |
| 686 | : null; |
| 687 | |
| 688 | /** |
| 689 | * If the status exist - Update it |
| 690 | */ |
| 691 | if (migrationStatus) { |
| 692 | /** |
| 693 | * If the previous property exists |
| 694 | */ |
| 695 | if (migrationStatus.hasOwnProperty('previous')) { |
| 696 | for (let index = 0; index < migrationStatus.previous.length; index++) { |
| 697 | var migrationPreviousStatus = self.mappedStatus[migrationStatus.previous[index]]; |
| 698 | |
| 699 | /** |
| 700 | * Change the progress step |
| 701 | */ |
| 702 | self.utilities.changeProgressStep(migrationPreviousStatus); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * Change the progress step |
| 708 | */ |
| 709 | self.utilities.changeProgressStep(migrationStatus, response.data, statusChanged); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * If the migration is still in progress |
| 715 | */ |
| 716 | if (!response.data.completed) { |
| 717 | self.getStatus(token); |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * If the migration has completed |
| 722 | */ |
| 723 | if (response.data.completed) { |
| 724 | self.utilities.hideHeaderLegend(); |
| 725 | self.utilities.logEvent('migrationCompleted', { |
| 726 | completed: true |
| 727 | }); |
| 728 | self.cleanUp( |
| 729 | false, |
| 730 | [], |
| 731 | false, |
| 732 | { |
| 733 | status: response.data.status |
| 734 | }); |
| 735 | } |
| 736 | |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | }) |
| 741 | .fail(function(error) { |
| 742 | if (error.hasOwnProperty('status') && error.status > 501) { |
| 743 | setTimeout(function () { |
| 744 | self.getStatus(token); |
| 745 | }, 10000, self, token); |
| 746 | } else { |
| 747 | |
| 748 | var migrationStatus = self.mappedStatus.hasOwnProperty(self.currentStatus) |
| 749 | ? self.mappedStatus[self.currentStatus] |
| 750 | : self.mappedStatus['download.backup.started']; |
| 751 | |
| 752 | self.utilities.logEvent('failedMigration', { |
| 753 | migrationStatus: self.currentStatus, |
| 754 | errorMessage: error?.responseJSON?.data |
| 755 | }); |
| 756 | |
| 757 | self.cleanUp( |
| 758 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 759 | error.responseJSON, |
| 760 | false, |
| 761 | null, |
| 762 | migrationStatus.selector |
| 763 | ); |
| 764 | } |
| 765 | }); |
| 766 | }; |
| 767 | |
| 768 | /** |
| 769 | * Start the migration |
| 770 | * |
| 771 | * @param wpNonce |
| 772 | */ |
| 773 | this.startMigration = function(wpNonce) { |
| 774 | var self = this; |
| 775 | var data = { |
| 776 | action: 'start_migration', |
| 777 | security: wpNonce |
| 778 | }; |
| 779 | |
| 780 | var sendFiles = $.post(ajaxurl, data, function(response) { |
| 781 | /** |
| 782 | * Show the completion screen if a local migration |
| 783 | * |
| 784 | * If not - Listen to the status updates |
| 785 | */ |
| 786 | if (response.data.localMigration) { |
| 787 | self.utilities.hideHeaderLegend(); |
| 788 | self.utilities.logEvent('localMigrationPartiallyCompleted', { completed: true }); |
| 789 | self.cleanUp(false, [], false, {}, null, true); |
| 790 | } else { |
| 791 | self.utilities.displayHeaderLegend('success', response.data.message); |
| 792 | self.getStatus(response.data.token); |
| 793 | } |
| 794 | }); |
| 795 | sendFiles.fail(function(error) { |
| 796 | self.utilities.logEvent('failedMigration', { |
| 797 | migrationStatus: 'prepareBackup', |
| 798 | errorMessage: error?.responseJSON?.data |
| 799 | }); |
| 800 | self.cleanUp( |
| 801 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 802 | error.responseJSON, |
| 803 | false, |
| 804 | null, |
| 805 | $('#progress__prepareBackup') |
| 806 | ); |
| 807 | }); |
| 808 | }; |
| 809 | |
| 810 | /** |
| 811 | * Start to prepare the migration |
| 812 | * |
| 813 | * @param migrationDetails |
| 814 | * @param key |
| 815 | */ |
| 816 | this.prepareMigration = function (migrationDetails, key) { |
| 817 | var self = this; |
| 818 | var data = { |
| 819 | action: 'preparing_transfer', |
| 820 | security: key, |
| 821 | migrationDetails: migrationDetails |
| 822 | }; |
| 823 | var backup = $.post(ajaxurl, data, function(response) { |
| 824 | |
| 825 | /** |
| 826 | * Change the template |
| 827 | */ |
| 828 | self.utilities.setTemplate(response.data.htmlTemplate); |
| 829 | |
| 830 | /** |
| 831 | * Update the legend message |
| 832 | */ |
| 833 | self.utilities.displayHeaderLegend('warning', response.data.message); |
| 834 | |
| 835 | /** |
| 836 | * Count how many steps exist |
| 837 | */ |
| 838 | self.utilities.checkMigrationProgressSteps(); |
| 839 | |
| 840 | /** |
| 841 | * Set the active |
| 842 | */ |
| 843 | self.utilities.updateProgressStep('active', $('#progress__prepareBackup'), true); |
| 844 | |
| 845 | /** |
| 846 | * If premium is required |
| 847 | */ |
| 848 | if (response.data.upgradeRequired) { |
| 849 | self.inPluginPurchase(migrationDetails, key); |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * If no premium is not required progress as normal |
| 854 | */ |
| 855 | if (!response.data.upgradeRequired) { |
| 856 | /** |
| 857 | * Start the ZIP |
| 858 | */ |
| 859 | if (response.data.useZipFallback) { |
| 860 | self.prepareCodebaseBackup(key); |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * If we don't use the Fallback |
| 865 | */ |
| 866 | if (!response.data.useZipFallback) { |
| 867 | /** |
| 868 | * Set prepare backup to completed |
| 869 | */ |
| 870 | self.utilities.updateProgressStep('completed', $('#progress__prepareBackup')); |
| 871 | |
| 872 | /** |
| 873 | * Set the backup started to active |
| 874 | */ |
| 875 | self.utilities.updateProgressStep('active', $('#progress__backupInstallation'), true); |
| 876 | |
| 877 | /** |
| 878 | * If the DB is excluded |
| 879 | * Go straight to the codebase archive |
| 880 | */ |
| 881 | if (response.data.excludeDatabase) { |
| 882 | self.archiveCreationStart(key); |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | * If the DB isn't excluded |
| 887 | */ |
| 888 | if (!response.data.excludeDatabase) { |
| 889 | /** |
| 890 | * Set the initial percentage for the db |
| 891 | */ |
| 892 | self.utilities.saveBackupPercentage('database', { |
| 893 | percentage: response.data.databasePercentage, |
| 894 | increment: 0, |
| 895 | }); |
| 896 | |
| 897 | /** |
| 898 | * Start the backup process |
| 899 | */ |
| 900 | self.prepareDatabaseBackup(key, response.data.useZipFallback); |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | }); |
| 905 | backup.fail(function(error) { |
| 906 | var transferMethod = data.migrationDetails.transferMethod; |
| 907 | |
| 908 | self.utilities.logEvent('failedMigration', { |
| 909 | migrationStatus: 'backupInstallation', |
| 910 | errorMessage: error?.responseJSON?.data |
| 911 | }); |
| 912 | |
| 913 | /** |
| 914 | * For cPanel migrations - Populate the modal with the current error message |
| 915 | * When the API is unable to create the FTP & DB details |
| 916 | */ |
| 917 | if (transferMethod === 'cpanel') { |
| 918 | self.screenRouting( |
| 919 | 'cpanelDomainSelection', |
| 920 | '', |
| 921 | '', |
| 922 | 'cPanelDomainSelectFailure', |
| 923 | { |
| 924 | content: '<b>Reason:</b> ' + error?.responseJSON?.data, |
| 925 | selector: '.transferito-text__p--regular' |
| 926 | } |
| 927 | ); |
| 928 | } else { |
| 929 | self.cleanUp( |
| 930 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 931 | error.responseJSON, |
| 932 | false, |
| 933 | null, |
| 934 | $('#progress__backupInstallation') |
| 935 | ); |
| 936 | } |
| 937 | |
| 938 | }); |
| 939 | }; |
| 940 | |
| 941 | /** |
| 942 | * Prepare the file list for the archive creation |
| 943 | * |
| 944 | * @param key |
| 945 | */ |
| 946 | this.prepareCodebaseBackup = function(key) { |
| 947 | var self = this; |
| 948 | var data = { |
| 949 | action: 'preparing_codebase', |
| 950 | security: key |
| 951 | }; |
| 952 | var codebasePreparation = $.post(ajaxurl, data, function(response) { |
| 953 | /** |
| 954 | * Set prepare backup to completed |
| 955 | */ |
| 956 | self.utilities.updateProgressStep('completed', $('#progress__prepareBackup')); |
| 957 | |
| 958 | /** |
| 959 | * Set the backup started to active |
| 960 | */ |
| 961 | self.utilities.updateProgressStep('active', $('#progress__backupInstallation'), true); |
| 962 | |
| 963 | /** |
| 964 | * Create the Codebase percent and increment value |
| 965 | */ |
| 966 | self.utilities.saveBackupPercentage('codebase', { |
| 967 | percentage: response.data.codebasePercentage, |
| 968 | increment: (response.data.codebasePercentage / response.data.amount), |
| 969 | }); |
| 970 | |
| 971 | /** |
| 972 | * Create the Database percent and increment value |
| 973 | */ |
| 974 | self.utilities.saveBackupPercentage('database', { |
| 975 | percentage: response.data.databasePercentage, |
| 976 | increment: 0, |
| 977 | }); |
| 978 | |
| 979 | /** |
| 980 | * Start adding files to the codebase |
| 981 | */ |
| 982 | self.addFilesToCodebaseBackup(key, 1, response.data.amount); |
| 983 | }); |
| 984 | codebasePreparation.fail(function(error) { |
| 985 | self.utilities.logEvent('failedMigration', { |
| 986 | migrationStatus: 'backupInstallation - preparing_codebase', |
| 987 | errorMessage: error?.responseJSON?.data |
| 988 | }); |
| 989 | self.cleanUp( |
| 990 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 991 | error.responseJSON, |
| 992 | false, |
| 993 | null, |
| 994 | $('#progress__backupInstallation') |
| 995 | ); |
| 996 | }); |
| 997 | }; |
| 998 | |
| 999 | /** |
| 1000 | * Add the files to the created archive |
| 1001 | * |
| 1002 | * @param key |
| 1003 | * @param fileIndex |
| 1004 | * @param maxAmount |
| 1005 | */ |
| 1006 | this.addFilesToCodebaseBackup = function(key, fileIndex, maxAmount) { |
| 1007 | var self = this; |
| 1008 | |
| 1009 | if (fileIndex > maxAmount) { |
| 1010 | self.codebaseCompleted(key); |
| 1011 | } else { |
| 1012 | /** |
| 1013 | * Update the progress for the codebase |
| 1014 | */ |
| 1015 | self.utilities.updateTheBackupProgress('codebase'); |
| 1016 | |
| 1017 | var data = { |
| 1018 | action: 'add_files_to_codebase_archive', |
| 1019 | security: key, |
| 1020 | currentFileIndex: fileIndex |
| 1021 | }; |
| 1022 | var addFiles = $.post(ajaxurl, data, function(response) { |
| 1023 | var newFileIndex = fileIndex + 1; |
| 1024 | self.addFilesToCodebaseBackup(key, newFileIndex, maxAmount); |
| 1025 | }); |
| 1026 | addFiles.fail(function(error) { |
| 1027 | self.utilities.logEvent('failedMigration', { |
| 1028 | migrationStatus: 'backupInstallation - add_files_to_codebase_archive', |
| 1029 | errorMessage: error?.responseJSON?.data |
| 1030 | }); |
| 1031 | self.cleanUp( |
| 1032 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1033 | error.responseJSON, |
| 1034 | false, |
| 1035 | null, |
| 1036 | $('#progress__backupInstallation') |
| 1037 | ); |
| 1038 | }); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * Notification for codebase archive creation process |
| 1044 | * |
| 1045 | * @param key |
| 1046 | */ |
| 1047 | this.codebaseCompleted = function(key) { |
| 1048 | var self = this; |
| 1049 | var data = { |
| 1050 | action: 'codebase_completion', |
| 1051 | security: key, |
| 1052 | }; |
| 1053 | var codebaseCompletion = $.post(ajaxurl, data, function(response) { |
| 1054 | self.checkArchiveCompletion(key); |
| 1055 | /** |
| 1056 | * Initialise the database archive process |
| 1057 | * If the DB hasn't been excluded |
| 1058 | */ |
| 1059 | if (!response.data.excludeDatabase) { |
| 1060 | self.prepareDatabaseBackup(key, true); |
| 1061 | } |
| 1062 | }); |
| 1063 | codebaseCompletion.fail(function(error) { |
| 1064 | self.utilities.logEvent('failedMigration', { |
| 1065 | migrationStatus: 'backupInstallation - codebase_completion', |
| 1066 | errorMessage: error?.responseJSON?.data |
| 1067 | }); |
| 1068 | self.cleanUp( |
| 1069 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1070 | error.responseJSON, |
| 1071 | false, |
| 1072 | null, |
| 1073 | $('#progress__backupInstallation') |
| 1074 | ); |
| 1075 | }); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * Prepare the DB to be backed up |
| 1080 | * |
| 1081 | * @param key |
| 1082 | * @param useZipFallback |
| 1083 | */ |
| 1084 | this.prepareDatabaseBackup = function(key, useZipFallback) { |
| 1085 | var self = this; |
| 1086 | var data = { |
| 1087 | action: 'preparing_database', |
| 1088 | security: key |
| 1089 | }; |
| 1090 | var databasePreparation = $.post(ajaxurl, data, function(response) { |
| 1091 | self.chunkDBExport(key, true, useZipFallback); |
| 1092 | }); |
| 1093 | databasePreparation.fail(function(error) { |
| 1094 | self.utilities.logEvent('failedMigration', { |
| 1095 | migrationStatus: 'backupInstallation - preparing_database', |
| 1096 | errorMessage: error?.responseJSON?.data |
| 1097 | }); |
| 1098 | self.cleanUp( |
| 1099 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1100 | error.responseJSON, |
| 1101 | false, |
| 1102 | null, |
| 1103 | $('#progress__backupInstallation') |
| 1104 | ); |
| 1105 | }); |
| 1106 | }; |
| 1107 | |
| 1108 | /** |
| 1109 | * Create DB Export Files |
| 1110 | * |
| 1111 | * @param key |
| 1112 | * @param firstRun |
| 1113 | * @param useZipFallback |
| 1114 | */ |
| 1115 | this.chunkDBExport = function(key, firstRun, useZipFallback) { |
| 1116 | var self = this; |
| 1117 | var data = { |
| 1118 | action: 'create_db_exports', |
| 1119 | security: key, |
| 1120 | firstRun: firstRun |
| 1121 | }; |
| 1122 | var chunkedExport = $.post(ajaxurl, data, function(response) { |
| 1123 | |
| 1124 | /** |
| 1125 | * Update our progress while we chunk |
| 1126 | * If exec is being used |
| 1127 | */ |
| 1128 | if (!useZipFallback && response.data.hasOwnProperty('tableIndex')) { |
| 1129 | |
| 1130 | /** |
| 1131 | * Only on the first run set the percentage |
| 1132 | */ |
| 1133 | if (response.data.fileIndex === 2) { |
| 1134 | self.utilities.saveBackupPercentage('database', { |
| 1135 | percentage: transferito.backupPercentage.database, |
| 1136 | increment: (transferito.backupPercentage.database / response.data.tableIndex), |
| 1137 | }); |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * Update the progress for the database |
| 1142 | */ |
| 1143 | self.utilities.updateTheBackupProgress('database'); |
| 1144 | } |
| 1145 | |
| 1146 | /** |
| 1147 | * Keep running the export until the export flag is true |
| 1148 | */ |
| 1149 | if (!response.data.completed) { |
| 1150 | self.chunkDBExport(key, false, useZipFallback); |
| 1151 | } |
| 1152 | |
| 1153 | /** |
| 1154 | * When the chunked export has been completed |
| 1155 | * Notify the application that the DB has been completed |
| 1156 | */ |
| 1157 | if (response.data.completed) { |
| 1158 | self.databaseCompleted(key); |
| 1159 | } |
| 1160 | }); |
| 1161 | chunkedExport.fail(function(error) { |
| 1162 | self.utilities.logEvent('failedMigration', { |
| 1163 | migrationStatus: 'backupInstallation - create_db_exports', |
| 1164 | errorMessage: error?.responseJSON?.data |
| 1165 | }); |
| 1166 | self.cleanUp( |
| 1167 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1168 | error.responseJSON, |
| 1169 | false, |
| 1170 | null, |
| 1171 | $('#progress__backupInstallation') |
| 1172 | ); |
| 1173 | }); |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * Notification for database export completion |
| 1178 | * |
| 1179 | * @param key |
| 1180 | */ |
| 1181 | this.databaseCompleted = function(key) { |
| 1182 | var self = this; |
| 1183 | var data = { |
| 1184 | action: 'database_completion', |
| 1185 | security: key, |
| 1186 | }; |
| 1187 | var databaseCompletion = $.post(ajaxurl, data, function(response) { |
| 1188 | /** |
| 1189 | * If we are using the zip fallback |
| 1190 | * Run the archive completion |
| 1191 | */ |
| 1192 | if (response.data.useZipFallback) { |
| 1193 | self.checkArchiveCompletion(key); |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * If zip fallback isn't used - Run the db move |
| 1198 | */ |
| 1199 | if (!response.data.useZipFallback) { |
| 1200 | self.databaseFilesRelocation(key); |
| 1201 | } |
| 1202 | }); |
| 1203 | databaseCompletion.fail(function(error) { |
| 1204 | self.utilities.logEvent('failedMigration', { |
| 1205 | migrationStatus: 'backupInstallation - database_completion', |
| 1206 | errorMessage: error?.responseJSON?.data |
| 1207 | }); |
| 1208 | self.cleanUp( |
| 1209 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1210 | error.responseJSON, |
| 1211 | false, |
| 1212 | null, |
| 1213 | $('#progress__backupInstallation') |
| 1214 | ); |
| 1215 | }); |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * Relocate the database files |
| 1220 | * |
| 1221 | * @param key |
| 1222 | */ |
| 1223 | this.databaseFilesRelocation = function(key) { |
| 1224 | var self = this; |
| 1225 | var data = { |
| 1226 | action: 'database_relocation', |
| 1227 | security: key, |
| 1228 | }; |
| 1229 | var databaseRelocation = $.post(ajaxurl, data, function(response) { |
| 1230 | self.checkDatabaseRelocation(key); |
| 1231 | }); |
| 1232 | databaseRelocation.fail(function(error) { |
| 1233 | self.utilities.logEvent('failedMigration', { |
| 1234 | migrationStatus: 'backupInstallation - database_relocation', |
| 1235 | errorMessage: error?.responseJSON?.data |
| 1236 | }); |
| 1237 | self.cleanUp( |
| 1238 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1239 | error.responseJSON, |
| 1240 | false, |
| 1241 | null, |
| 1242 | $('#progress__backupInstallation') |
| 1243 | ); |
| 1244 | }); |
| 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * Relocate the database files check |
| 1249 | * |
| 1250 | * @param key |
| 1251 | */ |
| 1252 | this.checkDatabaseRelocation = function(key) { |
| 1253 | var self = this; |
| 1254 | var data = { |
| 1255 | action: 'database_relocation_check', |
| 1256 | security: key, |
| 1257 | }; |
| 1258 | var databaseRelocationCheck = $.post(ajaxurl, data, function(response) { |
| 1259 | /** |
| 1260 | * If the DB isn't completed |
| 1261 | * Keep Polling until the job has completed |
| 1262 | */ |
| 1263 | if (!response.data.completed) { |
| 1264 | self.checkDatabaseRelocation(key); |
| 1265 | } |
| 1266 | |
| 1267 | /** |
| 1268 | * Once completed |
| 1269 | * Start the Archive creation |
| 1270 | */ |
| 1271 | if (response.data.completed) { |
| 1272 | self.backupSize = response.data.siteInfo.databasePercentage; |
| 1273 | self.utilities.updateProgressPercentage(response.data.siteInfo.databasePercentage, $('#backupInstallationProgressPercentage')); |
| 1274 | self.archiveCreationStart(key); |
| 1275 | } |
| 1276 | }); |
| 1277 | databaseRelocationCheck.fail(function(error) { |
| 1278 | self.utilities.logEvent('failedMigration', { |
| 1279 | migrationStatus: 'backupInstallation - database_relocation_check', |
| 1280 | errorMessage: error?.responseJSON?.data |
| 1281 | }); |
| 1282 | self.cleanUp( |
| 1283 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1284 | error.responseJSON, |
| 1285 | false, |
| 1286 | null, |
| 1287 | $('#progress__backupInstallation') |
| 1288 | ); |
| 1289 | }); |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Start the creation of the Archive |
| 1294 | * |
| 1295 | * @param key |
| 1296 | */ |
| 1297 | this.archiveCreationStart = function(key) { |
| 1298 | var self = this; |
| 1299 | var data = { |
| 1300 | action: 'archive_creation', |
| 1301 | security: key, |
| 1302 | }; |
| 1303 | var archiveCreation = $.post(ajaxurl, data, function() { |
| 1304 | self.checkArchiveProgress(key, transferito.backupSize); |
| 1305 | }); |
| 1306 | archiveCreation.fail(function(error) { |
| 1307 | self.utilities.logEvent('failedMigration', { |
| 1308 | migrationStatus: 'backupInstallation - archive_creation', |
| 1309 | errorMessage: error?.responseJSON?.data |
| 1310 | }); |
| 1311 | self.cleanUp( |
| 1312 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1313 | error.responseJSON, |
| 1314 | false, |
| 1315 | null, |
| 1316 | $('#progress__backupInstallation') |
| 1317 | ); |
| 1318 | }); |
| 1319 | } |
| 1320 | |
| 1321 | /** |
| 1322 | * Check the progress of the archive creation |
| 1323 | * |
| 1324 | * @param key |
| 1325 | * @param initial |
| 1326 | */ |
| 1327 | this.checkArchiveProgress = function(key, initial) { |
| 1328 | var self = this; |
| 1329 | var data = { |
| 1330 | action: 'archive_progress_check', |
| 1331 | security: key, |
| 1332 | }; |
| 1333 | var archiveProgressCheck = $.post(ajaxurl, data, function(response) { |
| 1334 | |
| 1335 | /** |
| 1336 | * Update the amount |
| 1337 | */ |
| 1338 | self.utilities.updateTheExecBackupProgress(response.data.progress, initial); |
| 1339 | |
| 1340 | /** |
| 1341 | * Poll every 5 second for the status |
| 1342 | */ |
| 1343 | if (!response.data.completed) { |
| 1344 | setTimeout(function () { |
| 1345 | self.checkArchiveProgress(key, initial); |
| 1346 | }, 2500, self, key, initial); |
| 1347 | } |
| 1348 | |
| 1349 | /** |
| 1350 | * Once the Archive has been completed progress |
| 1351 | */ |
| 1352 | if (response.data.completed) { |
| 1353 | self.prepareMigrationStart(response.data.information); |
| 1354 | } |
| 1355 | |
| 1356 | }); |
| 1357 | archiveProgressCheck.fail(function(error) { |
| 1358 | self.utilities.logEvent('failedMigration', { |
| 1359 | migrationStatus: 'backupInstallation - archive_progress_check', |
| 1360 | errorMessage: error?.responseJSON?.data |
| 1361 | }); |
| 1362 | self.cleanUp( |
| 1363 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1364 | error.responseJSON, |
| 1365 | false, |
| 1366 | null, |
| 1367 | $('#progress__backupInstallation') |
| 1368 | ); |
| 1369 | }); |
| 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * Archive Database exports |
| 1374 | * |
| 1375 | * @param key |
| 1376 | * @param information |
| 1377 | */ |
| 1378 | this.archiveDatabaseExports = function(key, information) { |
| 1379 | var self = this; |
| 1380 | var data = { |
| 1381 | action: 'archive_db_exports', |
| 1382 | security: key, |
| 1383 | }; |
| 1384 | var exportArchive = $.post(ajaxurl, data, function(response) { |
| 1385 | |
| 1386 | /** |
| 1387 | * Create the Database percent and increment value |
| 1388 | */ |
| 1389 | self.utilities.saveBackupPercentage('database', { |
| 1390 | percentage: transferito.backupPercentage.database, |
| 1391 | increment: (transferito.backupPercentage.database / response.data.amount), |
| 1392 | }); |
| 1393 | |
| 1394 | self.addDBExportsToCodebaseBackup(key, 1, response.data.amount, information) |
| 1395 | }); |
| 1396 | exportArchive.fail(function(error) { |
| 1397 | self.utilities.logEvent('failedMigration', { |
| 1398 | migrationStatus: 'backupInstallation - archive_db_exports', |
| 1399 | errorMessage: error?.responseJSON?.data |
| 1400 | }); |
| 1401 | self.cleanUp( |
| 1402 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1403 | error.responseJSON, |
| 1404 | false, |
| 1405 | null, |
| 1406 | $('#progress__backupInstallation') |
| 1407 | ); |
| 1408 | }); |
| 1409 | } |
| 1410 | |
| 1411 | /** |
| 1412 | * Add the files to the created archive |
| 1413 | * |
| 1414 | * @param key |
| 1415 | * @param fileIndex |
| 1416 | * @param maxAmount |
| 1417 | * @param information |
| 1418 | * |
| 1419 | * @todo Refactor to pass in a callback and request options - so "addFilesToCodebaseBackup" isn't duplicated |
| 1420 | */ |
| 1421 | this.addDBExportsToCodebaseBackup = function(key, fileIndex, maxAmount, information) { |
| 1422 | var self = this; |
| 1423 | |
| 1424 | if (fileIndex > maxAmount) { |
| 1425 | self.prepareMigrationStart(information); |
| 1426 | } else { |
| 1427 | |
| 1428 | /** |
| 1429 | * Update the progress for the database |
| 1430 | */ |
| 1431 | self.utilities.updateTheBackupProgress('database'); |
| 1432 | |
| 1433 | var data = { |
| 1434 | action: 'add_files_to_codebase_archive', |
| 1435 | security: key, |
| 1436 | currentFileIndex: fileIndex, |
| 1437 | addDatabaseExports: 1 |
| 1438 | }; |
| 1439 | var addFiles = $.post(ajaxurl, data, function(response) { |
| 1440 | var newFileIndex = fileIndex + 1; |
| 1441 | self.addDBExportsToCodebaseBackup(key, newFileIndex, maxAmount, information); |
| 1442 | }); |
| 1443 | addFiles.fail(function(error) { |
| 1444 | self.utilities.logEvent('failedMigration', { |
| 1445 | migrationStatus: 'backupInstallation - add_files_to_codebase_archive', |
| 1446 | errorMessage: error?.responseJSON?.data |
| 1447 | }); |
| 1448 | self.cleanUp( |
| 1449 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1450 | error.responseJSON, |
| 1451 | false, |
| 1452 | null, |
| 1453 | $('#progress__backupInstallation') |
| 1454 | ); |
| 1455 | }); |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * Fire the function to decide what action to perform when the archive creation is completed |
| 1461 | * |
| 1462 | * @param key |
| 1463 | */ |
| 1464 | this.checkArchiveCompletion = function(key) { |
| 1465 | var self = this; |
| 1466 | var data = { |
| 1467 | action: 'check_archive_completion', |
| 1468 | security: key, |
| 1469 | }; |
| 1470 | var archiveCompletion = $.post(ajaxurl, data, function(response) { |
| 1471 | /** |
| 1472 | * If the backup has completed |
| 1473 | * The zip export flag is truthy |
| 1474 | * Fire the start db zip export |
| 1475 | */ |
| 1476 | if (response.data.backupComplete && response.data.zipDatabaseExport) { |
| 1477 | self.archiveDatabaseExports(key, response.data.information); |
| 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * If the backup has been completed |
| 1482 | * The zip export flag is falsy |
| 1483 | * Upload or start the migration |
| 1484 | */ |
| 1485 | if (response.data.backupComplete && !response.data.zipDatabaseExport) { |
| 1486 | self.prepareMigrationStart(response.data.information); |
| 1487 | } |
| 1488 | }); |
| 1489 | archiveCompletion.fail(function(error) { |
| 1490 | self.utilities.logEvent('failedMigration', { |
| 1491 | migrationStatus: 'backupInstallation - check_archive_completion', |
| 1492 | errorMessage: error?.responseJSON?.data |
| 1493 | }); |
| 1494 | self.cleanUp( |
| 1495 | 'USE_CUSTOM_ERROR_MESSAGE', |
| 1496 | error.responseJSON, |
| 1497 | false, |
| 1498 | null, |
| 1499 | $('#progress__backupInstallation') |
| 1500 | ); |
| 1501 | }); |
| 1502 | } |
| 1503 | |
| 1504 | /** |
| 1505 | * Make a decision on whether to do a direct migration or upload |
| 1506 | * |
| 1507 | * @param information |
| 1508 | */ |
| 1509 | this.prepareMigrationStart = function (information) { |
| 1510 | /** |
| 1511 | * Set the backup started to active |
| 1512 | */ |
| 1513 | this.utilities.updateProgressStep('completed', $('#progress__backupInstallation')); |
| 1514 | |
| 1515 | /** |
| 1516 | * Hide the percentage on completion of codebase & database |
| 1517 | */ |
| 1518 | this.utilities.hideProgressPercentage($('#backupInstallationProgressPercentage')); |
| 1519 | |
| 1520 | /** |
| 1521 | * Fire the local upload to have an accessible file |
| 1522 | */ |
| 1523 | if (information.uploadFiles) { |
| 1524 | /** |
| 1525 | * Set the backup to active |
| 1526 | */ |
| 1527 | this.utilities.updateProgressStep('active', $('#progress__uploadBackup'), true); |
| 1528 | |
| 1529 | /** |
| 1530 | * Start the upload |
| 1531 | */ |
| 1532 | this.startUpload(information.securityKey); |
| 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * Start the migration |
| 1537 | */ |
| 1538 | if (!information.uploadFiles) { |
| 1539 | this.startMigration(information.securityKey); |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | /** |
| 1544 | * Start the local upload |
| 1545 | * @param wpNonce |
| 1546 | */ |
| 1547 | this.startUpload = function(wpNonce) { |
| 1548 | var self = this; |
| 1549 | var data = { |
| 1550 | action: 'initiate_local_upload', |
| 1551 | security: wpNonce |
| 1552 | }; |
| 1553 | var startLocalUpload = $.post(ajaxurl, data, function(response) { |
| 1554 | /** |
| 1555 | * Fire the process upload for the codebase |
| 1556 | */ |
| 1557 | self.processLocalUpload(response.data.backup.archive, '#codebaseProgressBar'); |
| 1558 | }); |
| 1559 | startLocalUpload.fail(function(error) { |
| 1560 | self.utilities.logEvent('failedMigration', { |
| 1561 | migrationStatus: 'uploadBackup - initiate_local_upload', |
| 1562 | errorMessage: error?.responseJSON?.data |
| 1563 | }); |
| 1564 | self.cleanUp( |
| 1565 | 'UPLOAD_START_FAILURE', |
| 1566 | error.responseJSON, |
| 1567 | false, |
| 1568 | null, |
| 1569 | $('#progress__uploadBackup') |
| 1570 | ); |
| 1571 | }); |
| 1572 | }; |
| 1573 | |
| 1574 | /** |
| 1575 | * Process the Local upload |
| 1576 | * |
| 1577 | * @param uploadDetail |
| 1578 | * @param progressSelector |
| 1579 | * @param ignoreLocalUploadProperties - If the DB is excluded ignores the upload flags and process the start |
| 1580 | * StartMigration method straight after the completeUpload has succeeded |
| 1581 | */ |
| 1582 | this.processLocalUpload = function(uploadDetail, progressSelector, ignoreLocalUploadProperties = false) { |
| 1583 | /** |
| 1584 | * Start the chunk upload |
| 1585 | */ |
| 1586 | this.uploadChunk(1, uploadDetail, progressSelector, ignoreLocalUploadProperties); |
| 1587 | }; |
| 1588 | |
| 1589 | /** |
| 1590 | * Upload the chunk |
| 1591 | * |
| 1592 | * @param part |
| 1593 | * @param uploadDetail |
| 1594 | * @param progressSelector |
| 1595 | * @param ignoreLocalUploadProperties - If the DB is excluded ignores the upload flags and process the start |
| 1596 | * StartMigration method straight after the completeUpload has succeeded |
| 1597 | */ |
| 1598 | this.uploadChunk = function(part, uploadDetail, progressSelector, ignoreLocalUploadProperties = false) { |
| 1599 | var self = this; |
| 1600 | var data = { |
| 1601 | action: 'upload_chunk', |
| 1602 | securityKey: $('#uploadChunkNonce').val(), |
| 1603 | uploadId: uploadDetail.uploadId, |
| 1604 | archiveType: uploadDetail.type, |
| 1605 | partNumber: part |
| 1606 | }; |
| 1607 | var chunkUpload = $.post(ajaxurl, data, function(response) { |
| 1608 | |
| 1609 | /** |
| 1610 | * Get all the parts |
| 1611 | */ |
| 1612 | var maxParts = uploadDetail.parts; |
| 1613 | |
| 1614 | /** |
| 1615 | * Calculate the percentage of the uplaod |
| 1616 | */ |
| 1617 | var percentage = Math.ceil((part / maxParts) * 100); |
| 1618 | |
| 1619 | |
| 1620 | /** |
| 1621 | * Update the percentage for the progress bar |
| 1622 | */ |
| 1623 | self.utilities.updateProgressPercentage(percentage, $('#progressPercentage')); |
| 1624 | |
| 1625 | /** |
| 1626 | * Call the chunk upload recursively |
| 1627 | */ |
| 1628 | if (part < maxParts) { |
| 1629 | var nextPart = part + 1; |
| 1630 | self.uploadChunk(nextPart, uploadDetail, progressSelector, ignoreLocalUploadProperties); |
| 1631 | } |
| 1632 | |
| 1633 | /** |
| 1634 | * Complete the upload |
| 1635 | */ |
| 1636 | if (part === maxParts) { |
| 1637 | self.completeUpload(uploadDetail.uploadId, uploadDetail.type, ignoreLocalUploadProperties); |
| 1638 | } |
| 1639 | |
| 1640 | }); |
| 1641 | chunkUpload.fail(function(error) { |
| 1642 | self.utilities.logEvent('failedMigration', { |
| 1643 | migrationStatus: 'uploadBackup - upload_chunk', |
| 1644 | errorMessage: error?.responseJSON?.data |
| 1645 | }); |
| 1646 | self.cleanUp( |
| 1647 | 'UPLOAD_CHUNK_FAILURE', |
| 1648 | error.responseJSON, |
| 1649 | false, |
| 1650 | null, |
| 1651 | $('#progress__uploadBackup') |
| 1652 | ); |
| 1653 | }); |
| 1654 | }; |
| 1655 | |
| 1656 | /** |
| 1657 | * Fire the complete upload to finalize the upload process |
| 1658 | * |
| 1659 | * @param uploadId |
| 1660 | * @param type |
| 1661 | * @param ignoreLocalUploadProperties - If the DB is excluded ignores the upload flags and process the start |
| 1662 | * StartMigration method straight after the completeUpload has succeeded |
| 1663 | */ |
| 1664 | this.completeUpload = function(uploadId, type, ignoreLocalUploadProperties) { |
| 1665 | var self = this; |
| 1666 | var data = { |
| 1667 | action: 'complete_upload', |
| 1668 | uploadId: uploadId, |
| 1669 | archiveType: type |
| 1670 | }; |
| 1671 | var completeUpload = $.post(ajaxurl, data, function(response) { |
| 1672 | |
| 1673 | /** |
| 1674 | * Set the backup to completed |
| 1675 | */ |
| 1676 | self.utilities.updateProgressStep('completed', $('#progress__uploadBackup')); |
| 1677 | |
| 1678 | /** |
| 1679 | * Hide the progress step |
| 1680 | */ |
| 1681 | self.utilities.hideProgressPercentage($('#progressPercentage')); |
| 1682 | |
| 1683 | /** |
| 1684 | * If the ignore upload properties flag has been set |
| 1685 | * Start the migration right away |
| 1686 | */ |
| 1687 | if (ignoreLocalUploadProperties) { |
| 1688 | self.startMigration(response.data.securityKey); |
| 1689 | } |
| 1690 | |
| 1691 | /** |
| 1692 | * If both backup archives are present |
| 1693 | * Update the flag |
| 1694 | */ |
| 1695 | if (!ignoreLocalUploadProperties) { |
| 1696 | self.localUploadComplete[type] = true; |
| 1697 | |
| 1698 | /** |
| 1699 | * Start the migration |
| 1700 | */ |
| 1701 | self.startMigration(response.data.securityKey); |
| 1702 | } |
| 1703 | |
| 1704 | }); |
| 1705 | completeUpload.fail(function(error) { |
| 1706 | self.utilities.logEvent('failedMigration', { |
| 1707 | migrationStatus: 'uploadBackup - complete_upload', |
| 1708 | errorMessage: error?.responseJSON?.data |
| 1709 | }); |
| 1710 | self.cleanUp( |
| 1711 | 'UPLOAD_COMPLETION_FAILURE', |
| 1712 | error.responseJSON, |
| 1713 | false, |
| 1714 | null, |
| 1715 | $('#progress__uploadBackup') |
| 1716 | ); |
| 1717 | }); |
| 1718 | }; |
| 1719 | |
| 1720 | /** |
| 1721 | * Clean up either fail or complete |
| 1722 | */ |
| 1723 | this.cleanUp = function ( |
| 1724 | hasError = false, |
| 1725 | errors = [], |
| 1726 | ignoreTemplateSwitch = false, |
| 1727 | metadata = null, |
| 1728 | selector = null, |
| 1729 | localMigration = false |
| 1730 | ) { |
| 1731 | |
| 1732 | var self = this; |
| 1733 | $.post(ajaxurl, { |
| 1734 | action: 'clean_up_files', |
| 1735 | securityKey: $('#cleanUpNonce').val(), |
| 1736 | hasError: hasError, |
| 1737 | errors: errors, |
| 1738 | metadata: metadata, |
| 1739 | localMigration: localMigration |
| 1740 | }) |
| 1741 | .always(function(response) { |
| 1742 | /** |
| 1743 | * Only change the template if the flag exists |
| 1744 | */ |
| 1745 | if (!ignoreTemplateSwitch && typeof response.data.htmlTemplate === 'string') { |
| 1746 | self.utilities.setTemplate(response.data.htmlTemplate); |
| 1747 | } |
| 1748 | |
| 1749 | /** |
| 1750 | * Display inline error |
| 1751 | */ |
| 1752 | if (!ignoreTemplateSwitch && typeof response.data.htmlTemplate !== 'string') { |
| 1753 | self.utilities.displayMigrationProgressFailure( |
| 1754 | selector, |
| 1755 | response.data.htmlTemplate.error |
| 1756 | ); |
| 1757 | } |
| 1758 | }); |
| 1759 | }; |
| 1760 | |
| 1761 | /** |
| 1762 | * Start looking for the WP installation directory |
| 1763 | */ |
| 1764 | this.startDirectorySearch = function() { |
| 1765 | var self = this; |
| 1766 | var securityKey = $('#directoryKey').val(); |
| 1767 | var directoryRequest = $.post(ajaxurl, { |
| 1768 | action: 'start_directory_search', |
| 1769 | securityKey: securityKey, |
| 1770 | }); |
| 1771 | |
| 1772 | directoryRequest.done(function(response) { |
| 1773 | var url = response?.data?.url; |
| 1774 | var directoryCheckId = response?.data?.directoryCheckId; |
| 1775 | self.getDirectoryCheckUpdate(url, directoryCheckId); |
| 1776 | }); |
| 1777 | |
| 1778 | directoryRequest.fail(function(response) { |
| 1779 | self.screenRouting( |
| 1780 | 'ftpAuthentication', |
| 1781 | '', |
| 1782 | '', |
| 1783 | 'errorFailedDirectorySearch' |
| 1784 | ); |
| 1785 | }); |
| 1786 | } |
| 1787 | |
| 1788 | /** |
| 1789 | * Poll to update UI on the status of the directory check |
| 1790 | * |
| 1791 | * @param url |
| 1792 | * @param directoryCheckId |
| 1793 | */ |
| 1794 | this.getDirectoryCheckUpdate = function(url, directoryCheckId) { |
| 1795 | var self = this; |
| 1796 | var securityKey = $('#directoryKey').val(); |
| 1797 | var directoryRequest = $.post(ajaxurl, { |
| 1798 | action: 'get_directory_check_update', |
| 1799 | securityKey: securityKey, |
| 1800 | url: url, |
| 1801 | directoryCheckId: directoryCheckId |
| 1802 | }); |
| 1803 | |
| 1804 | directoryRequest.done(function(response) { |
| 1805 | /** |
| 1806 | * If the check is still in process |
| 1807 | */ |
| 1808 | if (!response.data.complete && !response.data.found) { |
| 1809 | /** |
| 1810 | * Prefix an empty path |
| 1811 | */ |
| 1812 | var path = !response?.data?.path ? '/' : response.data.path; |
| 1813 | |
| 1814 | /** |
| 1815 | * Update the path in the UI |
| 1816 | */ |
| 1817 | $('#currentFTPPathCheck').html(path); |
| 1818 | |
| 1819 | /** |
| 1820 | * Continue to poll |
| 1821 | */ |
| 1822 | self.getDirectoryCheckUpdate(url, directoryCheckId) |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * If the directory has been found |
| 1827 | */ |
| 1828 | if (response.data.complete && response.data.found) { |
| 1829 | $('#manualDirectorySelection').prop('disabled', false); |
| 1830 | $('#ftpDirectorySelector').addClass('transferito__hide-element'); |
| 1831 | $('#directorySelectionCheckSuccess').removeClass('transferito__hide-element'); |
| 1832 | } |
| 1833 | |
| 1834 | /** |
| 1835 | * The directory cant be found on this server |
| 1836 | */ |
| 1837 | if (response.data.complete && !response.data.found) { |
| 1838 | self.screenRouting('ftpAuthentication', '', '', 'errorDirectoryNotFound'); |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * The directory check has completed with a failure |
| 1843 | */ |
| 1844 | if (response.data.complete && response.data.failed) { |
| 1845 | self.screenRouting('ftpAuthentication', '', '', 'errorDirectoryUpdateFailed'); |
| 1846 | } |
| 1847 | |
| 1848 | }); |
| 1849 | |
| 1850 | /** |
| 1851 | * The directory status update has failed |
| 1852 | */ |
| 1853 | directoryRequest.fail(function(response) { |
| 1854 | self.screenRouting('ftpAuthentication', '', '', 'errorDirectoryUpdateFailed'); |
| 1855 | }); |
| 1856 | } |
| 1857 | |
| 1858 | /** |
| 1859 | * Check the URL - To see if cPanel is available |
| 1860 | * |
| 1861 | * @param domain |
| 1862 | * @param localMigration |
| 1863 | * @param wpNonce |
| 1864 | * @param message |
| 1865 | * @param subMessage |
| 1866 | */ |
| 1867 | this.checkCpanelAvailability = function (domain, localMigration, wpNonce, message, subMessage) { |
| 1868 | /** |
| 1869 | * Show the loading screen |
| 1870 | */ |
| 1871 | this.utilities.showLoadingScreen(message, subMessage); |
| 1872 | |
| 1873 | /** |
| 1874 | * |
| 1875 | */ |
| 1876 | var self = this; |
| 1877 | var data = { |
| 1878 | action: 'check_cpanel_availability', |
| 1879 | domain: domain, |
| 1880 | localMigration: localMigration, |
| 1881 | securityKey: wpNonce |
| 1882 | }; |
| 1883 | var cPanelCheck = $.post(ajaxurl, data, function(response) { |
| 1884 | |
| 1885 | var transferMethod = response.data.transferMethod; |
| 1886 | var cPanelAllowed = response.data.cPanelAllowed; |
| 1887 | |
| 1888 | self.utilities.setTransferMethodOptions(transferMethod, cPanelAllowed); |
| 1889 | |
| 1890 | /** |
| 1891 | * |
| 1892 | */ |
| 1893 | if (transferMethod === 'localSiteMigration') { |
| 1894 | /** |
| 1895 | * Create the migration payload |
| 1896 | */ |
| 1897 | self.prepareMigration( |
| 1898 | { |
| 1899 | transferMethod: transferMethod, |
| 1900 | }, |
| 1901 | response.data.securityToken |
| 1902 | ); |
| 1903 | } else { |
| 1904 | self.utilities.setTemplate(response.data.htmlTemplate); |
| 1905 | } |
| 1906 | }); |
| 1907 | cPanelCheck.fail(function(error) { |
| 1908 | self.utilities.logEvent('failedMigration', { |
| 1909 | migrationStatus: 'destinationURL', |
| 1910 | errorMessage: error?.responseJSON?.data |
| 1911 | }); |
| 1912 | /** |
| 1913 | * Route to screen |
| 1914 | * No message |
| 1915 | * Display Error Modal |
| 1916 | */ |
| 1917 | self.screenRouting('destinationURL', '', '', 'errorIncorrectModal'); |
| 1918 | }); |
| 1919 | }; |
| 1920 | |
| 1921 | /** |
| 1922 | * Switch the migration method |
| 1923 | * |
| 1924 | * @param transferMethod |
| 1925 | * @param message |
| 1926 | * @param subMessage |
| 1927 | */ |
| 1928 | this.switchMode = function(transferMethod, message, subMessage) { |
| 1929 | /** |
| 1930 | * Show the loading screen |
| 1931 | */ |
| 1932 | this.utilities.showLoadingScreen(message, subMessage); |
| 1933 | |
| 1934 | /** |
| 1935 | * Call the API to switch the transfer method |
| 1936 | */ |
| 1937 | var self = this; |
| 1938 | var data = { |
| 1939 | action: 'switch_mode', |
| 1940 | securityKey: $('#nonce').val(), |
| 1941 | method: transferMethod |
| 1942 | }; |
| 1943 | var switchMode = $.post(ajaxurl, data, function(response) { |
| 1944 | self.utilities.setTransferMethodOptions(response.data.transferMethod, response.data.cPanelAllowed); |
| 1945 | self.utilities.setTemplate(response.data.htmlTemplate); |
| 1946 | }); |
| 1947 | switchMode.fail(function(error) { |
| 1948 | /** |
| 1949 | * @todo Remove - Display popup instead |
| 1950 | */ |
| 1951 | self.cleanUp('SWITCH_METHOD_FAILED', error.responseJSON); |
| 1952 | }); |
| 1953 | }; |
| 1954 | |
| 1955 | /** |
| 1956 | * Auth the cPanel request and move to the next step |
| 1957 | * |
| 1958 | * @param securityKey |
| 1959 | * @param message |
| 1960 | * @param cpanelDetails |
| 1961 | * @param selector |
| 1962 | */ |
| 1963 | this.cpanelAuthentication = function(securityKey, cpanelDetails, message, subMessage) { |
| 1964 | /** |
| 1965 | * Show the loading screen |
| 1966 | */ |
| 1967 | this.utilities.showLoadingScreen(message, subMessage); |
| 1968 | |
| 1969 | /** |
| 1970 | * |
| 1971 | */ |
| 1972 | var self = this; |
| 1973 | var data = { |
| 1974 | action: 'cpanel_authentication', |
| 1975 | auth: cpanelDetails, |
| 1976 | securityKey: securityKey |
| 1977 | }; |
| 1978 | var cpanelAuth = $.post(ajaxurl, data, function(response) { |
| 1979 | /** |
| 1980 | * Show the new template |
| 1981 | */ |
| 1982 | self.utilities.setTemplate(response.data.template); |
| 1983 | |
| 1984 | }); |
| 1985 | cpanelAuth.fail(function(error) { |
| 1986 | self.utilities.logEvent('failedMigration', { |
| 1987 | migrationStatus: 'cPanelAuth', |
| 1988 | errorMessage: error?.responseJSON?.data |
| 1989 | }); |
| 1990 | /** |
| 1991 | * Route to screen |
| 1992 | * No message |
| 1993 | * Display Error Modal |
| 1994 | */ |
| 1995 | self.screenRouting('cpanelAuthentication', '', '', 'errorFailedCpanelAuth'); |
| 1996 | }); |
| 1997 | }; |
| 1998 | |
| 1999 | /** |
| 2000 | * Validate the server detail |
| 2001 | * |
| 2002 | * @param securityKey |
| 2003 | * @param message |
| 2004 | * @param serverDetails |
| 2005 | * @param selector |
| 2006 | */ |
| 2007 | this.manualServerDetailValidation = function(securityKey, serverDetails, message, subMessage) { |
| 2008 | /** |
| 2009 | * Show the loading screen |
| 2010 | */ |
| 2011 | this.utilities.showLoadingScreen(message, subMessage); |
| 2012 | |
| 2013 | /** |
| 2014 | * Validate the FTP details |
| 2015 | */ |
| 2016 | var self = this; |
| 2017 | var data = { |
| 2018 | action: 'server_detail_validation', |
| 2019 | serverDetails: serverDetails, |
| 2020 | securityKey: securityKey |
| 2021 | }; |
| 2022 | var serverDetailValidation = $.post(ajaxurl, data, function(response) { |
| 2023 | |
| 2024 | /** |
| 2025 | * Show the new template |
| 2026 | */ |
| 2027 | self.utilities.setTemplate(response.data.template); |
| 2028 | |
| 2029 | /** |
| 2030 | * Disable the button |
| 2031 | */ |
| 2032 | $('#manualDirectorySelection').prop('disabled', true); |
| 2033 | |
| 2034 | /** |
| 2035 | * Start directory check call |
| 2036 | */ |
| 2037 | self.startDirectorySearch(); |
| 2038 | }); |
| 2039 | serverDetailValidation.fail(function(error) { |
| 2040 | self.utilities.logEvent('failedMigration', { |
| 2041 | migrationStatus: 'ftpAuth', |
| 2042 | errorMessage: error?.responseJSON?.data |
| 2043 | }); |
| 2044 | /** |
| 2045 | * Route to screen |
| 2046 | * No message |
| 2047 | * Display Error Modal |
| 2048 | */ |
| 2049 | self.screenRouting('ftpAuthentication', '', '', 'errorFailedFTPAuth'); |
| 2050 | }); |
| 2051 | }; |
| 2052 | |
| 2053 | /** |
| 2054 | * Validate the database details |
| 2055 | * |
| 2056 | * @param securityKey |
| 2057 | * @param message |
| 2058 | * @param databaseDetail |
| 2059 | * @param selector |
| 2060 | */ |
| 2061 | this.databaseDetailValidation = function(securityKey, databaseDetail, message, subMessage) { |
| 2062 | var self = this; |
| 2063 | |
| 2064 | /** |
| 2065 | * Show the loading screen |
| 2066 | */ |
| 2067 | this.utilities.showLoadingScreen(message, subMessage); |
| 2068 | |
| 2069 | /** |
| 2070 | * Validate the correct directory |
| 2071 | */ |
| 2072 | var data = { |
| 2073 | action: 'database_detail_validation', |
| 2074 | databaseDetail: databaseDetail, |
| 2075 | securityKey: securityKey |
| 2076 | }; |
| 2077 | var databaseValidation = $.post(ajaxurl, data, function(response) { |
| 2078 | /** |
| 2079 | * Begin the migration process |
| 2080 | */ |
| 2081 | self.prepareMigration(response.data.migrationDetail, response.data.securityKey); |
| 2082 | }); |
| 2083 | databaseValidation.fail(function(error) { |
| 2084 | self.utilities.logEvent('failedMigration', { |
| 2085 | migrationStatus: 'databaseAuth', |
| 2086 | errorMessage: error?.responseJSON?.data |
| 2087 | }); |
| 2088 | self.screenRouting('databaseAuthentication', '', '', 'errorFailedDatabaseAuth'); |
| 2089 | }); |
| 2090 | }; |
| 2091 | |
| 2092 | /** |
| 2093 | * Load the directory Selector |
| 2094 | */ |
| 2095 | this.loadDirectoryTemplate = function() { |
| 2096 | var self = this; |
| 2097 | $.post(ajaxurl, { action: 'load_directory_template' }) |
| 2098 | .always(function(response) { |
| 2099 | self.utilities.setTemplate(response.data.template, $('#manualScreenTemplate')); |
| 2100 | |
| 2101 | /** |
| 2102 | * Update the navigation |
| 2103 | */ |
| 2104 | $('#transferitoNav__manualFTPDirectorySelect') |
| 2105 | .removeClass('transferito-nav__item__indicator--in-complete') |
| 2106 | .removeClass('transferito-nav__item__indicator--completed'); |
| 2107 | |
| 2108 | /** |
| 2109 | * Fire directory call |
| 2110 | */ |
| 2111 | self.getDirectories(response.data.path); |
| 2112 | }); |
| 2113 | }; |
| 2114 | |
| 2115 | /** |
| 2116 | * Hide the quick start popup once they click the close button |
| 2117 | */ |
| 2118 | this.hideQuickStartPopup = function () { |
| 2119 | $.post(ajaxurl, { |
| 2120 | action: 'hide_quickstart_popup' |
| 2121 | }) |
| 2122 | .always(function(response) {}) |
| 2123 | }; |
| 2124 | |
| 2125 | /** |
| 2126 | * Redirect a user to a particular screen |
| 2127 | * |
| 2128 | * @param route |
| 2129 | * @param message |
| 2130 | * @param subMessage |
| 2131 | * @param showModal |
| 2132 | * @param customizedModalContent |
| 2133 | */ |
| 2134 | this.screenRouting = function(route, message, subMessage, showModal, customizedModalContent) { |
| 2135 | /** |
| 2136 | * Only show if a message exists |
| 2137 | */ |
| 2138 | if (message) { |
| 2139 | /** |
| 2140 | * Show the loading screen |
| 2141 | */ |
| 2142 | this.utilities.showLoadingScreen(message, subMessage); |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * Log event |
| 2147 | */ |
| 2148 | this.utilities.logEvent('screenRouting', { |
| 2149 | screen: route |
| 2150 | }); |
| 2151 | |
| 2152 | var self = this; |
| 2153 | var data = { |
| 2154 | action: 'screen_route_redirection', |
| 2155 | securityKey: $('#nonce').val(), |
| 2156 | route: route |
| 2157 | }; |
| 2158 | |
| 2159 | var routeScreen = $.post(ajaxurl, data, function(response) { |
| 2160 | self.utilities.setTemplate(response.data.htmlTemplate); |
| 2161 | |
| 2162 | if (route === 'directorySelector') { |
| 2163 | $('#manualDirectorySelection').prop('disabled', true); |
| 2164 | |
| 2165 | /** |
| 2166 | * Start directory check call |
| 2167 | */ |
| 2168 | self.startDirectorySearch(); |
| 2169 | } |
| 2170 | |
| 2171 | if (showModal) { |
| 2172 | self.utilities.displayModal(showModal, customizedModalContent); |
| 2173 | } |
| 2174 | }); |
| 2175 | routeScreen.fail(function(error) { |
| 2176 | self.utilities.logEvent('failedRouting', { |
| 2177 | route: route |
| 2178 | }); |
| 2179 | }); |
| 2180 | }; |
| 2181 | |
| 2182 | /** |
| 2183 | * Send the guide request |
| 2184 | */ |
| 2185 | this.sendGuideRequestForm = function(hostingDetail, message, subMessage) { |
| 2186 | /** |
| 2187 | * Add a loader into the modal Div |
| 2188 | */ |
| 2189 | this.utilities.setTemplate(this.utilities.loadingOnlyHTML(), this.utilities.modalSelector, 500); |
| 2190 | |
| 2191 | var self = this; |
| 2192 | var data = { |
| 2193 | action: 'send_request_form', |
| 2194 | data: hostingDetail, |
| 2195 | securityKey: hostingDetail.securityKey |
| 2196 | }; |
| 2197 | |
| 2198 | var sendRequest = $.post(ajaxurl, data); |
| 2199 | sendRequest.always(function() { |
| 2200 | self.utilities.displayModal('successSentGuideRequest'); |
| 2201 | }); |
| 2202 | } |
| 2203 | |
| 2204 | /** |
| 2205 | * Check the API Keys Validity |
| 2206 | */ |
| 2207 | this.apiValidityCheck = function(apiCheckPayload, loadingSelector) { |
| 2208 | /** |
| 2209 | * Set the loading spinner |
| 2210 | */ |
| 2211 | this.utilities.setTemplate( |
| 2212 | this.utilities.loadingScreenHTML( |
| 2213 | 'Please wait...', |
| 2214 | 'We are just validating your API Keys.' |
| 2215 | ), |
| 2216 | loadingSelector |
| 2217 | ); |
| 2218 | |
| 2219 | /** |
| 2220 | * Show the element |
| 2221 | */ |
| 2222 | loadingSelector.removeClass('transferito__hide-element'); |
| 2223 | |
| 2224 | var self = this; |
| 2225 | var data = { |
| 2226 | action: 'check_premium_api_keys', |
| 2227 | data: apiCheckPayload, |
| 2228 | securityKey: apiCheckPayload.securityKey |
| 2229 | }; |
| 2230 | |
| 2231 | /** |
| 2232 | * The API Keys are valid |
| 2233 | */ |
| 2234 | var sendRequest = $.post(ajaxurl, data, function(response) { |
| 2235 | /** |
| 2236 | * Clear the loading Selector |
| 2237 | */ |
| 2238 | self.utilities.setTemplate('', loadingSelector); |
| 2239 | |
| 2240 | /** |
| 2241 | * Display the Success Message |
| 2242 | */ |
| 2243 | $('#upgradeToPremiumCheckComplete').removeClass('transferito__hide-element'); |
| 2244 | |
| 2245 | /** |
| 2246 | * Log event |
| 2247 | */ |
| 2248 | self.utilities.logEvent('upgradeToPremiumModalSuccess', { |
| 2249 | upgraded: true |
| 2250 | }); |
| 2251 | }); |
| 2252 | |
| 2253 | /** |
| 2254 | * The API Keys aren't valid |
| 2255 | */ |
| 2256 | sendRequest.fail(function() { |
| 2257 | /** |
| 2258 | * Clear the loading Selector |
| 2259 | */ |
| 2260 | self.utilities.setTemplate('', loadingSelector); |
| 2261 | |
| 2262 | /** |
| 2263 | * Display the Entry Form |
| 2264 | */ |
| 2265 | $('#upgradeToPremiumAPIKeyEntry').removeClass('transferito__hide-element'); |
| 2266 | |
| 2267 | /** |
| 2268 | * Display the Error Message |
| 2269 | */ |
| 2270 | $('#upgradeToPremiumErrorMessage').removeClass('transferito__hide-element'); |
| 2271 | }); |
| 2272 | |
| 2273 | } |
| 2274 | |
| 2275 | /** |
| 2276 | * Send user through the premium upgrade flow |
| 2277 | */ |
| 2278 | this.inPluginPurchase = function(migrationDetails, key) { |
| 2279 | |
| 2280 | /** |
| 2281 | * Log event |
| 2282 | */ |
| 2283 | transferito.utilities.logEvent('upgradeToPremiumModalFired', { |
| 2284 | fired: true |
| 2285 | }); |
| 2286 | |
| 2287 | /** |
| 2288 | * Save the migration details |
| 2289 | */ |
| 2290 | transferito.utilities.saveTempMigrationDetails(migrationDetails, key); |
| 2291 | |
| 2292 | /** |
| 2293 | * Fire the modal |
| 2294 | */ |
| 2295 | transferito.utilities.displayModal('upgradeToPremiumPaymentModal'); |
| 2296 | } |
| 2297 | |
| 2298 | /** |
| 2299 | * Download the verification File to Connect to Destination Server |
| 2300 | */ |
| 2301 | this.downloadVerificationFile = function(securityKey) { |
| 2302 | |
| 2303 | var self = this; |
| 2304 | var data = { |
| 2305 | action: 'download_transferito_verification_file', |
| 2306 | securityKey: securityKey |
| 2307 | }; |
| 2308 | |
| 2309 | /** |
| 2310 | * The API Keys are valid |
| 2311 | */ |
| 2312 | var sendRequest = $.post(ajaxurl, data, function(response) { |
| 2313 | |
| 2314 | var anchor = document.createElement('a'); |
| 2315 | anchor.href = response.data.url; |
| 2316 | anchor.target = '_blank'; |
| 2317 | anchor.click(); |
| 2318 | |
| 2319 | $('#destinationServerConnectionCheckInProgress').removeClass('transferito__hide-element'); |
| 2320 | |
| 2321 | /** |
| 2322 | * Check connection |
| 2323 | */ |
| 2324 | self.validateConnection(securityKey); |
| 2325 | |
| 2326 | }); |
| 2327 | |
| 2328 | sendRequest.fail(function (res) { |
| 2329 | $('#destinationServerCheckStart').addClass('transferito__hide-element'); |
| 2330 | $('#destinationServerConnectionCheckInProgress').addClass('transferito__hide-element'); |
| 2331 | $('#destinationServerCheckCompletion').addClass('transferito__hide-element'); |
| 2332 | |
| 2333 | $('#destinationServerCheckFailure').removeClass('transferito__hide-element'); |
| 2334 | }); |
| 2335 | } |
| 2336 | |
| 2337 | /** |
| 2338 | * Check the connection status |
| 2339 | */ |
| 2340 | this.validateConnection = function(securityKey) { |
| 2341 | var self = this; |
| 2342 | var data = { |
| 2343 | action: 'transferito_validate_destination_server_connection', |
| 2344 | securityKey: securityKey |
| 2345 | }; |
| 2346 | |
| 2347 | /** |
| 2348 | * The API Keys are valid |
| 2349 | */ |
| 2350 | var sendRequest = $.post(ajaxurl, data, function(response) { |
| 2351 | $('#destinationServerCheckStart').addClass('transferito__hide-element'); |
| 2352 | $('#destinationServerConnectionCheckInProgress').addClass('transferito__hide-element'); |
| 2353 | $('#destinationServerCheckCompletion').removeClass('transferito__hide-element'); |
| 2354 | $('#proceedAfterDestinationServerConnection').prop('disabled', false); |
| 2355 | }); |
| 2356 | |
| 2357 | sendRequest.fail(function (res) { |
| 2358 | setTimeout(function (){ |
| 2359 | self.validateConnection(securityKey) |
| 2360 | }, 5000); |
| 2361 | }) |
| 2362 | } |
| 2363 | |
| 2364 | this.hideWelcomeScreen = function(securityKey) { |
| 2365 | var data = { |
| 2366 | action: 'transferito_hide_welcome_screen', |
| 2367 | securityKey: securityKey |
| 2368 | }; |
| 2369 | /** |
| 2370 | * The API Keys are valid |
| 2371 | */ |
| 2372 | var sendRequest = $.post(ajaxurl, data, function(response) {}); |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * Initialize |
| 2378 | */ |
| 2379 | var transferito = new Transferito(); |
| 2380 | |
| 2381 | /** |
| 2382 | * Check the status of the site |
| 2383 | * If it is a FREE Transfer or not |
| 2384 | */ |
| 2385 | transferito.checkSite(); |
| 2386 | |
| 2387 | /** |
| 2388 | * @todo InAPP Modal Upgrade - Event Listener |
| 2389 | */ |
| 2390 | window.addEventListener('message', (event) => { |
| 2391 | if (event?.data?.type === 'transferitoNotifyParent') { |
| 2392 | |
| 2393 | /** |
| 2394 | * Log event |
| 2395 | */ |
| 2396 | transferito.utilities.logEvent('upgradeToPremiumModalButtonClicked', { |
| 2397 | fired: true |
| 2398 | }); |
| 2399 | |
| 2400 | /** |
| 2401 | * Remove the iFRAME |
| 2402 | */ |
| 2403 | $('#upgradeToPremiumIFrame').remove(); |
| 2404 | |
| 2405 | /** |
| 2406 | * Display the API Key Entry Form |
| 2407 | */ |
| 2408 | $('#upgradeToPremiumAPIKeyEntry').removeClass('transferito__hide-element'); |
| 2409 | } |
| 2410 | }); |
| 2411 | |
| 2412 | |
| 2413 | |
| 2414 | /** |
| 2415 | * |
| 2416 | */ |
| 2417 | transferito.utilities.selector.on('click', '.transferito-ftp-authentication__folder-expander', function () { |
| 2418 | var childItems = $(this).next('.transferito-ftp-authentication__sub-folders'); |
| 2419 | if (childItems.length === 0) { |
| 2420 | return false; |
| 2421 | } |
| 2422 | childItems.toggle(); |
| 2423 | }); |
| 2424 | |
| 2425 | /** |
| 2426 | * |
| 2427 | */ |
| 2428 | transferito.utilities.selector.on('change', '.show-selected-folder', function() { |
| 2429 | $('#selectedFoldersDetails').toggle(); |
| 2430 | }); |
| 2431 | |
| 2432 | /** |
| 2433 | * Hide or show the Database Fields |
| 2434 | * Based on whether the checkbox is ticked or not |
| 2435 | */ |
| 2436 | transferito.utilities.selector.on('change', '.transferito__hide-database-details', function() { |
| 2437 | |
| 2438 | var excludeDatabaseSelector = $('#excludeDatabase'); |
| 2439 | var useExistingDatabaseSelector = $('#useExistingDatabase'); |
| 2440 | var selector = $(this); |
| 2441 | |
| 2442 | var excludeDatabase = excludeDatabaseSelector.prop('checked'); |
| 2443 | var useExistingDatabase = useExistingDatabaseSelector.prop('checked'); |
| 2444 | |
| 2445 | var oneSelected = (excludeDatabase || useExistingDatabase); |
| 2446 | var databaseFields = $('.transferito-database-authentication__input-fields'); |
| 2447 | |
| 2448 | var idToUncheck = selector.data('uncheckId'); |
| 2449 | var checkboxChecked = selector.prop('checked'); |
| 2450 | |
| 2451 | if (checkboxChecked) { |
| 2452 | var uncheckableID = '#' + idToUncheck; |
| 2453 | $(uncheckableID).prop('checked', false) |
| 2454 | } |
| 2455 | |
| 2456 | databaseFields.toggleClass('transferito-database-authentication__input-fields--hide', oneSelected); |
| 2457 | $('#manualServerMigrationStart').prop('disabled', !transferito.utilities.validateFormFields()); |
| 2458 | }); |
| 2459 | |
| 2460 | /** |
| 2461 | * Remove the error from the validation fields |
| 2462 | */ |
| 2463 | transferito.utilities.selector.on('keyup', '.transferito-input--error > .transferito-required', function() { |
| 2464 | var selector = $(this); |
| 2465 | if (selector.val()) { |
| 2466 | selector.parent().removeClass('transferito-input--error') |
| 2467 | } |
| 2468 | }); |
| 2469 | |
| 2470 | /** |
| 2471 | * Validation check for the domain input field |
| 2472 | * Disable or Enable the button based on the validity of the domain field |
| 2473 | */ |
| 2474 | transferito.utilities.selector.on('keyup', '#domain', function() { |
| 2475 | var domainEntry = $(this).val(); |
| 2476 | var domainIsEmpty = domainEntry.length === 0; |
| 2477 | $('#cpanelCheck').prop('disabled', domainIsEmpty); |
| 2478 | }); |
| 2479 | |
| 2480 | /** |
| 2481 | * Open the modal by ID |
| 2482 | */ |
| 2483 | transferito.utilities.selector.on('click', '.transferito-open-modal', function() { |
| 2484 | var modalID = $(this).data('transferitoModal'); |
| 2485 | transferito.utilities.displayModal(modalID); |
| 2486 | }); |
| 2487 | |
| 2488 | /** |
| 2489 | * Open the modal by ID |
| 2490 | */ |
| 2491 | transferito.utilities.modalSelector.on('click', '.transferito-open-modal', function() { |
| 2492 | var modalID = $(this).data('transferitoModal'); |
| 2493 | transferito.utilities.displayModal(modalID); |
| 2494 | }); |
| 2495 | |
| 2496 | /** |
| 2497 | * Close the open modal |
| 2498 | */ |
| 2499 | transferito.utilities.modalSelector.on('click', '.transferito__modal--close', function() { |
| 2500 | transferito.utilities.closeModal(); |
| 2501 | }); |
| 2502 | |
| 2503 | /** |
| 2504 | * Check to see if we can use cPanel |
| 2505 | */ |
| 2506 | transferito.utilities.selector.on('click', '.transferito__check-cpanel-availability', function() { |
| 2507 | /** |
| 2508 | * Disable the Button to stop double checks |
| 2509 | */ |
| 2510 | $(this).prop('disabled', true); |
| 2511 | |
| 2512 | transferito.checkCpanelAvailability( |
| 2513 | $('#domainProtocol').val() + $('#domain').val(), |
| 2514 | $('#localSiteMigration').is(':checked'), |
| 2515 | $('#cPanelCheckSecurity').val(), |
| 2516 | 'Please wait...', |
| 2517 | 'We\'re just checking your URL' |
| 2518 | ); |
| 2519 | }); |
| 2520 | |
| 2521 | /** |
| 2522 | * Toggle the password visibility |
| 2523 | */ |
| 2524 | transferito.utilities.selector.on('click', '.transferito__password-visibility', function() { |
| 2525 | |
| 2526 | var visibleClass = 'transferito__password-visibility--visible'; |
| 2527 | var selector = $(this); |
| 2528 | var inputField = $('#' + selector.data('transferitoPasswordField')); |
| 2529 | var passwordMasked = !selector.hasClass(visibleClass); |
| 2530 | |
| 2531 | /** |
| 2532 | * If the password is masked |
| 2533 | */ |
| 2534 | if (passwordMasked) { |
| 2535 | /** |
| 2536 | * Add the visibility class |
| 2537 | */ |
| 2538 | selector.addClass(visibleClass); |
| 2539 | |
| 2540 | /** |
| 2541 | * Change the input type |
| 2542 | */ |
| 2543 | inputField.prop('type', 'text'); |
| 2544 | } |
| 2545 | |
| 2546 | /** |
| 2547 | * If the password is visible |
| 2548 | */ |
| 2549 | if (!passwordMasked) { |
| 2550 | /** |
| 2551 | * Remove the visibility class |
| 2552 | */ |
| 2553 | selector.removeClass(visibleClass); |
| 2554 | |
| 2555 | /** |
| 2556 | * Change the input type |
| 2557 | */ |
| 2558 | inputField.prop('type', 'password'); |
| 2559 | } |
| 2560 | }); |
| 2561 | |
| 2562 | /** |
| 2563 | * Switch the transfer method |
| 2564 | */ |
| 2565 | transferito.utilities.selector.on('click', '.transferito__switch-mode', function() { |
| 2566 | /** |
| 2567 | * Disable the Button to stop double checks |
| 2568 | */ |
| 2569 | $(this).prop('disabled', true); |
| 2570 | |
| 2571 | /** |
| 2572 | * Switch the transfer method |
| 2573 | */ |
| 2574 | transferito.switchMode( |
| 2575 | $(this).data('transferitoTransferMethod'), |
| 2576 | $(this).data('transferitoTransferMethodMessage') |
| 2577 | ); |
| 2578 | }); |
| 2579 | |
| 2580 | |
| 2581 | /** |
| 2582 | * Authenticate cPanel details |
| 2583 | */ |
| 2584 | transferito.utilities.selector.on('click', '.transferito__cpanel-authentication', function() { |
| 2585 | /** |
| 2586 | * Disable the Button to stop double checks |
| 2587 | */ |
| 2588 | $(this).prop('disabled', true); |
| 2589 | |
| 2590 | /** |
| 2591 | * Validate that all required form fields have been completed |
| 2592 | */ |
| 2593 | var validateFields = transferito.utilities.validateFormFields(); |
| 2594 | |
| 2595 | /** |
| 2596 | * If validation has passed |
| 2597 | */ |
| 2598 | if (validateFields) { |
| 2599 | /** |
| 2600 | * Get the cPanel information |
| 2601 | */ |
| 2602 | var cPanelDetails = transferito.utilities.buildPayload(); |
| 2603 | |
| 2604 | /** |
| 2605 | * Get the wpNonce |
| 2606 | */ |
| 2607 | var securityKey = $('#cPanelMigration').val(); |
| 2608 | |
| 2609 | /** |
| 2610 | * Start the authentication |
| 2611 | */ |
| 2612 | transferito.cpanelAuthentication( |
| 2613 | securityKey, |
| 2614 | cPanelDetails, |
| 2615 | 'Please wait..', |
| 2616 | 'We\'re just validating your cPanel details.', |
| 2617 | $('#cPanelScreenTemplate') |
| 2618 | ); |
| 2619 | |
| 2620 | $(this).prop('disabled', false); |
| 2621 | } |
| 2622 | |
| 2623 | /** |
| 2624 | * Enable the button if validation has failed |
| 2625 | */ |
| 2626 | if (!validateFields) { |
| 2627 | $(this).prop('disabled', false); |
| 2628 | } |
| 2629 | }); |
| 2630 | |
| 2631 | /** |
| 2632 | * Start the migration for cpanel |
| 2633 | */ |
| 2634 | transferito.utilities.selector.on('click', '.transferito__cpanel-start-migration', function() { |
| 2635 | /** |
| 2636 | * Disable the Button to stop double migrations |
| 2637 | */ |
| 2638 | $(this).prop('disabled', true); |
| 2639 | |
| 2640 | /** |
| 2641 | * The migration security key |
| 2642 | */ |
| 2643 | var securityKey = $('#prepareTransfer').val(); |
| 2644 | |
| 2645 | /** |
| 2646 | * Create the migration payload |
| 2647 | */ |
| 2648 | var cpanelMigrationDetails = { |
| 2649 | transferMethod: 'cpanel', |
| 2650 | cpanelHost: $('#cpanelHost').val(), |
| 2651 | cpanelUser: $('#cpanelUser').val(), |
| 2652 | cpanelPass: $('#cpanelPass').val(), |
| 2653 | cpanelApiToken: $('#cpanelApiToken').val(), |
| 2654 | useApiToken: $('#useApiToken').val(), |
| 2655 | domain: $('#field__cpanelDomain').val() |
| 2656 | }; |
| 2657 | |
| 2658 | /** |
| 2659 | * Set the loading spinner |
| 2660 | */ |
| 2661 | transferito.utilities.setTemplate( |
| 2662 | transferito |
| 2663 | .utilities |
| 2664 | .loadingScreenHTML('Please wait...', 'We are just creating your FTP & Database details.') |
| 2665 | ); |
| 2666 | |
| 2667 | /** |
| 2668 | * Start the migration |
| 2669 | */ |
| 2670 | transferito.prepareMigration(cpanelMigrationDetails, securityKey); |
| 2671 | }); |
| 2672 | |
| 2673 | /** |
| 2674 | * Validate main server details |
| 2675 | */ |
| 2676 | transferito.utilities.selector.on('click', '.transferito__manual-server-details', function() { |
| 2677 | /** |
| 2678 | * Disable the Button to stop double checks |
| 2679 | */ |
| 2680 | $(this).prop('disabled', true); |
| 2681 | |
| 2682 | /** |
| 2683 | * Validate that all required form fields have been completed |
| 2684 | */ |
| 2685 | var validateFields = transferito.utilities.validateFormFields(); |
| 2686 | |
| 2687 | /** |
| 2688 | * If validation has passed |
| 2689 | */ |
| 2690 | if (validateFields) { |
| 2691 | /** |
| 2692 | * Get the manual server details information |
| 2693 | */ |
| 2694 | var serverDetail = transferito.utilities.buildPayload(); |
| 2695 | |
| 2696 | /** |
| 2697 | * Get the wpNonce |
| 2698 | */ |
| 2699 | var securityKey = $('#manualMigrationServerDetail').val(); |
| 2700 | |
| 2701 | /** |
| 2702 | * Remove port numbers |
| 2703 | */ |
| 2704 | var hostProtocolSplit = serverDetail.ftpHost.split('://'); |
| 2705 | |
| 2706 | /** |
| 2707 | * Remove the protocol from the host |
| 2708 | */ |
| 2709 | var protocolRemoved = hostProtocolSplit.length === 1 ? hostProtocolSplit[0] : hostProtocolSplit[1]; |
| 2710 | |
| 2711 | /** |
| 2712 | * Remove the protocol |
| 2713 | */ |
| 2714 | var hostPortSplit = protocolRemoved.split(':'); |
| 2715 | |
| 2716 | /** |
| 2717 | * Assign the modified host |
| 2718 | */ |
| 2719 | serverDetail.ftpHost = hostPortSplit[0]; |
| 2720 | |
| 2721 | /** |
| 2722 | * Start the validation |
| 2723 | */ |
| 2724 | transferito.manualServerDetailValidation( |
| 2725 | securityKey, |
| 2726 | serverDetail, |
| 2727 | 'Please wait.. ', |
| 2728 | 'We\'re just validating your FTP details.', |
| 2729 | ); |
| 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * Enable the button if validation has failed |
| 2734 | */ |
| 2735 | if (!validateFields) { |
| 2736 | $(this).prop('disabled', false); |
| 2737 | } |
| 2738 | }); |
| 2739 | |
| 2740 | /** |
| 2741 | * Validate the correct directory |
| 2742 | * @todo Cleanup to mimic new search directories |
| 2743 | * @deprecated |
| 2744 | */ |
| 2745 | transferito.utilities.selector.on('click', '.transferito__directory-selection-validation', function() { |
| 2746 | /** |
| 2747 | * Disable the Button to stop double checks |
| 2748 | */ |
| 2749 | $(this).prop('disabled', true); |
| 2750 | |
| 2751 | /** |
| 2752 | * |
| 2753 | */ |
| 2754 | transferito.screenRouting( |
| 2755 | 'databaseAuthentication', |
| 2756 | 'Please wait...', |
| 2757 | 'While we load the database details screen' |
| 2758 | ); |
| 2759 | }); |
| 2760 | |
| 2761 | /** |
| 2762 | * Continue to the Database Entry Screen |
| 2763 | */ |
| 2764 | transferito.utilities.selector.on('click', '.transferito__proceed-to_database-details', function() { |
| 2765 | /** |
| 2766 | * Disable the Button to stop double checks |
| 2767 | */ |
| 2768 | $(this).prop('disabled', true); |
| 2769 | |
| 2770 | /** |
| 2771 | * |
| 2772 | */ |
| 2773 | transferito.screenRouting( |
| 2774 | 'databaseAuthentication', |
| 2775 | 'Please wait...', |
| 2776 | 'While we load the database details screen' |
| 2777 | ); |
| 2778 | }); |
| 2779 | |
| 2780 | |
| 2781 | /** |
| 2782 | * Validate the database details |
| 2783 | */ |
| 2784 | transferito.utilities.selector.on('click', '.transferito__start-manual-migration', function() { |
| 2785 | /** |
| 2786 | * Disable the Button to stop double checks |
| 2787 | */ |
| 2788 | $(this).prop('disabled', true); |
| 2789 | |
| 2790 | /** |
| 2791 | * Validate that all required form fields have been completed |
| 2792 | */ |
| 2793 | var validateFields = transferito.utilities.validateFormFields(); |
| 2794 | |
| 2795 | /** |
| 2796 | * If validation has passed |
| 2797 | */ |
| 2798 | if (validateFields) { |
| 2799 | /** |
| 2800 | * Get the manual server details information |
| 2801 | */ |
| 2802 | var databaseDetail = transferito.utilities.buildPayload(); |
| 2803 | |
| 2804 | /** |
| 2805 | * Get the wpNonce |
| 2806 | */ |
| 2807 | var securityKey = $('#manualMigrationDatabaseDetail').val(); |
| 2808 | |
| 2809 | /** |
| 2810 | * Start the validation |
| 2811 | */ |
| 2812 | transferito.databaseDetailValidation( |
| 2813 | securityKey, |
| 2814 | databaseDetail, |
| 2815 | 'Please wait..', |
| 2816 | 'We\'re just validating your database details' |
| 2817 | ); |
| 2818 | } |
| 2819 | |
| 2820 | /** |
| 2821 | * Re enable the button |
| 2822 | */ |
| 2823 | if (!validateFields) { |
| 2824 | $(this).prop('disabled', false); |
| 2825 | } |
| 2826 | |
| 2827 | }); |
| 2828 | |
| 2829 | /** |
| 2830 | * Return to ftp screen |
| 2831 | */ |
| 2832 | transferito.utilities.selector.on('click', '.transferito__edit-directory', function() { |
| 2833 | /** |
| 2834 | * Disable the Button to stop double checks |
| 2835 | */ |
| 2836 | $(this).prop('disabled', true); |
| 2837 | |
| 2838 | /** |
| 2839 | * |
| 2840 | */ |
| 2841 | transferito.loadDirectoryTemplate(); |
| 2842 | }); |
| 2843 | |
| 2844 | /** |
| 2845 | * Close the modal by clicking on the background |
| 2846 | */ |
| 2847 | transferito.utilities.selector.on('click', '.transferito__modal', function(event) { |
| 2848 | |
| 2849 | var parentClassList = $(event.target).parents(); |
| 2850 | |
| 2851 | /** |
| 2852 | * Only close the modal if the class list does not include the inner modal class |
| 2853 | */ |
| 2854 | if (!parentClassList.hasClass('transferito__modal__inner')) { |
| 2855 | $(this).closest('.transferito__modal').addClass('transferito__modal--hide'); |
| 2856 | } |
| 2857 | }); |
| 2858 | |
| 2859 | /** |
| 2860 | * Toggle cPanel API Token |
| 2861 | */ |
| 2862 | transferito.utilities.selector.on('change', '.show-cpanel-password', function() { |
| 2863 | $('#cpanelPasswordElement').toggleClass('transferito__hide-element'); |
| 2864 | $('#cpanelAPITokenElement').toggleClass('transferito__hide-element'); |
| 2865 | $('#cpanelAuth').prop('disabled', !transferito.utilities.validateFormFields()); |
| 2866 | }); |
| 2867 | |
| 2868 | /** |
| 2869 | * Close the quickstart |
| 2870 | */ |
| 2871 | transferito.utilities.selector.on('click', '.transferito__modal--hide-quickstart', function() { |
| 2872 | $(this).closest('.transferito__modal--without').addClass('transferito__modal--hide'); |
| 2873 | transferito.hideQuickStartPopup(); |
| 2874 | }); |
| 2875 | |
| 2876 | /** |
| 2877 | * Welcome screen - Change the selected migration method |
| 2878 | * Display a video based on the method |
| 2879 | */ |
| 2880 | transferito.utilities.modalSelector.on('click', '.transferito-migration-method__selection-method', function() { |
| 2881 | var selector = $(this); |
| 2882 | var videoID = selector.data('associatedTutorialVideoId'); |
| 2883 | var selectedClass = 'transferito-migration-method__selection-method--selected'; |
| 2884 | var hiddenElementClass = 'transferito__hide-element'; |
| 2885 | |
| 2886 | $('.transferito-migration-method__selection-method').removeClass(selectedClass); |
| 2887 | $('.transferito-migration-method__recommended').addClass(hiddenElementClass) |
| 2888 | |
| 2889 | selector.addClass(selectedClass); |
| 2890 | selector.find('.transferito-migration-method__recommended').removeClass(hiddenElementClass); |
| 2891 | |
| 2892 | var videoHTML = '<iframe allowFullScreen id="ytplayer" type="text/html" src="https://www.youtube.com/embed/' |
| 2893 | videoHTML += videoID; |
| 2894 | videoHTML += '?autoplay=0&fs=1&rel=0" frameBorder="0"></iframe>'; |
| 2895 | |
| 2896 | transferito.utilities.setTemplate( |
| 2897 | videoHTML, |
| 2898 | transferito.utilities.modalSelector.find('#welcomeScreenVideo') |
| 2899 | ); |
| 2900 | }); |
| 2901 | |
| 2902 | /** |
| 2903 | * Switch to the correct migration method |
| 2904 | */ |
| 2905 | transferito.utilities.selector.on('click', '#selectTransferitoMigrationMethod', function() { |
| 2906 | var migrationMethod = $('.transferito-migration-method__selection-method--selected').data('selectMigrationMethod'); |
| 2907 | transferito.switchMode(migrationMethod, 'Please wait...', 'We\'re just preparing your migration method'); |
| 2908 | }); |
| 2909 | |
| 2910 | /** |
| 2911 | * Route the screen back to a desired screen |
| 2912 | */ |
| 2913 | transferito.utilities.selector.on('click', '.transferito__screen-routing', function() { |
| 2914 | transferito.screenRouting( |
| 2915 | $(this).data('screenRoute'), |
| 2916 | 'Please wait...', |
| 2917 | 'While we redirect you to the correct screen' |
| 2918 | ); |
| 2919 | }); |
| 2920 | |
| 2921 | /** |
| 2922 | * Validate the cPanel auth screen form fields - by checking at least two have been completed |
| 2923 | */ |
| 2924 | transferito.utilities.selector.on('change keyup paste', '.transferito-cpanel-authentication__input input', function() { |
| 2925 | setTimeout(function(){ |
| 2926 | $('#cpanelAuth').prop('disabled', !transferito.utilities.validateFormFields()); |
| 2927 | },0); |
| 2928 | }); |
| 2929 | |
| 2930 | /** |
| 2931 | * Validate the ftp auth screen form fields - by checking at least two have been completed |
| 2932 | */ |
| 2933 | transferito.utilities.selector.on('change keyup paste', '.transferito-ftp-authentication__input input', function() { |
| 2934 | setTimeout(function(){ |
| 2935 | $('#manualServerDetails').prop('disabled', !transferito.utilities.validateFormFields()); |
| 2936 | },0); |
| 2937 | }); |
| 2938 | |
| 2939 | /** |
| 2940 | * Validate the database auth screen form fields - by checking at least two have been completed |
| 2941 | */ |
| 2942 | transferito.utilities.selector.on('change keyup paste', '.transferito-database-authentication__input input', function() { |
| 2943 | setTimeout(function(){ |
| 2944 | $('#manualServerMigrationStart').prop('disabled', !transferito.utilities.validateFormFields()); |
| 2945 | },0); |
| 2946 | }); |
| 2947 | |
| 2948 | /** |
| 2949 | * Validate the hosting form fields - by checking at least two have been completed |
| 2950 | */ |
| 2951 | transferito.utilities.modalSelector.on('change keyup transferito__field-required', '.transferito-information__form-field input', function() { |
| 2952 | $('#fireRequestHostingGuide').prop('disabled', !transferito.utilities.validateFormFields()); |
| 2953 | }); |
| 2954 | |
| 2955 | /** |
| 2956 | * Switch the information instructions based on the dropdown result |
| 2957 | */ |
| 2958 | transferito.utilities.modalSelector.on('change', '#selectHostingProvider', function() { |
| 2959 | var guideID = 'guideFor_' + $(this).val(); |
| 2960 | var guideName = $('#tutorialName').val(); |
| 2961 | var videoID = $(this).find(':selected').data('guideVideo'); |
| 2962 | |
| 2963 | $('.transferito-information__steps-list').each(function() { |
| 2964 | var currentID = $(this).attr('id'); |
| 2965 | |
| 2966 | if (currentID === guideID) { |
| 2967 | $(this).removeClass('transferito__hide-element'); |
| 2968 | } else if (guideID === 'guideFor_not-listed') { |
| 2969 | transferito.utilities.displayFormGuideModal('requestHostingGuideForm', guideName); |
| 2970 | } else if (currentID !== guideID) { |
| 2971 | $(this).addClass('transferito__hide-element'); |
| 2972 | } |
| 2973 | }); |
| 2974 | |
| 2975 | /** |
| 2976 | * If the option contains a videoID |
| 2977 | * Replace current video with the new videoID |
| 2978 | */ |
| 2979 | if (videoID) { |
| 2980 | var videoURL = 'https://www.youtube.com/embed/' + videoID + '?autoplay=1&fs=1&rel=0'; |
| 2981 | var videoIframe = $('.transferito-information__video iframe:visible'); |
| 2982 | videoIframe.attr('src', videoURL); |
| 2983 | } |
| 2984 | }); |
| 2985 | |
| 2986 | /** |
| 2987 | * Process sending the guide details |
| 2988 | */ |
| 2989 | transferito.utilities.modalSelector.on('click', '.transferito__request-hosting-guide', function() { |
| 2990 | /** |
| 2991 | * Disable the Button to stop double checks |
| 2992 | */ |
| 2993 | $(this).prop('disabled', true); |
| 2994 | |
| 2995 | /** |
| 2996 | * Validate that all required form fields have been completed |
| 2997 | */ |
| 2998 | var validateFields = transferito.utilities.validateFormFields(); |
| 2999 | |
| 3000 | /** |
| 3001 | * If validation has passed |
| 3002 | */ |
| 3003 | if (validateFields) { |
| 3004 | /** |
| 3005 | * Get the manual server details information |
| 3006 | */ |
| 3007 | var hostingGuideDetail = { |
| 3008 | securityKey: $('#hostingGuideDetails').val(), |
| 3009 | guideName: $('#hostingGuideName').val(), |
| 3010 | hostingProvider: $('#field__hostingProvider').val(), |
| 3011 | emailAddress: $('#field__emailAddress').val() |
| 3012 | }; |
| 3013 | |
| 3014 | transferito.sendGuideRequestForm( |
| 3015 | hostingGuideDetail, |
| 3016 | 'Please wait...', |
| 3017 | 'We\'re just sending your request' |
| 3018 | ); |
| 3019 | } |
| 3020 | |
| 3021 | /** |
| 3022 | * Re-enable the button |
| 3023 | */ |
| 3024 | if (!validateFields) { |
| 3025 | $(this).prop('disabled', false); |
| 3026 | } |
| 3027 | }); |
| 3028 | |
| 3029 | /** |
| 3030 | * Log Event on external links clicked |
| 3031 | */ |
| 3032 | $('#wpwrap').on('click', '.transferito-log-event', function() { |
| 3033 | transferito.utilities.logEvent('externalLinkClicked', { |
| 3034 | destination: $(this).data('eventName') |
| 3035 | }); |
| 3036 | }); |
| 3037 | |
| 3038 | /** |
| 3039 | * When the Destination URL is pasted or selected via input autofill dropdown |
| 3040 | * If the Destination URL has a protocol - Strip it and select the domain protocol |
| 3041 | */ |
| 3042 | transferito.utilities.selector.on('paste change', '#domain', function(event) { |
| 3043 | var target = $(event.target); |
| 3044 | |
| 3045 | setTimeout(function(){ |
| 3046 | var pastedContent = target.val(); |
| 3047 | var splitContent = pastedContent.trim().split('://'); |
| 3048 | |
| 3049 | /** |
| 3050 | * Validate the correct protocol will be selected |
| 3051 | */ |
| 3052 | if (splitContent.length === 2) { |
| 3053 | var allowedProtocols = ['http://', 'https://']; |
| 3054 | var defaultProtocol = allowedProtocols[0]; |
| 3055 | var protocol = splitContent[0] + '://'; |
| 3056 | var domain = splitContent[1]; |
| 3057 | var isUserSpecifiedProtocolAllowed = allowedProtocols.includes(protocol); |
| 3058 | var validatedProtocol = isUserSpecifiedProtocolAllowed ? protocol : defaultProtocol; |
| 3059 | |
| 3060 | $('#domain').val(domain); |
| 3061 | $('#domainProtocol').val(validatedProtocol); |
| 3062 | |
| 3063 | $('#cpanelCheck').prop('disabled', false); |
| 3064 | } |
| 3065 | },0); |
| 3066 | |
| 3067 | }); |
| 3068 | |
| 3069 | /** |
| 3070 | * When the Upgrade API Keys are pasted or changed |
| 3071 | * Enable or Disable the "ResumeMigration" button |
| 3072 | */ |
| 3073 | transferito.utilities.modalSelector.on('paste change keyup', '.transferito-input__upgrade-premium-api-keys', function(event) { |
| 3074 | setTimeout(function(){ |
| 3075 | var validateFields = transferito.utilities.validateFormFields(); |
| 3076 | |
| 3077 | /** |
| 3078 | * If the fields are validated |
| 3079 | * The "validateFormFields" method returns true |
| 3080 | * Flip the response |
| 3081 | */ |
| 3082 | $('#updateYourAPIKeys').prop('disabled', !validateFields); |
| 3083 | },0); |
| 3084 | }); |
| 3085 | |
| 3086 | /** |
| 3087 | * Process sending the guide details |
| 3088 | */ |
| 3089 | transferito.utilities.modalSelector.on('click', '.transferito_upgrade-save-api-keys', function() { |
| 3090 | /** |
| 3091 | * Disable the Button to stop double checks |
| 3092 | */ |
| 3093 | $(this).prop('disabled', true); |
| 3094 | |
| 3095 | /** |
| 3096 | * Validate that all required form fields have been completed |
| 3097 | */ |
| 3098 | var validateFields = transferito.utilities.validateFormFields(); |
| 3099 | |
| 3100 | /** |
| 3101 | * If validation has passed |
| 3102 | */ |
| 3103 | if (validateFields) { |
| 3104 | |
| 3105 | var loadingSelector = $('#upgradeToPremiumLoading'); |
| 3106 | var apiKeyPayload = { |
| 3107 | publicKey: $('#upgradePremiumPublicKey').val(), |
| 3108 | secretKey: $('#upgradePremiumSecretKey').val(), |
| 3109 | securityKey: $('#upgradePremiumValidation').val() |
| 3110 | }; |
| 3111 | |
| 3112 | /** |
| 3113 | * Hide API Entry Screen |
| 3114 | */ |
| 3115 | $('#upgradeToPremiumAPIKeyEntry').addClass('transferito__hide-element'); |
| 3116 | |
| 3117 | /** |
| 3118 | * Run the API Key Check |
| 3119 | */ |
| 3120 | transferito.apiValidityCheck(apiKeyPayload, loadingSelector); |
| 3121 | } |
| 3122 | |
| 3123 | }); |
| 3124 | |
| 3125 | /** |
| 3126 | * Process sending the guide details |
| 3127 | */ |
| 3128 | transferito.utilities.modalSelector.on('click', '.transferito_upgraded-in-app-resume-migration', function() { |
| 3129 | /** |
| 3130 | * Disable the Button to stop double migrations being fired |
| 3131 | */ |
| 3132 | $(this).prop('disabled', true); |
| 3133 | |
| 3134 | /** |
| 3135 | * Fire the migration with the previous details |
| 3136 | */ |
| 3137 | transferito.prepareMigration( |
| 3138 | transferito.utilities.tempMigrationDetails.details, |
| 3139 | transferito.utilities.tempMigrationDetails.key |
| 3140 | ); |
| 3141 | |
| 3142 | /** |
| 3143 | * Reset the temp migration details |
| 3144 | */ |
| 3145 | transferito.utilities.clearTempMigrationDetails(); |
| 3146 | }); |
| 3147 | |
| 3148 | /** |
| 3149 | * |
| 3150 | */ |
| 3151 | transferito.utilities.selector.on('click', '.transferito__download-verification-file', function() { |
| 3152 | |
| 3153 | /** |
| 3154 | * Disable the Button to stop double checks |
| 3155 | */ |
| 3156 | $(this).prop('disabled', true); |
| 3157 | |
| 3158 | var securityKey = $('#connectToServer').val(); |
| 3159 | transferito.downloadVerificationFile(securityKey); |
| 3160 | }); |
| 3161 | |
| 3162 | /** |
| 3163 | * Welcome screen - Change the selected migration method |
| 3164 | * Display a video based on the method |
| 3165 | */ |
| 3166 | transferito.utilities.modalSelector.on('click', '#hideWelcomeScreenPopup', function() { |
| 3167 | var selector = $(this); |
| 3168 | var checked = selector.prop('checked'); |
| 3169 | var securityKey = $('#welcomeScreenSecurity').val(); |
| 3170 | |
| 3171 | /** |
| 3172 | * Perform action when the site is checked |
| 3173 | */ |
| 3174 | if (checked) { |
| 3175 | /** |
| 3176 | * Close the modal - when this is checked |
| 3177 | */ |
| 3178 | transferito.utilities.closeModal(); |
| 3179 | |
| 3180 | /** |
| 3181 | * Update users preference to not show the welcome screen again |
| 3182 | */ |
| 3183 | transferito.hideWelcomeScreen(securityKey); |
| 3184 | } |
| 3185 | }); |
| 3186 | |
| 3187 | /** |
| 3188 | * |
| 3189 | */ |
| 3190 | $('body').on('click', '.transferito-open-support-modal', function () { |
| 3191 | var modalName = $(this).data('transferitoModal'); |
| 3192 | transferito.utilities.displayModal(modalName) |
| 3193 | }); |
| 3194 | |
| 3195 | }); |
| 3196 | |
| 3197 | })(jQuery); |
| 3198 |