44
55use Ramsey \Uuid \Uuid ;
66use Illuminate \Support \Arr ;
7+ use Pterodactyl \Models \Egg ;
78use Pterodactyl \Models \User ;
9+ use Webmozart \Assert \Assert ;
810use Pterodactyl \Models \Server ;
911use Illuminate \Support \Collection ;
1012use Pterodactyl \Models \Allocation ;
1315use Pterodactyl \Repositories \Eloquent \EggRepository ;
1416use Pterodactyl \Repositories \Eloquent \ServerRepository ;
1517use Pterodactyl \Repositories \Wings \DaemonServerRepository ;
16- use Pterodactyl \Repositories \Eloquent \AllocationRepository ;
1718use Pterodactyl \Services \Deployment \FindViableNodesService ;
1819use Pterodactyl \Repositories \Eloquent \ServerVariableRepository ;
1920use Pterodactyl \Services \Deployment \AllocationSelectionService ;
2021use Pterodactyl \Exceptions \Http \Connection \DaemonConnectionException ;
2122
2223class ServerCreationService
2324{
24- /**
25- * @var \Pterodactyl\Repositories\Eloquent\AllocationRepository
26- */
27- private $ allocationRepository ;
28-
2925 /**
3026 * @var \Pterodactyl\Services\Deployment\AllocationSelectionService
3127 */
@@ -79,7 +75,6 @@ class ServerCreationService
7975 /**
8076 * CreationService constructor.
8177 *
82- * @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $allocationRepository
8378 * @param \Pterodactyl\Services\Deployment\AllocationSelectionService $allocationSelectionService
8479 * @param \Illuminate\Database\ConnectionInterface $connection
8580 * @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
@@ -92,7 +87,6 @@ class ServerCreationService
9287 * @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
9388 */
9489 public function __construct (
95- AllocationRepository $ allocationRepository ,
9690 AllocationSelectionService $ allocationSelectionService ,
9791 ConnectionInterface $ connection ,
9892 DaemonServerRepository $ daemonServerRepository ,
@@ -105,7 +99,6 @@ public function __construct(
10599 VariableValidatorService $ validatorService
106100 ) {
107101 $ this ->allocationSelectionService = $ allocationSelectionService ;
108- $ this ->allocationRepository = $ allocationRepository ;
109102 $ this ->configurationStructureService = $ configurationStructureService ;
110103 $ this ->connection = $ connection ;
111104 $ this ->findViableNodesService = $ findViableNodesService ;
@@ -149,14 +142,16 @@ public function handle(array $data, DeploymentObject $deployment = null): Server
149142
150143 // Auto-configure the node based on the selected allocation
151144 // if no node was defined.
152- if (is_null (Arr::get ($ data , 'node_id ' ))) {
153- $ data ['node_id ' ] = $ this ->getNodeFromAllocation ($ data ['allocation_id ' ]);
145+ if (empty ($ data ['node_id ' ])) {
146+ Assert::false (empty ($ data ['allocation_id ' ]), 'Expected a non-empty allocation_id in server creation data. ' );
147+
148+ $ data ['node_id ' ] = Allocation::query ()->findOrFail ($ data ['allocation_id ' ])->node_id ;
154149 }
155150
156- if (is_null (Arr:: get ( $ data, 'nest_id ' ) )) {
157- /** @var \Pterodactyl\Models\Egg $egg */
158- $ egg = $ this -> eggRepository -> setColumns ([ ' id ' , ' nest_id ' ])-> find (Arr:: get ( $ data , ' egg_id ' ));
159- $ data ['nest_id ' ] = $ egg ->nest_id ;
151+ if (empty ( $ data[ 'nest_id ' ] )) {
152+ Assert:: false ( empty ( $ data [ ' egg_id ' ]), ' Expected a non-empty egg_id in server creation data. ' );
153+
154+ $ data ['nest_id ' ] = Egg:: query ()-> findOrFail ( $ data [ ' egg_id ' ]) ->nest_id ;
160155 }
161156
162157 $ eggVariableData = $ this ->validatorService
@@ -269,7 +264,7 @@ private function storeAssignedAllocations(Server $server, array $data)
269264 $ records = array_merge ($ records , $ data ['allocation_additional ' ]);
270265 }
271266
272- $ this -> allocationRepository -> updateWhereIn ('id ' , $ records, [
267+ Allocation:: query ()-> whereIn ('id ' , $ records)-> update ( [
273268 'server_id ' => $ server ->id ,
274269 ]);
275270 }
@@ -295,22 +290,6 @@ private function storeEggVariables(Server $server, Collection $variables)
295290 }
296291 }
297292
298- /**
299- * Get the node that an allocation belongs to.
300- *
301- * @param int $id
302- * @return int
303- *
304- * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
305- */
306- private function getNodeFromAllocation (int $ id ): int
307- {
308- /** @var \Pterodactyl\Models\Allocation $allocation */
309- $ allocation = $ this ->allocationRepository ->setColumns (['id ' , 'node_id ' ])->find ($ id );
310-
311- return $ allocation ->node_id ;
312- }
313-
314293 /**
315294 * Create a unique UUID and UUID-Short combo for a server.
316295 *
0 commit comments