Replace database repository

This commit is contained in:
Lance Pioch 2022-10-24 00:19:14 -04:00
parent e49ba65709
commit 483c081d7f
9 changed files with 102 additions and 248 deletions

View file

@ -3,33 +3,25 @@
namespace Pterodactyl\Services\Databases\Hosts;
use Pterodactyl\Exceptions\Service\HasActiveServersException;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
use Pterodactyl\Models\DatabaseHost;
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
* @throws HasActiveServersException
*/
public function handle(int $host): int
{
$count = $this->databaseRepository->findCountWhere([['database_host_id', '=', $host]]);
if ($count > 0) {
/** @var DatabaseHost $host */
$host = DatabaseHost::query()->findOrFail($host);
if ($host->databases()->count() > 0) {
throw new HasActiveServersException(trans('exceptions.databases.delete_has_databases'));
}
return $this->repository->delete($host);
return $host->delete();
}
}