Fix server creation logic

This commit is contained in:
Dane Everitt 2019-12-16 21:02:30 -08:00
parent 85b47ceb79
commit 2a92304023
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 35 additions and 10 deletions

View file

@ -3,9 +3,9 @@
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\User;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Builder;
use Pterodactyl\Repositories\Concerns\Searchable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
@ -273,12 +273,16 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
*/
public function getByUuid(string $uuid): Server
{
Assert::notEmpty($uuid, 'Expected non-empty string as first argument passed to ' . __METHOD__);
try {
return $this->getBuilder()->with('nest', 'node')->where(function ($query) use ($uuid) {
$query->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
})->firstOrFail($this->getColumns());
/** @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;
} catch (ModelNotFoundException $exception) {
throw new RecordNotFoundException;
}