Skip to content

Commit

Permalink
Merge pull request #659 from portabilis/instalador
Browse files Browse the repository at this point in the history
[2.2] Permite utilizar o instalador para fazer o upgrade de versão
  • Loading branch information
edersoares committed Sep 30, 2019
2 parents fa8af87 + ac4a9f6 commit 1898b16
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
4 changes: 2 additions & 2 deletions public/install.php
Expand Up @@ -107,7 +107,7 @@ function boolIcon(bool $bool): string
crossorigin="anonymous">
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|PT+Mono">
<link rel="stylesheet" href="css/install.css">
<link rel="stylesheet" href="css/install.css?version=<?php echo $currIeducarVersion ?>">
</head>

<body>
Expand Down Expand Up @@ -335,6 +335,6 @@ function boolIcon(bool $bool): string
<script
src="https://www.promisejs.org/polyfills/promise-7.0.4.min.js">
</script>
<script src="js/install.js"></script>
<script src="js/install.js?version=<?php echo $currIeducarVersion ?>"></script>
</body>
</html>
49 changes: 39 additions & 10 deletions public/js/install.js
Expand Up @@ -36,10 +36,34 @@ if (updateButton) {
loading.style.display = 'block';
parent.parentNode.removeChild(parent);

get('/install.php?command=exec&param=migrate&id=' + timestamp)
.then(function (result) {
const steps = [
{
command: 'link',
description: 'Gerando symlinks'
}, {
command: 'migrate',
description: 'Executando migrações'
}
];

let base = new Promise(function (resolve) {
return resolve(true);
});

for (let i = 0; i < steps.length; i++) {
const step = steps[i];

base = base.then(function () {
let url = '/install.php?command=exec&param=' + step.command + '&id=' + timestamp;

if (step.extra) {
url += '&extra=' + step.extra;
}

return get(url);
}).then(function (result) {
return new Promise(function (resolve, reject) {
const interval = setInterval(function() {
const interval = setInterval(function () {
get('/install.php?command=consult&pid=' + result + '&id=' + timestamp)
.then(function (result) {
result = parseInt(result, 10);
Expand All @@ -48,19 +72,24 @@ if (updateButton) {
resolve(result);
clearInterval(interval);
} else if (result > 0) {
reject();
reject(step);
clearInterval(interval);
}
});
}, 1000);
});
}).then(function () {
alert('Atualização realizada com sucesso!');
$.location.reload(true);
}).catch(function () {
alert('Ocorreu um erro ao atualizar sua instalação' + "\n" + 'Verifique o log em storage/logs para identificar o problema e tente novamente.');
$.location.reload(true);
});
}

base.then(function () {
alert('Atualização realizada com sucesso!');
$.location.reload(true);
});

base.catch(function (error) {
alert('Ocorreu um erro ao atualizar sua instalação' + "\n" + 'Verifique o log em storage/logs para identificar o problema e tente novamente.');
$.location.reload(true);
});

return false;
});
Expand Down

0 comments on commit 1898b16

Please sign in to comment.