Aggiunto sistema per la verifica dei servizi Services in scadenza

This commit is contained in:
Dasc3er 2020-11-27 16:49:10 +01:00
parent 36c70ea16d
commit be313b3471
5 changed files with 141 additions and 8 deletions

View File

@ -575,8 +575,8 @@ if (!Auth::check() && (!empty($messages['info']) || !empty($messages['warning'])
// Messaggio informativo per l'esaurimento dello spazio totale disponibile nel server
$free_space = disk_free_space('.');
$space_limit = 200; // MB
if ($free_space < ($space_limit * 1024 ^ 2)) {
$space_limit = 1; // GB
if ($free_space < ($space_limit * 1024 ^ 3)) {
echo '
<div class="callout callout-warning">
<h4>

View File

@ -18,6 +18,9 @@
*/
// Elenco moduli installati
use Carbon\Carbon;
use Models\Cache;
echo '
<div class="row">
<div class="col-md-12 col-lg-6">
@ -41,6 +44,59 @@ echo '
</table>
</div>';
if (\API\Services::isEnabled()) {
// Informazioni su Services
$servizi = Cache::pool('Informazioni su Services')->content;
// Elaborazione dei servizi in scadenza
$limite_scadenze = (new Carbon())->addDays(60);
$servizi_in_scadenza = [];
foreach ($servizi as $servizio) {
// Gestione per data di scadenza
$scadenza = new Carbon($servizio['expiration_at']);
if (
(isset($servizio['expiration_at']) && $scadenza->lessThan($limite_scadenze))
) {
$servizi_in_scadenza[] = $servizio['name'].' ('.$scadenza->diffForHumans().')';
} // Gestione per crediti
elseif (
(isset($servizio['credits']) && $servizio['credits'] < 100)
) {
$servizi_in_scadenza[] = $servizio['name'].' ('.$servizio['credits'].' crediti)';
}
}
echo '
<div class="col-md-12 col-lg-6">
<div class="box box-info">
<div class="box-header">
<h3 class="box-title">
'.tr('Informazioni su Services').'
</h3>
</div>
</div>
<div class="box-body">';
if (empty($servizi_in_scadenza)) {
echo '
<p>'.tr('Nessun servizio in scadenza').'</p>';
} else {
echo '
<p>'.tr('I seguenti servizi sono in scadenza:').'</p><ul>';
foreach ($servizi_in_scadenza as $servizio) {
echo '
<li>'.$servizio.'</li>';
}
echo '
</ul>';
}
echo '
</div>
</div>';
}
// Widgets
echo '
<div class="col-md-12 col-lg-6">

View File

@ -0,0 +1,75 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.n.c.
*
* 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/>.
*/
namespace Modules\StatoServizi;
use API\Services;
use Carbon\Carbon;
use Hooks\CachedManager;
class ServicesHook extends CachedManager
{
public function getCacheName()
{
return 'Informazioni su Services';
}
public function cacheData()
{
$response = Services::request('POST', 'informazioni_servizi');
$body = Services::responseBody($response);
return $body['services'];
}
public function response()
{
$servizi = $this->getCache()->content;
// Elaborazione dei servizi in scadenza
$limite_scadenze = (new Carbon())->addDays(60);
$servizi_in_scadenza = [];
foreach ($servizi as $servizio) {
// Gestione per data di scadenza
$scadenza = new Carbon($servizio['expiration_at']);
if (
(isset($servizio['expiration_at']) && $scadenza->lessThan($limite_scadenze))
) {
$servizi_in_scadenza[] = $servizio['name'].' ('.$scadenza->diffForHumans().')';
}
// Gestione per crediti
elseif (
(isset($servizio['credits']) && $servizio['credits'] < 100)
) {
$servizi_in_scadenza[] = $servizio['name'].' ('.$servizio['credits'].' crediti)';
}
}
$message = tr('I seguenti servizi sono in scadenza: _LIST_', [
'_LIST_' => implode(', ', $servizi_in_scadenza),
]);
return [
'icon' => 'fa fa-refresh text-warning',
'message' => $message,
'show' => !empty($servizi_in_scadenza),
];
}
}

View File

@ -22,9 +22,6 @@ namespace Modules\StatoServizi;
use Hooks\CachedManager;
use Util\FileSystem;
/**
* Hook dedicato all'individuazione di nuove versioni del gestionale, pubblicate sulla repository ufficiale di GitHub.
*/
class SpaceHook extends CachedManager
{
public function getCacheName()
@ -46,7 +43,7 @@ class SpaceHook extends CachedManager
$osm_size = $this->getCache()->content;
$soft_quota = setting('Soft quota'); // Impostazione in MB
$space_limit = ($soft_quota / 100) * 95; // 95% dello spazion indicato
$space_limit = ($soft_quota / 100) * 95; // 95% dello spazio indicato
$space_limit = $space_limit * 1024 ^ 2; // Trasformazione in B
$message = tr('Attenzione: occupati _TOT_ dei _QUOTA_ previsti', [

View File

@ -51,9 +51,14 @@ ALTER TABLE `zz_widgets` CHANGE `text` `text` TEXT NULL;
-- Impostazione soft quota
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`, `help`) VALUES (NULL, 'Soft quota', '', 'integer', '0', 'Generali', NULL, 'Soft quota in MB');
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`, `help`) VALUES (NULL, 'Soft quota', '', 'integer', '0', 'Generali', NULL, 'Soft quota in MB');
-- Relativo hook per il calcolo dello spazio utilizzato
INSERT INTO `zz_hooks` (`id`, `name`, `class`, `enabled`, `id_module`, `processing_at`, `processing_token`) VALUES (NULL, 'Spazio', 'Modules\\StatoServizi\\SpaceHook', '1', (SELECT `id` FROM `zz_modules` WHERE `name`='Stato dei servizi'), NULL, NULL);
INSERT INTO `zz_cache` (`id`, `name`, `content`, `valid_time`, `expire_at`) VALUES (NULL, 'Spazio utilizzato', '', '15 minute', NOW());
INSERT INTO `zz_cache` (`id`, `name`, `content`, `valid_time`, `expire_at`) VALUES (NULL, 'Spazio utilizzato', '', '15 minute', NOW());
-- Introduzione hook per informazioni su Services
INSERT INTO `zz_hooks` (`id`, `name`, `class`, `enabled`, `id_module`, `processing_at`, `processing_token`) VALUES (NULL, 'Informazioni su Services', 'Modules\\StatoServizi\\ServicesHook', '1', (SELECT `id` FROM `zz_modules` WHERE `name`='Stato dei servizi'), NULL, NULL);
INSERT INTO `zz_cache` (`id`, `name`, `content`, `valid_time`, `expire_at`) VALUES (NULL, 'Informazioni su Services', '', '7 days', NOW());