2017-08-16 03:21:47 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-08-16 03:21:47 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
namespace Pterodactyl\Services\Nests;
|
2017-08-16 03:21:47 +00:00
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
|
2017-08-19 03:19:06 +00:00
|
|
|
use Pterodactyl\Exceptions\Service\HasActiveServersException;
|
2017-08-16 03:21:47 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
class NestDeletionService
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $serverRepository;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\NestRepositoryInterface
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* NestDeletionService constructor.
|
2017-08-16 03:21:47 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $serverRepository
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\NestRepositoryInterface $repository
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
ServerRepositoryInterface $serverRepository,
|
2017-10-07 04:57:53 +00:00
|
|
|
NestRepositoryInterface $repository
|
2017-08-16 03:21:47 +00:00
|
|
|
) {
|
|
|
|
$this->serverRepository = $serverRepository;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 04:57:53 +00:00
|
|
|
* Delete a nest from the system only if there are no servers attached to it.
|
2017-08-16 03:21:47 +00:00
|
|
|
*
|
2017-10-07 04:57:53 +00:00
|
|
|
* @param int $nest
|
2017-08-16 03:21:47 +00:00
|
|
|
* @return int
|
|
|
|
*
|
2017-08-19 03:19:06 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\HasActiveServersException
|
2017-08-16 03:21:47 +00:00
|
|
|
*/
|
2017-10-07 04:57:53 +00:00
|
|
|
public function handle(int $nest): int
|
2017-08-16 03:21:47 +00:00
|
|
|
{
|
2017-10-07 04:57:53 +00:00
|
|
|
$count = $this->serverRepository->findCountWhere([['nest_id', '=', $nest]]);
|
2017-08-16 03:21:47 +00:00
|
|
|
if ($count > 0) {
|
2019-10-04 05:14:47 +00:00
|
|
|
throw new HasActiveServersException(trans('exceptions.nest.delete_has_servers'));
|
2017-08-16 03:21:47 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 04:57:53 +00:00
|
|
|
return $this->repository->delete($nest);
|
2017-08-16 03:21:47 +00:00
|
|
|
}
|
|
|
|
}
|