64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Command;
|
|
|
|
use App\Service\DatabaseAnonymizer;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
#[AsCommand(
|
|
name: 'app:db:anonymize',
|
|
description: 'Anonymize personal data in the local database',
|
|
)]
|
|
final class DbAnonymizeCommand extends Command
|
|
{
|
|
public function __construct(
|
|
private readonly DatabaseAnonymizer $databaseAnonymizer,
|
|
private readonly LoggerInterface $logger,
|
|
private readonly string $environment,
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
|
|
if ('prod' === $this->environment) {
|
|
$io->error('The database anonymizer is disabled in the prod environment.');
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
try {
|
|
$report = $this->databaseAnonymizer->anonymizeAll();
|
|
} catch (\Throwable $exception) {
|
|
$this->logger->error('Database anonymization failed', [
|
|
'environment' => $this->environment,
|
|
'error' => $exception->getMessage(),
|
|
]);
|
|
|
|
$io->error($exception->getMessage());
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$io->success(sprintf(
|
|
'Anonymized %d users, %d newsletter consents, %d newsletter opt-in requests, %d booking drafts, and %d accommodation bookings.',
|
|
$report['users'],
|
|
$report['newsletterConsents'],
|
|
$report['newsletterOptInRequests'],
|
|
$report['bookingEditDrafts'],
|
|
$report['accommodationBookings'],
|
|
));
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|