2017-09-10 04:55:21 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-09-10 04:55:21 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-09-10 04:55:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Task;
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|
|
|
|
|
|
|
class TaskRepository extends EloquentRepository implements TaskRepositoryInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Task::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-09-17 04:10:00 +00:00
|
|
|
public function getTaskWithServer($id)
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-09-17 04:10:00 +00:00
|
|
|
Assert::integerish($id, 'First argument passed to getTaskWithServer must be numeric, received %s.');
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-11-05 18:38:39 +00:00
|
|
|
$instance = $this->getBuilder()->with('server.user')->find($id, $this->getColumns());
|
2017-09-17 04:10:00 +00:00
|
|
|
if (! $instance) {
|
|
|
|
throw new RecordNotFoundException;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-09-17 04:10:00 +00:00
|
|
|
public function getNextTask($schedule, $index)
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-09-17 04:10:00 +00:00
|
|
|
Assert::integerish($schedule, 'First argument passed to getNextTask must be integer, received %s.');
|
|
|
|
Assert::integerish($index, 'Second argument passed to getNextTask must be integer, received %s.');
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-17 04:10:00 +00:00
|
|
|
return $this->getBuilder()->where('schedule_id', '=', $schedule)
|
|
|
|
->where('sequence_id', '=', $index + 1)
|
|
|
|
->first($this->getColumns());
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
}
|