2017-09-10 04:55:21 +00:00
|
|
|
<?php
|
|
|
|
|
2017-09-13 04:45:19 +00:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-13 04:45:19 +00:00
|
|
|
use Pterodactyl\Models\Schedule;
|
2017-10-28 02:42:53 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2018-01-05 04:49:50 +00:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2017-10-28 02:42:53 +00:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
2017-09-13 04:45:19 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-13 04:45:19 +00:00
|
|
|
class ScheduleRepository extends EloquentRepository implements ScheduleRepositoryInterface
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-09-13 04:45:19 +00:00
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return the model backing this repository.
|
|
|
|
*
|
|
|
|
* @return string
|
2017-09-13 04:45:19 +00:00
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Schedule::class;
|
|
|
|
}
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-13 04:45:19 +00:00
|
|
|
/**
|
2017-10-28 02:42:53 +00:00
|
|
|
* Return all of the schedules for a given server.
|
|
|
|
*
|
|
|
|
* @param int $server
|
|
|
|
* @return \Illuminate\Support\Collection
|
2017-09-13 04:45:19 +00:00
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function findServerSchedules(int $server): Collection
|
2017-09-13 04:45:19 +00:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->withCount('tasks')->where('server_id', '=', $server)->get($this->getColumns());
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 04:45:19 +00:00
|
|
|
/**
|
2017-10-28 02:42:53 +00:00
|
|
|
* Return a schedule model with all of the associated tasks as a relationship.
|
|
|
|
*
|
|
|
|
* @param int $schedule
|
|
|
|
* @return \Pterodactyl\Models\Schedule
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-09-13 04:45:19 +00:00
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function getScheduleWithTasks(int $schedule): Schedule
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2018-01-05 04:49:50 +00:00
|
|
|
try {
|
|
|
|
return $this->getBuilder()->with('tasks')->findOrFail($schedule, $this->getColumns());
|
|
|
|
} catch (ModelNotFoundException $exception) {
|
2017-10-28 02:42:53 +00:00
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
2017-09-17 04:10:00 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-05 04:49:50 +00:00
|
|
|
* Return all of the schedules that should be processed.
|
|
|
|
*
|
|
|
|
* @param string $timestamp
|
|
|
|
* @return \Illuminate\Support\Collection
|
2017-09-17 04:10:00 +00:00
|
|
|
*/
|
2018-01-05 04:49:50 +00:00
|
|
|
public function getSchedulesToProcess(string $timestamp): Collection
|
2017-09-17 04:10:00 +00:00
|
|
|
{
|
|
|
|
return $this->getBuilder()->with('tasks')
|
|
|
|
->where('is_active', true)
|
2018-09-03 21:32:33 +00:00
|
|
|
->where('is_processing', false)
|
2017-09-17 04:10:00 +00:00
|
|
|
->where('next_run_at', '<=', $timestamp)
|
|
|
|
->get($this->getColumns());
|
|
|
|
}
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|