-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPushDailyFundTotals.php
More file actions
47 lines (40 loc) · 1.64 KB
/
PushDailyFundTotals.php
File metadata and controls
47 lines (40 loc) · 1.64 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
<?php
namespace MatchBot\Application\Commands;
use MatchBot\Application\Messenger\FundTotalUpdated;
use MatchBot\Domain\FundRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\RoutableMessageBus;
/**
* @see RetrospectivelyMatch which does a similar thing for just-closed campaigns as one of the last campaign close tasks.
*/
#[AsCommand(
name: 'matchbot:push-daily-fund-totals',
description: 'Pushes champion funds used totals to Salesforce, for all associated with open campaigns'
)]
class PushDailyFundTotals extends LockingCommand
{
public function __construct(
private readonly FundRepository $fundRepository,
private readonly RoutableMessageBus $bus,
) {
parent::__construct();
}
#[\Override]
public function doExecute(InputInterface $input, OutputInterface $output): int
{
$funds = $this->fundRepository->findForCampaignsRecentlyOpenAt(new \DateTimeImmutable('now'));
foreach ($funds as $fund) {
if ($fund->getFundType()->isPledge()) {
// Skip pledges from daily total push as Salesforce doesn't yet do anything with that info
// and it could be a lot of requests against a volume-limited Site.
continue;
}
$this->bus->dispatch(new Envelope(FundTotalUpdated::fromFund($fund)));
}
$output->writeln(sprintf('Pushed %d fund totals to Salesforce for open campaigns', count($funds)));
return 0;
}
}