Replace egg repository

This commit is contained in:
Lance Pioch 2022-10-23 17:27:18 -04:00
parent 860b2d890b
commit 6e4f7f16c1
11 changed files with 54 additions and 206 deletions

View file

@ -3,34 +3,30 @@
namespace Pterodactyl\Services\Eggs\Scripts;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
class InstallScriptService
{
/**
* InstallScriptService constructor.
*/
public function __construct(protected EggRepositoryInterface $repository)
{
}
/**
* Modify the install script for a given Egg.
* Modify the installation script for a given Egg.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
* @throws InvalidCopyFromException
*/
public function handle(Egg $egg, array $data): void
{
if (!is_null(array_get($data, 'copy_script_from'))) {
if (!$this->repository->isCopyableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {
$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) {
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
}
}
$this->repository->withoutFreshModel()->update($egg->id, [
$egg->update([
'script_install' => array_get($data, 'script_install'),
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
'script_entry' => array_get($data, 'script_entry'),