connection = $connection; $this->daemonServerRepository = $daemonServerRepository; $this->databaseRepository = $databaseRepository; $this->databaseManagementService = $databaseManagementService; $this->repository = $repository; $this->writer = $writer; } /** * Set if the server should be forcibly deleted from the panel (ignoring daemon errors) or not. * * @param bool $bool * @return $this */ public function withForce($bool = true) { $this->force = $bool; return $this; } /** * Delete a server from the panel and remove any associated databases from hosts. * * @param \Pterodactyl\Models\Server $server * * @throws \Throwable * @throws \Pterodactyl\Exceptions\DisplayException */ public function handle(Server $server) { try { $this->daemonServerRepository->setServer($server)->delete(); } catch (DaemonConnectionException $exception) { if ($this->force) { $this->writer->warning($exception); } else { throw $exception; } } $this->connection->transaction(function () use ($server) { $this->databaseRepository->setColumns('id')->findWhere([['server_id', '=', $server->id]])->each(function ($item) { $this->databaseManagementService->delete($item->id); }); $this->repository->delete($server->id); }); } }