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