545a776aeb
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
59 lines
2.1 KiB
PHP
59 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXC\Console\Tenant;
|
|
|
|
use KTXC\SystemStore\SystemStoreConfigurationService;
|
|
use Psr\Log\LoggerInterface;
|
|
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\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
#[AsCommand(name: 'tenant:store:remove', description: 'Remove a logical store from a tenant')]
|
|
class TenantStoreRemoveCommand extends Command
|
|
{
|
|
public function __construct(
|
|
private readonly SystemStoreConfigurationService $stores,
|
|
private readonly LoggerInterface $logger,
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this
|
|
->addArgument('tenant', InputArgument::REQUIRED, 'Tenant identifier')
|
|
->addArgument('name', InputArgument::REQUIRED, 'Logical store name');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$tenant = (string) $input->getArgument('tenant');
|
|
$name = (string) $input->getArgument('name');
|
|
|
|
try {
|
|
if (!$this->stores->remove($tenant, $name)) {
|
|
$io->warning("Logical store '{$name}' was not configured for tenant '{$tenant}'.");
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
$this->logger->info('Tenant logical store removed via console', compact('tenant', 'name'));
|
|
$io->success("Logical store '{$name}' removed from tenant '{$tenant}'.");
|
|
return Command::SUCCESS;
|
|
} catch (\Throwable $error) {
|
|
$this->logger->error('Tenant logical store removal failed', [
|
|
'tenant' => $tenant,
|
|
'name' => $name,
|
|
'error' => $error->getMessage(),
|
|
]);
|
|
$io->error('Failed to remove tenant store: ' . $error->getMessage());
|
|
return Command::FAILURE;
|
|
}
|
|
}
|
|
}
|