Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Eggs/Scripts/InstallScriptService.php
10287 views
1
<?php
2
3
namespace Pterodactyl\Services\Eggs\Scripts;
4
5
use Pterodactyl\Models\Egg;
6
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
7
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
8
9
class InstallScriptService
10
{
11
/**
12
* InstallScriptService constructor.
13
*/
14
public function __construct(protected EggRepositoryInterface $repository)
15
{
16
}
17
18
/**
19
* Modify the install script for a given Egg.
20
*
21
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
22
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
23
* @throws InvalidCopyFromException
24
*/
25
public function handle(Egg $egg, array $data): void
26
{
27
if (!is_null(array_get($data, 'copy_script_from'))) {
28
if (!$this->repository->isCopyableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {
29
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
30
}
31
}
32
33
$this->repository->withoutFreshModel()->update($egg->id, [
34
'script_install' => array_get($data, 'script_install'),
35
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
36
'script_entry' => array_get($data, 'script_entry'),
37
'script_container' => array_get($data, 'script_container'),
38
'copy_script_from' => array_get($data, 'copy_script_from'),
39
]);
40
}
41
}
42
43