diff --git a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php index 968111635..b92c6c781 100644 --- a/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php +++ b/app/Filament/Admin/Resources/NodeResource/Pages/EditNode.php @@ -599,7 +599,7 @@ class EditNode extends EditRecord $this->errored = true; Notification::make() - ->title(trans('admin/node.error_connecting')) + ->title(trans('admin/node.error_connecting', ['node' => $record->name])) ->body(trans('admin/node.error_connecting_description')) ->color('warning') ->icon('tabler-database') diff --git a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php index e19cb6c86..78b45b5c5 100644 --- a/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php +++ b/app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php @@ -19,6 +19,7 @@ use App\Models\ServerVariable; use App\Models\User; use App\Services\Databases\DatabaseManagementService; use App\Services\Eggs\EggChangerService; +use App\Services\Servers\BuildModificationService; use App\Services\Servers\RandomWordService; use App\Services\Servers\ReinstallServerService; use App\Services\Servers\ServerDeletionService; @@ -50,6 +51,7 @@ use Filament\Forms\Set; use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Validator; use LogicException; use Webbingbrasil\FilamentCopyActions\Forms\Actions\CopyAction; @@ -58,6 +60,15 @@ class EditServer extends EditRecord { protected static string $resource = ServerResource::class; + private bool $errored = false; + + private BuildModificationService $buildModificationService; + + public function boot(BuildModificationService $buildModificationService): void + { + $this->buildModificationService = $buildModificationService; + } + public function form(Form $form): Form { return $form @@ -947,6 +958,40 @@ class EditServer extends EditRecord return $data; } + protected function handleRecordUpdate(Model $record, array $data): Model + { + if (!$record instanceof Server) { + return $record; + } + + try { + $this->record = $this->buildModificationService->handle($record, $data, true); + + return $this->record; + } catch (Exception $exception) { + $this->errored = true; + + Notification::make() + ->title(trans('admin/server.notifications.error_connecting', ['node' => $record->node->name])) + ->body(trans('admin/server.notifications.error_connecting_description')) + ->color('warning') + ->icon('tabler-database') + ->warning() + ->send(); + + return parent::handleRecordUpdate($record, $data); + } + } + + protected function getSavedNotification(): ?Notification + { + if ($this->errored) { + return null; + } + + return parent::getSavedNotification(); + } + public function getRelationManagers(): array { return [ diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index 8d641406d..89ea0dd1e 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -8,6 +8,7 @@ use App\Models\Allocation; use Illuminate\Database\ConnectionInterface; use App\Exceptions\DisplayException; use App\Repositories\Daemon\DaemonServerRepository; +use Exception; use Illuminate\Http\Client\ConnectionException; class BuildModificationService @@ -27,7 +28,7 @@ class BuildModificationService * @throws \Throwable * @throws \App\Exceptions\DisplayException */ - public function handle(Server $server, array $data): Server + public function handle(Server $server, array $data, ?bool $shouldThrow = false): Server { /** @var \App\Models\Server $server */ $server = $this->connection->transaction(function () use ($server, $data) { @@ -66,6 +67,10 @@ class BuildModificationService $this->daemonServerRepository->setServer($server)->sync(); } catch (ConnectionException $exception) { logger()->warning($exception, ['server_id' => $server->id]); + + if ($shouldThrow) { + throw $exception; + } } } diff --git a/lang/en/admin/node.php b/lang/en/admin/node.php index 7ef2ffc5a..582d3a808 100644 --- a/lang/en/admin/node.php +++ b/lang/en/admin/node.php @@ -103,6 +103,6 @@ return [ 'databases' => 'Databases', 'backups' => 'Backups', - 'error_connecting' => 'Error connecting to the node', + 'error_connecting' => 'Error connecting to :node', 'error_connecting_description' => 'The configuration could not be automatically updated on Wings, you will need to manually update the configuration file.', ]; diff --git a/lang/en/admin/server.php b/lang/en/admin/server.php index a13dd269b..b7039ac84 100644 --- a/lang/en/admin/server.php +++ b/lang/en/admin/server.php @@ -117,5 +117,7 @@ return [ 'invalid_port_body' => ':i is not in the valid port range between :portFloor-:portCeil', 'already_exists' => 'Port already in use', 'already_exists_body' => ':i is already with an allocation', + 'error_connecting' => 'Error connecting to :node', + 'error_connecting_description' => 'The configuration could not be automatically synced on Wings, you will need to manually restart the server.', ], ];