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
|
@ -14,45 +14,23 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|||
|
||||
class BuildModificationService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
||||
*/
|
||||
private $structureService;
|
||||
|
||||
/**
|
||||
* BuildModificationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
|
||||
*/
|
||||
public function __construct(
|
||||
ServerConfigurationStructureService $structureService,
|
||||
ConnectionInterface $connection,
|
||||
DaemonServerRepository $daemonServerRepository
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonServerRepository $daemonServerRepository,
|
||||
private ServerConfigurationStructureService $structureService
|
||||
) {
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->connection = $connection;
|
||||
$this->structureService = $structureService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the build details for a specified server.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function handle(Server $server, array $data)
|
||||
public function handle(Server $server, array $data): Server
|
||||
{
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
$server = $this->connection->transaction(function () use ($server, $data) {
|
||||
|
@ -61,7 +39,7 @@ class BuildModificationService
|
|||
if (isset($data['allocation_id']) && $data['allocation_id'] != $server->allocation_id) {
|
||||
try {
|
||||
Allocation::query()->where('id', $data['allocation_id'])->where('server_id', $server->id)->firstOrFail();
|
||||
} catch (ModelNotFoundException $ex) {
|
||||
} catch (ModelNotFoundException) {
|
||||
throw new DisplayException('The requested default allocation is not currently assigned to this server.');
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +79,7 @@ class BuildModificationService
|
|||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
private function processAllocations(Server $server, array &$data)
|
||||
private function processAllocations(Server $server, array &$data): void
|
||||
{
|
||||
if (empty($data['add_allocations']) && empty($data['remove_allocations'])) {
|
||||
return;
|
||||
|
|
|
@ -13,23 +13,11 @@ class DetailsModificationService
|
|||
{
|
||||
use ReturnsUpdatedModels;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $serverRepository;
|
||||
|
||||
/**
|
||||
* DetailsModificationService constructor.
|
||||
*/
|
||||
public function __construct(ConnectionInterface $connection, DaemonServerRepository $serverRepository)
|
||||
public function __construct(private ConnectionInterface $connection, private DaemonServerRepository $serverRepository)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->serverRepository = $serverRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +45,7 @@ class DetailsModificationService
|
|||
$this->serverRepository->setServer($server)->revokeUserJTI($owner);
|
||||
} catch (DaemonConnectionException $exception) {
|
||||
// Do nothing. A failure here is not ideal, but it is likely to be caused by Wings
|
||||
// being offline, or in an entirely broken state. Remeber, these tokens reset every
|
||||
// being offline, or in an entirely broken state. Remember, these tokens reset every
|
||||
// few minutes by default, we're just trying to help it along a little quicker.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,13 @@ use Pterodactyl\Models\EggVariable;
|
|||
|
||||
class EnvironmentService
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $additional = [];
|
||||
private array $additional = [];
|
||||
|
||||
/**
|
||||
* Dynamically configure additional environment variables to be assigned
|
||||
* with a specific server.
|
||||
*/
|
||||
public function setEnvironmentKey(string $key, callable $closure)
|
||||
public function setEnvironmentKey(string $key, callable $closure): void
|
||||
{
|
||||
$this->additional[$key] = $closure;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,8 @@ class GetUserPermissionsService
|
|||
* Returns the server specific permissions that a user has. This checks
|
||||
* if they are an admin or a subuser for the server. If no permissions are
|
||||
* found, an empty array is returned.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function handle(Server $server, User $user)
|
||||
public function handle(Server $server, User $user): array
|
||||
{
|
||||
if ($user->root_admin || $user->id === $server->owner_id) {
|
||||
$permissions = ['*'];
|
||||
|
|
|
@ -8,35 +8,21 @@ use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
|||
|
||||
class ReinstallServerService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* ReinstallService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
DaemonServerRepository $daemonServerRepository
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonServerRepository $daemonServerRepository
|
||||
) {
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinstall a server on the remote daemon.
|
||||
*
|
||||
* @return \Pterodactyl\Models\Server
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function handle(Server $server)
|
||||
public function handle(Server $server): Server
|
||||
{
|
||||
return $this->connection->transaction(function () use ($server) {
|
||||
$server->fill(['status' => Server::STATUS_INSTALLING])->save();
|
||||
|
|
|
@ -7,14 +7,11 @@ use Pterodactyl\Models\Server;
|
|||
|
||||
class ServerConfigurationStructureService
|
||||
{
|
||||
private EnvironmentService $environment;
|
||||
|
||||
/**
|
||||
* ServerConfigurationStructureService constructor.
|
||||
*/
|
||||
public function __construct(EnvironmentService $environment)
|
||||
public function __construct(private EnvironmentService $environment)
|
||||
{
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,6 @@ use Illuminate\Support\Collection;
|
|||
use Pterodactyl\Models\Allocation;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Models\Objects\DeploymentObject;
|
||||
use Pterodactyl\Repositories\Eloquent\EggRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Services\Deployment\FindViableNodesService;
|
||||
|
@ -23,84 +22,18 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|||
class ServerCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Deployment\AllocationSelectionService
|
||||
*/
|
||||
private $allocationSelectionService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
||||
*/
|
||||
private $configurationStructureService;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Deployment\FindViableNodesService
|
||||
*/
|
||||
private $findViableNodesService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\VariableValidatorService
|
||||
*/
|
||||
private $validatorService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\EggRepository
|
||||
*/
|
||||
private $eggRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Eloquent\ServerVariableRepository
|
||||
*/
|
||||
private $serverVariableRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\ServerDeletionService
|
||||
*/
|
||||
private $serverDeletionService;
|
||||
|
||||
/**
|
||||
* CreationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
||||
* @param \Pterodactyl\Services\Servers\ServerDeletionService $serverDeletionService
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
* ServerCreationService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
AllocationSelectionService $allocationSelectionService,
|
||||
ConnectionInterface $connection,
|
||||
DaemonServerRepository $daemonServerRepository,
|
||||
EggRepository $eggRepository,
|
||||
FindViableNodesService $findViableNodesService,
|
||||
ServerConfigurationStructureService $configurationStructureService,
|
||||
ServerDeletionService $serverDeletionService,
|
||||
ServerRepository $repository,
|
||||
ServerVariableRepository $serverVariableRepository,
|
||||
VariableValidatorService $validatorService
|
||||
private AllocationSelectionService $allocationSelectionService,
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonServerRepository $daemonServerRepository,
|
||||
private FindViableNodesService $findViableNodesService,
|
||||
private ServerRepository $repository,
|
||||
private ServerDeletionService $serverDeletionService,
|
||||
private ServerVariableRepository $serverVariableRepository,
|
||||
private VariableValidatorService $validatorService
|
||||
) {
|
||||
$this->allocationSelectionService = $allocationSelectionService;
|
||||
$this->configurationStructureService = $configurationStructureService;
|
||||
$this->connection = $connection;
|
||||
$this->findViableNodesService = $findViableNodesService;
|
||||
$this->validatorService = $validatorService;
|
||||
$this->eggRepository = $eggRepository;
|
||||
$this->repository = $repository;
|
||||
$this->serverVariableRepository = $serverVariableRepository;
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->serverDeletionService = $serverDeletionService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,7 +170,7 @@ class ServerCreationService
|
|||
/**
|
||||
* Configure the allocations assigned to this server.
|
||||
*/
|
||||
private function storeAssignedAllocations(Server $server, array $data)
|
||||
private function storeAssignedAllocations(Server $server, array $data): void
|
||||
{
|
||||
$records = [$data['allocation_id']];
|
||||
if (isset($data['allocation_additional']) && is_array($data['allocation_additional'])) {
|
||||
|
@ -252,7 +185,7 @@ class ServerCreationService
|
|||
/**
|
||||
* Process environment variables passed for this server and store them in the database.
|
||||
*/
|
||||
private function storeEggVariables(Server $server, Collection $variables)
|
||||
private function storeEggVariables(Server $server, Collection $variables): void
|
||||
{
|
||||
$records = $variables->map(function ($result) use ($server) {
|
||||
return [
|
||||
|
|
|
@ -13,47 +13,22 @@ use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|||
|
||||
class ServerDeletionService
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $force = false;
|
||||
protected bool $force = false;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Databases\DatabaseManagementService
|
||||
*/
|
||||
private $databaseManagementService;
|
||||
|
||||
/**
|
||||
* DeletionService constructor.
|
||||
* ServerDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
DaemonServerRepository $daemonServerRepository,
|
||||
DatabaseManagementService $databaseManagementService
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonServerRepository $daemonServerRepository,
|
||||
private DatabaseManagementService $databaseManagementService
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
$this->databaseManagementService = $databaseManagementService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server should be forcibly deleted from the panel (ignoring daemon errors) or not.
|
||||
*
|
||||
* @param bool $bool
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withForce($bool = true)
|
||||
public function withForce(bool $bool = true): self
|
||||
{
|
||||
$this->force = $bool;
|
||||
|
||||
|
@ -66,7 +41,7 @@ class ServerDeletionService
|
|||
* @throws \Throwable
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function handle(Server $server)
|
||||
public function handle(Server $server): void
|
||||
{
|
||||
try {
|
||||
$this->daemonServerRepository->setServer($server)->delete();
|
||||
|
|
|
@ -14,25 +14,11 @@ class StartupModificationService
|
|||
{
|
||||
use HasUserLevels;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Servers\VariableValidatorService
|
||||
*/
|
||||
private $validatorService;
|
||||
|
||||
/**
|
||||
* StartupModificationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||
*/
|
||||
public function __construct(ConnectionInterface $connection, VariableValidatorService $validatorService)
|
||||
public function __construct(private ConnectionInterface $connection, private VariableValidatorService $validatorService)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->validatorService = $validatorService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +65,7 @@ class StartupModificationService
|
|||
/**
|
||||
* Update certain administrative settings for a server in the DB.
|
||||
*/
|
||||
protected function updateAdministrativeSettings(array $data, Server &$server)
|
||||
protected function updateAdministrativeSettings(array $data, Server &$server): void
|
||||
{
|
||||
$eggId = Arr::get($data, 'egg_id');
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Servers;
|
|||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||
|
||||
|
@ -13,42 +12,27 @@ class SuspensionService
|
|||
public const ACTION_SUSPEND = 'suspend';
|
||||
public const ACTION_UNSUSPEND = 'unsuspend';
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* SuspensionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
DaemonServerRepository $daemonServerRepository
|
||||
private DaemonServerRepository $daemonServerRepository
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspends a server on the system.
|
||||
*
|
||||
* @param string $action
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function toggle(Server $server, $action = self::ACTION_SUSPEND)
|
||||
public function toggle(Server $server, string $action = self::ACTION_SUSPEND): void
|
||||
{
|
||||
Assert::oneOf($action, [self::ACTION_SUSPEND, self::ACTION_UNSUSPEND]);
|
||||
|
||||
$isSuspending = $action === self::ACTION_SUSPEND;
|
||||
// Nothing needs to happen if we're suspending the server and it is already
|
||||
// Nothing needs to happen if we're suspending the server, and it is already
|
||||
// suspended in the database. Additionally, nothing needs to happen if the server
|
||||
// is not suspended and we try to un-suspend the instance.
|
||||
// is not suspended, and we try to un-suspend the instance.
|
||||
if ($isSuspending === $server->isSuspended()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -4,39 +4,23 @@ namespace Pterodactyl\Services\Servers;
|
|||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class TransferService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
||||
*/
|
||||
private $daemonServerRepository;
|
||||
|
||||
/**
|
||||
* TransferService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
DaemonServerRepository $daemonServerRepository,
|
||||
ServerRepositoryInterface $repository
|
||||
private DaemonServerRepository $daemonServerRepository
|
||||
) {
|
||||
$this->repository = $repository;
|
||||
$this->daemonServerRepository = $daemonServerRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests an archive from the daemon.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Server $server
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function requestArchive(Server $server)
|
||||
public function requestArchive(Server $server): void
|
||||
{
|
||||
$this->daemonServerRepository->setServer($server)->requestArchive();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
<?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\Services\Servers;
|
||||
|
||||
|
@ -20,17 +13,11 @@ class VariableValidatorService
|
|||
{
|
||||
use HasUserLevels;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Validation\Factory
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
/**
|
||||
* VariableValidatorService constructor.
|
||||
*/
|
||||
public function __construct(ValidationFactory $validator)
|
||||
public function __construct(private ValidationFactory $validator)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +29,7 @@ class VariableValidatorService
|
|||
{
|
||||
$query = EggVariable::query()->where('egg_id', $egg);
|
||||
if (!$this->isUserLevel(User::USER_LEVEL_ADMIN)) {
|
||||
// Don't attempt to validate variables if they aren't user editable
|
||||
// Don't attempt to validate variables if they aren't user editable,
|
||||
// and we're not running this at an admin level.
|
||||
$query = $query->where('user_editable', true)->where('user_viewable', true);
|
||||
}
|
||||
|
|
Reference in a new issue