Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Controllers/Admin/Nests/EggScriptController.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Http\Controllers\Admin\Nests;
4
5
use Illuminate\View\View;
6
use Pterodactyl\Models\Egg;
7
use Illuminate\Http\RedirectResponse;
8
use Prologue\Alerts\AlertsMessageBag;
9
use Illuminate\View\Factory as ViewFactory;
10
use Pterodactyl\Http\Controllers\Controller;
11
use Pterodactyl\Services\Eggs\Scripts\InstallScriptService;
12
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
13
use Pterodactyl\Http\Requests\Admin\Egg\EggScriptFormRequest;
14
15
class EggScriptController extends Controller
16
{
17
/**
18
* EggScriptController constructor.
19
*/
20
public function __construct(
21
protected AlertsMessageBag $alert,
22
protected EggRepositoryInterface $repository,
23
protected InstallScriptService $installScriptService,
24
protected ViewFactory $view,
25
) {
26
}
27
28
/**
29
* Handle requests to render installation script for an Egg.
30
*/
31
public function index(int $egg): View
32
{
33
$egg = $this->repository->getWithCopyAttributes($egg);
34
$copy = $this->repository->findWhere([
35
['copy_script_from', '=', null],
36
['nest_id', '=', $egg->nest_id],
37
['id', '!=', $egg],
38
]);
39
40
$rely = $this->repository->findWhere([
41
['copy_script_from', '=', $egg->id],
42
]);
43
44
return view('admin.eggs.scripts', [
45
'copyFromOptions' => $copy,
46
'relyOnScript' => $rely,
47
'egg' => $egg,
48
]);
49
}
50
51
/**
52
* Handle a request to update the installation script for an Egg.
53
*
54
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
55
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
56
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
57
*/
58
public function update(EggScriptFormRequest $request, Egg $egg): RedirectResponse
59
{
60
$this->installScriptService->handle($egg, $request->normalize());
61
$this->alert->success(trans('admin/nests.eggs.notices.script_updated'))->flash();
62
63
return redirect()->route('admin.nests.egg.scripts', $egg);
64
}
65
}
66
67