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