misc_pterodactyl-panel/app/Services/Eggs/Scripts/InstallScriptService.php

64 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2017-09-26 02:43:01 +00:00
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Services\Eggs\Scripts;
use Pterodactyl\Models\Egg;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
class InstallScriptService
{
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
*/
2017-08-12 21:30:27 +00:00
protected $repository;
/**
* InstallScriptService constructor.
*
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
*/
public function __construct(EggRepositoryInterface $repository)
{
2017-08-12 21:30:27 +00:00
$this->repository = $repository;
}
/**
* Modify the install script for a given Egg.
*
* @param int|\Pterodactyl\Models\Egg $egg
* @param array $data
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
2017-08-12 21:30:27 +00:00
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
*/
public function handle($egg, array $data)
{
if (! $egg instanceof Egg) {
$egg = $this->repository->find($egg);
}
if (! is_null(array_get($data, 'copy_script_from'))) {
2017-10-07 22:21:41 +00:00
if (! $this->repository->isCopiableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
}
}
2018-01-05 22:33:50 +00:00
$this->repository->withoutFreshModel()->update($egg->id, [
'script_install' => array_get($data, 'script_install'),
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
'script_entry' => array_get($data, 'script_entry'),
'script_container' => array_get($data, 'script_container'),
'copy_script_from' => array_get($data, 'copy_script_from'),
]);
}
}