misc_pterodactyl-panel/app/Services/Databases/Hosts/HostDeletionService.php
2022-10-24 00:19:14 -04:00

27 lines
683 B
PHP

<?php
namespace Pterodactyl\Services\Databases\Hosts;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Models\DatabaseHost;
class HostDeletionService
{
/**
* Delete a specified host from the Panel if no databases are
* attached to it.
*
* @throws HasActiveServersException
*/
public function handle(int $host): int
{
/** @var DatabaseHost $host */
$host = DatabaseHost::query()->findOrFail($host);
if ($host->databases()->count() > 0) {
throw new HasActiveServersException(trans('exceptions.databases.delete_has_databases'));
}
return $host->delete();
}
}