Files

49 lines
1.5 KiB
PHP
Raw Permalink Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Console\Commands\Location;
2026-10-05 18:10:18 -04:00
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
2026-10-05 18:10:18 -04:00
use Illuminate\Database\Eloquent\Collection;
use Pterodactyl\Contracts\Locations\DeletesLocations;
use Pterodactyl\Exceptions\Service\Location\HasActiveNodesException;
use Pterodactyl\Models\Location;
2026-10-05 18:10:18 -04:00
#[Description('Deletes a location from the Panel.')]
#[Signature('p:location:delete {--short= : The short code of the location to delete.}')]
class DeleteLocationCommand extends Command
{
2026-10-05 18:10:18 -04:00
/** @var Collection<int, Location> */
protected Collection $allLocations;
/**
* Respond to the command request.
*
2026-10-05 18:10:18 -04:00
* @throws HasActiveNodesException
*/
2026-10-05 18:10:18 -04:00
public function handle(DeletesLocations $locations): void
{
2026-10-05 18:10:18 -04:00
$this->allLocations ??= Location::all();
$short = $this->option('short') ?? $this->anticipate(
2021-01-23 12:33:34 -08:00
trans('command/messages.location.ask_short'),
2026-10-05 18:10:18 -04:00
$this->allLocations->pluck('short')->toArray()
2021-01-23 12:33:34 -08:00
);
2026-10-05 18:10:18 -04:00
$location = $this->allLocations->where('short', $short)->first();
if ($location === null) {
$this->error(trans('command/messages.location.no_location_found'));
2017-09-16 17:39:52 -05:00
if ($this->input->isInteractive()) {
2026-10-05 18:10:18 -04:00
$this->handle($locations);
}
return;
}
2026-10-05 18:10:18 -04:00
$locations->delete($location);
2017-09-16 17:39:52 -05:00
$this->line(trans('command/messages.location.deleted'));
}
}