2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-07-03 11:12:32 +02:00
|
|
|
include_once __DIR__.'/../../core.php';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$updateRate = 20;
|
2017-08-31 10:09:06 +02:00
|
|
|
$scriptValue = $updateRate * 5;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Aggiornamento tramite AJAX
|
|
|
|
*/
|
|
|
|
if (filter('action') == 'do_update') {
|
|
|
|
// Aggiornamento in progresso
|
|
|
|
if (Update::isUpdateAvailable()) {
|
2018-09-18 17:35:04 +02:00
|
|
|
$update = Update::getCurrentUpdate();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$result = Update::doUpdate($updateRate);
|
|
|
|
|
|
|
|
if (!empty($result)) {
|
|
|
|
// Aggiunta del messaggio generico riguardante l'aggiornamento
|
|
|
|
echo '
|
|
|
|
<script>
|
2018-09-18 17:35:04 +02:00
|
|
|
addVersion("'.$update['name'].'");
|
2017-08-04 16:28:16 +02:00
|
|
|
</script>';
|
|
|
|
|
|
|
|
if (is_array($result)) {
|
|
|
|
// Aggiunta del messaggio riguardante la conclusione dell'aggiornamento del database
|
|
|
|
if (!empty($update['sql']) && $result[1] == $result[2]) {
|
|
|
|
echo '
|
|
|
|
<script>
|
2017-09-10 14:35:41 +02:00
|
|
|
$("#progress .info").html($("#progress .info").html() + "<p> <i class=\"fa fa-check\"></i> '.tr('Aggiornamento del database (_FILENAME_)', [
|
|
|
|
'_FILENAME_' => '<i>'.$update['filename'].'.sql</i>',
|
|
|
|
]).'</p>");
|
2017-08-04 16:28:16 +02:00
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$rate = $result[1] - $result[0];
|
|
|
|
} elseif (!empty($update['script'])) {
|
|
|
|
// Aggiunta del messaggio riguardante la conclusione dello script
|
|
|
|
echo '
|
|
|
|
<script>
|
2017-09-10 14:35:41 +02:00
|
|
|
$("#progress .info").html($("#progress .info").html() + "<p> <i class=\"fa fa-check\"></i> '.tr('Esecuzione dello script di aggiornamento (_FILENAME_)', [
|
|
|
|
'_FILENAME_' => '<i>'.$update['filename'].'.php</i>',
|
|
|
|
]).'</p>");
|
2017-08-04 16:28:16 +02:00
|
|
|
</script>';
|
|
|
|
|
|
|
|
$rate = $scriptValue;
|
|
|
|
}
|
|
|
|
|
2018-02-15 09:57:52 +01:00
|
|
|
// Aumento della percentuale di completamento totale
|
2017-08-04 16:28:16 +02:00
|
|
|
if (!empty($rate)) {
|
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
addProgress('.$rate.');
|
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
$("#result").load("index.php?action=do_update&firstuse='.$_GET['firstuse'].'");
|
|
|
|
</script>';
|
|
|
|
} else {
|
|
|
|
// Fallimento
|
|
|
|
echo '
|
|
|
|
<div class="alert alert-danger">
|
2017-09-10 14:35:41 +02:00
|
|
|
<i class="fa fa-times"></i> '.tr("Errore durante l'esecuzione dell'aggiornamento alla versione _VERSION_", [
|
|
|
|
'_VERSION_' => $update['version'],
|
|
|
|
]).'
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Aggiornamento completato
|
|
|
|
elseif (Update::isUpdateCompleted()) {
|
|
|
|
Update::updateCleanup();
|
|
|
|
|
|
|
|
echo '
|
2019-01-06 14:18:48 +01:00
|
|
|
<p><strong>'.tr('Aggiornamento completato').'</strong> <i class="fa fa-smile-o"></i></p>
|
|
|
|
<script>
|
|
|
|
setPercent(100);
|
|
|
|
</script>';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Istruzioni per la prima installazione
|
|
|
|
if ($_GET['firstuse'] == 'true') {
|
|
|
|
echo '
|
2017-09-10 14:35:41 +02:00
|
|
|
<p class="text-danger">'.tr("E' fortemente consigliato rimuovere i permessi di scrittura dal file _FILE_", [
|
|
|
|
'_FILE_' => '<b>config.inc.php</b>',
|
2018-07-05 18:15:48 +02:00
|
|
|
]).'.</p>';
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-07-05 18:15:48 +02:00
|
|
|
echo '
|
2020-12-31 16:13:28 +01:00
|
|
|
<a class="btn btn-success btn-block" href="'.base_url().'">
|
2018-07-03 11:12:32 +02:00
|
|
|
<i class="fa fa-check"></i> '.tr('Continua').'
|
|
|
|
</a>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2020-12-31 16:13:28 +01:00
|
|
|
throw new \App\Exceptions\LegacyExitException;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
} elseif (Update::isUpdateAvailable()) {
|
|
|
|
// Controllo se l'aggiornamento è in esecuzione
|
|
|
|
if (Update::isUpdateLocked() && filter('force') === null) {
|
2017-09-04 12:02:29 +02:00
|
|
|
$pageTitle = tr('Aggiornamento in corso!');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2020-12-31 16:13:28 +01:00
|
|
|
include_once AppLegacy::filepath('include|custom|', 'top.php');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="box box-center box-danger box-solid text-center">
|
|
|
|
<div class="box-header with-border">
|
2017-09-04 12:02:29 +02:00
|
|
|
<h3 class="box-title">'.tr('Aggiornamento in corso!').'</h3>
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>
|
|
|
|
<div class="box-body">
|
2017-09-04 12:02:29 +02:00
|
|
|
<p>'.tr("E' attualmente in corso la procedura di aggiornamento del software, e pertanto siete pregati di attendere fino alla sua conclusione").'.</p>
|
|
|
|
<p>'.tr("Nel caso il problema persista, rivolgersi all'amministratore o all'assistenza ufficiale").'.</p>
|
2020-12-31 16:13:28 +01:00
|
|
|
<a class="btn btn-info" href="'.base_url().'/index.php"><i class="fa fa-repeat"></i> '.tr('Riprova').'</a>
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
|
2020-12-31 16:13:28 +01:00
|
|
|
include_once AppLegacy::filepath('include|custom|', 'bottom.php');
|
|
|
|
|
|
|
|
throw new \App\Exceptions\LegacyExitException;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$firstuse = !$dbo->isInstalled() ? 'true' : 'false';
|
|
|
|
|
2017-09-04 12:02:29 +02:00
|
|
|
$button = !$dbo->isInstalled() ? tr('Installa!') : tr('Aggiorna!');
|
|
|
|
$pageTitle = !$dbo->isInstalled() ? tr('Installazione') : tr('Aggiornamento');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2020-12-31 16:13:28 +01:00
|
|
|
include_once AppLegacy::filepath('include|custom|', 'top.php');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="box box-center-large box-warning text-center">
|
|
|
|
<div class="box-header with-border">
|
2017-09-04 12:02:29 +02:00
|
|
|
<h3 class="box-title">'.(!$dbo->isInstalled() ? tr('Installazione') : tr('Aggiornamento')).'</h3>
|
2017-08-04 16:28:16 +02:00
|
|
|
</div>
|
|
|
|
<div class="box-body">';
|
|
|
|
if (!$dbo->isInstalled()) {
|
|
|
|
echo '
|
2017-09-04 12:02:29 +02:00
|
|
|
<p><strong>'.tr("E' la prima volta che avvii OpenSTAManager e non hai ancora installato il database").'.</strong></p>';
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
|
|
|
echo '
|
2017-09-04 12:02:29 +02:00
|
|
|
<p>'.tr("E' necessario aggiornare il database a una nuova versione").'.</p>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
echo '
|
2018-02-18 19:53:23 +01:00
|
|
|
<p>'.tr("Premi il tasto _BUTTON_ per procedere con l'".(!$dbo->isInstalled() ? tr('installazione') : tr('aggiornamento')).'!', [
|
2017-09-10 14:35:41 +02:00
|
|
|
'_BUTTON_' => '<b>"'.$button.'"</b>',
|
|
|
|
]).'</p>
|
2017-08-04 16:28:16 +02:00
|
|
|
<input type="button" class="btn btn-primary" value="'.$button.'" onclick="continue_update()" id="contine_button">
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function continue_update(){
|
|
|
|
swal({
|
2018-02-15 09:57:52 +01:00
|
|
|
title: "'.(!$dbo->isInstalled() ? tr('Procedere con l\'installazione?') : tr('Procedere l\'aggiornamento?')).'",
|
|
|
|
text: "",
|
2017-08-04 16:28:16 +02:00
|
|
|
type: "warning",
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonClass: "btn btn-lg btn-success",
|
2017-09-04 12:02:29 +02:00
|
|
|
confirmButtonText: "'.tr('Procedi').'",
|
2017-08-04 16:28:16 +02:00
|
|
|
}).then(
|
|
|
|
function(){
|
|
|
|
$("#progress").show();
|
|
|
|
$("#result").load("index.php?action=do_update&firstuse='.$firstuse.'");
|
|
|
|
$("#contine_button").remove();
|
|
|
|
}, function(){});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div id="progress">
|
|
|
|
<div class="progress">
|
|
|
|
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%">
|
|
|
|
<span>0%</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<div class="box box-info text-center collapsed-box">
|
|
|
|
<div class="box-header with-border">
|
2017-09-04 12:02:29 +02:00
|
|
|
<h3 class="box-title"><a class="clickable" data-widget="collapse">'.tr('Log').'</a></h3>
|
2017-08-04 16:28:16 +02:00
|
|
|
<div class="box-tools pull-right">
|
|
|
|
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="box-body info text-left"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="result"></div>';
|
|
|
|
|
|
|
|
$total = 0;
|
2018-09-18 17:35:04 +02:00
|
|
|
$updates = Update::getTodoUpdates();
|
2017-08-31 10:09:06 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
foreach ($updates as $update) {
|
2017-08-31 10:09:06 +02:00
|
|
|
if ($update['sql'] && (!empty($update['done']) || is_null($update['done']))) {
|
2021-09-24 14:31:12 +02:00
|
|
|
$queries = readSQLFile(base_dir().'/'.$update['directory'].$update['filename'].'.sql', ';');
|
2017-08-04 16:28:16 +02:00
|
|
|
$total += count($queries);
|
2017-08-31 10:09:06 +02:00
|
|
|
|
|
|
|
if (intval($update['done']) > 1) {
|
|
|
|
$total -= intval($update['done']) - 2;
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($update['script']) {
|
|
|
|
$total += $scriptValue;
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 10:23:39 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
echo '
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
$(".login-box").fadeOut();
|
|
|
|
|
|
|
|
count = '.count($updates).';
|
|
|
|
current = 0;
|
|
|
|
versions = [];
|
|
|
|
|
|
|
|
progress = 0;
|
|
|
|
total = '.$total.';
|
|
|
|
});
|
|
|
|
|
|
|
|
function addProgress(rate){
|
|
|
|
progress += rate;
|
|
|
|
percent = progress / total * 100;
|
|
|
|
percent = Math.round(percent);
|
2017-09-06 10:48:59 +02:00
|
|
|
percent = percent > 100 ? 100 : percent;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2019-01-06 14:18:48 +01:00
|
|
|
setPercent(percent);
|
|
|
|
}
|
2020-09-07 15:04:06 +02:00
|
|
|
|
2019-01-06 14:18:48 +01:00
|
|
|
function setPercent(percent){
|
2017-08-04 16:28:16 +02:00
|
|
|
$("#progress .progress-bar").width(percent + "%");
|
|
|
|
$("#progress .progress-bar span").text(percent + "%");
|
|
|
|
}
|
|
|
|
|
|
|
|
function addVersion(version){
|
|
|
|
if(versions.indexOf(version) === -1){
|
|
|
|
versions.push(version);
|
|
|
|
current += 1;
|
|
|
|
|
2017-09-10 14:35:41 +02:00
|
|
|
$("#progress .info").html($("#progress .info").html() + "<p><strong>'.tr('Aggiornamento _DONE_ di _TODO_ (_VERSION_)', [
|
|
|
|
'_DONE_' => '" + current + "',
|
|
|
|
'_TODO_' => '" + count + "',
|
2019-02-21 15:09:11 +01:00
|
|
|
'_VERSION_' => '" + version.trim() + "',
|
2017-09-10 14:35:41 +02:00
|
|
|
]).'</strong></p>");
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
}
|