1212use Javascript ;
1313use Illuminate \Http \Request ;
1414use Pterodactyl \Models \Node ;
15+ use Illuminate \Http \Response ;
16+ use Pterodactyl \Models \Allocation ;
1517use Prologue \Alerts \AlertsMessageBag ;
1618use Pterodactyl \Http \Controllers \Controller ;
1719use Pterodactyl \Services \Nodes \NodeUpdateService ;
2325use Pterodactyl \Http \Requests \Admin \Node \NodeFormRequest ;
2426use Pterodactyl \Contracts \Repository \NodeRepositoryInterface ;
2527use Pterodactyl \Http \Requests \Admin \Node \AllocationFormRequest ;
28+ use Pterodactyl \Services \Allocations \AllocationDeletionService ;
2629use Pterodactyl \Contracts \Repository \LocationRepositoryInterface ;
2730use Pterodactyl \Contracts \Repository \AllocationRepositoryInterface ;
2831use Pterodactyl \Http \Requests \Admin \Node \AllocationAliasFormRequest ;
@@ -78,11 +81,16 @@ class NodesController extends Controller
7881 * @var \Pterodactyl\Services\Helpers\SoftwareVersionService
7982 */
8083 protected $ versionService ;
84+ /**
85+ * @var \Pterodactyl\Services\Allocations\AllocationDeletionService
86+ */
87+ private $ allocationDeletionService ;
8188
8289 /**
8390 * NodesController constructor.
8491 *
8592 * @param \Prologue\Alerts\AlertsMessageBag $alert
93+ * @param \Pterodactyl\Services\Allocations\AllocationDeletionService $allocationDeletionService
8694 * @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
8795 * @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
8896 * @param \Illuminate\Cache\Repository $cache
@@ -95,6 +103,7 @@ class NodesController extends Controller
95103 */
96104 public function __construct (
97105 AlertsMessageBag $ alert ,
106+ AllocationDeletionService $ allocationDeletionService ,
98107 AllocationRepositoryInterface $ allocationRepository ,
99108 AssignmentService $ assignmentService ,
100109 CacheRepository $ cache ,
@@ -106,6 +115,7 @@ public function __construct(
106115 SoftwareVersionService $ versionService
107116 ) {
108117 $ this ->alert = $ alert ;
118+ $ this ->allocationDeletionService = $ allocationDeletionService ;
109119 $ this ->allocationRepository = $ allocationRepository ;
110120 $ this ->assignmentService = $ assignmentService ;
111121 $ this ->cache = $ cache ;
@@ -262,17 +272,14 @@ public function updateSettings(NodeFormRequest $request, Node $node)
262272 /**
263273 * Removes a single allocation from a node.
264274 *
265- * @param int $node
266- * @param int $allocation
267- * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
275+ * @param \Pterodactyl\Models\Allocation $allocation
276+ * @return \Illuminate\Http\Response
277+ *
278+ * @throws \Pterodactyl\Exceptions\Service\Allocation\ServerUsingAllocationException
268279 */
269- public function allocationRemoveSingle ($ node , $ allocation )
280+ public function allocationRemoveSingle (Allocation $ allocation ): Response
270281 {
271- $ this ->allocationRepository ->deleteWhere ([
272- ['id ' , '= ' , $ allocation ],
273- ['node_id ' , '= ' , $ node ],
274- ['server_id ' , '= ' , null ],
275- ]);
282+ $ this ->allocationDeletionService ->handle ($ allocation );
276283
277284 return response ('' , 204 );
278285 }
0 commit comments