2017-07-02 21:29:58 -05:00
|
|
|
<?php
|
|
|
|
|
2017-07-15 11:52:34 -05:00
|
|
|
namespace Pterodactyl\Repositories\Eloquent;
|
2017-07-02 21:29:58 -05:00
|
|
|
|
2017-07-15 11:52:34 -05:00
|
|
|
use Pterodactyl\Models\Server;
|
2019-12-16 21:02:30 -08:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2018-01-04 22:49:50 -06:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2017-07-21 21:17:42 -05:00
|
|
|
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
2017-07-15 11:52:34 -05:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
|
2017-08-18 22:19:06 -05:00
|
|
|
class ServerRepository extends EloquentRepository implements ServerRepositoryInterface
|
2017-07-02 21:29:58 -05:00
|
|
|
{
|
2017-07-08 14:07:51 -05:00
|
|
|
/**
|
2018-01-04 22:49:50 -06:00
|
|
|
* Return the model backing this repository.
|
2017-07-15 11:52:34 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function model(): string
|
2017-07-15 11:52:34 -05:00
|
|
|
{
|
|
|
|
return Server::class;
|
|
|
|
}
|
|
|
|
|
2017-08-30 21:11:14 -05:00
|
|
|
/**
|
2018-01-04 22:49:50 -06:00
|
|
|
* Return a server by UUID.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-08-30 21:11:14 -05:00
|
|
|
*/
|
2018-01-04 22:49:50 -06:00
|
|
|
public function getByUuid(string $uuid): Server
|
2017-08-30 21:11:14 -05:00
|
|
|
{
|
2018-01-04 22:49:50 -06:00
|
|
|
try {
|
2019-12-16 21:02:30 -08:00
|
|
|
/** @var \Pterodactyl\Models\Server $model */
|
|
|
|
$model = $this->getBuilder()
|
|
|
|
->with('nest', 'node')
|
|
|
|
->where(function (Builder $query) use ($uuid) {
|
|
|
|
$query->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
|
|
|
|
})
|
|
|
|
->firstOrFail($this->getColumns());
|
|
|
|
|
|
|
|
return $model;
|
2022-10-14 10:59:20 -06:00
|
|
|
} catch (ModelNotFoundException) {
|
2021-01-23 12:33:34 -08:00
|
|
|
throw new RecordNotFoundException();
|
2017-08-30 21:11:14 -05:00
|
|
|
}
|
2018-01-04 22:49:50 -06:00
|
|
|
}
|
2017-07-02 21:29:58 -05:00
|
|
|
}
|