Delete schedule repository

This commit is contained in:
Lance Pioch 2022-10-22 19:49:18 -04:00
parent 860b2d890b
commit e0f5856589
4 changed files with 12 additions and 78 deletions

View file

@ -1,21 +0,0 @@
<?php
namespace Pterodactyl\Contracts\Repository;
use Pterodactyl\Models\Schedule;
use Illuminate\Support\Collection;
interface ScheduleRepositoryInterface extends RepositoryInterface
{
/**
* Return all the schedules for a given server.
*/
public function findServerSchedules(int $server): Collection;
/**
* Return a schedule model with all the associated tasks as a relationship.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getScheduleWithTasks(int $schedule): Schedule;
}

View file

@ -12,7 +12,7 @@ use Illuminate\Http\JsonResponse;
use Pterodactyl\Facades\Activity;
use Pterodactyl\Helpers\Utilities;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
use Pterodactyl\Exceptions\Model\DataValidationException;
use Pterodactyl\Services\Schedules\ProcessScheduleService;
use Pterodactyl\Transformers\Api\Client\ScheduleTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
@ -28,7 +28,7 @@ class ScheduleController extends ClientApiController
/**
* ScheduleController constructor.
*/
public function __construct(private ScheduleRepository $repository, private ProcessScheduleService $service)
public function __construct(private ProcessScheduleService $service)
{
parent::__construct();
}
@ -48,13 +48,13 @@ class ScheduleController extends ClientApiController
/**
* Store a new schedule for a server.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws DisplayException
* @throws DataValidationException
*/
public function store(StoreScheduleRequest $request, Server $server): array
{
/** @var \Pterodactyl\Models\Schedule $model */
$model = $this->repository->create([
/** @var Schedule $model */
$model = Schedule::query()->create([
'server_id' => $server->id,
'name' => $request->input('name'),
'cron_day_of_week' => $request->input('day_of_week'),
@ -96,8 +96,8 @@ class ScheduleController extends ClientApiController
/**
* Updates a given schedule with the new data provided.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws DisplayException
* @throws DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule): array
@ -124,7 +124,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)
@ -156,7 +156,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();
@ -166,7 +166,7 @@ class ScheduleController extends ClientApiController
/**
* Get the next run timestamp based on the cron data provided.
*
* @throws \Pterodactyl\Exceptions\DisplayException
* @throws DisplayException
*/
protected function getNextRunAt(Request $request): Carbon
{
@ -178,7 +178,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.');
}
}

View file

@ -14,7 +14,6 @@ use Pterodactyl\Repositories\Eloquent\SessionRepository;
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
use Pterodactyl\Repositories\Eloquent\LocationRepository;
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
use Pterodactyl\Repositories\Eloquent\AllocationRepository;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
@ -31,7 +30,6 @@ use Pterodactyl\Contracts\Repository\SessionRepositoryInterface;
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
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;
@ -55,7 +53,6 @@ class RepositoryServiceProvider extends ServiceProvider
$this->app->bind(LocationRepositoryInterface::class, LocationRepository::class);
$this->app->bind(NestRepositoryInterface::class, NestRepository::class);
$this->app->bind(NodeRepositoryInterface::class, NodeRepository::class);
$this->app->bind(ScheduleRepositoryInterface::class, ScheduleRepository::class);
$this->app->bind(ServerRepositoryInterface::class, ServerRepository::class);
$this->app->bind(ServerVariableRepositoryInterface::class, ServerVariableRepository::class);
$this->app->bind(SessionRepositoryInterface::class, SessionRepository::class);

View file

@ -1,42 +0,0 @@
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Schedule;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
class ScheduleRepository extends EloquentRepository implements ScheduleRepositoryInterface
{
/**
* Return the model backing this repository.
*/
public function model(): string
{
return Schedule::class;
}
/**
* Return all the schedules for a given server.
*/
public function findServerSchedules(int $server): Collection
{
return $this->getBuilder()->withCount('tasks')->where('server_id', '=', $server)->get($this->getColumns());
}
/**
* Return a schedule model with all the associated tasks as a relationship.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getScheduleWithTasks(int $schedule): Schedule
{
try {
return $this->getBuilder()->with('tasks')->findOrFail($schedule, $this->getColumns());
} catch (ModelNotFoundException) {
throw new RecordNotFoundException();
}
}
}