Compare commits
1 commit
develop
...
replace-eg
Author | SHA1 | Date | |
---|---|---|---|
|
a0728026d7 |
6 changed files with 13 additions and 62 deletions
|
@ -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;
|
|
||||||
}
|
|
|
@ -13,7 +13,6 @@ use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||||
use Pterodactyl\Services\Eggs\Variables\VariableUpdateService;
|
use Pterodactyl\Services\Eggs\Variables\VariableUpdateService;
|
||||||
use Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest;
|
use Pterodactyl\Http\Requests\Admin\Egg\EggVariableFormRequest;
|
||||||
use Pterodactyl\Services\Eggs\Variables\VariableCreationService;
|
use Pterodactyl\Services\Eggs\Variables\VariableCreationService;
|
||||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
|
||||||
|
|
||||||
class EggVariableController extends Controller
|
class EggVariableController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -25,7 +24,6 @@ class EggVariableController extends Controller
|
||||||
protected VariableCreationService $creationService,
|
protected VariableCreationService $creationService,
|
||||||
protected VariableUpdateService $updateService,
|
protected VariableUpdateService $updateService,
|
||||||
protected EggRepositoryInterface $repository,
|
protected EggRepositoryInterface $repository,
|
||||||
protected EggVariableRepositoryInterface $variableRepository,
|
|
||||||
protected ViewFactory $view
|
protected ViewFactory $view
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@ -80,7 +78,7 @@ class EggVariableController extends Controller
|
||||||
*/
|
*/
|
||||||
public function destroy(int $egg, EggVariable $variable): RedirectResponse
|
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', [
|
$this->alert->success(trans('admin/nests.variables.notices.variable_deleted', [
|
||||||
'variable' => $variable->name,
|
'variable' => $variable->name,
|
||||||
]))->flash();
|
]))->flash();
|
||||||
|
|
|
@ -18,7 +18,6 @@ use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
|
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
|
||||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||||
use Pterodactyl\Repositories\Eloquent\EggVariableRepository;
|
|
||||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||||
|
@ -34,7 +33,6 @@ use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
|
||||||
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
||||||
|
|
||||||
|
@ -51,7 +49,6 @@ class RepositoryServiceProvider extends ServiceProvider
|
||||||
$this->app->bind(DatabaseRepositoryInterface::class, DatabaseRepository::class);
|
$this->app->bind(DatabaseRepositoryInterface::class, DatabaseRepository::class);
|
||||||
$this->app->bind(DatabaseHostRepositoryInterface::class, DatabaseHostRepository::class);
|
$this->app->bind(DatabaseHostRepositoryInterface::class, DatabaseHostRepository::class);
|
||||||
$this->app->bind(EggRepositoryInterface::class, EggRepository::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(LocationRepositoryInterface::class, LocationRepository::class);
|
||||||
$this->app->bind(NestRepositoryInterface::class, NestRepository::class);
|
$this->app->bind(NestRepositoryInterface::class, NestRepository::class);
|
||||||
$this->app->bind(NodeRepositoryInterface::class, NodeRepository::class);
|
$this->app->bind(NodeRepositoryInterface::class, NodeRepository::class);
|
||||||
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ namespace Pterodactyl\Services\Eggs\Variables;
|
||||||
use Pterodactyl\Models\EggVariable;
|
use Pterodactyl\Models\EggVariable;
|
||||||
use Pterodactyl\Traits\Services\ValidatesValidationRules;
|
use Pterodactyl\Traits\Services\ValidatesValidationRules;
|
||||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
|
||||||
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
|
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
|
||||||
|
|
||||||
class VariableCreationService
|
class VariableCreationService
|
||||||
|
@ -15,7 +14,7 @@ class VariableCreationService
|
||||||
/**
|
/**
|
||||||
* VariableCreationService constructor.
|
* 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') ?? [];
|
$options = array_get($data, 'options') ?? [];
|
||||||
|
|
||||||
return $this->repository->create([
|
/** @var EggVariable $eggVariable */
|
||||||
|
$eggVariable = EggVariable::query()->create([
|
||||||
'egg_id' => $egg,
|
'egg_id' => $egg,
|
||||||
'name' => $data['name'] ?? '',
|
'name' => $data['name'] ?? '',
|
||||||
'description' => $data['description'] ?? '',
|
'description' => $data['description'] ?? '',
|
||||||
|
@ -57,5 +57,7 @@ class VariableCreationService
|
||||||
'user_editable' => in_array('user_editable', $options),
|
'user_editable' => in_array('user_editable', $options),
|
||||||
'rules' => $data['rules'] ?? '',
|
'rules' => $data['rules'] ?? '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
return $eggVariable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ use Pterodactyl\Models\EggVariable;
|
||||||
use Pterodactyl\Exceptions\DisplayException;
|
use Pterodactyl\Exceptions\DisplayException;
|
||||||
use Pterodactyl\Traits\Services\ValidatesValidationRules;
|
use Pterodactyl\Traits\Services\ValidatesValidationRules;
|
||||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||||
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
|
|
||||||
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
|
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
|
||||||
|
|
||||||
class VariableUpdateService
|
class VariableUpdateService
|
||||||
|
@ -17,7 +16,7 @@ class VariableUpdateService
|
||||||
/**
|
/**
|
||||||
* VariableUpdateService constructor.
|
* 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')]));
|
throw new ReservedVariableNameException(trans('exceptions.service.variables.reserved_name', ['name' => array_get($data, 'env_variable')]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$search = $this->repository->setColumns('id')->findCountWhere([
|
$search = EggVariable::query()
|
||||||
['env_variable', '=', $data['env_variable']],
|
->where('env_variable', $data['env_variable'])
|
||||||
['egg_id', '=', $variable->egg_id],
|
->where('egg_id', $variable->egg_id)
|
||||||
['id', '!=', $variable->id],
|
->whereNot('id', $variable->id)
|
||||||
]);
|
->count();
|
||||||
|
|
||||||
if ($search > 0) {
|
if ($search > 0) {
|
||||||
throw new DisplayException(trans('exceptions.service.variables.env_not_unique', ['name' => array_get($data, 'env_variable')]));
|
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') ?? [];
|
$options = array_get($data, 'options') ?? [];
|
||||||
|
|
||||||
return $this->repository->withoutFreshModel()->update($variable->id, [
|
return $variable->update([
|
||||||
'name' => $data['name'] ?? '',
|
'name' => $data['name'] ?? '',
|
||||||
'description' => $data['description'] ?? '',
|
'description' => $data['description'] ?? '',
|
||||||
'env_variable' => $data['env_variable'] ?? '',
|
'env_variable' => $data['env_variable'] ?? '',
|
||||||
|
|
Loading…
Reference in a new issue