2017-01-13 23:16:57 -05:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-09-15 22:13:33 -05:00
|
|
|
namespace Pterodactyl\Console\Commands\Location;
|
2017-01-13 23:16:57 -05:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Console\Attributes\Description;
|
|
|
|
|
use Illuminate\Console\Attributes\Signature;
|
2017-01-13 23:16:57 -05:00
|
|
|
use Illuminate\Console\Command;
|
2026-10-11 06:17:07 -04:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Contracts\Locations\CreatesLocations;
|
2017-01-13 23:16:57 -05:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Description('Creates a new location on the system via the CLI.')]
|
|
|
|
|
#[Signature('p:location:make
|
|
|
|
|
{--short= : The shortcode name of this location (ex. us1).}
|
|
|
|
|
{--long= : A longer description of this location.}')]
|
2017-09-15 22:13:33 -05:00
|
|
|
class MakeLocationCommand extends Command
|
2017-01-13 23:16:57 -05:00
|
|
|
{
|
|
|
|
|
/**
|
2017-09-15 22:13:33 -05:00
|
|
|
* Handle the command execution process.
|
2017-01-13 23:16:57 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function handle(CreatesLocations $locations): int
|
2017-01-13 23:16:57 -05:00
|
|
|
{
|
2026-10-11 20:11:13 -04:00
|
|
|
$input = [
|
2026-10-11 16:30:09 -04:00
|
|
|
'short' => $this->option('short') ?? $this->ask(trans('command/messages.location.ask_short')),
|
|
|
|
|
'long' => $this->option('long') ?? $this->ask(trans('command/messages.location.ask_long')),
|
2026-10-11 20:11:13 -04:00
|
|
|
];
|
2017-01-13 23:16:57 -05:00
|
|
|
|
2026-10-11 06:17:07 -04:00
|
|
|
try {
|
2026-10-11 20:11:13 -04:00
|
|
|
$location = $locations->create($input);
|
2026-10-11 06:17:07 -04:00
|
|
|
} catch (ValidationException $validationException) {
|
|
|
|
|
foreach ($validationException->validator->errors()->all() as $error) {
|
2026-10-05 18:10:18 -04:00
|
|
|
$this->error($error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 22:13:33 -05:00
|
|
|
$this->line(trans('command/messages.location.created', [
|
|
|
|
|
'name' => $location->short,
|
|
|
|
|
'id' => $location->id,
|
|
|
|
|
]));
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
return 0;
|
2017-01-13 23:16:57 -05:00
|
|
|
}
|
|
|
|
|
}
|