2017-10-07 21:16:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Nests;
|
|
|
|
|
|
|
|
use Illuminate\View\View;
|
2020-10-06 04:29:35 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
2017-10-07 21:16:51 +00:00
|
|
|
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\Services\Eggs\Scripts\InstallScriptService;
|
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
|
|
|
use Pterodactyl\Http\Requests\Admin\Egg\EggScriptFormRequest;
|
|
|
|
|
|
|
|
class EggScriptController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* EggScriptController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected AlertsMessageBag $alert,
|
|
|
|
protected EggRepositoryInterface $repository,
|
|
|
|
protected InstallScriptService $installScriptService,
|
|
|
|
protected ViewFactory $view
|
2017-10-07 21:16:51 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle requests to render installation script for an Egg.
|
|
|
|
*/
|
|
|
|
public function index(int $egg): View
|
|
|
|
{
|
|
|
|
$egg = $this->repository->getWithCopyAttributes($egg);
|
|
|
|
$copy = $this->repository->findWhere([
|
|
|
|
['copy_script_from', '=', null],
|
|
|
|
['nest_id', '=', $egg->nest_id],
|
|
|
|
['id', '!=', $egg],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$rely = $this->repository->findWhere([
|
|
|
|
['copy_script_from', '=', $egg->id],
|
|
|
|
]);
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
return $this->view->make('admin.eggs.scripts', [
|
2017-10-07 21:16:51 +00:00
|
|
|
'copyFromOptions' => $copy,
|
|
|
|
'relyOnScript' => $rely,
|
|
|
|
'egg' => $egg,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a request to update the installation script for an Egg.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
|
|
|
|
*/
|
2020-10-06 04:29:35 +00:00
|
|
|
public function update(EggScriptFormRequest $request, Egg $egg): RedirectResponse
|
2017-10-07 21:16:51 +00:00
|
|
|
{
|
|
|
|
$this->installScriptService->handle($egg, $request->normalize());
|
|
|
|
$this->alert->success(trans('admin/nests.eggs.notices.script_updated'))->flash();
|
|
|
|
|
|
|
|
return redirect()->route('admin.nests.egg.scripts', $egg);
|
|
|
|
}
|
|
|
|
}
|