diff --git a/app/Contracts/Repository/EggRepositoryInterface.php b/app/Contracts/Repository/EggRepositoryInterface.php deleted file mode 100644 index 948440285..000000000 --- a/app/Contracts/Repository/EggRepositoryInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -repository->getWithCopyAttributes($egg); - $copy = $this->repository->findWhere([ - ['copy_script_from', '=', null], - ['id', '!=', $egg], - ]); + $egg = Egg::with('scriptFrom', 'configFrom') + ->where('id', $egg) + ->firstOrFail(); - $rely = $this->repository->findWhere([ - ['copy_script_from', '=', $egg->id], - ]); + $copy = Egg::query() + ->whereNull('copy_script_from') + ->where('nest_id', $egg->nest_id) + ->whereNot('id', $egg->id) + ->firstOrFail(); + + $rely = Egg::query()->where('copy_script_from', $egg->id)->firstOrFail(); return $this->view->make('admin.eggs.scripts', [ 'copyFromOptions' => $copy, diff --git a/app/Http/Controllers/Admin/Eggs/EggVariableController.php b/app/Http/Controllers/Admin/Eggs/EggVariableController.php index aa72d2868..2e86db653 100644 --- a/app/Http/Controllers/Admin/Eggs/EggVariableController.php +++ b/app/Http/Controllers/Admin/Eggs/EggVariableController.php @@ -9,7 +9,6 @@ use Illuminate\Http\RedirectResponse; use Prologue\Alerts\AlertsMessageBag; use Illuminate\View\Factory as ViewFactory; use App\Http\Controllers\Controller; -use App\Contracts\Repository\EggRepositoryInterface; use App\Services\Eggs\Variables\VariableUpdateService; use App\Http\Requests\Admin\Egg\EggVariableFormRequest; use App\Services\Eggs\Variables\VariableCreationService; @@ -24,7 +23,6 @@ class EggVariableController extends Controller protected AlertsMessageBag $alert, protected VariableCreationService $creationService, protected VariableUpdateService $updateService, - protected EggRepositoryInterface $repository, protected EggVariableRepositoryInterface $variableRepository, protected ViewFactory $view ) { @@ -32,12 +30,10 @@ class EggVariableController extends Controller /** * Handle request to view the variables attached to an Egg. - * - * @throws \App\Exceptions\Repository\RecordNotFoundException */ public function view(int $egg): View { - $egg = $this->repository->getWithVariables($egg); + $egg = Egg::with('variables')->findOrFail($egg); return $this->view->make('admin.eggs.variables', ['egg' => $egg]); } diff --git a/app/Http/Controllers/Admin/Servers/ServerViewController.php b/app/Http/Controllers/Admin/Servers/ServerViewController.php index 8c41ecd46..00ac8340e 100644 --- a/app/Http/Controllers/Admin/Servers/ServerViewController.php +++ b/app/Http/Controllers/Admin/Servers/ServerViewController.php @@ -4,7 +4,6 @@ namespace App\Http\Controllers\Admin\Servers; use App\Models\Egg; use App\Models\Node; -use App\Repositories\Eloquent\EggRepository; use Illuminate\View\View; use Illuminate\Http\Request; use App\Models\Server; @@ -27,7 +26,6 @@ class ServerViewController extends Controller public function __construct( private DatabaseHostRepository $databaseHostRepository, private MountRepository $mountRepository, - private EggRepository $eggRepository, private NodeRepository $nodeRepository, private EnvironmentService $environmentService, private ViewFactory $view diff --git a/app/Providers/RepositoryServiceProvider.php b/app/Providers/RepositoryServiceProvider.php index 8ca9eb196..7eb3e05bf 100644 --- a/app/Providers/RepositoryServiceProvider.php +++ b/app/Providers/RepositoryServiceProvider.php @@ -3,13 +3,11 @@ namespace App\Providers; use Illuminate\Support\ServiceProvider; -use App\Repositories\Eloquent\EggRepository; use App\Repositories\Eloquent\NodeRepository; use App\Repositories\Eloquent\SessionRepository; use App\Repositories\Eloquent\SubuserRepository; use App\Repositories\Eloquent\DatabaseRepository; use App\Repositories\Eloquent\SettingsRepository; -use App\Contracts\Repository\EggRepositoryInterface; use App\Repositories\Eloquent\EggVariableRepository; use App\Contracts\Repository\NodeRepositoryInterface; use App\Repositories\Eloquent\DatabaseHostRepository; @@ -30,7 +28,6 @@ class RepositoryServiceProvider extends ServiceProvider // Eloquent Repositories $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(NodeRepositoryInterface::class, NodeRepository::class); $this->app->bind(SessionRepositoryInterface::class, SessionRepository::class); diff --git a/app/Repositories/Eloquent/EggRepository.php b/app/Repositories/Eloquent/EggRepository.php deleted file mode 100644 index 603162101..000000000 --- a/app/Repositories/Eloquent/EggRepository.php +++ /dev/null @@ -1,75 +0,0 @@ -getBuilder()->with('variables')->findOrFail($id, $this->getColumns()); - } catch (ModelNotFoundException) { - throw new RecordNotFoundException(); - } - } - - /** - * Return all eggs and their relations to be used in the daemon API. - */ - public function getAllWithCopyAttributes(): Collection - { - return $this->getBuilder()->with('scriptFrom', 'configFrom')->get($this->getColumns()); - } - - /** - * Return an egg with the scriptFrom and configFrom relations loaded onto the model. - * - * @param int|string $value - * - * @throws \App\Exceptions\Repository\RecordNotFoundException - */ - public function getWithCopyAttributes($value, string $column = 'id'): Egg - { - Assert::true(is_digit($value) || is_string($value), 'First argument passed to getWithCopyAttributes must be an integer or string, received %s.'); - - try { - return $this->getBuilder()->with('scriptFrom', 'configFrom')->where($column, '=', $value)->firstOrFail($this->getColumns()); - } catch (ModelNotFoundException) { - throw new RecordNotFoundException(); - } - } - - /** - * Return all the data needed to export a service. - * - * @throws \App\Exceptions\Repository\RecordNotFoundException - */ - public function getWithExportAttributes(int $id): Egg - { - try { - return $this->getBuilder()->with('scriptFrom', 'configFrom', 'variables')->findOrFail($id, $this->getColumns()); - } catch (ModelNotFoundException) { - throw new RecordNotFoundException(); - } - } -} diff --git a/app/Services/Eggs/EggCreationService.php b/app/Services/Eggs/EggCreationService.php index b3d910de5..9a4893ad4 100644 --- a/app/Services/Eggs/EggCreationService.php +++ b/app/Services/Eggs/EggCreationService.php @@ -4,7 +4,6 @@ namespace App\Services\Eggs; use Ramsey\Uuid\Uuid; use App\Models\Egg; -use App\Contracts\Repository\EggRepositoryInterface; use Illuminate\Contracts\Config\Repository as ConfigRepository; use App\Exceptions\Service\Egg\NoParentConfigurationFoundException; @@ -13,7 +12,7 @@ class EggCreationService /** * EggCreationService constructor. */ - public function __construct(private ConfigRepository $config, private EggRepositoryInterface $repository) + public function __construct(private ConfigRepository $config) { } @@ -27,18 +26,19 @@ class EggCreationService { $data['config_from'] = array_get($data, 'config_from'); if (!is_null($data['config_from'])) { - $results = $this->repository->findCountWhere([ - ['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.egg.invalid_copy_id')); } } - return $this->repository->create(array_merge($data, [ + return Egg::query()->create(array_merge($data, [ 'uuid' => Uuid::uuid4()->toString(), - 'author' => $this->config->get('panel.service.author'), - ]), true, true); + 'author' => $this->config->get('pterodactyl.service.author'), + ])); } } diff --git a/app/Services/Eggs/EggDeletionService.php b/app/Services/Eggs/EggDeletionService.php index e5068140c..8f01b5218 100644 --- a/app/Services/Eggs/EggDeletionService.php +++ b/app/Services/Eggs/EggDeletionService.php @@ -2,21 +2,13 @@ namespace App\Services\Eggs; -use App\Contracts\Repository\EggRepositoryInterface; use App\Exceptions\Service\Egg\HasChildrenException; use App\Exceptions\Service\HasActiveServersException; +use App\Models\Egg; use App\Models\Server; class EggDeletionService { - /** - * EggDeletionService constructor. - */ - public function __construct( - protected EggRepositoryInterface $repository - ) { - } - /** * Delete an Egg from the database if it has no active servers attached to it. * @@ -29,11 +21,13 @@ class EggDeletionService throw new HasActiveServersException(trans('exceptions.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.egg.has_children')); } - return $this->repository->delete($egg); + $egg = Egg::query()->findOrFail($egg); + + return $egg->delete(); } } diff --git a/app/Services/Eggs/EggUpdateService.php b/app/Services/Eggs/EggUpdateService.php index 83b056b3c..e8952730d 100644 --- a/app/Services/Eggs/EggUpdateService.php +++ b/app/Services/Eggs/EggUpdateService.php @@ -3,18 +3,10 @@ namespace App\Services\Eggs; use App\Models\Egg; -use App\Contracts\Repository\EggRepositoryInterface; use App\Exceptions\Service\Egg\NoParentConfigurationFoundException; class EggUpdateService { - /** - * EggUpdateService constructor. - */ - public function __construct(protected EggRepositoryInterface $repository) - { - } - /** * Update an egg. * @@ -24,10 +16,12 @@ class EggUpdateService */ public function handle(Egg $egg, array $data): void { - if (!is_null(array_get($data, 'config_from'))) { - $results = $this->repository->findCountWhere([ - ['id', '=', array_get($data, 'config_from')], - ]); + $eggId = array_get($data, 'config_from'); + if ($eggId) { + $results = Egg::query() + ->where('nest_id', $egg->nest_id) + ->where('id', $eggId) + ->count(); if ($results !== 1) { throw new NoParentConfigurationFoundException(trans('exceptions.egg.invalid_copy_id')); @@ -38,6 +32,6 @@ class EggUpdateService // 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); } } diff --git a/app/Services/Eggs/Scripts/InstallScriptService.php b/app/Services/Eggs/Scripts/InstallScriptService.php index 593419c5c..824c79482 100644 --- a/app/Services/Eggs/Scripts/InstallScriptService.php +++ b/app/Services/Eggs/Scripts/InstallScriptService.php @@ -3,26 +3,15 @@ namespace App\Services\Eggs\Scripts; use App\Models\Egg; -use App\Contracts\Repository\EggRepositoryInterface; class InstallScriptService { - /** - * InstallScriptService constructor. - */ - public function __construct(protected EggRepositoryInterface $repository) - { - } - /** * Modify the install script for a given Egg. - * - * @throws \App\Exceptions\Model\DataValidationException - * @throws \App\Exceptions\Repository\RecordNotFoundException */ public function handle(Egg $egg, array $data): void { - $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'), diff --git a/app/Services/Eggs/Sharing/EggExporterService.php b/app/Services/Eggs/Sharing/EggExporterService.php index c95a99abf..ce67ff2bc 100644 --- a/app/Services/Eggs/Sharing/EggExporterService.php +++ b/app/Services/Eggs/Sharing/EggExporterService.php @@ -6,16 +6,9 @@ use Carbon\Carbon; use App\Models\Egg; use Illuminate\Support\Collection; use App\Models\EggVariable; -use App\Contracts\Repository\EggRepositoryInterface; class EggExporterService { - /** - * EggExporterService constructor. - */ - public function __construct(protected EggRepositoryInterface $repository) - { - } /** * Return a JSON representation of an egg and its variables. @@ -24,7 +17,7 @@ class EggExporterService */ 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 PANEL',