misc_pterodactyl-panel/app/Repositories/Eloquent/TaskRepository.php

48 lines
1.3 KiB
PHP
Raw Normal View History

<?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.
*
* @return string
*/
public function model()
{
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 $exception) {
2021-01-23 20:33:34 +00:00
throw new RecordNotFoundException();
2017-09-17 04:10:00 +00:00
}
}
/**
* Returns the next task in a schedule.
*
2020-06-28 22:43:44 +00:00
* @return \Pterodactyl\Models\Task|null
*/
public function getNextTask(int $schedule, int $index)
{
2017-09-17 04:10:00 +00:00
return $this->getBuilder()->where('schedule_id', '=', $schedule)
->where('sequence_id', '=', $index + 1)
->first($this->getColumns());
}
}