Repository navigation
Expand file tree
/
Copy pathPatchCampaignFunding58084.php
More file actions
82 lines (69 loc) · 3 KB
/
Copy pathPatchCampaignFunding58084.php
File metadata and controls
82 lines (69 loc) · 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
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
namespace MatchBot\Application\Commands;
use Doctrine\ORM\EntityManagerInterface;
use MatchBot\Application\Matching\Adapter;
use MatchBot\Application\RealTimeMatchingStorage;
use MatchBot\Domain\CampaignFundingRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'matchbot:patch-campaign-funding-58084',
description: 'One-time patch to subtract £5,000 from CampaignFunding ID 58084'
)]
class PatchCampaignFunding58084 extends LockingCommand
{
public const int TARGET_FUNDING_ID = 58084;
public const string AMOUNT_TO_SUBTRACT = '5000';
public const string REDIS_FLAG_KEY = 'patch-campaign-funding-58084-applied';
public function __construct(
private CampaignFundingRepository $campaignFundingRepository,
private Adapter $matchingAdapter,
private EntityManagerInterface $entityManager,
private RealTimeMatchingStorage $matchingStorage,
private LoggerInterface $logger,
) {
parent::__construct();
}
#[\Override]
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
if ($this->matchingStorage->get(self::REDIS_FLAG_KEY) === '1') {
$output->writeln('Patch for CampaignFunding ' . self::TARGET_FUNDING_ID . ' has already been applied.');
return 0;
}
$funding = $this->campaignFundingRepository->find(self::TARGET_FUNDING_ID);
if ($funding === null) {
$output->writeln('CampaignFunding ' . self::TARGET_FUNDING_ID . ' not found (likely not in this environment). Skipping.');
$this->logger->info('CampaignFunding ' . self::TARGET_FUNDING_ID . ' not found for one-time patch; skipped.');
return 0;
}
$amountBefore = $this->matchingAdapter->getAmountAvailable($funding);
$this->logger->info(sprintf(
'Applying one-time patch for CampaignFunding ID %d: subtracting £%s from current available £%s',
self::TARGET_FUNDING_ID,
self::AMOUNT_TO_SUBTRACT,
$amountBefore
));
$newTotal = $this->matchingAdapter->subtractAmount(
funding: $funding,
amount: self::AMOUNT_TO_SUBTRACT,
donationId: null,
extraComment: 'One-time patch to use £5,000 incorrectly returned funds'
);
$this->entityManager->flush();
// Mark as completed in Redis so this one-time job does not run again on subsequent ticks
$this->matchingStorage->set(self::REDIS_FLAG_KEY, '1', []);
$message = sprintf(
'Successfully patched CampaignFunding ID %d. Subtracted £%s. New available balance is £%s.',
self::TARGET_FUNDING_ID,
self::AMOUNT_TO_SUBTRACT,
$newTotal
);
$output->writeln($message);
$this->logger->info($message);
return 0;
}
}