misc_pterodactyl-panel/app/Services/Nodes/NodeDeletionService.php

37 lines
866 B
PHP
Raw Normal View History

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