64 lines
2 KiB
PHP
64 lines
2 KiB
PHP
<?php
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin\Nests;
|
|
|
|
use Illuminate\View\View;
|
|
use Pterodactyl\Models\Egg;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Prologue\Alerts\AlertsMessageBag;
|
|
use Illuminate\View\Factory as ViewFactory;
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
use Pterodactyl\Services\Eggs\Scripts\InstallScriptService;
|
|
use Pterodactyl\Http\Requests\Admin\Egg\EggScriptFormRequest;
|
|
|
|
class EggScriptController extends Controller
|
|
{
|
|
/**
|
|
* EggScriptController constructor.
|
|
*/
|
|
public function __construct(
|
|
protected AlertsMessageBag $alert,
|
|
protected InstallScriptService $installScriptService,
|
|
protected ViewFactory $view
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Handle requests to render installation script for an Egg.
|
|
*/
|
|
public function index(int $egg): View
|
|
{
|
|
$egg = Egg::with('scriptFrom', 'configFrom')
|
|
->where('id', $egg)
|
|
->firstOrFail();
|
|
|
|
$copy = Egg::query()
|
|
->whereNull('copy_script_from')
|
|
->where('nest_id', $egg->nest_id)
|
|
->whereNot('id', $egg->id)
|
|
->firstOrFail();
|
|
|
|
$rely = Egg::query()->where('copy_script_from', $egg->id)->firstOrFail();
|
|
|
|
return $this->view->make('admin.eggs.scripts', [
|
|
'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
|
|
*/
|
|
public function update(EggScriptFormRequest $request, Egg $egg): RedirectResponse
|
|
{
|
|
$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);
|
|
}
|
|
}
|