2017-10-19 03:32:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Databases\Hosts;
|
|
|
|
|
|
|
|
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
2022-10-24 04:19:14 +00:00
|
|
|
use Pterodactyl\Models\DatabaseHost;
|
2017-10-19 03:32:19 +00:00
|
|
|
|
|
|
|
class HostDeletionService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Delete a specified host from the Panel if no databases are
|
|
|
|
* attached to it.
|
|
|
|
*
|
2022-10-24 04:19:14 +00:00
|
|
|
* @throws HasActiveServersException
|
2017-10-19 03:32:19 +00:00
|
|
|
*/
|
|
|
|
public function handle(int $host): int
|
|
|
|
{
|
2022-10-24 04:19:14 +00:00
|
|
|
/** @var DatabaseHost $host */
|
|
|
|
$host = DatabaseHost::query()->findOrFail($host);
|
|
|
|
|
|
|
|
if ($host->databases()->count() > 0) {
|
2017-10-19 03:32:19 +00:00
|
|
|
throw new HasActiveServersException(trans('exceptions.databases.delete_has_databases'));
|
|
|
|
}
|
|
|
|
|
2022-10-24 04:19:14 +00:00
|
|
|
return $host->delete();
|
2017-10-19 03:32:19 +00:00
|
|
|
}
|
|
|
|
}
|