2017-10-07 21:16:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Nests;
|
|
|
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
use Pterodactyl\Models\Egg;
|
|
|
|
use Pterodactyl\Models\EggVariable;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\View\Factory as ViewFactory;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
|
|
|
use Pterodactyl\Services\Eggs\Variables\VariableUpdateService;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest;
|
|
|
|
use Pterodactyl\Services\Eggs\Variables\VariableCreationService;
|
|
|
|
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
|
|
|
|
|
|
|
class EggVariableController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* EggVariableController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected AlertsMessageBag $alert,
|
|
|
|
protected VariableCreationService $creationService,
|
|
|
|
protected VariableUpdateService $updateService,
|
|
|
|
protected EggRepositoryInterface $repository,
|
|
|
|
protected EggVariableRepositoryInterface $variableRepository,
|
|
|
|
protected ViewFactory $view
|
2017-10-07 21:16:51 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request to view the variables attached to an Egg.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
|
|
|
public function view(int $egg): View
|
|
|
|
{
|
|
|
|
$egg = $this->repository->getWithVariables($egg);
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
return $this->view->make('admin.eggs.variables', ['egg' => $egg]);
|
2017-10-07 21:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a request to create a new Egg variable.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2018-05-13 16:19:35 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException
|
2017-10-07 21:16:51 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
|
|
|
|
*/
|
|
|
|
public function store(EggVariableFormRequest $request, Egg $egg): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->creationService->handle($egg->id, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/nests.variables.notices.variable_created'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.egg.variables', $egg->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a request to update an existing Egg variable.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
|
|
|
|
*/
|
|
|
|
public function update(EggVariableFormRequest $request, Egg $egg, EggVariable $variable): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->updateService->handle($variable, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/nests.variables.notices.variable_updated', [
|
|
|
|
'variable' => $variable->name,
|
|
|
|
]))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.egg.variables', $egg->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a request to delete an existing Egg variable from the Panel.
|
|
|
|
*/
|
|
|
|
public function destroy(int $egg, EggVariable $variable): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->variableRepository->delete($variable->id);
|
|
|
|
$this->alert->success(trans('admin/nests.variables.notices.variable_deleted', [
|
|
|
|
'variable' => $variable->name,
|
|
|
|
]))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.egg.variables', $egg);
|
|
|
|
}
|
|
|
|
}
|