Remove ServerRepository and ServerRepositoryInterface
This commit is contained in:
parent
22d560de64
commit
4d7ea155b1
19 changed files with 63 additions and 146 deletions
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Contracts\Repository;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
|
||||
interface ServerRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return a server by UUID.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getByUuid(string $uuid): Server;
|
||||
}
|
|
@ -10,7 +10,6 @@ use Pterodactyl\Models\Allocation;
|
|||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
||||
use Pterodactyl\Services\Helpers\SoftwareVersionService;
|
||||
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
||||
|
@ -27,7 +26,6 @@ class NodeViewController extends Controller
|
|||
private AllocationRepository $allocationRepository,
|
||||
private LocationRepository $locationRepository,
|
||||
private NodeRepository $repository,
|
||||
private ServerRepository $serverRepository,
|
||||
private SoftwareVersionService $versionService,
|
||||
private ViewFactory $view
|
||||
) {
|
||||
|
|
|
@ -19,7 +19,6 @@ use Pterodactyl\Services\Allocations\AssignmentService;
|
|||
use Pterodactyl\Services\Helpers\SoftwareVersionService;
|
||||
use Pterodactyl\Http\Requests\Admin\Node\NodeFormRequest;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Http\Requests\Admin\Node\AllocationFormRequest;
|
||||
use Pterodactyl\Services\Allocations\AllocationDeletionService;
|
||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
|
@ -41,7 +40,6 @@ class NodesController extends Controller
|
|||
protected NodeDeletionService $deletionService,
|
||||
protected LocationRepositoryInterface $locationRepository,
|
||||
protected NodeRepositoryInterface $repository,
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected NodeUpdateService $updateService,
|
||||
protected SoftwareVersionService $versionService,
|
||||
protected ViewFactory $view
|
||||
|
|
|
@ -14,7 +14,6 @@ use Illuminate\Contracts\View\Factory as ViewFactory;
|
|||
use Pterodactyl\Repositories\Eloquent\NestRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
||||
use Pterodactyl\Repositories\Eloquent\LocationRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
||||
|
@ -32,7 +31,6 @@ class ServerViewController extends Controller
|
|||
private MountRepository $mountRepository,
|
||||
private NestRepository $nestRepository,
|
||||
private NodeRepository $nodeRepository,
|
||||
private ServerRepository $repository,
|
||||
private EnvironmentService $environmentService,
|
||||
private ViewFactory $view
|
||||
) {
|
||||
|
|
|
@ -28,7 +28,6 @@ use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
|||
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
||||
use Pterodactyl\Services\Databases\DatabaseManagementService;
|
||||
use Illuminate\Contracts\Config\Repository as ConfigRepository;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
||||
|
@ -52,7 +51,6 @@ class ServersController extends Controller
|
|||
protected ServerDeletionService $deletionService,
|
||||
protected DetailsModificationService $detailsModificationService,
|
||||
protected ReinstallServerService $reinstallService,
|
||||
protected ServerRepositoryInterface $repository,
|
||||
protected MountRepository $mountRepository,
|
||||
protected NestRepositoryInterface $nestRepository,
|
||||
protected ServerConfigurationStructureService $serverConfigurationStructureService,
|
||||
|
@ -91,9 +89,8 @@ class ServersController extends Controller
|
|||
throw new DisplayException(trans('admin/server.exceptions.marked_as_failed'));
|
||||
}
|
||||
|
||||
$this->repository->update($server->id, [
|
||||
'status' => $server->isInstalled() ? Server::STATUS_INSTALLING : null,
|
||||
], true, true);
|
||||
$server->status = $server->isInstalled() ? Server::STATUS_INSTALLING : null;
|
||||
$server->save();
|
||||
|
||||
$this->alert->success(trans('admin/server.alerts.install_toggled'))->flash();
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ use Illuminate\Http\JsonResponse;
|
|||
use Pterodactyl\Facades\Activity;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Transformers\Api\Client\AllocationTransformer;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Services\Allocations\FindAssignableAllocationService;
|
||||
|
@ -22,10 +21,8 @@ class NetworkAllocationController extends ClientApiController
|
|||
/**
|
||||
* NetworkAllocationController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
private FindAssignableAllocationService $assignableAllocationService,
|
||||
private ServerRepository $serverRepository
|
||||
) {
|
||||
public function __construct(private FindAssignableAllocationService $assignableAllocationService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -72,7 +69,8 @@ class NetworkAllocationController extends ClientApiController
|
|||
*/
|
||||
public function setPrimary(SetPrimaryAllocationRequest $request, Server $server, Allocation $allocation): array
|
||||
{
|
||||
$this->serverRepository->update($server->id, ['allocation_id' => $allocation->id]);
|
||||
$server->allocation()->associate($allocation);
|
||||
$server->save();
|
||||
|
||||
Activity::event('server:allocation.primary')
|
||||
->subject($allocation)
|
||||
|
|
|
@ -6,7 +6,6 @@ use Illuminate\Http\Response;
|
|||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Facades\Activity;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Services\Servers\ReinstallServerService;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
@ -19,10 +18,8 @@ class SettingsController extends ClientApiController
|
|||
/**
|
||||
* SettingsController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
private ServerRepository $repository,
|
||||
private ReinstallServerService $reinstallServerService
|
||||
) {
|
||||
public function __construct(private ReinstallServerService $reinstallServerService)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -34,15 +31,12 @@ class SettingsController extends ClientApiController
|
|||
*/
|
||||
public function rename(RenameServerRequest $request, Server $server): JsonResponse
|
||||
{
|
||||
$this->repository->update($server->id, [
|
||||
'name' => $request->input('name'),
|
||||
]);
|
||||
$server->name = $request->input('name');
|
||||
$server->save();
|
||||
|
||||
if ($server->name !== $request->input('name')) {
|
||||
Activity::event('server:settings.rename')
|
||||
->property(['old' => $server->name, 'new' => $request->input('name')])
|
||||
->log();
|
||||
}
|
||||
Activity::event('server:settings.rename')
|
||||
->property(['old' => $server->name, 'new' => $request->input('name')])
|
||||
->log();
|
||||
|
||||
return new JsonResponse([], Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ use Pterodactyl\Facades\Activity;
|
|||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Services\Eggs\EggConfigurationService;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Http\Resources\Wings\ServerConfigurationCollection;
|
||||
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
||||
|
||||
|
@ -20,7 +19,6 @@ class ServerDetailsController extends Controller
|
|||
*/
|
||||
public function __construct(
|
||||
protected ConnectionInterface $connection,
|
||||
private ServerRepository $repository,
|
||||
private ServerConfigurationStructureService $configurationStructureService,
|
||||
private EggConfigurationService $eggConfigurationService
|
||||
) {
|
||||
|
@ -30,11 +28,10 @@ class ServerDetailsController extends Controller
|
|||
* Returns details about the server that allows Wings to self-recover and ensure
|
||||
* that the state of the server matches the Panel at all times.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function __invoke(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
$server = Server::findOrFailByUuid($uuid);
|
||||
|
||||
return new JsonResponse([
|
||||
'settings' => $this->configurationStructureService->handle($server),
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Pterodactyl\Events\Server\Installed as ServerInstalled;
|
||||
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
|
||||
use Pterodactyl\Http\Requests\Api\Remote\InstallationDataRequest;
|
||||
|
@ -18,18 +18,16 @@ class ServerInstallController extends Controller
|
|||
/**
|
||||
* ServerInstallController constructor.
|
||||
*/
|
||||
public function __construct(private ServerRepository $repository, private EventDispatcher $eventDispatcher)
|
||||
public function __construct(private EventDispatcher $eventDispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns installation information for a server.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function index(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
$server = Server::findOrFailByUuid($uuid);
|
||||
$egg = $server->egg;
|
||||
|
||||
return new JsonResponse([
|
||||
|
@ -42,23 +40,27 @@ class ServerInstallController extends Controller
|
|||
/**
|
||||
* Updates the installation state of a server.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function store(InstallationDataRequest $request, string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
$server = Server::findOrFailByUuid($uuid);
|
||||
|
||||
$status = $request->boolean('successful') ? null : Server::STATUS_INSTALL_FAILED;
|
||||
if ($server->status === Server::STATUS_SUSPENDED) {
|
||||
$status = Server::STATUS_SUSPENDED;
|
||||
}
|
||||
|
||||
$this->repository->update($server->id, ['status' => $status, 'installed_at' => CarbonImmutable::now()], true, true);
|
||||
$previouslyInstalledAt = $server->installed_at;
|
||||
|
||||
$server->status = $status;
|
||||
$server->installed_at = now();
|
||||
$server->save();
|
||||
|
||||
// If the server successfully installed, fire installed event.
|
||||
// This logic allows individually disabling install and reinstall notifications separately.
|
||||
$isInitialInstall = is_null($server->installed_at);
|
||||
$isInitialInstall = is_null($previouslyInstalledAt);
|
||||
if ($isInitialInstall && config()->get('pterodactyl.email.send_install_notification', true)) {
|
||||
$this->eventDispatcher->dispatch(new ServerInstalled($server));
|
||||
} elseif (!$isInitialInstall && config()->get('pterodactyl.email.send_reinstall_notification', true)) {
|
||||
|
|
|
@ -8,11 +8,11 @@ use Illuminate\Http\Response;
|
|||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\ServerTransfer;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Services\Nodes\NodeJWTService;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonTransferRepository;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
|
@ -24,7 +24,6 @@ class ServerTransferController extends Controller
|
|||
*/
|
||||
public function __construct(
|
||||
private ConnectionInterface $connection,
|
||||
private ServerRepository $repository,
|
||||
private DaemonServerRepository $daemonServerRepository,
|
||||
private DaemonTransferRepository $daemonTransferRepository,
|
||||
private NodeJWTService $jwtService
|
||||
|
@ -39,7 +38,7 @@ class ServerTransferController extends Controller
|
|||
*/
|
||||
public function archive(Request $request, string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
$server = Server::findOrFailByUuid($uuid);
|
||||
|
||||
// Unsuspend the server and don't continue the transfer.
|
||||
if (!$request->input('successful')) {
|
||||
|
@ -78,7 +77,7 @@ class ServerTransferController extends Controller
|
|||
*/
|
||||
public function failure(string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
$server = Server::findOrFailByUuid($uuid);
|
||||
|
||||
return $this->processFailedTransfer($server->transfer);
|
||||
}
|
||||
|
@ -90,7 +89,7 @@ class ServerTransferController extends Controller
|
|||
*/
|
||||
public function success(string $uuid): JsonResponse
|
||||
{
|
||||
$server = $this->repository->getByUuid($uuid);
|
||||
$server = Server::findOrFailByUuid($uuid);
|
||||
$transfer = $server->transfer;
|
||||
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
|
|
|
@ -5,17 +5,14 @@ namespace Pterodactyl\Http\Controllers\Base;
|
|||
use Illuminate\View\View;
|
||||
use Illuminate\View\Factory as ViewFactory;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
/**
|
||||
* IndexController constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected ServerRepositoryInterface $repository,
|
||||
protected ViewFactory $view
|
||||
) {
|
||||
public function __construct(protected ViewFactory $view)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -233,9 +233,9 @@ class Server extends Model
|
|||
/**
|
||||
* Gets the default allocation for a server.
|
||||
*/
|
||||
public function allocation(): HasOne
|
||||
public function allocation(): BelongsTo
|
||||
{
|
||||
return $this->hasOne(Allocation::class, 'id', 'allocation_id');
|
||||
return $this->belongsTo(Allocation::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -365,7 +365,7 @@ class Server extends Model
|
|||
/**
|
||||
* Checks if the server is currently in a transferable state. If not, an
|
||||
* exception is raised. This should be called whenever something needs to make
|
||||
* sure the server is able to be transferred and is not currently being transferred
|
||||
* sure the server can be transferred and is not currently being transferred
|
||||
* or installed.
|
||||
*/
|
||||
public function validateTransferState()
|
||||
|
@ -378,4 +378,15 @@ class Server extends Model
|
|||
throw new ServerStateConflictException($this);
|
||||
}
|
||||
}
|
||||
|
||||
public static function findOrFailByUuid(string $uuid): Server
|
||||
{
|
||||
/** @var Server $server */
|
||||
$server = Server::with(['nest', 'node'])
|
||||
->where('uuidShort', $uuid)
|
||||
->orWhere('uuid', $uuid)
|
||||
->firstOrFail();
|
||||
|
||||
return $server;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
|||
use Pterodactyl\Repositories\Eloquent\TaskRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\UserRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\SessionRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\SubuserRepository;
|
||||
use Pterodactyl\Repositories\Eloquent\DatabaseRepository;
|
||||
|
@ -25,7 +24,6 @@ use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
|||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
|
||||
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerVariableRepository;
|
||||
use Pterodactyl\Contracts\Repository\SessionRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
||||
|
@ -56,7 +54,6 @@ class RepositoryServiceProvider extends ServiceProvider
|
|||
$this->app->bind(NestRepositoryInterface::class, NestRepository::class);
|
||||
$this->app->bind(NodeRepositoryInterface::class, NodeRepository::class);
|
||||
$this->app->bind(ScheduleRepositoryInterface::class, ScheduleRepository::class);
|
||||
$this->app->bind(ServerRepositoryInterface::class, ServerRepository::class);
|
||||
$this->app->bind(ServerVariableRepositoryInterface::class, ServerVariableRepository::class);
|
||||
$this->app->bind(SessionRepositoryInterface::class, SessionRepository::class);
|
||||
$this->app->bind(SettingsRepositoryInterface::class, SettingsRepository::class);
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class ServerRepository extends EloquentRepository implements ServerRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*/
|
||||
public function model(): string
|
||||
{
|
||||
return Server::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a server by UUID.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getByUuid(string $uuid): Server
|
||||
{
|
||||
try {
|
||||
/** @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) {
|
||||
throw new RecordNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace Pterodactyl\Services\Eggs;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Egg\HasChildrenException;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class EggDeletionService
|
||||
{
|
||||
|
@ -13,7 +13,6 @@ class EggDeletionService
|
|||
* EggDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected EggRepositoryInterface $repository
|
||||
) {
|
||||
}
|
||||
|
@ -26,8 +25,7 @@ class EggDeletionService
|
|||
*/
|
||||
public function handle(int $egg): int
|
||||
{
|
||||
$servers = $this->serverRepository->findCountWhere([['egg_id', '=', $egg]]);
|
||||
if ($servers > 0) {
|
||||
if (Server::query()->where('egg_id', $egg)->count()) {
|
||||
throw new HasActiveServersException(trans('exceptions.nest.egg.delete_has_servers'));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Pterodactyl\Services\Nests;
|
||||
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class NestDeletionService
|
||||
{
|
||||
|
@ -12,7 +12,6 @@ class NestDeletionService
|
|||
* NestDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected NestRepositoryInterface $repository
|
||||
) {
|
||||
}
|
||||
|
@ -20,12 +19,11 @@ class NestDeletionService
|
|||
/**
|
||||
* Delete a nest from the system only if there are no servers attached to it.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
* @throws HasActiveServersException
|
||||
*/
|
||||
public function handle(int $nest): int
|
||||
{
|
||||
$count = $this->serverRepository->findCountWhere([['nest_id', '=', $nest]]);
|
||||
if ($count > 0) {
|
||||
if (Server::query()->where('nest_id', $nest)->count() > 0) {
|
||||
throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers'));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ use Pterodactyl\Models\Node;
|
|||
use Illuminate\Contracts\Translation\Translator;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class NodeDeletionService
|
||||
{
|
||||
|
@ -15,7 +14,6 @@ class NodeDeletionService
|
|||
*/
|
||||
public function __construct(
|
||||
protected NodeRepositoryInterface $repository,
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected Translator $translator
|
||||
) {
|
||||
}
|
||||
|
@ -23,16 +21,15 @@ class NodeDeletionService
|
|||
/**
|
||||
* Delete a node from the panel if no servers are attached to it.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
||||
* @throws HasActiveServersException
|
||||
*/
|
||||
public function handle(int|Node $node): int
|
||||
{
|
||||
if ($node instanceof Node) {
|
||||
$node = $node->id;
|
||||
if (is_int($node)) {
|
||||
$node = Node::query()->findOrFail($node);
|
||||
}
|
||||
|
||||
$servers = $this->serverRepository->setColumns('id')->findCountWhere([['node_id', '=', $node]]);
|
||||
if ($servers > 0) {
|
||||
if ($node->servers()->count() > 0) {
|
||||
throw new HasActiveServersException($this->translator->get('exceptions.node.servers_attached'));
|
||||
}
|
||||
|
||||
|
|
|
@ -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\ServerRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
use Pterodactyl\Services\Deployment\FindViableNodesService;
|
||||
use Pterodactyl\Repositories\Eloquent\ServerVariableRepository;
|
||||
|
@ -29,7 +28,6 @@ class ServerCreationService
|
|||
private ConnectionInterface $connection,
|
||||
private DaemonServerRepository $daemonServerRepository,
|
||||
private FindViableNodesService $findViableNodesService,
|
||||
private ServerRepository $repository,
|
||||
private ServerDeletionService $serverDeletionService,
|
||||
private ServerVariableRepository $serverVariableRepository,
|
||||
private VariableValidatorService $validatorService
|
||||
|
@ -82,7 +80,7 @@ class ServerCreationService
|
|||
//
|
||||
// If that connection fails out we will attempt to perform a cleanup by just
|
||||
// deleting the server itself from the system.
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
/** @var Server $server */
|
||||
$server = $this->connection->transaction(function () use ($data, $eggVariableData) {
|
||||
// Create the server and assign any additional allocations to it.
|
||||
$server = $this->createModel($data);
|
||||
|
@ -136,8 +134,8 @@ class ServerCreationService
|
|||
{
|
||||
$uuid = $this->generateUniqueUuidCombo();
|
||||
|
||||
/** @var \Pterodactyl\Models\Server $model */
|
||||
$model = $this->repository->create([
|
||||
/** @var Server $model */
|
||||
$model = Server::create([
|
||||
'external_id' => Arr::get($data, 'external_id'),
|
||||
'uuid' => $uuid,
|
||||
'uuidShort' => substr($uuid, 0, 8),
|
||||
|
|
|
@ -6,7 +6,6 @@ use Pterodactyl\Models\User;
|
|||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Illuminate\Contracts\Translation\Translator;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
|
||||
class UserDeletionService
|
||||
{
|
||||
|
@ -15,7 +14,6 @@ class UserDeletionService
|
|||
*/
|
||||
public function __construct(
|
||||
protected UserRepositoryInterface $repository,
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected Translator $translator
|
||||
) {
|
||||
}
|
||||
|
@ -23,16 +21,15 @@ class UserDeletionService
|
|||
/**
|
||||
* Delete a user from the panel only if they have no servers attached to their account.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws DisplayException
|
||||
*/
|
||||
public function handle(int|User $user): ?bool
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$user = $user->id;
|
||||
if (is_int($user)) {
|
||||
$user = User::query()->findOrFail($user);
|
||||
}
|
||||
|
||||
$servers = $this->serverRepository->setColumns('id')->findCountWhere([['owner_id', '=', $user]]);
|
||||
if ($servers > 0) {
|
||||
if ($user->servers()->count() > 0) {
|
||||
throw new DisplayException($this->translator->get('admin/user.exceptions.user_has_servers'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue