forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskRepository.php
More file actions
52 lines (47 loc) · 1.4 KB
/
TaskRepository.php
File metadata and controls
52 lines (47 loc) · 1.4 KB
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
45
46
47
48
49
50
51
52
<?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.
*
* @param int $id
* @return \Pterodactyl\Models\Task
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getTaskWithServer(int $id): Task
{
try {
return $this->getBuilder()->with('server.user')->findOrFail($id, $this->getColumns());
} catch (ModelNotFoundException $exception) {
throw new RecordNotFoundException;
}
}
/**
* Returns the next task in a schedule.
*
* @param int $schedule
* @param int $index
* @return null|\Pterodactyl\Models\Task
*/
public function getNextTask(int $schedule, int $index)
{
return $this->getBuilder()->where('schedule_id', '=', $schedule)
->where('sequence_id', '=', $index + 1)
->first($this->getColumns());
}
}