-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClaimGiftAid.php
More file actions
72 lines (60 loc) · 2.3 KB
/
ClaimGiftAid.php
File metadata and controls
72 lines (60 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace MatchBot\Application\Commands;
use Doctrine\ORM\EntityManagerInterface;
use MatchBot\Domain\Donation;
use MatchBot\Domain\DonationRepository;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\RoutableMessageBus;
use Symfony\Component\Messenger\Stamp\BusNameStamp;
use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp;
/**
* Send applicable donations to ClaimBot for HMRC Gift Aid claims.
*/
class ClaimGiftAid extends LockingCommand
{
protected static $defaultName = 'matchbot:claim-gift-aid';
public function __construct(
private DonationRepository $donationRepository,
private EntityManagerInterface $entityManager,
private RoutableMessageBus $bus,
) {
parent::__construct();
}
#[\Override]
protected function configure(): void
{
$this->setDescription('Sends applicable donations to ClaimBot for HMRC Gift Aid claims');
$this->addOption(
'with-resends',
null,
InputOption::VALUE_NONE,
'Tells the command to send donations again, even if they were queued before. Non-Production only',
);
}
#[\Override]
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$toClaim = $this->donationRepository->findReadyToClaimGiftAid(
!empty($input->getOption('with-resends')),
);
if (count($toClaim) > 0) {
foreach ($toClaim as $donation) {
$stamps = [
new BusNameStamp('claimbot.donation.claim'),
new TransportMessageIdStamp("claimbot.donation.claim.{$donation->getUuid()}"),
];
$this->bus->dispatch(new Envelope($donation->toClaimBotModel(), $stamps));
$donation->setTbgGiftAidRequestQueuedAt(new \DateTimeImmutable());
$this->entityManager->persist($donation);
}
$this->entityManager->flush();
}
$numberSent = count($toClaim);
$output->writeln("Submitted $numberSent donations to the ClaimBot queue");
return 0;
}
}