diff --git a/app/Filament/Pages/Supporto/Modifiche.php b/app/Filament/Pages/Supporto/Modifiche.php index 105f7ce..caf2bd5 100644 --- a/app/Filament/Pages/Supporto/Modifiche.php +++ b/app/Filament/Pages/Supporto/Modifiche.php @@ -3,8 +3,13 @@ namespace App\Filament\Pages\Supporto; use BackedEnum; +use Filament\Notifications\Notification; use Filament\Pages\Page; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Process; +use Throwable; use UnitEnum; class Modifiche extends Page @@ -23,6 +28,30 @@ class Modifiche extends Page protected string $view = 'filament.pages.supporto.modifiche'; + public string $currentVersion = '0.0.0'; + + public string $versionSource = 'config'; + + public string $updateChannel = 'free'; + + public bool $updateForce = false; + + public bool $updateDryRun = false; + + public ?int $lastUpdateExitCode = null; + + public ?string $lastUpdateOutput = null; + + public ?string $lastUpdateAt = null; + + /** @var array */ + public array $latestCommits = []; + + public function mount(): void + { + $this->reloadDashboardData(); + } + public static function canAccess(): bool { $user = Auth::user(); @@ -33,4 +62,117 @@ public static function canAccess(): bool // Pagina informativa: accessibile a chi accede al pannello. return true; } + + public function canRunUpdate(): bool + { + $user = Auth::user(); + + return $user && method_exists($user, 'hasAnyRole') + && $user->hasAnyRole(['super-admin', 'admin', 'amministratore']); + } + + public function reloadDashboardData(): void + { + $this->loadVersionInfo(); + $this->loadLatestCommits(); + } + + public function runUpdate(): void + { + if (! $this->canRunUpdate()) { + Notification::make() + ->title('Permessi insufficienti') + ->body('Solo super-admin/admin/amministratore possono lanciare gli aggiornamenti.') + ->danger() + ->send(); + + return; + } + + $params = [ + '--channel' => $this->updateChannel, + '--apply' => true, + ]; + + if ($this->updateDryRun) { + $params['--dry-run'] = true; + } + + if ($this->updateForce) { + $params['--force'] = true; + } + + try { + $exitCode = Artisan::call('netgescon:update', $params); + $output = trim((string) Artisan::output()); + + $this->lastUpdateExitCode = $exitCode; + $this->lastUpdateOutput = $output; + $this->lastUpdateAt = now()->format('d/m/Y H:i:s'); + + $this->reloadDashboardData(); + + Notification::make() + ->title($exitCode === 0 ? 'Aggiornamento completato' : 'Aggiornamento terminato con errori') + ->body($exitCode === 0 ? 'Procedura conclusa. Versione e commit aggiornati.' : 'Controlla il log tecnico nella sezione output.') + ->{$exitCode === 0 ? 'success' : 'danger'}() + ->send(); + } catch (Throwable $e) { + $this->lastUpdateExitCode = 1; + $this->lastUpdateAt = now()->format('d/m/Y H:i:s'); + $this->lastUpdateOutput = 'Errore durante esecuzione update: ' . $e->getMessage(); + + Notification::make() + ->title('Errore durante update') + ->body($e->getMessage()) + ->danger() + ->send(); + } + } + + private function loadVersionInfo(): void + { + $versionFile = base_path('VERSION'); + if (File::exists($versionFile)) { + $fileVersion = trim((string) File::get($versionFile)); + if ($fileVersion !== '') { + $this->currentVersion = $fileVersion; + $this->versionSource = 'VERSION'; + + return; + } + } + + $this->currentVersion = (string) config('netgescon.version', '0.0.0'); + $this->versionSource = 'config'; + } + + private function loadLatestCommits(): void + { + $this->latestCommits = []; + + $format = '%H|%h|%an|%ad|%s'; + $command = 'git log -n 20 --date=format:"%d/%m/%Y %H:%M" --pretty=format:"' . $format . '"'; + $result = Process::path(base_path())->run($command); + + if (! $result->successful()) { + return; + } + + $lines = preg_split('/\r\n|\r|\n/', trim($result->output())) ?: []; + foreach ($lines as $line) { + $parts = explode('|', $line, 5); + if (count($parts) !== 5) { + continue; + } + + $this->latestCommits[] = [ + 'hash' => (string) $parts[0], + 'short_hash' => (string) $parts[1], + 'author' => (string) $parts[2], + 'date' => (string) $parts[3], + 'message' => (string) $parts[4], + ]; + } + } } diff --git a/docs/NETGESCON-MODIFICHE.md b/docs/NETGESCON-MODIFICHE.md index a7ef240..a209f4b 100644 --- a/docs/NETGESCON-MODIFICHE.md +++ b/docs/NETGESCON-MODIFICHE.md @@ -23,3 +23,4 @@ # Modifiche NetGescon | 11/03/2026 | 0.8.x-dev | CTI Panasonic / Sync staging->sviluppo | Introdotti mirror payload CTI opzionale (solo staging) e comando `cti:sync-postit-from-staging` per riallineamento unidirezionale record `chiamate_post_it` Panasonic verso sviluppo | [U] | | 11/03/2026 | 0.8.x-dev | Ticket Mobile / Allegati | Fix accesso allegati con route protetta `admin.tickets.attachments.view` (stop 403 da URL `/storage`), anteprima in modal e lista allegati stile catalogo con descrizione per file in inserimento mobile (foto + documenti) | [U] | | 11/03/2026 | 0.8.x-dev | CTI Panasonic / Tracciamento | Aggiunto `trace_id` in risposta incoming/call-ended e log strutturato (`CTI Panasonic trace`) per audit chiamate reali/test, ricerca eventi mancanti e diagnosi `event_id`/telefono/canale mirror | [U] | +| 12/03/2026 | 0.8.x-dev | Supporto / Modifiche / Update | Pagina `admin-filament/supporto/modifiche` resa compatta (font piccolo), aggiunta tabella ultimi commit con descrizione e pulsante per eseguire `netgescon:update --apply` con esito/output e versione corrente visibile | [U] | diff --git a/resources/views/filament/pages/supporto/modifiche.blade.php b/resources/views/filament/pages/supporto/modifiche.blade.php index fdb8ae3..e82ddf0 100644 --- a/resources/views/filament/pages/supporto/modifiche.blade.php +++ b/resources/views/filament/pages/supporto/modifiche.blade.php @@ -1,5 +1,5 @@ -
+
- -
-
-
NetGescon
-
Versione: {{ config('netgescon.version', '0.0.0') }}
-
- -
-
Legenda:
-
- U = utenti finali - P = assistenza / sviluppatori - E = errori non bloccanti - E! = errori bloccanti + +
+
+
NetGescon - Modifiche e Aggiornamenti
+
+ Versione corrente: {{ $this->currentVersion }} + fonte {{ $this->versionSource }}
+ +
+
Legenda rapida
+
+ U utenti finali + P assistenza/sviluppo + E non bloccante + E! bloccante +
+
+
+
+ + +
+
+
Aggiornamento da server distribution
+
+ + + +
+ +
+ + Lancia aggiornamento + + + Aggiorna dati pagina + +
+ + @if(! $this->canRunUpdate()) +
Permesso update non disponibile per il tuo ruolo.
+ @endif +
+ +
+
Esito ultimo update
+
+
Ultima esecuzione: {{ $this->lastUpdateAt ?? '-' }}
+
+ Exit code: + @if($this->lastUpdateExitCode === null) + - + @elseif($this->lastUpdateExitCode === 0) + 0 OK + @else + {{ $this->lastUpdateExitCode }} ERRORE + @endif +
+
+
+
+ + @if(filled($this->lastUpdateOutput)) +
+
Output tecnico
+
{{ $this->lastUpdateOutput }}
+
+ @endif +
+ + +
Ultimi commit (descrizioni)
+ +
+ + + + + + + + + + + @forelse($this->latestCommits as $commit) + + + + + + + @empty + + + + @endforelse + +
DataCommitAutoreDescrizione
{{ $commit['date'] }}{{ $commit['short_hash'] }}{{ $commit['author'] }}{{ $commit['message'] }}
Nessun commit disponibile.
@@ -48,15 +144,16 @@ $gitRawHtml = str_replace(array_keys($replacements), array_values($replacements), $gitRawHtml); @endphp - -
+ +
Registro funzionale (manuale)
+
{!! $rawHtml !!}
- -
Changelog Automatico da Git
-
+ +
Changelog automatico da script
+
{!! $gitRawHtml !!}