| Current Path : /proc/3751963/cwd/public_html/pano.4uweb.ca/src/CliCommand/ |
| Current File : //proc/3751963/cwd/public_html/pano.4uweb.ca/src/CliCommand/UserDelete.php |
<?php
/**
* @package panopticon
* @copyright Copyright (c)2023-2024 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license https://www.gnu.org/licenses/agpl-3.0.txt GNU Affero General Public License, version 3 or later
*/
namespace Akeeba\Panopticon\CliCommand;
defined('AKEEBA') || die;
use Akeeba\Panopticon\CliCommand\Attribute\ConfigAssertion;
use Akeeba\Panopticon\CliCommand\Trait\PrintFormattedArrayTrait;
use Akeeba\Panopticon\Factory;
use Akeeba\Panopticon\Model\Users;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'user:delete',
description: 'Delete a user',
hidden: false,
)]
#[ConfigAssertion(true)]
class UserDelete extends AbstractCommand
{
use PrintFormattedArrayTrait;
protected function execute(InputInterface $input, OutputInterface $output): int
{
$container = Factory::getContainer();
/** @var Users $model */
$model = $container->mvcFactory->makeTempModel('Users');
$id = intval($input->getArgument('id'));
try
{
$model
->findOrFail($id)
->delete();
}
catch (\Exception $e)
{
$this->ioStyle->error([
sprintf('Could not delete user %d', $id),
$e->getMessage()
]);
return Command::FAILURE;
}
return Command::SUCCESS;
}
protected function configure(): void
{
$this
->addArgument('id', InputArgument::REQUIRED, 'The numeric user ID to delete');
}
}