/
TaskRepository.php
44 lines (39 loc) · 1.26 KB
/
TaskRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?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());
}
}