Complete migration of node controllers/repositories to new service structure
This commit is contained in:
parent
669119c8f8
commit
7277f728a9
|
@ -84,10 +84,18 @@ interface RepositoryInterface
|
||||||
* Delete a given record from the database.
|
* Delete a given record from the database.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return bool|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function delete($id);
|
public function delete($id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete records matching the given attributes.
|
||||||
|
*
|
||||||
|
* @param array $attributes
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function deleteWhere(array $attributes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a model that has the specific ID passed.
|
* Find a model that has the specific ID passed.
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,17 +24,14 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Admin;
|
namespace Pterodactyl\Http\Controllers\Admin;
|
||||||
|
|
||||||
use Alert;
|
|
||||||
use Javascript;
|
use Javascript;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Pterodactyl\Models\Node;
|
use Pterodactyl\Models\Node;
|
||||||
use Pterodactyl\Models\Allocation;
|
|
||||||
use Prologue\Alerts\AlertsMessageBag;
|
use Prologue\Alerts\AlertsMessageBag;
|
||||||
use Pterodactyl\Http\Controllers\Controller;
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
use Pterodactyl\Services\Nodes\UpdateService;
|
use Pterodactyl\Services\Nodes\UpdateService;
|
||||||
use Pterodactyl\Services\Nodes\CreationService;
|
use Pterodactyl\Services\Nodes\CreationService;
|
||||||
use Pterodactyl\Services\Nodes\DeletionService;
|
use Pterodactyl\Services\Nodes\DeletionService;
|
||||||
use Illuminate\Contracts\Translation\Translator;
|
|
||||||
use Illuminate\Cache\Repository as CacheRepository;
|
use Illuminate\Cache\Repository as CacheRepository;
|
||||||
use Pterodactyl\Services\Allocations\AssignmentService;
|
use Pterodactyl\Services\Allocations\AssignmentService;
|
||||||
use Pterodactyl\Http\Requests\Admin\Node\NodeFormRequest;
|
use Pterodactyl\Http\Requests\Admin\Node\NodeFormRequest;
|
||||||
|
@ -86,11 +83,6 @@ class NodesController extends Controller
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Illuminate\Contracts\Translation\Translator
|
|
||||||
*/
|
|
||||||
protected $translator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Nodes\UpdateService
|
* @var \Pterodactyl\Services\Nodes\UpdateService
|
||||||
*/
|
*/
|
||||||
|
@ -107,7 +99,6 @@ class NodesController extends Controller
|
||||||
* @param \Pterodactyl\Services\Nodes\DeletionService $deletionService
|
* @param \Pterodactyl\Services\Nodes\DeletionService $deletionService
|
||||||
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $locationRepository
|
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $locationRepository
|
||||||
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
|
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
|
||||||
* @param \Illuminate\Contracts\Translation\Translator $translator
|
|
||||||
* @param \Pterodactyl\Services\Nodes\UpdateService $updateService
|
* @param \Pterodactyl\Services\Nodes\UpdateService $updateService
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -119,7 +110,6 @@ class NodesController extends Controller
|
||||||
DeletionService $deletionService,
|
DeletionService $deletionService,
|
||||||
LocationRepositoryInterface $locationRepository,
|
LocationRepositoryInterface $locationRepository,
|
||||||
NodeRepositoryInterface $repository,
|
NodeRepositoryInterface $repository,
|
||||||
Translator $translator,
|
|
||||||
UpdateService $updateService
|
UpdateService $updateService
|
||||||
) {
|
) {
|
||||||
$this->alert = $alert;
|
$this->alert = $alert;
|
||||||
|
@ -130,7 +120,6 @@ class NodesController extends Controller
|
||||||
$this->deletionService = $deletionService;
|
$this->deletionService = $deletionService;
|
||||||
$this->locationRepository = $locationRepository;
|
$this->locationRepository = $locationRepository;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->translator = $translator;
|
|
||||||
$this->updateService = $updateService;
|
$this->updateService = $updateService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +145,7 @@ class NodesController extends Controller
|
||||||
{
|
{
|
||||||
$locations = $this->locationRepository->all();
|
$locations = $this->locationRepository->all();
|
||||||
if (count($locations) < 1) {
|
if (count($locations) < 1) {
|
||||||
$this->alert->warning($this->translator->trans('admin/node.notices.location_required'))->flash();
|
$this->alert->warning(trans('admin/node.notices.location_required'))->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.locations');
|
return redirect()->route('admin.locations');
|
||||||
}
|
}
|
||||||
|
@ -175,7 +164,7 @@ class NodesController extends Controller
|
||||||
public function store(NodeFormRequest $request)
|
public function store(NodeFormRequest $request)
|
||||||
{
|
{
|
||||||
$node = $this->creationService->handle($request->normalize());
|
$node = $this->creationService->handle($request->normalize());
|
||||||
$this->alert->info($this->translator->trans('admin/node.notices.node_created'))->flash();
|
$this->alert->info(trans('admin/node.notices.node_created'))->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.nodes.view.allocation', $node->id);
|
return redirect()->route('admin.nodes.view.allocation', $node->id);
|
||||||
}
|
}
|
||||||
|
@ -262,7 +251,7 @@ class NodesController extends Controller
|
||||||
public function updateSettings(NodeFormRequest $request, Node $node)
|
public function updateSettings(NodeFormRequest $request, Node $node)
|
||||||
{
|
{
|
||||||
$this->updateService->handle($node, $request->normalize());
|
$this->updateService->handle($node, $request->normalize());
|
||||||
$this->alert->success($this->translator->trans('admin/node.notices.node_updated'))->flash();
|
$this->alert->success(trans('admin/node.notices.node_updated'))->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.nodes.view.settings', $node->id)->withInput();
|
return redirect()->route('admin.nodes.view.settings', $node->id)->withInput();
|
||||||
}
|
}
|
||||||
|
@ -276,12 +265,11 @@ class NodesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function allocationRemoveSingle($node, $allocation)
|
public function allocationRemoveSingle($node, $allocation)
|
||||||
{
|
{
|
||||||
$query = Allocation::where('node_id', $node)->whereNull('server_id')->where('id', $allocation)->delete();
|
$this->allocationRepository->deleteWhere([
|
||||||
if ($query < 1) {
|
['id', '=', $allocation],
|
||||||
return response()->json([
|
['node_id', '=', $node],
|
||||||
'error' => 'Unable to find an allocation matching those details to delete.',
|
['server_id', '=', null],
|
||||||
], 400);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
return response('', 204);
|
return response('', 204);
|
||||||
}
|
}
|
||||||
|
@ -295,15 +283,14 @@ class NodesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function allocationRemoveBlock(Request $request, $node)
|
public function allocationRemoveBlock(Request $request, $node)
|
||||||
{
|
{
|
||||||
$query = Allocation::where('node_id', $node)
|
$this->allocationRepository->deleteWhere([
|
||||||
->whereNull('server_id')
|
['node_id', '=', $node],
|
||||||
->where('ip', $request->input('ip'))
|
['server_id', '=', null],
|
||||||
->delete();
|
['ip', '=', $request->input('ip')],
|
||||||
if ($query < 1) {
|
]);
|
||||||
Alert::danger('There was an error while attempting to delete allocations on that IP.')->flash();
|
|
||||||
} else {
|
$this->alert->success(trans('admin/node.notices.unallocated_deleted', ['ip' => $request->input('ip')]))
|
||||||
Alert::success('Deleted all unallocated ports for <code>' . $request->input('ip') . '</code>.')->flash();
|
->flash();
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->route('admin.nodes.view.allocation', $node);
|
return redirect()->route('admin.nodes.view.allocation', $node);
|
||||||
}
|
}
|
||||||
|
@ -337,7 +324,7 @@ class NodesController extends Controller
|
||||||
public function createAllocation(AllocationFormRequest $request, Node $node)
|
public function createAllocation(AllocationFormRequest $request, Node $node)
|
||||||
{
|
{
|
||||||
$this->assignmentService->handle($node, $request->normalize());
|
$this->assignmentService->handle($node, $request->normalize());
|
||||||
$this->alert->success($this->translator->trans('admin/node.notices.allocations_added'))->flash();
|
$this->alert->success(trans('admin/node.notices.allocations_added'))->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.nodes.view.allocation', $node->id);
|
return redirect()->route('admin.nodes.view.allocation', $node->id);
|
||||||
}
|
}
|
||||||
|
@ -353,7 +340,7 @@ class NodesController extends Controller
|
||||||
public function delete($node)
|
public function delete($node)
|
||||||
{
|
{
|
||||||
$this->deletionService->handle($node);
|
$this->deletionService->handle($node);
|
||||||
$this->alert->success($this->translator->trans('admin/node.notices.node_deleted'))->flash();
|
$this->alert->success(trans('admin/node.notices.node_deleted'))->flash();
|
||||||
|
|
||||||
return redirect()->route('admin.nodes');
|
return redirect()->route('admin.nodes');
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,11 +119,19 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
||||||
*/
|
*/
|
||||||
public function delete($id, $destroy = false)
|
public function delete($id, $destroy = false)
|
||||||
{
|
{
|
||||||
if ($destroy) {
|
$instance = $this->getBuilder()->where($this->getModel()->getKeyName(), $id);
|
||||||
return $this->getBuilder()->where($this->getModel()->getKeyName(), $id)->forceDelete();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getBuilder()->where($this->getModel()->getKeyName(), $id)->delete();
|
return ($destroy) ? $instance->forceDelete() : $instance->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function deleteWhere(array $attributes, $force = false)
|
||||||
|
{
|
||||||
|
$instance = $this->getBuilder()->where($attributes);
|
||||||
|
|
||||||
|
return ($force) ? $instance->forceDelete() : $instance->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,5 +33,6 @@ return [
|
||||||
'location_required' => 'You must have at least one location configured before you can add a node to this panel.',
|
'location_required' => 'You must have at least one location configured before you can add a node to this panel.',
|
||||||
'node_created' => 'Successfully created new node. You can automatically configure the daemon on this machine by visiting the \'Configuration\' tab. <strong>Before you can add any servers you must first allocate at least one IP address and port.</strong>',
|
'node_created' => 'Successfully created new node. You can automatically configure the daemon on this machine by visiting the \'Configuration\' tab. <strong>Before you can add any servers you must first allocate at least one IP address and port.</strong>',
|
||||||
'node_updated' => 'Node information has been updated. If any daemon settings were changed you will need to reboot it for those changes to take effect.',
|
'node_updated' => 'Node information has been updated. If any daemon settings were changed you will need to reboot it for those changes to take effect.',
|
||||||
|
'unallocated_deleted' => 'Deleted all unallocatred ports for <code>:ip</code>.',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue