Show update output accordion for refresh and upgrade
This commit is contained in:
@@ -17,6 +17,9 @@ use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class ServerUpdates extends Page implements HasActions, HasTable
|
||||
{
|
||||
@@ -33,23 +36,61 @@ class ServerUpdates extends Page implements HasActions, HasTable
|
||||
|
||||
public array $packages = [];
|
||||
|
||||
public ?string $currentVersion = null;
|
||||
|
||||
public ?int $behindCount = null;
|
||||
|
||||
public array $recentChanges = [];
|
||||
|
||||
public ?string $lastCheckedAt = null;
|
||||
|
||||
public ?string $jabaliOutput = null;
|
||||
|
||||
public ?string $jabaliOutputTitle = null;
|
||||
|
||||
public ?string $jabaliOutputAt = null;
|
||||
|
||||
public bool $isChecking = false;
|
||||
|
||||
public bool $isUpgrading = false;
|
||||
|
||||
public array $refreshOutput = [];
|
||||
|
||||
public ?string $refreshOutputAt = null;
|
||||
|
||||
public ?string $refreshOutputTitle = null;
|
||||
|
||||
protected ?AgentClient $agent = null;
|
||||
|
||||
protected bool $updatesLoaded = false;
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return __('Server Updates');
|
||||
return __('System Updates');
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('Server Updates');
|
||||
return __('System Updates');
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->loadUpdates(false);
|
||||
$this->loadVersionInfo();
|
||||
}
|
||||
|
||||
public function getUpdateStatusLabelProperty(): string
|
||||
{
|
||||
if ($this->behindCount === null) {
|
||||
return __('Not checked');
|
||||
}
|
||||
|
||||
if ($this->behindCount === 0) {
|
||||
return __('Up to date');
|
||||
}
|
||||
|
||||
return __(':count commit(s) behind', ['count' => $this->behindCount]);
|
||||
}
|
||||
|
||||
protected function getAgent(): AgentClient
|
||||
@@ -57,15 +98,39 @@ class ServerUpdates extends Page implements HasActions, HasTable
|
||||
return $this->agent ??= new AgentClient;
|
||||
}
|
||||
|
||||
public function loadUpdates(bool $refreshTable = true): void
|
||||
public function loadUpdates(bool $refreshTable = true, bool $refreshApt = false): void
|
||||
{
|
||||
try {
|
||||
$result = $this->getAgent()->updatesList();
|
||||
$result = $this->getAgent()->updatesList($refreshApt);
|
||||
$this->packages = $result['packages'] ?? [];
|
||||
$this->updatesLoaded = true;
|
||||
|
||||
if ($refreshApt) {
|
||||
$refreshOutput = $result['refresh_output'] ?? [];
|
||||
$refreshLines = is_array($refreshOutput) ? $refreshOutput : [$refreshOutput];
|
||||
$this->refreshOutput = ! empty(array_filter($refreshLines, static fn ($line) => $line !== null && $line !== ''))
|
||||
? $refreshLines
|
||||
: [__('No output captured.')];
|
||||
$this->refreshOutputAt = now()->format('Y-m-d H:i:s');
|
||||
$this->refreshOutputTitle = __('Update Refresh Output');
|
||||
}
|
||||
|
||||
$warnings = $result['warnings'] ?? [];
|
||||
if (! empty($warnings)) {
|
||||
Notification::make()
|
||||
->title(__('Update check completed with warnings'))
|
||||
->body(implode("\n", array_filter($warnings)))
|
||||
->warning()
|
||||
->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->packages = [];
|
||||
$this->updatesLoaded = true;
|
||||
if ($refreshApt) {
|
||||
$this->refreshOutput = [$e->getMessage()];
|
||||
$this->refreshOutputAt = now()->format('Y-m-d H:i:s');
|
||||
$this->refreshOutputTitle = __('Update Refresh Output');
|
||||
}
|
||||
Notification::make()
|
||||
->title(__('Failed to load updates'))
|
||||
->body($e->getMessage())
|
||||
@@ -78,15 +143,103 @@ class ServerUpdates extends Page implements HasActions, HasTable
|
||||
}
|
||||
}
|
||||
|
||||
public function loadVersionInfo(): void
|
||||
{
|
||||
$this->currentVersion = $this->readVersion();
|
||||
}
|
||||
|
||||
public function checkForUpdates(): void
|
||||
{
|
||||
$this->isChecking = true;
|
||||
|
||||
try {
|
||||
$exitCode = Artisan::call('jabali:upgrade', ['--check' => true]);
|
||||
$output = trim(Artisan::output());
|
||||
|
||||
if ($exitCode !== 0) {
|
||||
throw new \RuntimeException($output !== '' ? $output : __('Update check failed.'));
|
||||
}
|
||||
|
||||
$this->jabaliOutput = $output !== '' ? $output : __('No output captured.');
|
||||
$this->jabaliOutputTitle = __('Update Check Output');
|
||||
$this->jabaliOutputAt = now()->format('Y-m-d H:i:s');
|
||||
$this->lastCheckedAt = $this->jabaliOutputAt;
|
||||
$this->parseUpdateOutput($output);
|
||||
|
||||
Notification::make()
|
||||
->title(__('Update check completed'))
|
||||
->success()
|
||||
->send();
|
||||
} catch (\Throwable $e) {
|
||||
$this->jabaliOutput = $e->getMessage();
|
||||
$this->jabaliOutputTitle = __('Update Check Output');
|
||||
$this->jabaliOutputAt = now()->format('Y-m-d H:i:s');
|
||||
Notification::make()
|
||||
->title(__('Update check failed'))
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
} finally {
|
||||
$this->isChecking = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function performUpgrade(): void
|
||||
{
|
||||
$this->isUpgrading = true;
|
||||
|
||||
try {
|
||||
$exitCode = Artisan::call('jabali:upgrade', ['--force' => true]);
|
||||
$output = trim(Artisan::output());
|
||||
|
||||
if ($exitCode !== 0) {
|
||||
throw new \RuntimeException($output !== '' ? $output : __('Upgrade failed.'));
|
||||
}
|
||||
|
||||
$this->jabaliOutput = $output !== '' ? $output : __('No output captured.');
|
||||
$this->jabaliOutputTitle = __('Upgrade Output');
|
||||
$this->jabaliOutputAt = now()->format('Y-m-d H:i:s');
|
||||
$this->loadVersionInfo();
|
||||
$this->behindCount = 0;
|
||||
$this->recentChanges = [];
|
||||
|
||||
Notification::make()
|
||||
->title(__('Upgrade completed'))
|
||||
->success()
|
||||
->send();
|
||||
} catch (\Throwable $e) {
|
||||
$this->jabaliOutput = $e->getMessage();
|
||||
$this->jabaliOutputTitle = __('Upgrade Output');
|
||||
$this->jabaliOutputAt = now()->format('Y-m-d H:i:s');
|
||||
Notification::make()
|
||||
->title(__('Upgrade failed'))
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
} finally {
|
||||
$this->isUpgrading = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function runUpdates(): void
|
||||
{
|
||||
try {
|
||||
$this->getAgent()->updatesRun();
|
||||
$result = $this->getAgent()->updatesRun();
|
||||
$output = $result['output'] ?? [];
|
||||
$outputLines = is_array($output) ? $output : [$output];
|
||||
$this->refreshOutput = ! empty(array_filter($outputLines, static fn ($line) => $line !== null && $line !== ''))
|
||||
? $outputLines
|
||||
: [__('No output captured.')];
|
||||
$this->refreshOutputAt = now()->format('Y-m-d H:i:s');
|
||||
$this->refreshOutputTitle = __('System Update Output');
|
||||
Notification::make()
|
||||
->title(__('Updates completed'))
|
||||
->success()
|
||||
->send();
|
||||
} catch (\Exception $e) {
|
||||
$this->refreshOutput = [$e->getMessage()];
|
||||
$this->refreshOutputAt = now()->format('Y-m-d H:i:s');
|
||||
$this->refreshOutputTitle = __('System Update Output');
|
||||
Notification::make()
|
||||
->title(__('Update failed'))
|
||||
->body($e->getMessage())
|
||||
@@ -97,6 +250,38 @@ class ServerUpdates extends Page implements HasActions, HasTable
|
||||
$this->loadUpdates();
|
||||
}
|
||||
|
||||
protected function parseUpdateOutput(string $output): void
|
||||
{
|
||||
$this->behindCount = null;
|
||||
$this->recentChanges = [];
|
||||
|
||||
if (preg_match('/Updates available:\s+(\d+)/', $output, $matches)) {
|
||||
$this->behindCount = (int) $matches[1];
|
||||
} elseif (str_contains(strtolower($output), 'up to date')) {
|
||||
$this->behindCount = 0;
|
||||
}
|
||||
|
||||
if (preg_match('/Recent changes:\s*(.+)$/s', $output, $matches)) {
|
||||
$lines = preg_split('/\r?\n/', trim($matches[1]));
|
||||
$this->recentChanges = array_values(array_filter($lines, static fn (string $line): bool => trim($line) !== ''));
|
||||
}
|
||||
}
|
||||
|
||||
protected function readVersion(): string
|
||||
{
|
||||
$versionFile = base_path('VERSION');
|
||||
if (! File::exists($versionFile)) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
$content = File::get($versionFile);
|
||||
if (preg_match('/VERSION=(.+)/', $content, $matches)) {
|
||||
return trim($matches[1]);
|
||||
}
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
@@ -133,7 +318,7 @@ class ServerUpdates extends Page implements HasActions, HasTable
|
||||
Action::make('refresh')
|
||||
->label(__('Refresh'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(fn () => $this->loadUpdates()),
|
||||
->action(fn () => $this->loadUpdates(true, true)),
|
||||
Action::make('runUpdates')
|
||||
->label(__('Run Updates'))
|
||||
->icon('heroicon-o-arrow-path-rounded-square')
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<details class="mt-4 rounded border border-gray-200 bg-white p-4 shadow-sm open:shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<summary class="cursor-pointer list-none text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
{{ $refreshOutputTitle ?? __('Update Output') }}
|
||||
@if($refreshOutputAt)
|
||||
<span class="ml-2 text-xs font-normal text-gray-500 dark:text-gray-400">
|
||||
{{ __('Last refreshed at :time', ['time' => $refreshOutputAt]) }}
|
||||
</span>
|
||||
@endif
|
||||
</summary>
|
||||
<div class="mt-3 text-sm text-gray-700 dark:text-gray-200">
|
||||
<pre class="whitespace-pre-wrap break-words rounded bg-gray-50 p-4 text-xs text-gray-800 dark:bg-gray-900/50 dark:text-gray-200">{{ implode("\n", $refreshOutput) }}</pre>
|
||||
</div>
|
||||
</details>
|
||||
@@ -1,5 +1,95 @@
|
||||
<x-filament-panels::page>
|
||||
<x-filament::section>
|
||||
<x-slot name="heading">
|
||||
{{ __('Jabali Panel Update') }}
|
||||
</x-slot>
|
||||
<x-slot name="description">
|
||||
{{ __('Update the panel codebase and assets.') }}
|
||||
</x-slot>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
<div class="rounded-lg border border-gray-200 bg-white p-4 text-sm shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<div class="text-xs uppercase text-gray-500 dark:text-gray-400">{{ __('Current Version') }}</div>
|
||||
<div class="mt-1 text-lg font-semibold text-gray-900 dark:text-gray-100">{{ $currentVersion ?? 'unknown' }}</div>
|
||||
</div>
|
||||
<div class="rounded-lg border border-gray-200 bg-white p-4 text-sm shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<div class="text-xs uppercase text-gray-500 dark:text-gray-400">{{ __('Status') }}</div>
|
||||
<div class="mt-1 text-lg font-semibold text-gray-900 dark:text-gray-100">{{ $this->updateStatusLabel }}</div>
|
||||
</div>
|
||||
<div class="rounded-lg border border-gray-200 bg-white p-4 text-sm shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<div class="text-xs uppercase text-gray-500 dark:text-gray-400">{{ __('Last Checked') }}</div>
|
||||
<div class="mt-1 text-lg font-semibold text-gray-900 dark:text-gray-100">{{ $lastCheckedAt ?? __('Not checked') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (! empty($recentChanges))
|
||||
<div class="mt-4 rounded-lg border border-gray-200 bg-white p-4 text-sm shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<div class="text-xs font-semibold uppercase text-gray-500 dark:text-gray-400">{{ __('Recent Changes') }}</div>
|
||||
<ul class="mt-2 list-inside list-disc space-y-1 text-gray-700 dark:text-gray-200">
|
||||
@foreach ($recentChanges as $change)
|
||||
<li>{{ $change }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="mt-4 flex flex-wrap items-center gap-2">
|
||||
<x-filament::button
|
||||
icon="heroicon-o-magnifying-glass"
|
||||
color="gray"
|
||||
wire:click="checkForUpdates"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="checkForUpdates"
|
||||
>
|
||||
{{ __('Check for updates') }}
|
||||
</x-filament::button>
|
||||
|
||||
<x-filament::button
|
||||
icon="heroicon-o-arrow-path-rounded-square"
|
||||
color="primary"
|
||||
wire:click="performUpgrade"
|
||||
wire:loading.attr="disabled"
|
||||
wire:target="performUpgrade"
|
||||
>
|
||||
{{ __('Upgrade now') }}
|
||||
</x-filament::button>
|
||||
</div>
|
||||
|
||||
@if ($jabaliOutput !== null)
|
||||
<details class="mt-4 rounded border border-gray-200 bg-white p-4 shadow-sm open:shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<summary class="cursor-pointer list-none text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
{{ $jabaliOutputTitle ?? __('Jabali Update Output') }}
|
||||
@if ($jabaliOutputAt)
|
||||
<span class="ml-2 text-xs font-normal text-gray-500 dark:text-gray-400">
|
||||
{{ __('Last run at :time', ['time' => $jabaliOutputAt]) }}
|
||||
</span>
|
||||
@endif
|
||||
</summary>
|
||||
<div class="mt-3 text-sm text-gray-700 dark:text-gray-200">
|
||||
<pre class="whitespace-pre-wrap break-words rounded bg-gray-50 p-4 text-xs text-gray-800 dark:bg-gray-900/50 dark:text-gray-200">{{ $jabaliOutput }}</pre>
|
||||
</div>
|
||||
</details>
|
||||
@endif
|
||||
</x-filament::section>
|
||||
|
||||
{{ $this->table }}
|
||||
|
||||
@if ($refreshOutputAt)
|
||||
<details class="mt-4 rounded border border-gray-200 bg-white p-4 shadow-sm open:shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
||||
<summary class="cursor-pointer list-none text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
{{ $refreshOutputTitle ?? __('System Update Output') }}
|
||||
<span class="ml-2 text-xs font-normal text-gray-500 dark:text-gray-400">
|
||||
{{ __('Last run at :time', ['time' => $refreshOutputAt]) }}
|
||||
</span>
|
||||
</summary>
|
||||
<div class="mt-3 text-sm text-gray-700 dark:text-gray-200">
|
||||
@php
|
||||
$outputLines = is_array($refreshOutput) ? $refreshOutput : [$refreshOutput];
|
||||
@endphp
|
||||
<pre class="whitespace-pre-wrap break-words rounded bg-gray-50 p-4 text-xs text-gray-800 dark:bg-gray-900/50 dark:text-gray-200">{{ implode("\n", $outputLines) }}</pre>
|
||||
</div>
|
||||
</details>
|
||||
@endif
|
||||
|
||||
<x-filament-actions::modals />
|
||||
</x-filament-panels::page>
|
||||
|
||||
Reference in New Issue
Block a user