Add database management back to front-end and begin some refactoring
Here we go again boys...
This commit is contained in:
parent
2b80de03df
commit
97dc0519d6
32 changed files with 774 additions and 407 deletions
53
app/Services/Databases/Hosts/HostDeletionService.php
Normal file
53
app/Services/Databases/Hosts/HostDeletionService.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Databases\Hosts;
|
||||
|
||||
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface;
|
||||
|
||||
class HostDeletionService
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
|
||||
*/
|
||||
private $databaseRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* HostDeletionService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\DatabaseHostRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(
|
||||
DatabaseRepositoryInterface $databaseRepository,
|
||||
DatabaseHostRepositoryInterface $repository
|
||||
) {
|
||||
$this->databaseRepository = $databaseRepository;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specified host from the Panel if no databases are
|
||||
* attached to it.
|
||||
*
|
||||
* @param int $host
|
||||
* @return int
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
Reference in a new issue