2017-09-16 03:13:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console\Commands\Location;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2022-10-23 08:25:49 +00:00
|
|
|
use Pterodactyl\Models\Location;
|
2017-09-16 03:13:33 +00:00
|
|
|
use Pterodactyl\Services\Locations\LocationDeletionService;
|
|
|
|
|
|
|
|
class DeleteLocationCommand extends Command
|
|
|
|
{
|
2017-09-21 05:16:01 +00:00
|
|
|
protected $description = 'Deletes a location from the Panel.';
|
|
|
|
|
2017-09-16 22:39:52 +00:00
|
|
|
protected $signature = 'p:location:delete {--short= : The short code of the location to delete.}';
|
2017-09-16 03:13:33 +00:00
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
protected Collection $locations;
|
|
|
|
|
2017-09-16 03:13:33 +00:00
|
|
|
/**
|
|
|
|
* DeleteLocationCommand constructor.
|
|
|
|
*/
|
2022-10-23 08:25:49 +00:00
|
|
|
public function __construct(private LocationDeletionService $deletionService)
|
|
|
|
{
|
2017-09-16 03:13:33 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to the command request.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-10-23 08:25:49 +00:00
|
|
|
$this->locations = $this->locations ?? Location::all();
|
2017-09-16 03:13:33 +00:00
|
|
|
$short = $this->option('short') ?? $this->anticipate(
|
2021-01-23 20:33:34 +00:00
|
|
|
trans('command/messages.location.ask_short'),
|
|
|
|
$this->locations->pluck('short')->toArray()
|
|
|
|
);
|
2017-09-16 03:13:33 +00:00
|
|
|
|
|
|
|
$location = $this->locations->where('short', $short)->first();
|
|
|
|
if (is_null($location)) {
|
|
|
|
$this->error(trans('command/messages.location.no_location_found'));
|
2017-09-16 22:39:52 +00:00
|
|
|
if ($this->input->isInteractive()) {
|
2017-09-16 03:13:33 +00:00
|
|
|
$this->handle();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->deletionService->handle($location->id);
|
2017-09-16 22:39:52 +00:00
|
|
|
$this->line(trans('command/messages.location.deleted'));
|
2017-09-16 03:13:33 +00:00
|
|
|
}
|
|
|
|
}
|