connection = $connection; $this->repository = $repository; $this->writer = $writer; $this->daemonServerRepository = $daemonServerRepository; } /** * Suspends a server on the system. * * @param int|\Pterodactyl\Models\Server $server * @param string $action * * @throws \Throwable */ public function toggle(Server $server, $action = self::ACTION_SUSPEND) { Assert::oneOf($action, [self::ACTION_SUSPEND, self::ACTION_UNSUSPEND]); if ( $action === self::ACTION_SUSPEND && $server->suspended || $action === self::ACTION_UNSUSPEND && ! $server->suspended ) { return; } $this->connection->transaction(function () use ($action, $server) { $this->repository->withoutFreshModel()->update($server->id, [ 'suspended' => $action === self::ACTION_SUSPEND, ]); $this->daemonServerRepository->setServer($server)->suspend($action === self::ACTION_UNSUSPEND); }); } }