Add location control through API

This commit is contained in:
Dane Everitt 2018-01-03 21:14:53 -06:00
parent 15289b76a7
commit f32cee3ae5
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 176 additions and 19 deletions

View file

@ -10,6 +10,7 @@
namespace Pterodactyl\Services\Locations;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Location;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
@ -43,15 +44,16 @@ class LocationDeletionService
/**
* Delete an existing location.
*
* @param int $location
* @param int|\Pterodactyl\Models\Location $location
* @return int|null
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
*/
public function handle($location)
{
Assert::integerish($location, 'First argument passed to handle must be numeric, received %s.');
$location = ($location instanceof Location) ? $location->id : $location;
Assert::integerish($location, 'First argument passed to handle must be numeric or an instance of ' . Location::class . ', received %s.');
$count = $this->nodeRepository->findCountWhere([['location_id', '=', $location]]);
if ($count > 0) {