misc_pterodactyl-panel/app/Services/Databases/Hosts/HostDeletionService.php

28 lines
683 B
PHP
Raw Normal View History

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