Replace database repository
This commit is contained in:
parent
e49ba65709
commit
483c081d7f
9 changed files with 102 additions and 248 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue