Replace task repo too
This commit is contained in:
parent
e0f5856589
commit
451522e6cf
4 changed files with 5 additions and 73 deletions
|
@ -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;
|
|
||||||
}
|
|
|
@ -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::query()->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;
|
||||||
|
@ -20,7 +19,6 @@ 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;
|
||||||
|
@ -58,7 +56,6 @@ class RepositoryServiceProvider extends ServiceProvider
|
||||||
$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,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