Replace egg repository
This commit is contained in:
parent
860b2d890b
commit
6e4f7f16c1
11 changed files with 54 additions and 206 deletions
|
@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Eggs;
|
|||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
|
||||
|
||||
|
@ -14,33 +13,35 @@ class EggCreationService
|
|||
/**
|
||||
* EggCreationService constructor.
|
||||
*/
|
||||
public function __construct(private ConfigRepository $config, private EggRepositoryInterface $repository)
|
||||
public function __construct(private ConfigRepository $config)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new service option and assign it to the given service.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
||||
* @throws NoParentConfigurationFoundException
|
||||
*/
|
||||
public function handle(array $data): Egg
|
||||
{
|
||||
$data['config_from'] = array_get($data, 'config_from');
|
||||
if (!is_null($data['config_from'])) {
|
||||
$results = $this->repository->findCountWhere([
|
||||
['nest_id', '=', array_get($data, 'nest_id')],
|
||||
['id', '=', array_get($data, 'config_from')],
|
||||
]);
|
||||
$results = Egg::query()
|
||||
->where('nest_id', array_get($data, 'nest_id'))
|
||||
->where('id', array_get($data, 'config_from'))
|
||||
->count();
|
||||
|
||||
if ($results !== 1) {
|
||||
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->repository->create(array_merge($data, [
|
||||
/** @var Egg $egg */
|
||||
$egg = Egg::query()->create(array_merge($data, [
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
'author' => $this->config->get('pterodactyl.service.author'),
|
||||
]), true, true);
|
||||
]));
|
||||
|
||||
return $egg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,27 +2,25 @@
|
|||
|
||||
namespace Pterodactyl\Services\Eggs;
|
||||
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Egg\HasChildrenException;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Models\Egg;
|
||||
|
||||
class EggDeletionService
|
||||
{
|
||||
/**
|
||||
* EggDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected EggRepositoryInterface $repository
|
||||
) {
|
||||
public function __construct(protected ServerRepositoryInterface $serverRepository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an Egg from the database if it has no active servers attached to it.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Egg\HasChildrenException
|
||||
* @throws HasActiveServersException
|
||||
* @throws HasChildrenException
|
||||
*/
|
||||
public function handle(int $egg): int
|
||||
{
|
||||
|
@ -31,11 +29,13 @@ class EggDeletionService
|
|||
throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));
|
||||
}
|
||||
|
||||
$children = $this->repository->findCountWhere([['config_from', '=', $egg]]);
|
||||
$children = Egg::query()->where('config_from', $egg)->count();
|
||||
if ($children > 0) {
|
||||
throw new HasChildrenException(trans('exceptions.nest.egg.has_children'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($egg);
|
||||
$egg = Egg::query()->findOrFail($egg);
|
||||
|
||||
return $egg->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,42 +3,33 @@
|
|||
namespace Pterodactyl\Services\Eggs;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException;
|
||||
|
||||
class EggUpdateService
|
||||
{
|
||||
/**
|
||||
* EggUpdateService constructor.
|
||||
*/
|
||||
public function __construct(protected EggRepositoryInterface $repository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a service option.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Egg\NoParentConfigurationFoundException
|
||||
* @throws NoParentConfigurationFoundException
|
||||
*/
|
||||
public function handle(Egg $egg, array $data): void
|
||||
{
|
||||
if (!is_null(array_get($data, 'config_from'))) {
|
||||
$results = $this->repository->findCountWhere([
|
||||
['nest_id', '=', $egg->nest_id],
|
||||
['id', '=', array_get($data, 'config_from')],
|
||||
]);
|
||||
$eggId = array_get($data, 'config_from');
|
||||
if (!is_null($eggId)) {
|
||||
$results = Egg::query()
|
||||
->where('nest_id', $egg->nest_id)
|
||||
->where('id', $eggId)
|
||||
->count();
|
||||
|
||||
if ($results !== 1) {
|
||||
throw new NoParentConfigurationFoundException(trans('exceptions.nest.egg.must_be_child'));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(dane): Once the admin UI is done being reworked and this is exposed
|
||||
// TODO: (Dane) Once the admin UI is done being reworked and this is exposed
|
||||
// in said UI, remove this so that you can actually update the denylist.
|
||||
unset($data['file_denylist']);
|
||||
|
||||
$this->repository->withoutFreshModel()->update($egg->id, $data);
|
||||
$egg->update($data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -6,25 +6,18 @@ use Carbon\Carbon;
|
|||
use Pterodactyl\Models\Egg;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Models\EggVariable;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
|
||||
class EggExporterService
|
||||
{
|
||||
/**
|
||||
* EggExporterService constructor.
|
||||
*/
|
||||
public function __construct(protected EggRepositoryInterface $repository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a JSON representation of an egg and its variables.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws RecordNotFoundException
|
||||
*/
|
||||
public function handle(int $egg): string
|
||||
{
|
||||
$egg = $this->repository->getWithExportAttributes($egg);
|
||||
$egg = Egg::with(['scriptFrom', 'configFrom', 'variables'])->findOrFail($egg);
|
||||
|
||||
$struct = [
|
||||
'_comment' => 'DO NOT EDIT: FILE GENERATED AUTOMATICALLY BY PTERODACTYL PANEL - PTERODACTYL.IO',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue