Files
firefly-iii/public/v1/js/ff/install/index.js

159 lines
5.0 KiB
JavaScript
Raw Normal View History

2018-03-10 07:17:05 +01:00
/*
* index.js
2020-02-16 13:59:41 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-03-10 07:17:05 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-03-10 07:17:05 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-03-10 07:17:05 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-03-10 07:17:05 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-03-10 07:17:05 +01:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-03-10 07:17:05 +01:00
*/
$(function () {
"use strict";
//var status = $('#status-box');
// set HTML to "migrating...":
2023-04-15 10:14:14 +02:00
console.log('Starting...');
startRunningCommands(0);
2018-03-10 07:17:05 +01:00
});
2023-04-15 10:14:14 +02:00
function startRunningCommands(index) {
console.log('Now in startRunningCommands with index' + index);
2019-03-30 11:03:39 +01:00
if (0 === index) {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-spin fa-spinner"></span> Running first command...');
2019-03-30 11:03:39 +01:00
}
runCommand(index);
}
function runCommand(index) {
2023-04-15 10:14:14 +02:00
console.log('Now in runCommand(' + index + '): ' + runCommandUrl);
$.post(runCommandUrl, {_token: token, index: parseInt(index)}).done(function (data) {
2019-03-30 11:03:39 +01:00
if (data.error === false) {
// increase index
index++;
if(data.hasNextCommand) {
// inform user
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-spin fa-spinner"></span> Just executed ' + data.previous + '...');
2019-03-30 11:03:39 +01:00
console.log('Will call next command.');
runCommand(index);
} else {
completeDone();
console.log('Finished!');
}
} else {
displaySoftFail(data.errorMessage);
console.error(data);
}
}).fail(function () {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-warning"></span> Command failed! See log files :(');
2019-03-30 11:03:39 +01:00
});
}
2018-03-10 07:17:05 +01:00
function startMigration() {
2023-04-15 10:14:14 +02:00
console.log('Now in startMigration');
2022-04-12 18:19:30 +02:00
$.post(migrateUrl, {_token: token}).done(function (data) {
2019-03-30 11:03:39 +01:00
if (data.error === false) {
2019-02-04 20:35:46 +01:00
// move to decrypt routine.
startDecryption();
} else {
displaySoftFail(data.message);
}
}).fail(function () {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-warning"></span> Migration failed! See log files :(');
2019-02-04 20:35:46 +01:00
});
}
function startDecryption() {
2023-04-15 10:14:14 +02:00
console.log('Now in startDecryption');
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-spin fa-spinner"></span> Setting up DB #2...');
2022-04-12 18:19:30 +02:00
$.post(decryptUrl, {_token: token}).done(function (data) {
2019-03-30 11:03:39 +01:00
if (data.error === false) {
2019-02-04 20:35:46 +01:00
// move to decrypt routine.
2018-04-06 13:36:36 +02:00
startPassport();
} else {
displaySoftFail(data.message);
}
2018-03-10 07:17:05 +01:00
}).fail(function () {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-warning"></span> Migration failed! See log files :(');
2018-03-10 07:17:05 +01:00
});
}
/**
*
*/
function startPassport() {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-spin fa-spinner"></span> Setting up OAuth2...');
2022-04-12 18:19:30 +02:00
$.post(keysUrl, {_token: token}).done(function (data) {
2019-03-30 11:03:39 +01:00
if (data.error === false) {
2018-04-06 13:36:36 +02:00
startUpgrade();
} else {
displaySoftFail(data.message);
}
2018-03-10 07:17:05 +01:00
}).fail(function () {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-warning"></span> OAuth2 failed! See log files :(');
2018-03-10 07:17:05 +01:00
});
}
/**
*
*/
function startUpgrade() {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-spin fa-spinner"></span> Upgrading database...');
2022-04-12 18:19:30 +02:00
$.post(upgradeUrl, {_token: token}).done(function (data) {
2019-03-30 11:03:39 +01:00
if (data.error === false) {
2018-04-06 13:36:36 +02:00
startVerify();
} else {
displaySoftFail(data.message);
}
2018-03-10 07:17:05 +01:00
}).fail(function () {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-warning"></span> Upgrade failed! See log files :(');
2018-03-10 07:17:05 +01:00
});
}
2018-03-11 18:46:18 +01:00
/**
*
*/
function startVerify() {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-spin fa-spinner"></span> Verify database integrity...');
2022-04-12 18:19:30 +02:00
$.post(verifyUrl, {_token: token}).done(function (data) {
2019-03-30 11:03:39 +01:00
if (data.error === false) {
2018-04-06 13:36:36 +02:00
completeDone();
} else {
displaySoftFail(data.message);
}
2018-03-11 18:46:18 +01:00
}).fail(function () {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-warning"></span> Verification failed! See log files :(');
2018-03-11 18:46:18 +01:00
});
}
2018-03-10 07:17:05 +01:00
/**
*
*/
function completeDone() {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-thumbs-up"></span> Installation + upgrade complete! Wait to be redirected...');
2018-03-10 07:17:05 +01:00
setTimeout(function () {
2022-04-12 18:19:30 +02:00
window.location = homeUrl;
2018-03-10 07:17:05 +01:00
}, 3000);
2018-04-06 13:36:36 +02:00
}
function displaySoftFail(message) {
2021-06-11 19:50:05 +02:00
$('#status-box').html('<span class="fa fa-warning"></span> ' + message + '<br /><br />Please read the ' +
'<a href="https://docs.firefly-iii.org/">' +
'documentation</a> about this, and upgrade by hand.');
2023-04-15 10:14:14 +02:00
}