Path: blob/1.0-develop/app/Console/Commands/User/DeleteUserCommand.php
7461 views
<?php12namespace Pterodactyl\Console\Commands\User;34use Pterodactyl\Models\User;5use Webmozart\Assert\Assert;6use Illuminate\Console\Command;7use Pterodactyl\Services\Users\UserDeletionService;89class DeleteUserCommand extends Command10{11protected $description = 'Deletes a user from the Panel if no servers are attached to their account.';1213protected $signature = 'p:user:delete {--user=}';1415/**16* DeleteUserCommand constructor.17*/18public function __construct(private UserDeletionService $deletionService)19{20parent::__construct();21}2223public function handle(): int24{25$search = $this->option('user') ?? $this->ask(trans('command/messages.user.search_users'));26Assert::notEmpty($search, 'Search term should be an email address, got: %s.');2728$results = User::query()29->where('id', 'LIKE', "$search%")30->orWhere('username', 'LIKE', "$search%")31->orWhere('email', 'LIKE', "$search%")32->get();3334if (count($results) < 1) {35$this->error(trans('command/messages.user.no_users_found'));36if ($this->input->isInteractive()) {37return $this->handle();38}3940return 1;41}4243if ($this->input->isInteractive()) {44$tableValues = [];45foreach ($results as $user) {46$tableValues[] = [$user->id, $user->email, $user->name];47}4849$this->table(['User ID', 'Email', 'Name'], $tableValues);50if (!$deleteUser = $this->ask(trans('command/messages.user.select_search_user'))) {51return $this->handle();52}53} else {54if (count($results) > 1) {55$this->error(trans('command/messages.user.multiple_found'));5657return 1;58}5960$deleteUser = $results->first();61}6263if ($this->confirm(trans('command/messages.user.confirm_delete')) || !$this->input->isInteractive()) {64$this->deletionService->handle($deleteUser);65$this->info(trans('command/messages.user.deleted'));66}6768return 0;69}70}717273