alert = $alert; $this->dispatcher = $dispatcher; $this->repository = $repository; $this->locationRepository = $locationRepository; $this->nodeRepository = $nodeRepository; $this->suspensionService = $suspensionService; $this->transferService = $transferService; } /** * Starts a transfer of a server to a new node. * * @param \Illuminate\Http\Request $request * @param \Pterodactyl\Models\Server $server * @return \Illuminate\Http\RedirectResponse * * @throws \Throwable */ public function transfer(Request $request, Server $server) { $validatedData = $request->validate([ 'node_id' => 'required|exists:nodes,id', 'allocation_id' => 'required|bail|unique:servers|exists:allocations,id', 'allocation_additional' => 'nullable', ]); $node_id = $validatedData['node_id']; $allocation_id = $validatedData['allocation_id']; $additional_allocations = $validatedData['allocation_additional'] ?? []; // Check if the node is viable for the transfer. $node = $this->nodeRepository->getNodeWithResourceUsage($node_id); if ($node->isViable($server->memory, $server->disk)) { // Suspend the server and request an archive to be created. // $this->suspensionService->toggle($server, 'suspend'); $this->transferService->requestArchive($server); $this->alert->success(trans('admin/server.alerts.transfer_started'))->flash(); } else { $this->alert->danger(trans('admin/server.alerts.transfer_not_viable'))->flash(); } return redirect()->route('admin.servers.view.manage', $server->id); } }