mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-11-04 06:56:53 +01:00 
			
		
		
		
	Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> Co-authored-by: Boy132 <Boy132@users.noreply.github.com> Co-authored-by: Lance Pioch <git@lance.sh>
		
			
				
	
	
		
			70 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App\Filament\Admin\Resources\DatabaseHosts\Pages;
 | 
						|
 | 
						|
use App\Filament\Admin\Resources\DatabaseHosts\DatabaseHostResource;
 | 
						|
use App\Models\DatabaseHost;
 | 
						|
use App\Services\Databases\Hosts\HostUpdateService;
 | 
						|
use App\Traits\Filament\CanCustomizeHeaderActions;
 | 
						|
use App\Traits\Filament\CanCustomizeHeaderWidgets;
 | 
						|
use Filament\Actions\Action;
 | 
						|
use Filament\Actions\ActionGroup;
 | 
						|
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
 | 
						|
{
 | 
						|
    use CanCustomizeHeaderActions;
 | 
						|
    use CanCustomizeHeaderWidgets;
 | 
						|
 | 
						|
    protected static string $resource = DatabaseHostResource::class;
 | 
						|
 | 
						|
    private HostUpdateService $hostUpdateService;
 | 
						|
 | 
						|
    public function boot(HostUpdateService $hostUpdateService): void
 | 
						|
    {
 | 
						|
        $this->hostUpdateService = $hostUpdateService;
 | 
						|
    }
 | 
						|
 | 
						|
    /** @return array<Action|ActionGroup> */
 | 
						|
    protected function getDefaultHeaderActions(): 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 [];
 | 
						|
    }
 | 
						|
 | 
						|
    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();
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |