Skip to content

Commit c71b8c2

Browse files
committed
Add anonymise-donations CLI command
Sometimes we need to run the anonymiser in order to investigate issues in our application. This adds a command to allow it from the developer environment. Ticket: https://phabricator.wikimedia.org/T400323
1 parent 180c4d9 commit c71b8c2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

cli/AnonymiseDonationsCommand.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)