2017-08-09 04:24:55 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-08-09 04:24:55 +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
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
namespace Pterodactyl\Services\Eggs\Scripts;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Models\Egg;
|
|
|
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
2017-10-07 21:16:51 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2017-10-07 21:16:51 +00:00
|
|
|
class InstallScriptService
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-08-12 21:30:27 +00:00
|
|
|
protected $repository;
|
2017-08-09 04:24:55 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-07 21:16:51 +00:00
|
|
|
* InstallScriptService constructor.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $repository
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function __construct(EggRepositoryInterface $repository)
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2017-08-12 21:30:27 +00:00
|
|
|
$this->repository = $repository;
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 21:16:51 +00:00
|
|
|
* Modify the install script for a given Egg.
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
2017-10-07 21:16:51 +00:00
|
|
|
* @param int|\Pterodactyl\Models\Egg $egg
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param array $data
|
2017-08-09 04:24:55 +00:00
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-08-12 21:30:27 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-10-07 21:16:51 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Egg\InvalidCopyFromException
|
2017-08-09 04:24:55 +00:00
|
|
|
*/
|
2017-10-07 21:16:51 +00:00
|
|
|
public function handle($egg, array $data)
|
2017-08-09 04:24:55 +00:00
|
|
|
{
|
2017-10-07 21:16:51 +00:00
|
|
|
if (! $egg instanceof Egg) {
|
|
|
|
$egg = $this->repository->find($egg);
|
2017-08-12 20:29:01 +00:00
|
|
|
}
|
2017-08-09 04:24:55 +00:00
|
|
|
|
2017-08-12 20:29:01 +00:00
|
|
|
if (! is_null(array_get($data, 'copy_script_from'))) {
|
2018-05-13 14:50:56 +00:00
|
|
|
if (! $this->repository->isCopyableScript(array_get($data, 'copy_script_from'), $egg->nest_id)) {
|
2017-10-07 21:16:51 +00:00
|
|
|
throw new InvalidCopyFromException(trans('exceptions.nest.egg.invalid_copy_id'));
|
2017-08-09 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 22:33:50 +00:00
|
|
|
$this->repository->withoutFreshModel()->update($egg->id, [
|
2017-08-12 20:29:01 +00:00
|
|
|
'script_install' => array_get($data, 'script_install'),
|
2017-10-07 21:16:51 +00:00
|
|
|
'script_is_privileged' => array_get($data, 'script_is_privileged', 1),
|
2017-08-12 20:29:01 +00: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 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|