2017-08-05 22:20:07 +00:00
|
|
|
<?php
|
2022-01-15 16:10:37 +00:00
|
|
|
|
2017-08-05 22:20:07 +00:00
|
|
|
namespace Pterodactyl\Services\Nodes;
|
|
|
|
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Models\Node;
|
2017-08-05 22:20:07 +00:00
|
|
|
use Illuminate\Contracts\Translation\Translator;
|
|
|
|
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
2017-08-27 19:55:25 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
2017-08-05 22:20:07 +00:00
|
|
|
|
2017-08-27 20:10:51 +00:00
|
|
|
class NodeDeletionService
|
2017-08-05 22:20:07 +00:00
|
|
|
{
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* NodeDeletionService constructor.
|
2017-08-05 22:20:07 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2022-10-14 16:59:20 +00:00
|
|
|
protected NodeRepositoryInterface $repository,
|
|
|
|
protected Translator $translator
|
2017-08-05 22:20:07 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a node from the panel if no servers are attached to it.
|
|
|
|
*
|
2022-10-21 01:17:03 +00:00
|
|
|
* @throws HasActiveServersException
|
2017-08-05 22:20:07 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function handle(int|Node $node): int
|
2017-08-05 22:20:07 +00:00
|
|
|
{
|
2022-10-21 01:17:03 +00:00
|
|
|
if (is_int($node)) {
|
|
|
|
$node = Node::query()->findOrFail($node);
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-21 01:17:03 +00:00
|
|
|
if ($node->servers()->count() > 0) {
|
2022-01-15 16:10:37 +00:00
|
|
|
throw new HasActiveServersException($this->translator->get('exceptions.node.servers_attached'));
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->repository->delete($node);
|
|
|
|
}
|
|
|
|
}
|