-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScheduledOutOfSyncFundsCheck.php
More file actions
82 lines (72 loc) · 3.03 KB
/
ScheduledOutOfSyncFundsCheck.php
File metadata and controls
82 lines (72 loc) · 3.03 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
namespace MatchBot\Application\Commands;
use Doctrine\ORM\EntityManagerInterface;
use MatchBot\Application\Matching;
use MatchBot\Domain\CampaignFundingRepository;
use MatchBot\Domain\DonationRepository;
use MatchBot\Domain\FundingWithdrawalRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackHeaderBlock;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\ChatterInterface;
use Symfony\Component\Notifier\Message\ChatMessage;
#[AsCommand(
name: 'matchbot:scheduled-out-of-sync-funds-check',
description: "For running via a cron job. Checks for out of sync funds but doesn't " .
"attempt to fix them. Sends output to Slack"
)]
class ScheduledOutOfSyncFundsCheck extends HandleOutOfSyncFunds
{
public function __construct(
CampaignFundingRepository $campaignFundingRepository,
EntityManagerInterface $entityManager,
FundingWithdrawalRepository $fundingWithdrawalRepository,
Matching\Adapter $matchingAdapter,
DonationRepository $donationRepository,
private ChatterInterface $chatter,
LoggerInterface $logger,
) {
parent::__construct($campaignFundingRepository, $entityManager, $fundingWithdrawalRepository, $matchingAdapter, $donationRepository, $logger);
}
#[\Override]
protected function configure(): void
{
// Don't call parent which would add the `mode` argument.
}
#[\Override]
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$bufferedOutput = new BufferedOutput();
$arrayInput = new ArrayInput(
['mode' => 'check'],
new InputDefinition([new InputArgument('mode', InputArgument::REQUIRED)]),
);
parent::doExecute($arrayInput, $bufferedOutput);
$chatMessage = new ChatMessage('Out of sync funds check');
$message = 'Out of sync funds check completed' .
($this->outOfSyncFundFound ? " OUT OF SYNC FUNDS DETECTED" : " no out of sync funds detected");
$output->writeln($message);
if ($this->outOfSyncFundFound) {
$env = getenv('APP_ENV');
\assert(is_string($env));
$options = (new SlackOptions())
->block((new SlackHeaderBlock(sprintf(
'[%s] %s',
$env,
$message,
))))
->block((new SlackSectionBlock())->text($bufferedOutput->fetch()));
$chatMessage->options($options);
$this->chatter->send($chatMessage);
}
return 0;
}
}