Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Console/Commands/Location/DeleteLocationCommand.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Console\Commands\Location;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Collection;
7
use Pterodactyl\Services\Locations\LocationDeletionService;
8
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
9
10
class DeleteLocationCommand extends Command
11
{
12
protected $description = 'Deletes a location from the Panel.';
13
14
protected $signature = 'p:location:delete {--short= : The short code of the location to delete.}';
15
16
protected Collection $locations;
17
18
/**
19
* DeleteLocationCommand constructor.
20
*/
21
public function __construct(
22
private LocationDeletionService $deletionService,
23
private LocationRepositoryInterface $repository,
24
) {
25
parent::__construct();
26
}
27
28
/**
29
* Respond to the command request.
30
*
31
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
32
* @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException
33
*/
34
public function handle()
35
{
36
$this->locations = $this->locations ?? $this->repository->all();
37
$short = $this->option('short') ?? $this->anticipate(
38
trans('command/messages.location.ask_short'),
39
$this->locations->pluck('short')->toArray()
40
);
41
42
$location = $this->locations->where('short', $short)->first();
43
if (is_null($location)) {
44
$this->error(trans('command/messages.location.no_location_found'));
45
if ($this->input->isInteractive()) {
46
$this->handle();
47
}
48
49
return;
50
}
51
52
$this->deletionService->handle($location->id);
53
$this->line(trans('command/messages.location.deleted'));
54
}
55
}
56
57