Compare commits
3 commits
develop
...
replace-sc
Author | SHA1 | Date | |
---|---|---|---|
|
29c3d80e5b | ||
|
451522e6cf | ||
|
e0f5856589 |
7 changed files with 17 additions and 151 deletions
|
@ -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;
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Contracts\Repository;
|
|
||||||
|
|
||||||
use Pterodactyl\Models\Task;
|
|
||||||
|
|
||||||
interface TaskRepositoryInterface extends RepositoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Get a task and the server relationship for that task.
|
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
||||||
*/
|
|
||||||
public function getTaskForJobProcess(int $id): Task;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the next task in a schedule.
|
|
||||||
*/
|
|
||||||
public function getNextTask(int $schedule, int $index): ?Task;
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ use Illuminate\Http\JsonResponse;
|
||||||
use Pterodactyl\Facades\Activity;
|
use Pterodactyl\Facades\Activity;
|
||||||
use Pterodactyl\Helpers\Utilities;
|
use Pterodactyl\Helpers\Utilities;
|
||||||
use Pterodactyl\Exceptions\DisplayException;
|
use Pterodactyl\Exceptions\DisplayException;
|
||||||
use Pterodactyl\Repositories\Eloquent\ScheduleRepository;
|
use Pterodactyl\Exceptions\Model\DataValidationException;
|
||||||
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
use Pterodactyl\Services\Schedules\ProcessScheduleService;
|
||||||
use Pterodactyl\Transformers\Api\Client\ScheduleTransformer;
|
use Pterodactyl\Transformers\Api\Client\ScheduleTransformer;
|
||||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||||
|
@ -28,7 +28,7 @@ class ScheduleController extends ClientApiController
|
||||||
/**
|
/**
|
||||||
* ScheduleController constructor.
|
* ScheduleController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(private ScheduleRepository $repository, private ProcessScheduleService $service)
|
public function __construct(private ProcessScheduleService $service)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
@ -48,13 +48,13 @@ class ScheduleController extends ClientApiController
|
||||||
/**
|
/**
|
||||||
* Store a new schedule for a server.
|
* Store a new schedule for a server.
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws DisplayException
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws DataValidationException
|
||||||
*/
|
*/
|
||||||
public function store(StoreScheduleRequest $request, Server $server): array
|
public function store(StoreScheduleRequest $request, Server $server): array
|
||||||
{
|
{
|
||||||
/** @var \Pterodactyl\Models\Schedule $model */
|
/** @var Schedule $model */
|
||||||
$model = $this->repository->create([
|
$model = Schedule::query()->create([
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'name' => $request->input('name'),
|
'name' => $request->input('name'),
|
||||||
'cron_day_of_week' => $request->input('day_of_week'),
|
'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.
|
* Updates a given schedule with the new data provided.
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws DisplayException
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws DataValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
*/
|
*/
|
||||||
public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule): array
|
public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule): array
|
||||||
|
@ -124,7 +124,7 @@ class ScheduleController extends ClientApiController
|
||||||
$data['is_processing'] = false;
|
$data['is_processing'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->repository->update($schedule->id, $data);
|
$schedule->update($data);
|
||||||
|
|
||||||
Activity::event('server:schedule.update')
|
Activity::event('server:schedule.update')
|
||||||
->subject($schedule)
|
->subject($schedule)
|
||||||
|
@ -156,7 +156,7 @@ class ScheduleController extends ClientApiController
|
||||||
*/
|
*/
|
||||||
public function delete(DeleteScheduleRequest $request, Server $server, Schedule $schedule): JsonResponse
|
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();
|
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.
|
* Get the next run timestamp based on the cron data provided.
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws DisplayException
|
||||||
*/
|
*/
|
||||||
protected function getNextRunAt(Request $request): Carbon
|
protected function getNextRunAt(Request $request): Carbon
|
||||||
{
|
{
|
||||||
|
@ -178,7 +178,7 @@ class ScheduleController extends ClientApiController
|
||||||
$request->input('month'),
|
$request->input('month'),
|
||||||
$request->input('day_of_week')
|
$request->input('day_of_week')
|
||||||
);
|
);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception) {
|
||||||
throw new DisplayException('The cron data provided does not evaluate to a valid expression.');
|
throw new DisplayException('The cron data provided does not evaluate to a valid expression.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ use Pterodactyl\Models\Schedule;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Pterodactyl\Facades\Activity;
|
use Pterodactyl\Facades\Activity;
|
||||||
use Pterodactyl\Models\Permission;
|
use Pterodactyl\Models\Permission;
|
||||||
use Pterodactyl\Repositories\Eloquent\TaskRepository;
|
|
||||||
use Pterodactyl\Exceptions\Http\HttpForbiddenException;
|
use Pterodactyl\Exceptions\Http\HttpForbiddenException;
|
||||||
use Pterodactyl\Transformers\Api\Client\TaskTransformer;
|
use Pterodactyl\Transformers\Api\Client\TaskTransformer;
|
||||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||||
|
@ -23,7 +22,7 @@ class ScheduleTaskController extends ClientApiController
|
||||||
/**
|
/**
|
||||||
* ScheduleTaskController constructor.
|
* ScheduleTaskController constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(private TaskRepository $repository)
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
@ -45,11 +44,11 @@ class ScheduleTaskController extends ClientApiController
|
||||||
throw new HttpForbiddenException("A backup task cannot be created when the server's backup limit is set to 0.");
|
throw new HttpForbiddenException("A backup task cannot be created when the server's backup limit is set to 0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \Pterodactyl\Models\Task|null $lastTask */
|
/** @var Task|null $lastTask */
|
||||||
$lastTask = $schedule->tasks()->orderByDesc('sequence_id')->first();
|
$lastTask = $schedule->tasks()->orderByDesc('sequence_id')->first();
|
||||||
|
|
||||||
/** @var \Pterodactyl\Models\Task $task */
|
/** @var Task $task */
|
||||||
$task = $this->repository->create([
|
$task = Task::query()->create([
|
||||||
'schedule_id' => $schedule->id,
|
'schedule_id' => $schedule->id,
|
||||||
'sequence_id' => ($lastTask->sequence_id ?? 0) + 1,
|
'sequence_id' => ($lastTask->sequence_id ?? 0) + 1,
|
||||||
'action' => $request->input('action'),
|
'action' => $request->input('action'),
|
||||||
|
@ -84,7 +83,7 @@ class ScheduleTaskController extends ClientApiController
|
||||||
throw new HttpForbiddenException("A backup task cannot be created when the server's backup limit is set to 0.");
|
throw new HttpForbiddenException("A backup task cannot be created when the server's backup limit is set to 0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->repository->update($task->id, [
|
$task->update([
|
||||||
'action' => $request->input('action'),
|
'action' => $request->input('action'),
|
||||||
'payload' => $request->input('payload') ?? '',
|
'payload' => $request->input('payload') ?? '',
|
||||||
'time_offset' => $request->input('time_offset'),
|
'time_offset' => $request->input('time_offset'),
|
||||||
|
|
|
@ -6,7 +6,6 @@ use Illuminate\Support\ServiceProvider;
|
||||||
use Pterodactyl\Repositories\Eloquent\EggRepository;
|
use Pterodactyl\Repositories\Eloquent\EggRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\NestRepository;
|
use Pterodactyl\Repositories\Eloquent\NestRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\TaskRepository;
|
|
||||||
use Pterodactyl\Repositories\Eloquent\UserRepository;
|
use Pterodactyl\Repositories\Eloquent\UserRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
|
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||||
|
@ -14,14 +13,12 @@ use Pterodactyl\Repositories\Eloquent\SessionRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
|
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
|
||||||
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
||||||
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\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\UserRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||||
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
||||||
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
|
||||||
|
@ -31,7 +28,6 @@ use Pterodactyl\Contracts\Repository\SessionRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||||
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\EggVariableRepositoryInterface;
|
||||||
|
@ -55,13 +51,11 @@ class RepositoryServiceProvider extends ServiceProvider
|
||||||
$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);
|
||||||
$this->app->bind(ScheduleRepositoryInterface::class, ScheduleRepository::class);
|
|
||||||
$this->app->bind(ServerRepositoryInterface::class, ServerRepository::class);
|
$this->app->bind(ServerRepositoryInterface::class, ServerRepository::class);
|
||||||
$this->app->bind(ServerVariableRepositoryInterface::class, ServerVariableRepository::class);
|
$this->app->bind(ServerVariableRepositoryInterface::class, ServerVariableRepository::class);
|
||||||
$this->app->bind(SessionRepositoryInterface::class, SessionRepository::class);
|
$this->app->bind(SessionRepositoryInterface::class, SessionRepository::class);
|
||||||
$this->app->bind(SettingsRepositoryInterface::class, SettingsRepository::class);
|
$this->app->bind(SettingsRepositoryInterface::class, SettingsRepository::class);
|
||||||
$this->app->bind(SubuserRepositoryInterface::class, SubuserRepository::class);
|
$this->app->bind(SubuserRepositoryInterface::class, SubuserRepository::class);
|
||||||
$this->app->bind(TaskRepositoryInterface::class, TaskRepository::class);
|
|
||||||
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
|
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Repositories\Eloquent;
|
|
||||||
|
|
||||||
use Pterodactyl\Models\Task;
|
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
||||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
|
||||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
||||||
|
|
||||||
class TaskRepository extends EloquentRepository implements TaskRepositoryInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return the model backing this repository.
|
|
||||||
*/
|
|
||||||
public function model(): string
|
|
||||||
{
|
|
||||||
return Task::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a task and the server relationship for that task.
|
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
||||||
*/
|
|
||||||
public function getTaskForJobProcess(int $id): Task
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return $this->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());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue