mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 10:16:51 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			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 ? trans('admin/databasehost.delete_help') : trans('filament-actions::delete.single.modal.actions.delete.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(trans('admin/databasehost.error'))
 | 
						|
                ->body($exception->getMessage())
 | 
						|
                ->color('danger')
 | 
						|
                ->icon('tabler-database')
 | 
						|
                ->danger()
 | 
						|
                ->send();
 | 
						|
 | 
						|
            throw new Halt();
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |