misc_pterodactyl-panel/app/Services/Databases/Hosts/HostDeletionService.php
Matthew Penner cbcf62086f
Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
2022-10-14 10:59:20 -06:00

35 lines
1 KiB
PHP

<?php
namespace Pterodactyl\Services\Databases\Hosts;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
class HostDeletionService
{
/**
* HostDeletionService constructor.
*/
public function __construct(
private DatabaseRepositoryInterface $databaseRepository,
private DatabaseHostRepositoryInterface $repository
) {
}
/**
* Delete a specified host from the Panel if no databases are
* attached to it.
*
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
*/
public function handle(int $host): int
{
$count = $this->databaseRepository->findCountWhere([['database_host_id', '=', $host]]);
if ($count > 0) {
throw new HasActiveServersException(trans('exceptions.databases.delete_has_databases'));
}
return $this->repository->delete($host);
}
}