mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 06:24:44 +02:00

* update composer.lock * run pint * fix phpstan * update migrations (sqlite `dropForeign`) * fix migrations * Reset these back for now * Alphabetize the rules * run `php artisan filament:upgrade` --------- Co-authored-by: Lance Pioch <git@lance.sh>
36 lines
815 B
PHP
36 lines
815 B
PHP
<?php
|
|
|
|
namespace App\Services\Nodes;
|
|
|
|
use App\Models\Node;
|
|
use Illuminate\Contracts\Translation\Translator;
|
|
use App\Exceptions\Service\HasActiveServersException;
|
|
|
|
class NodeDeletionService
|
|
{
|
|
/**
|
|
* NodeDeletionService constructor.
|
|
*/
|
|
public function __construct(
|
|
protected Translator $translator
|
|
) {}
|
|
|
|
/**
|
|
* Delete a node from the panel if no servers are attached to it.
|
|
*
|
|
* @throws HasActiveServersException
|
|
*/
|
|
public function handle(int|Node $node): int
|
|
{
|
|
if (is_int($node)) {
|
|
$node = Node::findOrFail($node);
|
|
}
|
|
|
|
if ($node->servers()->count() > 0) {
|
|
throw new HasActiveServersException($this->translator->get('exceptions.node.servers_attached'));
|
|
}
|
|
|
|
return (int) $node->delete();
|
|
}
|
|
}
|