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;
|
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
|
|
|
*/
|
2022-10-24 02:17:24 +00:00
|
|
|
public function __construct(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-24 02:17:24 +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-24 02:17:24 +00:00
|
|
|
if (is_int($node)) {
|
|
|
|
$node = Node::query()->findOrFail($node);
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 02:17:24 +00:00
|
|
|
$servers = $node->servers()->count();
|
2017-08-05 22:20:07 +00:00
|
|
|
if ($servers > 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
|
|
|
}
|
|
|
|
|
2022-10-24 02:17:24 +00:00
|
|
|
return $node->delete();
|
2017-08-05 22:20:07 +00:00
|
|
|
}
|
|
|
|
}
|