Skip to content

Commit 6b8464e

Browse files
committed
Nest & Egg management working through the ACP now.
1 parent df87ea0 commit 6b8464e

32 files changed

+616
-566
lines changed

app/Exceptions/Service/ServiceOption/HasChildrenException.php renamed to app/Exceptions/Service/Egg/HasChildrenException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* https://opensource.org/licenses/MIT
88
*/
99

10-
namespace Pterodactyl\Exceptions\Service\ServiceOption;
10+
namespace Pterodactyl\Exceptions\Service\Egg;
1111

1212
use Pterodactyl\Exceptions\DisplayException;
1313

app/Exceptions/Service/ServiceVariable/ReservedVariableNameException.php renamed to app/Exceptions/Service/Egg/InvalidCopyFromException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* https://opensource.org/licenses/MIT
88
*/
99

10-
namespace Pterodactyl\Exceptions\Service\ServiceVariable;
10+
namespace Pterodactyl\Exceptions\Service\Egg;
1111

12-
use Exception;
12+
use Pterodactyl\Exceptions\DisplayException;
1313

14-
class ReservedVariableNameException extends Exception
14+
class InvalidCopyFromException extends DisplayException
1515
{
1616
}

app/Exceptions/Service/ServiceOption/NoParentConfigurationFoundException.php renamed to app/Exceptions/Service/Egg/NoParentConfigurationFoundException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
* https://opensource.org/licenses/MIT
88
*/
99

10-
namespace Pterodactyl\Exceptions\Service\ServiceOption;
10+
namespace Pterodactyl\Exceptions\Service\Egg;
1111

12-
class NoParentConfigurationFoundException extends \Exception
12+
use Pterodactyl\Exceptions\DisplayException;
13+
14+
class NoParentConfigurationFoundException extends DisplayException
1315
{
1416
}

app/Exceptions/Service/ServiceOption/InvalidCopyFromException.php renamed to app/Exceptions/Service/Egg/Variable/ReservedVariableNameException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
* https://opensource.org/licenses/MIT
88
*/
99

10-
namespace Pterodactyl\Exceptions\Service\ServiceOption;
10+
namespace Pterodactyl\Exceptions\Service\Egg\Variable;
1111

12-
class InvalidCopyFromException extends \Exception
12+
use Pterodactyl\Exceptions\DisplayException;
13+
14+
class ReservedVariableNameException extends DisplayException
1315
{
1416
}

app/Http/Controllers/API/Remote/OptionRetrievalController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use Illuminate\Http\JsonResponse;
1313
use Pterodactyl\Http\Controllers\Controller;
1414
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
15-
use Pterodactyl\Services\Services\Options\OptionConfigurationFileService;
15+
use Pterodactyl\Services\Services\Options\EggConfigurationService;
1616

