openstamanager/include/init/update.php

261 lines
9.7 KiB
PHP
Raw Normal View History

<?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/>.
*/
include_once __DIR__.'/../../core.php';
$updateRate = 20;
$scriptValue = $updateRate * 5;
/*
* Aggiornamento tramite AJAX
*/
if (filter('action') == 'do_update') {
// Aggiornamento in progresso
if (Update::isUpdateAvailable()) {
$update = Update::getCurrentUpdate();
$result = Update::doUpdate($updateRate);
if (!empty($result)) {
2024-05-16 18:02:50 +02:00
// Adding a generic message regarding the update
echo '
2024-05-16 18:02:50 +02:00
<script>
addVersion("'.$update['name'].'");
</script>';
2024-05-21 16:26:19 +02:00
if (is_array($result)) {
2024-05-16 18:02:50 +02:00
// Adding a message about the completion of the database update
if (!empty($update['sql']) && $result[1] == $result[2]) {
echo '
2024-05-16 18:02:50 +02:00
<script>
$("#progress .info").html($("#progress .info").html() + "<p><i class=\"fa fa-check\"></i> '.tr('Aggiornamento del database (_FILENAME_)', [
2024-05-21 16:26:19 +02:00
'_FILENAME_' => '<i>'.$update['filename'].'.sql</i>',
]).'</p>");
2024-05-16 18:02:50 +02:00
</script>';
}
2024-05-21 16:26:19 +02:00
$rate = $result[1] - $result[0];
} elseif (!empty($update['script'])) {
2024-05-16 18:02:50 +02:00
// Adding a message about the completion of the script
echo '
2024-05-16 18:02:50 +02:00
<script>
$("#progress .info").html($("#progress .info").html() + "<p><i class=\"fa fa-check\"></i> '.tr('Esecuzione dello script di aggiornamento (_FILENAME_)', [
2024-05-21 16:26:19 +02:00
'_FILENAME_' => '<i>'.$update['filename'].'.php</i>',
]).'</p>");
2024-05-16 18:02:50 +02:00
</script>';
2024-05-21 16:26:19 +02:00
$rate = $scriptValue;
}
2024-05-21 16:26:19 +02:00
2024-05-16 18:02:50 +02:00
// Increasing the total completion percentage
if (!empty($rate)) {
echo '
2024-05-16 18:02:50 +02:00
<script>
addProgress('.$rate.');
</script>';
}
2024-05-21 16:26:19 +02:00
echo '
2024-05-16 18:02:50 +02:00
<script>
$("#result").load("index.php?action=do_update&firstuse='.$_GET['firstuse'].'");
</script>';
} else {
2024-05-16 18:02:50 +02:00
// Failure
echo '
2024-05-16 18:02:50 +02:00
<div class="alert alert-danger">
<i class="fa fa-times"></i> '.tr("Errore durante l'esecuzione dell'aggiornamento alla versione _VERSION_", [
2024-05-21 16:26:19 +02:00
'_VERSION_' => $update['version'],
]).'
2024-05-16 18:02:50 +02:00
</div>';
}
}
2024-05-16 18:02:50 +02:00
// Update completed
elseif (Update::isUpdateCompleted()) {
Update::updateCleanup();
2024-05-21 16:26:19 +02:00
echo '
2024-05-16 18:02:50 +02:00
<p><strong>'.tr('Aggiornamento completato').'</strong> 😃</p>
<script>
setPercent(100);
</script>';
2024-05-21 16:26:19 +02:00
2024-05-16 18:02:50 +02:00
// Instructions for the first installation
if ($_GET['firstuse'] == 'true') {
echo '
2024-05-16 18:02:50 +02:00
<p class="text-danger">'.tr('Si consiglia di rimuovere i permessi di scrittura dal file _FILE_', [
2024-05-21 16:26:19 +02:00
'_FILE_' => '<b>config.inc.php</b>',
]).'.</p>';
2018-07-05 18:15:48 +02:00
}
2024-05-21 16:26:19 +02:00
2018-07-05 18:15:48 +02:00
echo '
2024-05-16 18:02:50 +02:00
<a class="btn btn-success btn-block" href="'.base_path().'">
<i class="fa fa-check"></i> '.tr('Continua').'
</a>';
}
2024-01-15 15:30:45 +01:00
exit;
} elseif (Update::isUpdateAvailable()) {
2024-05-16 18:02:50 +02:00
// Check if the update is in progress
2024-04-22 14:39:25 +02:00
if (Update::isUpdateLocked() && filter('force') != '1') {
$pageTitle = tr('Aggiornamento in corso!');
2018-06-26 09:41:43 +02:00
include_once App::filepath('include|custom|', 'top.php');
echo '
2024-05-16 18:02:50 +02:00
<div class="card card-danger card-outline text-center">
<div class="card-header">
<h3 class="card-title">'.tr('Aggiornamento in corso!').'</h3>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body">
2023-08-04 14:54:28 +02:00
<p>'.tr('Il software si trova attualmente nella fase di aggiornamento, potrebbero volerci fino a 10 minuti, siete pregati di attendere sino alla sua conclusione').'.</p>
<p>'.tr("In caso di problemi rivolgersi all'amministratore di sistema o all'assistenza del gestionale").'.</p>
2024-05-16 18:02:50 +02:00
<a class="btn btn-info" href="'.base_path().'/index.php"><i class="fa fa-redo"></i> '.tr('Riprova').'</a>
</div>
</div>';
2018-06-26 09:41:43 +02:00
include_once App::filepath('include|custom|', 'bottom.php');
2024-01-15 15:30:45 +01:00
exit;
}
$firstuse = !$dbo->isInstalled() ? 'true' : 'false';
$button = !$dbo->isInstalled() ? tr('Installa!') : tr('Aggiorna!');
$pageTitle = !$dbo->isInstalled() ? tr('Installazione') : tr('Aggiornamento');
2018-06-26 09:41:43 +02:00
include_once App::filepath('include|custom|', 'top.php');
echo '
2024-05-16 18:02:50 +02:00
<div class="card card-warning card-center-large text-center">
<div class="card-header">
2024-05-17 00:32:46 +02:00
<h3 class="card-title"><i class="fa fa-refresh"></i> '.(!$dbo->isInstalled() ? tr('Installazione') : tr('Aggiornamento')).'</h3>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body">';
if (!$dbo->isInstalled()) {
echo '
<p><strong>'.tr("E' la prima volta che avvii OpenSTAManager e non hai ancora installato il database").'.</strong></p>';
} else {
echo '
<p>'.tr("E' necessario aggiornare il database a una nuova versione").'.</p>';
}
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')).'!', [
2024-03-22 15:52:24 +01:00
'_BUTTON_' => '<b>"'.$button.'"</b>',
]).'</p>
2024-05-16 18:02:50 +02:00
<input type="button" class="btn btn-primary" value="'.$button.'" onclick="continue_update()" id="continue_button">
<script>
function continue_update(){
swal({
title: "'.(!$dbo->isInstalled() ? tr('Procedere con l\'installazione?') : tr('Procedere l\'aggiornamento?')).'",
text: "",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn btn-lg btn-success",
confirmButtonText: "'.tr('Procedi').'",
}).then(
function(){
$("#progress").show();
$("#result").load("index.php?action=do_update&firstuse='.$firstuse.'");
2024-05-16 18:02:50 +02:00
$("#continue_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>
2024-05-16 18:02:50 +02:00
<div class="card card-info text-center collapsed-card">
<div class="card-header with-border">
<h3 class="card-title"><a class="clickable" data-card-widget="collapse">'.tr('Log').'</a></h3>
<div class="card-tools pull-right">
2024-05-23 17:51:21 +02:00
<button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fa fa-plus"></i></button>
</div>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body info text-left"></div>
</div>
</div>
<div id="result"></div>';
$total = 0;
$updates = Update::getTodoUpdates();
foreach ($updates as $update) {
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', ';');
$total += count($queries);
if (intval($update['done']) > 1) {
$total -= intval($update['done']) - 2;
}
}
if ($update['script']) {
$total += $scriptValue;
}
}
2021-10-18 10:23:39 +02:00
echo '
2024-05-16 18:02:50 +02:00
<script>
$(document).ready(function(){
2024-05-17 00:32:46 +02:00
$(".login-box").fadeOut();
2024-05-16 18:02:50 +02:00
count = '.count($updates).';
current = 0;
versions = [];
2024-05-16 18:02:50 +02:00
progress = 0;
total = '.$total.';
});
2024-05-16 18:02:50 +02:00
function addProgress(rate){
progress += rate;
percent = progress / total * 100;
percent = Math.round(percent);
percent = percent > 100 ? 100 : percent;
2024-05-16 18:02:50 +02:00
setPercent(percent);
}
2020-09-07 15:04:06 +02:00
2024-05-16 18:02:50 +02:00
function setPercent(percent){
$("#progress .progress-bar").width(percent + "%");
$("#progress .progress-bar span").text(percent + "%");
}
2024-05-16 18:02:50 +02:00
function addVersion(version){
if(versions.indexOf(version) === -1){
versions.push(version);
current += 1;
2024-05-16 18:02:50 +02:00
$("#progress .info").html($("#progress .info").html() + "<p><strong>'.tr('Aggiornamento _DONE_ di _TODO_ (_VERSION_)', [
2024-05-21 16:26:19 +02:00
'_DONE_' => '" + current + "',
'_TODO_' => '" + count + "',
'_VERSION_' => '" + version.trim() + "',
]).'</strong></p>");
2024-05-16 18:02:50 +02:00
}
}
</script>
</div>
</div>';
2024-05-21 16:26:19 +02:00
}