diff --git a/app/Contracts/Repository/EggVariableRepositoryInterface.php b/app/Contracts/Repository/EggVariableRepositoryInterface.php deleted file mode 100644 index cf33e9b6f..000000000 --- a/app/Contracts/Repository/EggVariableRepositoryInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -variableRepository->delete($variable->id); + $variable->delete(); $this->alert->success(trans('admin/eggs.variables.notices.variable_deleted', [ 'variable' => $variable->name, ]))->flash(); diff --git a/app/Http/Controllers/Api/Client/Servers/SubuserController.php b/app/Http/Controllers/Api/Client/Servers/SubuserController.php index 6324a5300..679d2d009 100644 --- a/app/Http/Controllers/Api/Client/Servers/SubuserController.php +++ b/app/Http/Controllers/Api/Client/Servers/SubuserController.php @@ -8,7 +8,6 @@ use Illuminate\Http\JsonResponse; use App\Facades\Activity; use App\Models\Permission; use Illuminate\Support\Facades\Log; -use App\Repositories\Eloquent\SubuserRepository; use App\Services\Subusers\SubuserCreationService; use App\Repositories\Daemon\DaemonServerRepository; use App\Transformers\Api\Client\SubuserTransformer; @@ -25,7 +24,6 @@ class SubuserController extends ClientApiController * SubuserController constructor. */ public function __construct( - private SubuserRepository $repository, private SubuserCreationService $creationService, private DaemonServerRepository $serverRepository ) { @@ -110,9 +108,7 @@ class SubuserController extends ClientApiController // have actually changed for the user. if ($permissions !== $current) { $log->transaction(function ($instance) use ($request, $subuser, $server) { - $this->repository->update($subuser->id, [ - 'permissions' => $this->getDefaultPermissions($request), - ]); + $subuser->update(['permissions' => $this->getDefaultPermissions($request)]); try { $this->serverRepository->setServer($server)->revokeUserJTI($subuser->user_id); diff --git a/app/Providers/RepositoryServiceProvider.php b/app/Providers/RepositoryServiceProvider.php index 594c43b1d..381546bdd 100644 --- a/app/Providers/RepositoryServiceProvider.php +++ b/app/Providers/RepositoryServiceProvider.php @@ -3,11 +3,7 @@ namespace App\Providers; use Illuminate\Support\ServiceProvider; -use App\Repositories\Eloquent\SubuserRepository; -use App\Repositories\Eloquent\EggVariableRepository; use App\Repositories\Eloquent\DatabaseHostRepository; -use App\Contracts\Repository\SubuserRepositoryInterface; -use App\Contracts\Repository\EggVariableRepositoryInterface; use App\Contracts\Repository\DatabaseHostRepositoryInterface; class RepositoryServiceProvider extends ServiceProvider @@ -19,7 +15,5 @@ class RepositoryServiceProvider extends ServiceProvider { // Eloquent Repositories $this->app->bind(DatabaseHostRepositoryInterface::class, DatabaseHostRepository::class); - $this->app->bind(EggVariableRepositoryInterface::class, EggVariableRepository::class); - $this->app->bind(SubuserRepositoryInterface::class, SubuserRepository::class); } } diff --git a/app/Repositories/Eloquent/EggVariableRepository.php b/app/Repositories/Eloquent/EggVariableRepository.php deleted file mode 100644 index 83c2d8387..000000000 --- a/app/Repositories/Eloquent/EggVariableRepository.php +++ /dev/null @@ -1,31 +0,0 @@ -getBuilder()->where([ - ['egg_id', '=', $egg], - ['user_viewable', '=', 1], - ['user_editable', '=', 1], - ])->get($this->getColumns()); - } -} diff --git a/app/Repositories/Eloquent/SubuserRepository.php b/app/Repositories/Eloquent/SubuserRepository.php deleted file mode 100644 index 1a3eee25d..000000000 --- a/app/Repositories/Eloquent/SubuserRepository.php +++ /dev/null @@ -1,69 +0,0 @@ -relationLoaded('server') || $refresh) { - $subuser->load('server'); - } - - if (!$subuser->relationLoaded('user') || $refresh) { - $subuser->load('user'); - } - - return $subuser; - } - - /** - * Return a subuser with the associated permissions relationship. - */ - public function getWithPermissions(Subuser $subuser, bool $refresh = false): Subuser - { - if (!$subuser->relationLoaded('permissions') || $refresh) { - $subuser->load('permissions'); - } - - if (!$subuser->relationLoaded('user') || $refresh) { - $subuser->load('user'); - } - - return $subuser; - } - - /** - * Return a subuser and associated permissions given a user_id and server_id. - * - * @throws \App\Exceptions\Repository\RecordNotFoundException - */ - public function getWithPermissionsUsingUserAndServer(int $user, int $server): Subuser - { - $instance = $this->getBuilder()->with('permissions')->where([ - ['user_id', '=', $user], - ['server_id', '=', $server], - ])->first(); - - if (is_null($instance)) { - throw new RecordNotFoundException(); - } - - return $instance; - } -} diff --git a/app/Services/Eggs/Variables/VariableCreationService.php b/app/Services/Eggs/Variables/VariableCreationService.php index cb8cfce94..d2213f5be 100644 --- a/app/Services/Eggs/Variables/VariableCreationService.php +++ b/app/Services/Eggs/Variables/VariableCreationService.php @@ -5,7 +5,6 @@ namespace App\Services\Eggs\Variables; use App\Models\EggVariable; use App\Traits\Services\ValidatesValidationRules; use Illuminate\Contracts\Validation\Factory as ValidationFactory; -use App\Contracts\Repository\EggVariableRepositoryInterface; use App\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; } } diff --git a/app/Services/Eggs/Variables/VariableUpdateService.php b/app/Services/Eggs/Variables/VariableUpdateService.php index 99546724c..34f88647b 100644 --- a/app/Services/Eggs/Variables/VariableUpdateService.php +++ b/app/Services/Eggs/Variables/VariableUpdateService.php @@ -7,7 +7,6 @@ use App\Models\EggVariable; use App\Exceptions\DisplayException; use App\Traits\Services\ValidatesValidationRules; use Illuminate\Contracts\Validation\Factory as ValidationFactory; -use App\Contracts\Repository\EggVariableRepositoryInterface; use App\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'] ?? '', diff --git a/app/Services/Subusers/SubuserCreationService.php b/app/Services/Subusers/SubuserCreationService.php index a55c4e1e6..0f9508ba7 100644 --- a/app/Services/Subusers/SubuserCreationService.php +++ b/app/Services/Subusers/SubuserCreationService.php @@ -8,7 +8,6 @@ use App\Models\Server; use App\Models\Subuser; use Illuminate\Database\ConnectionInterface; use App\Services\Users\UserCreationService; -use App\Repositories\Eloquent\SubuserRepository; use App\Exceptions\Service\Subuser\UserIsServerOwnerException; use App\Exceptions\Service\Subuser\ServerSubuserExistsException; @@ -19,7 +18,6 @@ class SubuserCreationService */ public function __construct( private ConnectionInterface $connection, - private SubuserRepository $subuserRepository, private UserCreationService $userCreationService, ) { } @@ -56,12 +54,12 @@ class SubuserCreationService throw new UserIsServerOwnerException(trans('exceptions.subusers.user_is_owner')); } - $subuserCount = $this->subuserRepository->findCountWhere([['user_id', '=', $user->id], ['server_id', '=', $server->id]]); + $subuserCount = $server->subusers()->where('user_id', $user->id)->count(); if ($subuserCount !== 0) { throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists')); } - return $this->subuserRepository->create([ + return Subuser::query()->create([ 'user_id' => $user->id, 'server_id' => $server->id, 'permissions' => array_unique($permissions),