mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 01:44:45 +02:00

* update ApiKeyResource * update DatabaseHostResource * update MountResource * update RoleResource * update UserResource * WebhookResource * fix phpstan * add back label translations for resources * add back other labels * upstream changes
74 lines
2.2 KiB
PHP
74 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Admin\Resources\DatabaseHostResource\Pages;
|
|
|
|
use App\Filament\Admin\Resources\DatabaseHostResource;
|
|
use App\Filament\Admin\Resources\DatabaseHostResource\RelationManagers\DatabasesRelationManager;
|
|
use App\Models\DatabaseHost;
|
|
use App\Services\Databases\Hosts\HostUpdateService;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Filament\Support\Exceptions\Halt;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use PDOException;
|
|
|
|
class EditDatabaseHost extends EditRecord
|
|
{
|
|
protected static string $resource = DatabaseHostResource::class;
|
|
|
|
private HostUpdateService $hostUpdateService;
|
|
|
|
public function boot(HostUpdateService $hostUpdateService): void
|
|
{
|
|
$this->hostUpdateService = $hostUpdateService;
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
DeleteAction::make()
|
|
->label(fn (DatabaseHost $databaseHost) => $databaseHost->databases()->count() > 0 ? 'Database Host Has Databases' : trans('filament-actions::delete.single.label'))
|
|
->disabled(fn (DatabaseHost $databaseHost) => $databaseHost->databases()->count() > 0),
|
|
$this->getSaveFormAction()->formId('form'),
|
|
];
|
|
}
|
|
|
|
protected function getFormActions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getRelationManagers(): array
|
|
{
|
|
if (DatabasesRelationManager::canViewForRecord($this->getRecord(), static::class)) {
|
|
return [
|
|
DatabasesRelationManager::class,
|
|
];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
protected function handleRecordUpdate(Model $record, array $data): Model
|
|
{
|
|
if (!$record instanceof DatabaseHost) {
|
|
return $record;
|
|
}
|
|
|
|
try {
|
|
return $this->hostUpdateService->handle($record, $data);
|
|
} catch (PDOException $exception) {
|
|
Notification::make()
|
|
->title('Error connecting to database host')
|
|
->body($exception->getMessage())
|
|
->color('danger')
|
|
->icon('tabler-database')
|
|
->danger()
|
|
->send();
|
|
|
|
throw new Halt();
|
|
}
|
|
}
|
|
}
|