Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/TaskRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\Task;
6
use Illuminate\Database\Eloquent\ModelNotFoundException;
7
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
8
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
9
10
class TaskRepository extends EloquentRepository implements TaskRepositoryInterface
11
{
12
/**
13
* Return the model backing this repository.
14
*/
15
public function model(): string
16
{
17
return Task::class;
18
}
19
20
/**
21
* Get a task and the server relationship for that task.
22
*
23
* @throws RecordNotFoundException
24
*/
25
public function getTaskForJobProcess(int $id): Task
26
{
27
try {
28
return $this->getBuilder()->with('server.user', 'schedule')->findOrFail($id, $this->getColumns());
29
} catch (ModelNotFoundException) {
30
throw new RecordNotFoundException();
31
}
32
}
33
34
/**
35
* Returns the next task in a schedule.
36
*/
37
public function getNextTask(int $schedule, int $index): ?Task
38
{
39
return $this->getBuilder()->where('schedule_id', '=', $schedule)
40
->orderBy('sequence_id')
41
->where('sequence_id', '>', $index)
42
->first($this->getColumns());
43
}
44
}
45
46