From 60c32cdb817ccda927a53e47f9cc4a848d57495f Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sat, 16 Mar 2024 19:20:55 -0400 Subject: [PATCH] Remove schedule and task repositories --- .../ScheduleRepositoryInterface.php | 21 --------- .../Repository/TaskRepositoryInterface.php | 20 --------- .../Api/Client/Servers/ScheduleController.php | 12 ++--- .../Client/Servers/ScheduleTaskController.php | 6 +-- app/Providers/RepositoryServiceProvider.php | 6 --- .../Eloquent/ScheduleRepository.php | 42 ------------------ app/Repositories/Eloquent/TaskRepository.php | 44 ------------------- 7 files changed, 8 insertions(+), 143 deletions(-) delete mode 100644 app/Contracts/Repository/ScheduleRepositoryInterface.php delete mode 100644 app/Contracts/Repository/TaskRepositoryInterface.php delete mode 100644 app/Repositories/Eloquent/ScheduleRepository.php delete mode 100644 app/Repositories/Eloquent/TaskRepository.php diff --git a/app/Contracts/Repository/ScheduleRepositoryInterface.php b/app/Contracts/Repository/ScheduleRepositoryInterface.php deleted file mode 100644 index 27c09a208..000000000 --- a/app/Contracts/Repository/ScheduleRepositoryInterface.php +++ /dev/null @@ -1,21 +0,0 @@ -repository->create([ + $model = Schedule::query()->create([ 'server_id' => $server->id, 'name' => $request->input('name'), 'cron_day_of_week' => $request->input('day_of_week'), @@ -121,7 +121,7 @@ class ScheduleController extends ClientApiController $data['is_processing'] = false; } - $this->repository->update($schedule->id, $data); + $schedule->update($data); Activity::event('server:schedule.update') ->subject($schedule) @@ -153,7 +153,7 @@ class ScheduleController extends ClientApiController */ public function delete(DeleteScheduleRequest $request, Server $server, Schedule $schedule): JsonResponse { - $this->repository->delete($schedule->id); + $schedule->delete(); Activity::event('server:schedule.delete')->subject($schedule)->property('name', $schedule->name)->log(); @@ -175,7 +175,7 @@ class ScheduleController extends ClientApiController $request->input('month'), $request->input('day_of_week') ); - } catch (\Exception $exception) { + } catch (Exception) { throw new DisplayException('The cron data provided does not evaluate to a valid expression.'); } } diff --git a/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php b/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php index fc89e4120..295b87b67 100644 --- a/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php +++ b/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php @@ -10,7 +10,6 @@ use Illuminate\Http\JsonResponse; use App\Facades\Activity; use App\Models\Permission; use Illuminate\Database\ConnectionInterface; -use App\Repositories\Eloquent\TaskRepository; use App\Exceptions\Http\HttpForbiddenException; use App\Transformers\Api\Client\TaskTransformer; use App\Http\Requests\Api\Client\ClientApiRequest; @@ -26,7 +25,6 @@ class ScheduleTaskController extends ClientApiController */ public function __construct( private ConnectionInterface $connection, - private TaskRepository $repository ) { parent::__construct(); } @@ -72,7 +70,7 @@ class ScheduleTaskController extends ClientApiController $sequenceId = $requestSequenceId; } - return $this->repository->create([ + return Task::query()->create([ 'schedule_id' => $schedule->id, 'sequence_id' => $sequenceId, 'action' => $request->input('action'), @@ -128,7 +126,7 @@ class ScheduleTaskController extends ClientApiController ->decrement('sequence_id'); } - $this->repository->update($task->id, [ + $task->update([ 'sequence_id' => $sequenceId, 'action' => $request->input('action'), 'payload' => $request->input('payload') ?? '', diff --git a/app/Providers/RepositoryServiceProvider.php b/app/Providers/RepositoryServiceProvider.php index bdce7eee5..5677f51ee 100644 --- a/app/Providers/RepositoryServiceProvider.php +++ b/app/Providers/RepositoryServiceProvider.php @@ -5,25 +5,21 @@ namespace App\Providers; use Illuminate\Support\ServiceProvider; use App\Repositories\Eloquent\EggRepository; use App\Repositories\Eloquent\NodeRepository; -use App\Repositories\Eloquent\TaskRepository; use App\Repositories\Eloquent\ApiKeyRepository; use App\Repositories\Eloquent\SessionRepository; use App\Repositories\Eloquent\SubuserRepository; use App\Repositories\Eloquent\DatabaseRepository; -use App\Repositories\Eloquent\ScheduleRepository; use App\Repositories\Eloquent\SettingsRepository; use App\Repositories\Eloquent\AllocationRepository; use App\Contracts\Repository\EggRepositoryInterface; use App\Repositories\Eloquent\EggVariableRepository; use App\Contracts\Repository\NodeRepositoryInterface; -use App\Contracts\Repository\TaskRepositoryInterface; use App\Repositories\Eloquent\DatabaseHostRepository; use App\Contracts\Repository\ApiKeyRepositoryInterface; use App\Repositories\Eloquent\ServerVariableRepository; use App\Contracts\Repository\SessionRepositoryInterface; use App\Contracts\Repository\SubuserRepositoryInterface; use App\Contracts\Repository\DatabaseRepositoryInterface; -use App\Contracts\Repository\ScheduleRepositoryInterface; use App\Contracts\Repository\SettingsRepositoryInterface; use App\Contracts\Repository\AllocationRepositoryInterface; use App\Contracts\Repository\EggVariableRepositoryInterface; @@ -45,11 +41,9 @@ class RepositoryServiceProvider extends ServiceProvider $this->app->bind(EggRepositoryInterface::class, EggRepository::class); $this->app->bind(EggVariableRepositoryInterface::class, EggVariableRepository::class); $this->app->bind(NodeRepositoryInterface::class, NodeRepository::class); - $this->app->bind(ScheduleRepositoryInterface::class, ScheduleRepository::class); $this->app->bind(ServerVariableRepositoryInterface::class, ServerVariableRepository::class); $this->app->bind(SessionRepositoryInterface::class, SessionRepository::class); $this->app->bind(SettingsRepositoryInterface::class, SettingsRepository::class); $this->app->bind(SubuserRepositoryInterface::class, SubuserRepository::class); - $this->app->bind(TaskRepositoryInterface::class, TaskRepository::class); } } diff --git a/app/Repositories/Eloquent/ScheduleRepository.php b/app/Repositories/Eloquent/ScheduleRepository.php deleted file mode 100644 index c8af978dd..000000000 --- a/app/Repositories/Eloquent/ScheduleRepository.php +++ /dev/null @@ -1,42 +0,0 @@ -getBuilder()->withCount('tasks')->where('server_id', '=', $server)->get($this->getColumns()); - } - - /** - * Return a schedule model with all the associated tasks as a relationship. - * - * @throws \App\Exceptions\Repository\RecordNotFoundException - */ - public function getScheduleWithTasks(int $schedule): Schedule - { - try { - return $this->getBuilder()->with('tasks')->findOrFail($schedule, $this->getColumns()); - } catch (ModelNotFoundException) { - throw new RecordNotFoundException(); - } - } -} diff --git a/app/Repositories/Eloquent/TaskRepository.php b/app/Repositories/Eloquent/TaskRepository.php deleted file mode 100644 index 4c63f8748..000000000 --- a/app/Repositories/Eloquent/TaskRepository.php +++ /dev/null @@ -1,44 +0,0 @@ -getBuilder()->with('server.user', 'schedule')->findOrFail($id, $this->getColumns()); - } catch (ModelNotFoundException) { - throw new RecordNotFoundException(); - } - } - - /** - * Returns the next task in a schedule. - */ - public function getNextTask(int $schedule, int $index): ?Task - { - return $this->getBuilder()->where('schedule_id', '=', $schedule) - ->orderBy('sequence_id') - ->where('sequence_id', '>', $index) - ->first($this->getColumns()); - } -}