1717
class OptionRetrievalController extends Controller
1818
{
1919
/**
20-
* @var \Pterodactyl\Services\Services\Options\OptionConfigurationFileService
20+
* @var \Pterodactyl\Services\Services\Options\EggConfigurationService
2121
*/
2222
protected $configurationFileService;
2323

@@ -29,12 +29,12 @@ class OptionRetrievalController extends Controller
2929
/**
3030
* OptionUpdateController constructor.
3131
*
32-
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
33-
* @param \Pterodactyl\Services\Services\Options\OptionConfigurationFileService $configurationFileService
32+
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
33+
* @param \Pterodactyl\Services\Services\Options\EggConfigurationService $configurationFileService
3434
*/
3535
public function __construct(
3636
EggRepositoryInterface $repository,
37-
OptionConfigurationFileService $configurationFileService
37+
EggConfigurationService $configurationFileService
3838
) {
3939
$this->configurationFileService = $configurationFileService;
4040
$this->repository = $repository;

app/Http/Controllers/Admin/Nests/EggController.php

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,120 @@
99

1010
namespace Pterodactyl\Http\Controllers\Admin\Nests;
1111

12+
use Javascript;
1213
use Illuminate\View\View;
1314
use Pterodactyl\Models\Egg;
15+
use Illuminate\Http\RedirectResponse;
16+
use Prologue\Alerts\AlertsMessageBag;
1417
use Pterodactyl\Http\Controllers\Controller;
18+
use Pterodactyl\Services\Eggs\EggUpdateService;
19+
use Pterodactyl\Services\Eggs\EggCreationService;
20+
use Pterodactyl\Services\Eggs\EggDeletionService;
21+
use Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest;
1522
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
23+
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
1624

1725
class EggController extends Controller
1826
{
27+
protected $alert;
28+
protected $creationService;
29+
protected $deletionService;
30+
protected $nestRepository;
1931
protected $repository;
32+
protected $updateService;
2033

21-
public function __construct(EggRepositoryInterface $repository)
22-
{
34+
public function __construct(
35+
AlertsMessageBag $alert,
36+
EggCreationService $creationService,
37+
EggDeletionService $deletionService,
38+
EggRepositoryInterface $repository,
39+
EggUpdateService $updateService,
40+
NestRepositoryInterface $nestRepository
41+
) {
42+
$this->alert = $alert;
43+
$this->creationService = $creationService;
44+
$this->deletionService = $deletionService;
45+
$this->nestRepository = $nestRepository;
2346
$this->repository = $repository;
47+
$this->updateService = $updateService;
48+
}
49+
50+
/**
51+
* Handle a request to display the Egg creation page.
52+
*
53+
* @return \Illuminate\View\View
54+
*
55+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
56+
*/
57+
public function create(): View
58+
{
59+
$nests = $this->nestRepository->getWithEggs();
60+
Javascript::put(['nests' => $nests->keyBy('id')]);
61+
62+
return view('admin.eggs.new', ['nests' => $nests]);
63+
}
64+
65+
/**
66+
* Handle request to store a new Egg.
67+
*
68+
* @param \Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest $request
69+
* @return \Illuminate\Http\RedirectResponse
70+
*
71+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
72+
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
73+
*/
74+
public function store(EggFormRequest $request): RedirectResponse
75+
{
76+
$egg = $this->creationService->handle($request->normalize());
77+
$this->alert->success(trans('admin/nests.eggs.notices.egg_created'))->flash();
78+
79+
return redirect()->route('admin.nests.egg.view', $egg->id);
2480
}
2581

82+
/**
83+
* Handle request to view a single Egg.
84+
*
85+
* @param \Pterodactyl\Models\Egg $egg
86+
* @return \Illuminate\View\View
87+
*/
2688
public function view(Egg $egg): View
2789
{
28-
return view('admin.eggs.view', [
29-
'egg' => $egg,
30-
]);
90+
return view('admin.eggs.view', ['egg' => $egg]);
91+
}
92+
93+
/**
94+
* Handle request to update an Egg.
95+
*
96+
* @param \Pterodactyl\Http\Requests\Admin\Egg\EggFormRequest $request
97+
* @param \Pterodactyl\Models\Egg $egg
98+
* @return \Illuminate\Http\RedirectResponse
99+
*
100+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
101+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
102+
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
103+
*/
104+
public function update(EggFormRequest $request, Egg $egg): RedirectResponse
105+
{
106+
$this->updateService->handle($egg, $request->normalize());
107+
$this->alert->success(trans('admin/nests.eggs.notices.updated'))->flash();
108+
109+
return redirect()->route('admin.nests.egg.view', $egg->id);
110+
}
111+
112+
/**
113+
* Handle request to destroy an egg.
114+
*
115+
* @param \Pterodactyl\Models\Egg $egg
116+
* @return \Illuminate\Http\RedirectResponse
117+
*
118+
* @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException
119+
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
120+
*/
121+
public function destroy(Egg $egg): RedirectResponse
122+
{
123+
$this->deletionService->handle($egg->id);
124+
$this->alert->success(trans('admin/nests.eggs.notices.deleted'))->flash();
125+
126+
return redirect()->route('admin.nests.view', $egg->nest_id);
31127
}
32128
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* This software is licensed under the terms of the MIT license.
7+
* https://opensource.org/licenses/MIT
8+
*/
9+
10+
namespace Pterodactyl\Http\Controllers\Admin\Nests;
11+
12+
use Illuminate\View\View;
13+
use Illuminate\Http\RedirectResponse;
14+
use Prologue\Alerts\AlertsMessageBag;
15+
use Pterodactyl\Http\Controllers\Controller;
16+
use Pterodactyl\Services\Eggs\Scripts\InstallScriptService;
17+
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
18+
use Pterodactyl\Http\Requests\Admin\Egg\EggScriptFormRequest;
19+
20+
class EggScriptController extends Controller
21+
{
22+
/**
23+
* @var \Prologue\Alerts\AlertsMessageBag
24+
*/
25+
protected $alert;
26+
27+
/**
28+
* @var \Pterodactyl\Services\Eggs\Scripts\InstallScriptService
29+
*/
30+
protected $installScriptService;
31+
32+
/**
33+
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
34+
*/
35+
protected $repository;
36+
37+
/**
38+
* EggScriptController constructor.
39+
*
40+
* @param \Prologue\Alerts\AlertsMessageBag $alert
41+
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
42+
* @param \Pterodactyl\Services\Eggs\Scripts\InstallScriptService $installScriptService
43+
*/
44+
public function __construct(
45+
AlertsMessageBag $alert,
46+
EggRepositoryInterface $repository,
47+
InstallScriptService $installScriptService
48+
) {
49+
$this->alert = $alert;
50+
$this->installScriptService = $installScriptService;
51+
$this->repository = $repository;
52+
}
53+
54+
/**
55+
* Handle requests to render installation script for an Egg.
56+
*
57+
* @param int $egg
58+
* @return \Illuminate\View\View
59+
*/
60+
public function index(int $egg): View
61+
{
62+
$egg = $this->repository->getWithCopyAttributes($egg);
63+
$copy = $this->repository->findWhere([
64+
['copy_script_from', '=', null],
65+
['nest_id', '=', $egg->nest_id],
66+
['id', '!=', $egg],
67+
]);
68+
69+
$rely = $this->repository->findWhere([
70+
['copy_script_from', '=', $egg->id],
71+
]);
72+
73+
return view('admin.eggs.scripts', [
74+
'copyFromOptions' => $copy,
75+
'relyOnScript' => $rely,
76+
'egg' => $egg,
77+
]);
78+
}
79+
80+
/**
81+
* Handle a request to update the installation script for an Egg.
82+
*
83+
* @param \Pterodactyl\Http\Requests\Admin\Egg\EggScriptFormRequest $request
84+
* @param int $egg
85+
* @return \Illuminate\Http\RedirectResponse
86+
*
87+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
88+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
89+
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
90+
*/
91+
public function update(EggScriptFormRequest $request, int $egg): RedirectResponse
92+
{
93+
$this->installScriptService->handle($egg, $request->normalize());
94+
$this->alert->success(trans('admin/nests.eggs.notices.script_updated'))->flash();
95+
96+
return redirect()->route('admin.nests.egg.scripts', $egg);
97+
}
98+
}

0 commit comments

Comments
 (0)