-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathWebhookCommand.php
More file actions
62 lines (49 loc) · 1.71 KB
/
WebhookCommand.php
File metadata and controls
62 lines (49 loc) · 1.71 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
<?php
namespace Welp\MailchimpBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Welp\MailchimpBundle\Provider\ListProviderInterface;
use Welp\MailchimpBundle\Subscriber\ListRepository;
class WebhookCommand extends Command
{
/**
* The configured list provider.
*
* @var ListProviderInterface
*/
private ListProviderInterface $listProvider;
/**
* The configured list repository.
*
* @var ListRepository
*/
private ListRepository $listRepository;
public function __construct(ListProviderInterface $listProvider, ListRepository $listRepository)
{
$this->listProvider = $listProvider;
$this->listRepository = $listRepository;
parent::__construct();
}
protected function configure(): void
{
$this
->setDescription('Add main webhook to a MailChimp List')
->setName('welp:mailchimp:webhook')
;
// @TODO add params : listId, webhookurl
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(sprintf('<info>%s</info>', $this->getDescription()));
$lists = $this->listProvider->getLists();
foreach ($lists as $list) {
$url = $list->getWebhookUrl().'?hooksecret='.$list->getWebhookSecret();
$output->writeln('Add webhook to list: '.$list->getListId());
$output->writeln('Webhook url: '.$url);
$this->listRepository->registerMainWebhook($list->getListId(), $url);
}
$output->writeln('✔ done');
return Command::SUCCESS;
}
}