Remove ServerRepository and ServerRepositoryInterface
This commit is contained in:
parent
22d560de64
commit
4d7ea155b1
19 changed files with 63 additions and 146 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue