From f5907bf476041d9db90bd4697992f8db384a1e08 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Mon, 16 Oct 2017 13:08:53 -0400 Subject: [PATCH] Some changes --- install/js/install-script.js | 14 ++++++++++---- install/js/migration-handler.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 install/js/migration-handler.js diff --git a/install/js/install-script.js b/install/js/install-script.js index ef4e54c9..b6515cb0 100644 --- a/install/js/install-script.js +++ b/install/js/install-script.js @@ -106,7 +106,7 @@ function executeMigration(migrationNumber, latestMigrationNumber, direction) { console.info('---'); if (migrationNumber === latestMigrationNumber || (migrationNumber === 1 && direction === 'down')) { updateProgressBar(migrationNumber, latestMigrationNumber, direction === 'down', true); - console.log('DONE'); + console.log('%c Success! ', 'color: white; background-color: green; font-size: 2em'); } else { updateProgressBar(migrationNumber, latestMigrationNumber, false, false); var newMigrationNumber = direction === 'up' ? migrationNumber + 1 : migrationNumber - 1; @@ -120,7 +120,15 @@ function executeMigration(migrationNumber, latestMigrationNumber, direction) { message = response.responseText; } $('#error-block').html("An error occurred! (Error Code: " + migrationNumber + ")
" + message).show(); - updateProgressBar(migrationNumber, latestMigrationNumber, true, true); + + updateProgressBar(migrationNumber, latestMigrationNumber, true, false); + + if (direction === 'up') { + // Revert! + executeMigration(migrationNumber - 1, 1, 'down'); + } else { + console.error("I even failed to roll back. Yikes! :'("); + } console.error(message); } }) @@ -136,8 +144,6 @@ function updateProgressBar(migrationNumber, latestMigrationNumber, isError, isFi if (isFinished) { var $errorBlock = $('#error-block'); $errorBlock.html($errorBlock.html() + '

Successfully reverted database to before the installation/update.'); - } else { - executeMigration(migrationNumber - 1, latestMigrationNumber, 'down', true); } } else { var percentage = Math.round(migrationNumber / latestMigrationNumber * 100); diff --git a/install/js/migration-handler.js b/install/js/migration-handler.js new file mode 100644 index 00000000..ba3793c6 --- /dev/null +++ b/install/js/migration-handler.js @@ -0,0 +1,14 @@ +function executeMigration(migrationNumber, direction, success, error) { + var heskPath = $('p#hesk-path').text(); + + $.ajax({ + url: heskPath + 'install/ajax/process-migration.php', + method: 'POST', + data: JSON.stringify({ + migrationNumber: migrationNumber, + direction: direction + }), + success: success(data), + error: error(data) + }) +} \ No newline at end of file