Replace egg variable repository

This commit is contained in:
Lance Pioch 2022-10-23 04:12:34 -04:00
parent 860b2d890b
commit a0728026d7
6 changed files with 13 additions and 62 deletions

View file

@ -1,14 +0,0 @@
<?php
namespace Pterodactyl\Contracts\Repository;
use Illuminate\Support\Collection;
interface EggVariableRepositoryInterface extends RepositoryInterface
{
/**
* Return editable variables for a given egg. Editable variables must be set to
* user viewable in order to be picked up by this function.
*/
public function getEditableVariables(int $egg): Collection;
}

View file

@ -13,7 +13,6 @@ use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Services\Eggs\Variables\VariableUpdateService;
use Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest;
use Pterodactyl\Services\Eggs\Variables\VariableCreationService;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
class EggVariableController extends Controller
{
@ -25,7 +24,6 @@ class EggVariableController extends Controller
protected VariableCreationService $creationService,
protected VariableUpdateService $updateService,
protected EggRepositoryInterface $repository,
protected EggVariableRepositoryInterface $variableRepository,
protected ViewFactory $view
) {
}
@ -80,7 +78,7 @@ class EggVariableController extends Controller
*/
public function destroy(int $egg, EggVariable $variable): RedirectResponse
{
$this->variableRepository->delete($variable->id);
$variable->delete();
$this->alert->success(trans('admin/nests.variables.notices.variable_deleted', [
'variable' => $variable->name,
]))->flash();

View file

@ -18,7 +18,6 @@ use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Repositories\Eloquent\EggVariableRepository;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
@ -34,7 +33,6 @@ use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
@ -51,7 +49,6 @@ class RepositoryServiceProvider extends ServiceProvider
$this->app->bind(DatabaseRepositoryInterface::class, DatabaseRepository::class);
$this->app->bind(DatabaseHostRepositoryInterface::class, DatabaseHostRepository::class);
$this->app->bind(EggRepositoryInterface::class, EggRepository::class);
$this->app->bind(EggVariableRepositoryInterface::class, EggVariableRepository::class);
$this->app->bind(LocationRepositoryInterface::class, LocationRepository::class);
$this->app->bind(NestRepositoryInterface::class, NestRepository::class);
$this->app->bind(NodeRepositoryInterface::class, NodeRepository::class);

View file

@ -1,31 +0,0 @@
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Illuminate\Support\Collection;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
class EggVariableRepository extends EloquentRepository implements EggVariableRepositoryInterface
{
/**
* Return the model backing this repository.
*/
public function model(): string
{
return EggVariable::class;
}
/**
* Return editable variables for a given egg. Editable variables must be set to
* user viewable in order to be picked up by this function.
*/
public function getEditableVariables(int $egg): Collection
{
return $this->getBuilder()->where([
['egg_id', '=', $egg],
['user_viewable', '=', 1],
['user_editable', '=', 1],
])->get($this->getColumns());
}
}

View file

@ -5,7 +5,6 @@ namespace Pterodactyl\Services\Eggs\Variables;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Traits\Services\ValidatesValidationRules;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
class VariableCreationService
@ -15,7 +14,7 @@ class VariableCreationService
/**
* VariableCreationService constructor.
*/
public function __construct(private EggVariableRepositoryInterface $repository, private ValidationFactory $validator)
public function __construct(private ValidationFactory $validator)
{
}
@ -47,7 +46,8 @@ class VariableCreationService
$options = array_get($data, 'options') ?? [];
return $this->repository->create([
/** @var EggVariable $eggVariable */
$eggVariable = EggVariable::query()->create([
'egg_id' => $egg,
'name' => $data['name'] ?? '',
'description' => $data['description'] ?? '',
@ -57,5 +57,7 @@ class VariableCreationService
'user_editable' => in_array('user_editable', $options),
'rules' => $data['rules'] ?? '',
]);
return $eggVariable;
}
}

View file

@ -7,7 +7,6 @@ use Pterodactyl\Models\EggVariable;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Traits\Services\ValidatesValidationRules;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
class VariableUpdateService
@ -17,7 +16,7 @@ class VariableUpdateService
/**
* VariableUpdateService constructor.
*/
public function __construct(private EggVariableRepositoryInterface $repository, private ValidationFactory $validator)
public function __construct(private ValidationFactory $validator)
{
}
@ -45,11 +44,11 @@ class VariableUpdateService
throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', ['name' => array_get($data, 'env_variable')]));
}
$search = $this->repository->setColumns('id')->findCountWhere([
['env_variable', '=', $data['env_variable']],
['egg_id', '=', $variable->egg_id],
['id', '!=', $variable->id],
]);
$search = EggVariable::query()
->where('env_variable', $data['env_variable'])
->where('egg_id', $variable->egg_id)
->whereNot('id', $variable->id)
->count();
if ($search > 0) {
throw new DisplayException(trans('exceptions.service.variables.env_not_unique', ['name' => array_get($data, 'env_variable')]));
@ -66,7 +65,7 @@ class VariableUpdateService
$options = array_get($data, 'options') ?? [];
return $this->repository->withoutFreshModel()->update($variable->id, [
return $variable->update([
'name' => $data['name'] ?? '',
'description' => $data['description'] ?? '',
'env_variable' => $data['env_variable'] ?? '',