2424
2525namespace Pterodactyl \Http \Controllers \Admin ;
2626
27- use Alert ;
2827use Javascript ;
2928use Illuminate \Http \Request ;
3029use Pterodactyl \Models \Node ;
31- use Pterodactyl \Models \Allocation ;
3230use Prologue \Alerts \AlertsMessageBag ;
3331use Pterodactyl \Http \Controllers \Controller ;
3432use Pterodactyl \Services \Nodes \UpdateService ;
3533use Pterodactyl \Services \Nodes \CreationService ;
3634use Pterodactyl \Services \Nodes \DeletionService ;
37- use Illuminate \Contracts \Translation \Translator ;
3835use Illuminate \Cache \Repository as CacheRepository ;
3936use Pterodactyl \Services \Allocations \AssignmentService ;
4037use Pterodactyl \Http \Requests \Admin \Node \NodeFormRequest ;
@@ -86,11 +83,6 @@ class NodesController extends Controller
8683 */
8784 protected $ repository ;
8885
89- /**
90- * @var \Illuminate\Contracts\Translation\Translator
91- */
92- protected $ translator ;
93-
9486 /**
9587 * @var \Pterodactyl\Services\Nodes\UpdateService
9688 */
@@ -107,7 +99,6 @@ class NodesController extends Controller
10799 * @param \Pterodactyl\Services\Nodes\DeletionService $deletionService
108100 * @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $locationRepository
109101 * @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
110- * @param \Illuminate\Contracts\Translation\Translator $translator
111102 * @param \Pterodactyl\Services\Nodes\UpdateService $updateService
112103 */
113104 public function __construct (
@@ -119,7 +110,6 @@ public function __construct(
119110 DeletionService $ deletionService ,
120111 LocationRepositoryInterface $ locationRepository ,
121112 NodeRepositoryInterface $ repository ,
122- Translator $ translator ,
123113 UpdateService $ updateService
124114 ) {
125115 $ this ->alert = $ alert ;
@@ -130,7 +120,6 @@ public function __construct(
130120 $ this ->deletionService = $ deletionService ;
131121 $ this ->locationRepository = $ locationRepository ;
132122 $ this ->repository = $ repository ;
133- $ this ->translator = $ translator ;
134123 $ this ->updateService = $ updateService ;
135124 }
136125
@@ -156,7 +145,7 @@ public function create()
156145 {
157146 $ locations = $ this ->locationRepository ->all ();
158147 if (count ($ locations ) < 1 ) {
159- $ this ->alert ->warning ($ this -> translator -> trans ('admin/node.notices.location_required ' ))->flash ();
148+ $ this ->alert ->warning (trans ('admin/node.notices.location_required ' ))->flash ();
160149
161150 return redirect ()->route ('admin.locations ' );
162151 }
@@ -175,7 +164,7 @@ public function create()
175164 public function store (NodeFormRequest $ request )
176165 {
177166 $ node = $ this ->creationService ->handle ($ request ->normalize ());
178- $ this ->alert ->info ($ this -> translator -> trans ('admin/node.notices.node_created ' ))->flash ();
167+ $ this ->alert ->info (trans ('admin/node.notices.node_created ' ))->flash ();
179168
180169 return redirect ()->route ('admin.nodes.view.allocation ' , $ node ->id );
181170 }
@@ -262,7 +251,7 @@ public function viewServers($node)
262251 public function updateSettings (NodeFormRequest $ request , Node $ node )
263252 {
264253 $ this ->updateService ->handle ($ node , $ request ->normalize ());
265- $ this ->alert ->success ($ this -> translator -> trans ('admin/node.notices.node_updated ' ))->flash ();
254+ $ this ->alert ->success (trans ('admin/node.notices.node_updated ' ))->flash ();
266255
267256 return redirect ()->route ('admin.nodes.view.settings ' , $ node ->id )->withInput ();
268257 }
@@ -276,12 +265,11 @@ public function updateSettings(NodeFormRequest $request, Node $node)
276265 */
277266 public function allocationRemoveSingle ($ node , $ allocation )
278267 {
279- $ query = Allocation::where ('node_id ' , $ node )->whereNull ('server_id ' )->where ('id ' , $ allocation )->delete ();
280- if ($ query < 1 ) {
281- return response ()->json ([
282- 'error ' => 'Unable to find an allocation matching those details to delete. ' ,
283- ], 400 );
284- }
268+ $ this ->allocationRepository ->deleteWhere ([
269+ ['id ' , '= ' , $ allocation ],
270+ ['node_id ' , '= ' , $ node ],
271+ ['server_id ' , '= ' , null ],
272+ ]);
285273
286274 return response ('' , 204 );
287275 }
@@ -295,15 +283,14 @@ public function allocationRemoveSingle($node, $allocation)
295283 */
296284 public function allocationRemoveBlock (Request $ request , $ node )
297285 {
298- $ query = Allocation::where ('node_id ' , $ node )
299- ->whereNull ('server_id ' )
300- ->where ('ip ' , $ request ->input ('ip ' ))
301- ->delete ();
302- if ($ query < 1 ) {
303- Alert::danger ('There was an error while attempting to delete allocations on that IP. ' )->flash ();
304- } else {
305- Alert::success ('Deleted all unallocated ports for <code> ' . $ request ->input ('ip ' ) . '</code>. ' )->flash ();
306- }
286+ $ this ->allocationRepository ->deleteWhere ([
287+ ['node_id ' , '= ' , $ node ],
288+ ['server_id ' , '= ' , null ],
289+ ['ip ' , '= ' , $ request ->input ('ip ' )],
290+ ]);
291+
292+ $ this ->alert ->success (trans ('admin/node.notices.unallocated_deleted ' , ['ip ' => $ request ->input ('ip ' )]))
293+ ->flash ();
307294
308295 return redirect ()->route ('admin.nodes.view.allocation ' , $ node );
309296 }
@@ -337,7 +324,7 @@ public function allocationSetAlias(AllocationAliasFormRequest $request)
337324 public function createAllocation (AllocationFormRequest $ request , Node $ node )
338325 {
339326 $ this ->assignmentService ->handle ($ node , $ request ->normalize ());
340- $ this ->alert ->success ($ this -> translator -> trans ('admin/node.notices.allocations_added ' ))->flash ();
327+ $ this ->alert ->success (trans ('admin/node.notices.allocations_added ' ))->flash ();
341328
342329 return redirect ()->route ('admin.nodes.view.allocation ' , $ node ->id );
343330 }
@@ -353,7 +340,7 @@ public function createAllocation(AllocationFormRequest $request, Node $node)
353340 public function delete ($ node )
354341 {
355342 $ this ->deletionService ->handle ($ node );
356- $ this ->alert ->success ($ this -> translator -> trans ('admin/node.notices.node_deleted ' ))->flash ();
343+ $ this ->alert ->success (trans ('admin/node.notices.node_deleted ' ))->flash ();
357344
358345 return redirect ()->route ('admin.nodes ' );
359346 }
0 commit comments