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