-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPullMetaCampaignFromSF.php
72 lines (63 loc) · 2.6 KB
/
PullMetaCampaignFromSF.php
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\Application\Assertion;
use MatchBot\Domain\CampaignRepository;
use MatchBot\Domain\DonationRepository;
use MatchBot\Domain\DonationService;
use MatchBot\Domain\FundRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
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\MessageBusInterface;
use Symfony\Component\Messenger\RoutableMessageBus;
use Symfony\Component\Messenger\Stamp\BusNameStamp;
use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp;
/**
*
*/
#[AsCommand(
name: 'matchbot:pull-meta-campaign-from-sf',
description: 'Pulls a meta campaign (or at least all its related individual campaigns) from Salesforce into the
matchbot db. Should improve performance and reduce chance of any db contention particularly if run shortly before
campaign start time'
)]
class PullMetaCampaignFromSF extends LockingCommand
{
/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function __construct(
private CampaignRepository $campaignRepository,
private FundRepository $fundRepository
) {
parent::__construct();
}
public function configure(): void
{
$this->addArgument('metaCampaignSlug', InputArgument::REQUIRED);
}
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$metaCampaginSlug = $input->getArgument('metaCampaignSlug');
\assert(is_string($metaCampaginSlug));
Assertion::betweenLength($metaCampaginSlug, minLength: 5, maxLength: 50);
Assertion::regex($metaCampaginSlug, '/^[A-Za-z0-9-]+$/');
['newFetchCount' => $newFetchCount, 'updatedCount' => $updatedCount, 'campaigns' => $campaigns] =
$this->campaignRepository->fetchAllForMetaCampaign($metaCampaginSlug);
$total = $newFetchCount + $updatedCount;
$i = 0;
foreach ($campaigns as $campaign) {
$i++;
$output->writeln("Pulling funds for ($i of $total) '{$campaign->getCampaignName()}'");
$this->fundRepository->pullForCampaign($campaign);
}
$output->writeln("Fetched $total campaigns total from Salesforce for '$metaCampaginSlug'");
$output->writeln("$newFetchCount new campaigns added to DB, $updatedCount campaigns updated");
return 0;
}
}