2017-08-09 05:24:55 +01:00
|
|
|
<?php
|
|
|
|
|
2017-10-07 22:16:51 +01:00
|
|
|
namespace Pterodactyl\Services\Eggs\Scripts;
|
2017-08-09 05:24:55 +01:00
|
|
|
|
2017-10-07 05:57:53 +01:00
|
|
|
use Pterodactyl\Models\Egg;
|
2017-10-07 22:16:51 +01:00
|
|
|
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
|
2017-08-09 05:24:55 +01:00
|
|
|
|
2017-10-07 22:16:51 +01:00
|
|
|
class InstallScriptService
|
2017-08-09 05:24:55 +01:00
|
|
|
{
|
|
|
|
/**
|
2022-10-23 22:27:18 +01:00
|
|
|
* Modify the installation script for a given Egg.
|
2017-08-09 05:24:55 +01:00
|
|
|
*
|
2022-10-23 22:27:18 +01:00
|
|
|
* @throws InvalidCopyFromException
|
2017-08-09 05:24:55 +01:00
|
|
|
*/
|
2022-10-14 17:59:20 +01:00
|
|
|
public function handle(Egg $egg, array $data): void
|
2017-08-09 05:24:55 +01:00
|
|
|
{
|
2022-10-23 22:27:18 +01:00
|
|
|
$copyFromEggId = array_get($data, 'copy_script_from');
|
|
|
|
if (!is_null($copyFromEggId)) {
|
|
|
|
$isCopyableScript = $egg->nest->eggs()
|
|
|
|
->where('id', $copyFromEggId)
|
|
|
|
->whereNull('copy_script_from')
|
|
|
|
->exists();
|
|
|
|
|
|
|
|
if (!$isCopyableScript) {
|
2017-10-07 22:16:51 +01:00
|
|
|
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
|
2017-08-09 05:24:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-23 22:27:18 +01:00
|
|
|
$egg->update([
|
2017-08-12 21:29:01 +01:00
|
|
|
'script_install' => array_get($data, 'script_install'),
|
2017-10-07 22:16:51 +01:00
|
|
|
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
|
2017-08-12 21:29:01 +01:00
|
|
|
'script_entry' => array_get($data, 'script_entry'),
|
|
|
|
'script_container' => array_get($data, 'script_container'),
|
|
|
|
'copy_script_from' => array_get($data, 'copy_script_from'),
|
|
|
|
]);
|
2017-08-09 05:24:55 +01:00
|
|
|
}
|
|
|
|
}
|