Replace node repository
This commit is contained in:
parent
7266c66ebf
commit
aeb7590a6d
14 changed files with 101 additions and 250 deletions
|
@ -2,39 +2,26 @@
|
|||
|
||||
namespace Pterodactyl\Services\Locations;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
|
||||
|
||||
class LocationDeletionService
|
||||
{
|
||||
/**
|
||||
* LocationDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected LocationRepositoryInterface $repository,
|
||||
protected NodeRepositoryInterface $nodeRepository
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing location.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
|
||||
* @throws HasActiveNodesException
|
||||
*/
|
||||
public function handle(Location|int $location): ?int
|
||||
{
|
||||
$location = ($location instanceof Location) ? $location->id : $location;
|
||||
/** @var Location $location */
|
||||
$location = ($location instanceof Location) ? $location : Location::query()->findOrFail($location);
|
||||
|
||||
Assert::integerish($location, 'First argument passed to handle must be numeric or an instance of ' . Location::class . ', received %s.');
|
||||
|
||||
$count = $this->nodeRepository->findCountWhere([['location_id', '=', $location]]);
|
||||
$count = $location->nodes()->count();
|
||||
if ($count > 0) {
|
||||
throw new HasActiveNodesException(trans('exceptions.locations.has_nodes'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($location);
|
||||
return $location->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,21 +6,19 @@ use Ramsey\Uuid\Uuid;
|
|||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
|
||||
class NodeCreationService
|
||||
{
|
||||
/**
|
||||
* NodeCreationService constructor.
|
||||
*/
|
||||
public function __construct(private Encrypter $encrypter, protected NodeRepositoryInterface $repository)
|
||||
public function __construct(private Encrypter $encrypter)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new node on the panel.
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle(array $data): Node
|
||||
{
|
||||
|
@ -28,6 +26,9 @@ class NodeCreationService
|
|||
$data['daemon_token'] = $this->encrypter->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
|
||||
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
|
||||
|
||||
return $this->repository->create($data, true, true);
|
||||
/** @var Node $node */
|
||||
$node = Node::query()->create($data);
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,38 +4,33 @@ namespace Pterodactyl\Services\Nodes;
|
|||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* NodeDeletionService constructor.
|
||||
*/
|
||||
public function __construct(
|
||||
protected NodeRepositoryInterface $repository,
|
||||
protected ServerRepositoryInterface $serverRepository,
|
||||
protected Translator $translator
|
||||
) {
|
||||
public function __construct(protected Translator $translator)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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]]);
|
||||
$servers = $node->servers()->count();
|
||||
if ($servers > 0) {
|
||||
throw new HasActiveServersException($this->translator->get('exceptions.node.servers_attached'));
|
||||
}
|
||||
|
||||
return $this->repository->delete($node);
|
||||
return $node->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ use Pterodactyl\Models\Node;
|
|||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Pterodactyl\Repositories\Eloquent\NodeRepository;
|
||||
use Pterodactyl\Repositories\Wings\DaemonConfigurationRepository;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use Pterodactyl\Exceptions\Service\Node\ConfigurationNotPersistedException;
|
||||
|
@ -20,8 +19,7 @@ class NodeUpdateService
|
|||
public function __construct(
|
||||
private ConnectionInterface $connection,
|
||||
private DaemonConfigurationRepository $configurationRepository,
|
||||
private Encrypter $encrypter,
|
||||
private NodeRepository $repository
|
||||
private Encrypter $encrypter
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -39,7 +37,7 @@ class NodeUpdateService
|
|||
|
||||
[$updated, $exception] = $this->connection->transaction(function () use ($data, $node) {
|
||||
/** @var \Pterodactyl\Models\Node $updated */
|
||||
$updated = $this->repository->withFreshModel()->update($node->id, $data, true, true);
|
||||
$updated = (clone $node)->update($data);
|
||||
|
||||
try {
|
||||
// If we're changing the FQDN for the node, use the newly provided FQDN for the connection
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue