Files

45 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2017-09-09 23:55:21 -05:00
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Task;
use Illuminate\Database\Eloquent\ModelNotFoundException;
2017-09-09 23:55:21 -05:00
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class TaskRepository extends EloquentRepository implements TaskRepositoryInterface
{
/**
* Return the model backing this repository.
2017-09-09 23:55:21 -05:00
*/
2022-10-14 10:59:20 -06:00
public function model(): string
2017-09-09 23:55:21 -05:00
{
return Task::class;
}
/**
* Get a task and the server relationship for that task.
*
2024-10-21 19:18:20 -06:00
* @throws RecordNotFoundException
2017-09-09 23:55:21 -05:00
*/
public function getTaskForJobProcess(int $id): Task
2017-09-09 23:55:21 -05:00
{
try {
return $this->getBuilder()->with('server.user', 'schedule')->findOrFail($id, $this->getColumns());
2022-10-14 10:59:20 -06:00
} catch (ModelNotFoundException) {
2021-01-23 12:33:34 -08:00
throw new RecordNotFoundException();
2017-09-16 23:10:00 -05:00
}
2017-09-09 23:55:21 -05:00
}
/**
* Returns the next task in a schedule.
2017-09-09 23:55:21 -05:00
*/
2022-10-14 10:59:20 -06:00
public function getNextTask(int $schedule, int $index): ?Task
2017-09-09 23:55:21 -05:00
{
2017-09-16 23:10:00 -05:00
return $this->getBuilder()->where('schedule_id', '=', $schedule)
2022-10-14 10:59:20 -06:00
->orderBy('sequence_id')
2022-03-28 21:31:35 +02:00
->where('sequence_id', '>', $index)
2017-09-16 23:10:00 -05:00
->first($this->getColumns());
2017-09-09 23:55:21 -05:00
}
}