-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchbot-cli.php
executable file
·103 lines (87 loc) · 3.39 KB
/
matchbot-cli.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env php
<?php
declare(strict_types=1);
use MatchBot\Application\Commands\CallFrequentTasks;
use MatchBot\Application\Commands\CancelStaleDonationFundTips;
use MatchBot\Application\Commands\ClaimGiftAid;
use MatchBot\Application\Commands\Command;
use MatchBot\Application\Commands\DeleteStalePaymentDetails;
use MatchBot\Application\Commands\ExpireMatchFunds;
use MatchBot\Application\Commands\HandleOutOfSyncFunds;
use MatchBot\Application\Commands\LockingCommand;
use MatchBot\Application\Commands\PullIndividualCampaignFromSF;
use MatchBot\Application\Commands\PullMetaCampaignFromSF;
use MatchBot\Application\Commands\PushDonations;
use MatchBot\Application\Commands\RedistributeMatchFunds;
use MatchBot\Application\Commands\ResetMatching;
use MatchBot\Application\Commands\RetrospectivelyMatch;
use MatchBot\Application\Commands\ScheduledOutOfSyncFundsCheck;
use MatchBot\Application\Commands\SendStatistics;
use MatchBot\Application\Commands\SetupTestMandate;
use MatchBot\Application\Commands\TakeRegularGivingDonations;
use MatchBot\Application\Commands\UpdateCampaigns;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleEvent;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Messenger\Command\ConsumeMessagesCommand;
use Symfony\Component\Notifier\ChatterInterface;
$psr11App = require __DIR__ . '/bootstrap.php';
$commands = array_map($psr11App->get(...), [
// Alphabetical list:
CallFrequentTasks::class,
CancelStaleDonationFundTips::class,
ClaimGiftAid::class,
ConsumeMessagesCommand::class,
DeleteStalePaymentDetails::class,
ExpireMatchFunds::class,
HandleOutOfSyncFunds::class,
PullIndividualCampaignFromSF::class,
PullMetaCampaignFromSF::class,
PushDonations::class,
RedistributeMatchFunds::class,
ResetMatching::class,
RetrospectivelyMatch::class,
ScheduledOutOfSyncFundsCheck::class,
SendStatistics::class,
SetupTestMandate::class,
TakeRegularGivingDonations::class,
UpdateCampaigns::class,
]);
$chatter = $psr11App->get(ChatterInterface::class);
assert($chatter instanceof ChatterInterface);
$dispatcher = new EventDispatcher();
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleEvent $event) use ($psr11App) {
$logger = $psr11App->get(Logger::class);
$input = $event->getInput();
if ($input->getOption(Command::CLI_OPTION_NOLOG)) {
array_filter(
$logger->getHandlers(),
(static fn ($handler) => $handler instanceof StreamHandler)
)[0]->setLevel(LogLevel::WARNING);
}
});
$cliApp = new Application();
$cliApp->setDispatcher($dispatcher);
$cliApp->getDefinition()->addOption(
new InputOption(
Command::CLI_OPTION_NOLOG,
null,
InputOption::VALUE_NONE,
'Suppresses debug & info log, show only warnings and errors'
)
);
foreach ($commands as $command) {
if ($command instanceof LockingCommand) { // i.e. not Symfony Messenger's built-in consumer.
$command->setLockFactory($psr11App->get(LockFactory::class));
$command->setLogger($psr11App->get(LoggerInterface::class));
}
$cliApp->add($command);
}
$cliApp->run();