Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Databases/Hosts/HostDeletionService.php
10263 views
1
<?php
2
3
namespace Pterodactyl\Services\Databases\Hosts;
4
5
use Pterodactyl\Exceptions\Service\HasActiveServersException;
6
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
7
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
8
9
class HostDeletionService
10
{
11
/**
12
* HostDeletionService constructor.
13
*/
14
public function __construct(
15
private DatabaseRepositoryInterface $databaseRepository,
16
private DatabaseHostRepositoryInterface $repository,
17
) {
18
}
19
20
/**
21
* Delete a specified host from the Panel if no databases are
22
* attached to it.
23
*
24
* @throws HasActiveServersException
25
*/
26
public function handle(int $host): int
27
{
28
$count = $this->databaseRepository->findCountWhere([['database_host_id', '=', $host]]);
29
if ($count > 0) {
30
throw new HasActiveServersException(trans('exceptions.databases.delete_has_databases'));
31
}
32
33
return $this->repository->delete($host);
34
}
35
}
36
37