|
| 1 | +<?php |
| 2 | + |
| 3 | +declare( strict_types = 1 ); |
| 4 | + |
| 5 | +namespace WMDE\Fundraising\Frontend\Cli; |
| 6 | + |
| 7 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 8 | +use Symfony\Component\Console\Command\Command; |
| 9 | +use Symfony\Component\Console\Input\InputInterface; |
| 10 | +use Symfony\Component\Console\Output\OutputInterface; |
| 11 | +use WMDE\Clock\SystemClock; |
| 12 | +use WMDE\Fundraising\DonationContext\DataAccess\DatabaseDonationAnonymizer; |
| 13 | +use WMDE\Fundraising\DonationContext\Domain\AnonymizationException; |
| 14 | +use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
| 15 | + |
| 16 | +/** |
| 17 | + * This is for anonymising a donation in your local environment, to use it do the following: |
| 18 | + * |
| 19 | + * 1. Create a donation using the form |
| 20 | + * 2. Run: `docker compose exec app php bin/console app:anonymise-donations` |
| 21 | + */ |
| 22 | +#[AsCommand( name: 'app:anonymise-donations' )] |
| 23 | +class AnonymiseDonationsCommand extends Command { |
| 24 | + |
| 25 | + public function __construct( private readonly FunFunFactory $ffFactory ) { |
| 26 | + parent::__construct(); |
| 27 | + } |
| 28 | + |
| 29 | + protected function execute( InputInterface $input, OutputInterface $output ): int { |
| 30 | + $donationAnonymizer = new DatabaseDonationAnonymizer( |
| 31 | + $this->ffFactory->getDonationRepository(), |
| 32 | + $this->ffFactory->getEntityManager(), |
| 33 | + new SystemClock(), |
| 34 | + new \DateInterval( 'P2D' ) |
| 35 | + ); |
| 36 | + |
| 37 | + try { |
| 38 | + $donationAnonymizer->anonymizeAll(); |
| 39 | + } catch ( AnonymizationException $e ) { |
| 40 | + return Command::FAILURE; |
| 41 | + } |
| 42 | + |
| 43 | + return Command::SUCCESS; |
| 44 | + } |
| 45 | +} |
0 commit comments