Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
parent
95e15d2c8a
commit
cbcf62086f
573 changed files with 4387 additions and 9411 deletions
|
@ -10,16 +10,14 @@ class AllocationRepository extends EloquentRepository implements AllocationRepos
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Allocation::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the allocations that exist for a node that are not currently
|
||||
* Return all the allocations that exist for a node that are not currently
|
||||
* allocated.
|
||||
*/
|
||||
public function getUnassignedAllocationIds(int $node): array
|
||||
|
@ -57,10 +55,8 @@ class AllocationRepository extends EloquentRepository implements AllocationRepos
|
|||
|
||||
/**
|
||||
* Return a single allocation from those meeting the requirements.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Allocation|null
|
||||
*/
|
||||
public function getRandomAllocation(array $nodes, array $ports, bool $dedicated = false)
|
||||
public function getRandomAllocation(array $nodes, array $ports, bool $dedicated = false): ?Allocation
|
||||
{
|
||||
$query = Allocation::query()->whereNull('server_id');
|
||||
|
||||
|
|
|
@ -11,16 +11,14 @@ class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInt
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return ApiKey::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the account API keys that exist for a specific user.
|
||||
* Get all the account API keys that exist for a specific user.
|
||||
*/
|
||||
public function getAccountKeys(User $user): Collection
|
||||
{
|
||||
|
@ -30,7 +28,7 @@ class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInt
|
|||
}
|
||||
|
||||
/**
|
||||
* Get all of the application API keys that exist for a specific user.
|
||||
* Get all the application API keys that exist for a specific user.
|
||||
*/
|
||||
public function getApplicationKeys(User $user): Collection
|
||||
{
|
||||
|
|
|
@ -5,24 +5,20 @@ namespace Pterodactyl\Repositories\Eloquent;
|
|||
use Carbon\Carbon;
|
||||
use Pterodactyl\Models\Backup;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class BackupRepository extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Backup::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if too many backups have been generated by the server.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Backup[]|\Illuminate\Support\Collection
|
||||
*/
|
||||
public function getBackupsGeneratedDuringTimespan(int $server, int $seconds = 600)
|
||||
public function getBackupsGeneratedDuringTimespan(int $server, int $seconds = 600): array|Collection
|
||||
{
|
||||
return $this->getBuilder()
|
||||
->withTrashed()
|
||||
|
|
|
@ -10,10 +10,8 @@ class DatabaseHostRepository extends EloquentRepository implements DatabaseHostR
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return DatabaseHost::class;
|
||||
}
|
||||
|
|
|
@ -11,48 +11,24 @@ use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
|||
|
||||
class DatabaseRepository extends EloquentRepository implements DatabaseRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $connection = self::DEFAULT_CONNECTION_NAME;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\DatabaseManager
|
||||
*/
|
||||
protected $database;
|
||||
protected string $connection = self::DEFAULT_CONNECTION_NAME;
|
||||
|
||||
/**
|
||||
* DatabaseRepository constructor.
|
||||
*/
|
||||
public function __construct(Application $application, DatabaseManager $database)
|
||||
public function __construct(Application $application, private DatabaseManager $database)
|
||||
{
|
||||
parent::__construct($application);
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Database::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connection name to execute statements against.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnection(string $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the connection to execute statements against.
|
||||
*/
|
||||
|
@ -62,7 +38,17 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all of the databases belonging to a server.
|
||||
* Set the connection name to execute statements against.
|
||||
*/
|
||||
public function setConnection(string $connection): self
|
||||
{
|
||||
$this->connection = $connection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the databases belonging to a server.
|
||||
*/
|
||||
public function getDatabasesForServer(int $server): Collection
|
||||
{
|
||||
|
@ -70,7 +56,7 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all of the databases for a given host with the server relationship loaded.
|
||||
* Return all the databases for a given host with the server relationship loaded.
|
||||
*/
|
||||
public function getDatabasesForHost(int $host, int $count = 25): LengthAwarePaginator
|
||||
{
|
||||
|
@ -89,16 +75,18 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
|
|||
|
||||
/**
|
||||
* Create a new database user on a given connection.
|
||||
*
|
||||
* @param $max_connections
|
||||
*/
|
||||
public function createUser(string $username, string $remote, string $password, $max_connections): bool
|
||||
public function createUser(string $username, string $remote, string $password, ?int $max_connections): bool
|
||||
{
|
||||
if (!$max_connections) {
|
||||
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'', $username, $remote, $password));
|
||||
} else {
|
||||
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\' WITH MAX_USER_CONNECTIONS %s', $username, $remote, $password, $max_connections));
|
||||
$args = [$username, $remote, $password];
|
||||
$command = 'CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'';
|
||||
|
||||
if (!empty($max_connections)) {
|
||||
$args[] = $max_connections;
|
||||
$command .= ' WITH MAX_USER_CONNECTIONS %s';
|
||||
}
|
||||
|
||||
return $this->run(sprintf($command, ...$args));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,8 +120,6 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
|
|||
|
||||
/**
|
||||
* Drop a given user on a specific connection.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function dropUser(string $username, string $remote): bool
|
||||
{
|
||||
|
|
|
@ -13,10 +13,8 @@ class EggRepository extends EloquentRepository implements EggRepositoryInterface
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Egg::class;
|
||||
}
|
||||
|
@ -30,7 +28,7 @@ class EggRepository extends EloquentRepository implements EggRepositoryInterface
|
|||
{
|
||||
try {
|
||||
return $this->getBuilder()->with('variables')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -52,17 +50,17 @@ class EggRepository extends EloquentRepository implements EggRepositoryInterface
|
|||
*/
|
||||
public function getWithCopyAttributes($value, string $column = 'id'): Egg
|
||||
{
|
||||
Assert::true((is_digit($value) || is_string($value)), 'First argument passed to getWithCopyAttributes must be an integer or string, received %s.');
|
||||
Assert::true(is_digit($value) || is_string($value), 'First argument passed to getWithCopyAttributes must be an integer or string, received %s.');
|
||||
|
||||
try {
|
||||
return $this->getBuilder()->with('scriptFrom', 'configFrom')->where($column, '=', $value)->firstOrFail($this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the data needed to export a service.
|
||||
* Return all the data needed to export a service.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
|
@ -70,7 +68,7 @@ class EggRepository extends EloquentRepository implements EggRepositoryInterface
|
|||
{
|
||||
try {
|
||||
return $this->getBuilder()->with('scriptFrom', 'configFrom', 'variables')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,8 @@ class EggVariableRepository extends EloquentRepository implements EggVariableRep
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return EggVariable::class;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Pterodactyl\Repositories\Eloquent;
|
|||
use Illuminate\Http\Request;
|
||||
use Webmozart\Assert\Assert;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Pterodactyl\Repositories\Repository;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
|
@ -16,21 +17,14 @@ use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
|||
|
||||
abstract class EloquentRepository extends Repository implements RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useRequestFilters = false;
|
||||
protected bool $useRequestFilters = false;
|
||||
|
||||
/**
|
||||
* Determines if the repository function should use filters off the request object
|
||||
* present when returning results. This allows repository methods to be called in API
|
||||
* context's such that we can pass through ?filter[name]=Dane&sort=desc for example.
|
||||
*
|
||||
* @param bool $usingFilters
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function usingRequestFilters($usingFilters = true)
|
||||
public function usingRequestFilters(bool $usingFilters = true): self
|
||||
{
|
||||
$this->useRequestFilters = $usingFilters;
|
||||
|
||||
|
@ -39,20 +33,16 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
|
||||
/**
|
||||
* Returns the request instance.
|
||||
*
|
||||
* @return \Illuminate\Http\Request
|
||||
*/
|
||||
protected function request()
|
||||
protected function request(): Request
|
||||
{
|
||||
return $this->app->make(Request::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paginate the response data based on the page para.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
protected function paginate(Builder $instance, int $default = 50)
|
||||
protected function paginate(Builder $instance, int $default = 50): LengthAwarePaginator
|
||||
{
|
||||
if (!$this->useRequestFilters) {
|
||||
return $instance->paginate($default);
|
||||
|
@ -64,20 +54,16 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
/**
|
||||
* Return an instance of the eloquent model bound to this
|
||||
* repository instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function getModel()
|
||||
public function getModel(): Model
|
||||
{
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the builder to use for this repository.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function getBuilder()
|
||||
public function getBuilder(): Builder
|
||||
{
|
||||
return $this->getModel()->newQuery();
|
||||
}
|
||||
|
@ -85,11 +71,9 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
/**
|
||||
* Create a new record in the database and return the associated model.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|bool
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function create(array $fields, bool $validate = true, bool $force = false)
|
||||
public function create(array $fields, bool $validate = true, bool $force = false): Model|bool
|
||||
{
|
||||
$instance = $this->getBuilder()->newModelInstance();
|
||||
($force) ? $instance->forceFill($fields) : $instance->fill($fields);
|
||||
|
@ -108,15 +92,13 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
/**
|
||||
* Find a model that has the specific ID passed.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function find(int $id)
|
||||
public function find(int $id): Model
|
||||
{
|
||||
try {
|
||||
return $this->getBuilder()->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -132,15 +114,13 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
/**
|
||||
* Find and return the first matching instance for the given fields.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function findFirstWhere(array $fields)
|
||||
public function findFirstWhere(array $fields): Model
|
||||
{
|
||||
try {
|
||||
return $this->getBuilder()->where($fields)->firstOrFail($this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -174,18 +154,14 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
/**
|
||||
* Update a given ID with the passed array of fields.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|bool
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function update($id, array $fields, bool $validate = true, bool $force = false)
|
||||
public function update(int $id, array $fields, bool $validate = true, bool $force = false): Model|bool
|
||||
{
|
||||
try {
|
||||
$instance = $this->getBuilder()->where('id', $id)->firstOrFail();
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
|
||||
|
@ -204,12 +180,8 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
|
||||
/**
|
||||
* Update a model using the attributes passed.
|
||||
*
|
||||
* @param array|\Closure $attributes
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function updateWhere($attributes, array $values)
|
||||
public function updateWhere(array $attributes, array $values): int
|
||||
{
|
||||
return $this->getBuilder()->where($attributes)->update($values);
|
||||
}
|
||||
|
@ -228,12 +200,10 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
/**
|
||||
* Update a record if it exists in the database, otherwise create it.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function updateOrCreate(array $where, array $fields, bool $validate = true, bool $force = false)
|
||||
public function updateOrCreate(array $where, array $fields, bool $validate = true, bool $force = false): Model|bool
|
||||
{
|
||||
foreach ($where as $item) {
|
||||
Assert::true(is_scalar($item) || is_null($item), 'First argument passed to updateOrCreate should be an array of scalar or null values, received an array value of %s.');
|
||||
|
@ -241,7 +211,7 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
|
|||
|
||||
try {
|
||||
$instance = $this->setColumns('id')->findFirstWhere($where);
|
||||
} catch (RecordNotFoundException $exception) {
|
||||
} catch (RecordNotFoundException) {
|
||||
return $this->create(array_merge($where, $fields), $validate, $force);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,8 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Location::class;
|
||||
}
|
||||
|
@ -29,7 +27,7 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all of the available locations with the nodes as a relationship.
|
||||
* Return all the available locations with the nodes as a relationship.
|
||||
*/
|
||||
public function getAllWithNodes(): Collection
|
||||
{
|
||||
|
@ -37,9 +35,7 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all of the nodes and their respective count of servers for a location.
|
||||
*
|
||||
* @return mixed
|
||||
* Return all the nodes and their respective count of servers for a location.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
|
@ -47,7 +43,7 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
|||
{
|
||||
try {
|
||||
return $this->getBuilder()->with('nodes.servers')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -55,15 +51,13 @@ class LocationRepository extends EloquentRepository implements LocationRepositor
|
|||
/**
|
||||
* Return a location and the count of nodes in that location.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithNodeCount(int $id): Location
|
||||
{
|
||||
try {
|
||||
return $this->getBuilder()->withCount('nodes')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,8 @@ class MountRepository extends EloquentRepository
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Mount::class;
|
||||
}
|
||||
|
@ -29,9 +27,7 @@ class MountRepository extends EloquentRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all of the mounts and their respective relations.
|
||||
*
|
||||
* @return mixed
|
||||
* Return all the mounts and their respective relations.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
|
||||
|
@ -17,10 +11,8 @@ class NestRepository extends EloquentRepository implements NestRepositoryInterfa
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Nest::class;
|
||||
}
|
||||
|
@ -28,13 +20,9 @@ class NestRepository extends EloquentRepository implements NestRepositoryInterfa
|
|||
/**
|
||||
* Return a nest or all nests with their associated eggs and variables.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection|\Pterodactyl\Models\Nest
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithEggs(int $id = null)
|
||||
public function getWithEggs(int $id = null): Collection|Nest
|
||||
{
|
||||
$instance = $this->getBuilder()->with('eggs', 'eggs.variables');
|
||||
|
||||
|
@ -53,11 +41,9 @@ class NestRepository extends EloquentRepository implements NestRepositoryInterfa
|
|||
/**
|
||||
* Return a nest or all nests and the count of eggs and servers for that nest.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Nest|\Illuminate\Database\Eloquent\Collection
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithCounts(int $id = null)
|
||||
public function getWithCounts(int $id = null): Collection|Nest
|
||||
{
|
||||
$instance = $this->getBuilder()->withCount(['eggs', 'servers']);
|
||||
|
||||
|
|
|
@ -10,10 +10,8 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Node::class;
|
||||
}
|
||||
|
@ -105,7 +103,7 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
|
|||
$node->allocations()
|
||||
->orderByRaw('server_id IS NOT NULL DESC, server_id IS NULL')
|
||||
->orderByRaw('INET_ATON(ip) ASC')
|
||||
->orderBy('port', 'asc')
|
||||
->orderBy('port')
|
||||
->with('server:id,name')
|
||||
->paginate(50)
|
||||
);
|
||||
|
|
|
@ -10,11 +10,9 @@ class PermissionRepository extends EloquentRepository implements PermissionRepos
|
|||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
throw new Exception('This functionality is not implemented.');
|
||||
}
|
||||
|
|
|
@ -6,10 +6,7 @@ use Pterodactyl\Models\RecoveryToken;
|
|||
|
||||
class RecoveryTokenRepository extends EloquentRepository
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return RecoveryToken::class;
|
||||
}
|
||||
|
|
|
@ -12,16 +12,14 @@ class ScheduleRepository extends EloquentRepository implements ScheduleRepositor
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Schedule::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the schedules for a given server.
|
||||
* Return all the schedules for a given server.
|
||||
*/
|
||||
public function findServerSchedules(int $server): Collection
|
||||
{
|
||||
|
@ -29,7 +27,7 @@ class ScheduleRepository extends EloquentRepository implements ScheduleRepositor
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a schedule model with all of the associated tasks as a relationship.
|
||||
* Return a schedule model with all the associated tasks as a relationship.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
|
@ -37,7 +35,7 @@ class ScheduleRepository extends EloquentRepository implements ScheduleRepositor
|
|||
{
|
||||
try {
|
||||
return $this->getBuilder()->with('tasks')->findOrFail($schedule, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Server::class;
|
||||
}
|
||||
|
@ -77,7 +75,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
return $this->getBuilder()->with('egg.variables', 'variables')
|
||||
->where($this->getModel()->getKeyName(), '=', $id)
|
||||
->firstOrFail($this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +153,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
->firstOrFail($this->getColumns());
|
||||
|
||||
return $model;
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +167,7 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all of the servers that exist for a given node in a paginated response.
|
||||
* Returns all the servers that exist for a given node in a paginated response.
|
||||
*/
|
||||
public function loadAllServersForNode(int $node, int $limit): LengthAwarePaginator
|
||||
{
|
||||
|
|
|
@ -9,10 +9,8 @@ class ServerVariableRepository extends EloquentRepository implements ServerVaria
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return ServerVariable::class;
|
||||
}
|
||||
|
|
|
@ -10,16 +10,14 @@ class SessionRepository extends EloquentRepository implements SessionRepositoryI
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Session::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the active sessions for a user.
|
||||
* Return all the active sessions for a user.
|
||||
*/
|
||||
public function getUserSessions(int $user): Collection
|
||||
{
|
||||
|
@ -28,10 +26,8 @@ class SessionRepository extends EloquentRepository implements SessionRepositoryI
|
|||
|
||||
/**
|
||||
* Delete a session for a given user.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function deleteUserSession(int $user, string $session)
|
||||
public function deleteUserSession(int $user, string $session): ?int
|
||||
{
|
||||
return $this->getBuilder()->where('user_id', $user)->where('id', $session)->delete();
|
||||
}
|
||||
|
|
|
@ -7,22 +7,14 @@ use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
|
|||
|
||||
class SettingsRepository extends EloquentRepository implements SettingsRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $cache = [];
|
||||
private static array $cache = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $databaseMiss = [];
|
||||
private static array $databaseMiss = [];
|
||||
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Setting::class;
|
||||
}
|
||||
|
@ -31,7 +23,6 @@ class SettingsRepository extends EloquentRepository implements SettingsRepositor
|
|||
* Store a new persistent setting in the database.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function set(string $key, string $value = null)
|
||||
{
|
||||
|
@ -44,12 +35,8 @@ class SettingsRepository extends EloquentRepository implements SettingsRepositor
|
|||
|
||||
/**
|
||||
* Retrieve a persistent setting from the database.
|
||||
*
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key, $default = null)
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
// If item has already been requested return it from the cache. If
|
||||
// we already know it is missing, immediately return the default value.
|
||||
|
|
|
@ -10,10 +10,8 @@ class SubuserRepository extends EloquentRepository implements SubuserRepositoryI
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Subuser::class;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,8 @@ class TaskRepository extends EloquentRepository implements TaskRepositoryInterfa
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return Task::class;
|
||||
}
|
||||
|
@ -28,20 +26,18 @@ class TaskRepository extends EloquentRepository implements TaskRepositoryInterfa
|
|||
{
|
||||
try {
|
||||
return $this->getBuilder()->with('server.user', 'schedule')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next task in a schedule.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Task|null
|
||||
*/
|
||||
public function getNextTask(int $schedule, int $index)
|
||||
public function getNextTask(int $schedule, int $index): ?Task
|
||||
{
|
||||
return $this->getBuilder()->where('schedule_id', '=', $schedule)
|
||||
->orderBy('sequence_id', 'asc')
|
||||
->orderBy('sequence_id')
|
||||
->where('sequence_id', '>', $index)
|
||||
->first($this->getColumns());
|
||||
}
|
||||
|
|
|
@ -9,10 +9,8 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa
|
|||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
public function model(): string
|
||||
{
|
||||
return User::class;
|
||||
}
|
||||
|
|
Reference in a new issue