Repository navigation
Expand file tree
/
Copy pathRegenerateStatsForCampaign.php
More file actions
58 lines (50 loc) · 1.81 KB
/
Copy pathRegenerateStatsForCampaign.php
File metadata and controls
58 lines (50 loc) · 1.81 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
<?php
declare(strict_types=1);
namespace MatchBot\Application\Commands;
use Doctrine\ORM\EntityManagerInterface;
use MatchBot\Domain\CampaignRepository;
use MatchBot\Domain\CampaignService;
use MatchBot\Domain\Salesforce18Id;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'matchbot:regenerate-stats-for-campaign',
description: 'Regenerates campaign statistics for a campaign in case automatic processes failed to updated it in time'
)]
class RegenerateStatsForCampaign extends LockingCommand
{
public function __construct(
private EntityManagerInterface $em,
private CampaignRepository $campaignRepository,
private CampaignService $campaignService,
private LoggerInterface $logger,
) {
parent::__construct();
}
#[\Override]
public function configure(): void
{
$this->addArgument(
'CampaignSFID',
InputArgument::REQUIRED,
'18 Character Salesforce ID of the campaign, as found in the donate page URI etc',
);
}
#[\Override]
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
// @phpstan-ignore cast.string
$campaignId = Salesforce18Id::ofCampaign((string) $input->getArgument('CampaignSFID'));
$campaign = $this->campaignRepository->findOneBySalesforceId($campaignId);
if (!$campaign) {
$this->logger->error("Campaign {$campaignId->value} not found, cannot regenerate stats");
return 1;
}
$this->campaignService->regenerateStats($campaign);
$this->em->flush();
return 0;
}
}