mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-28 10:24:45 +02:00
34 lines
951 B
PHP
34 lines
951 B
PHP
<?php
|
|
|
|
namespace App\Services\Eggs;
|
|
|
|
use App\Exceptions\Service\Egg\HasChildrenException;
|
|
use App\Exceptions\Service\HasActiveServersException;
|
|
use App\Models\Egg;
|
|
use App\Models\Server;
|
|
|
|
class EggDeletionService
|
|
{
|
|
/**
|
|
* Delete an Egg from the database if it has no active servers attached to it.
|
|
*
|
|
* @throws \App\Exceptions\Service\HasActiveServersException
|
|
* @throws \App\Exceptions\Service\Egg\HasChildrenException
|
|
*/
|
|
public function handle(int $egg): int
|
|
{
|
|
if (Server::query()->where('egg_id', $egg)->count()) {
|
|
throw new HasActiveServersException(trans('exceptions.egg.delete_has_servers'));
|
|
}
|
|
|
|
$children = Egg::query()->where('config_from', $egg)->count();
|
|
if ($children > 0) {
|
|
throw new HasChildrenException(trans('exceptions.egg.has_children'));
|
|
}
|
|
|
|
$egg = Egg::query()->findOrFail($egg);
|
|
|
|
return (int) $egg->delete();
|
|
}
|
|
}
|