|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CodeCloud\Bundle\ShopifyBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Exception\StoreNotFoundException; |
|
6
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Model\ShopifyStoreManagerInterface; |
|
7
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Service\WebhookCreatorInterface; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class WebhooksCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var WebhookCreatorInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $webhookCreator; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var ShopifyStoreManagerInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $storeManager; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
private $topics = []; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param WebhookCreatorInterface $webhookCreator |
|
33
|
|
|
* @param ShopifyStoreManagerInterface $storeManager |
|
34
|
|
|
* @param array $topics |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(WebhookCreatorInterface $webhookCreator, ShopifyStoreManagerInterface $storeManager, array $topics) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->webhookCreator = $webhookCreator; |
|
39
|
|
|
$this->storeManager = $storeManager; |
|
40
|
|
|
$this->topics = $topics; |
|
41
|
|
|
parent::__construct(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function configure() |
|
45
|
|
|
{ |
|
46
|
|
|
$this |
|
47
|
|
|
->setName('codecloud:shopify:webhooks') |
|
48
|
|
|
->setDescription('Interact with Shopify Webhooks') |
|
49
|
|
|
->addArgument('store', InputArgument::REQUIRED, 'The store to install webhooks in') |
|
50
|
|
|
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete existing webhooks') |
|
51
|
|
|
->addOption('list', null, InputOption::VALUE_NONE, 'List existing webhooks') |
|
52
|
|
|
; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
56
|
|
|
{ |
|
57
|
|
|
if (!$this->storeManager->storeExists($store = $input->getArgument('store'))) { |
|
58
|
|
|
throw new StoreNotFoundException($store); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if ($input->getOption('list')) { |
|
62
|
|
|
$output->writeln(print_r($this->webhookCreator->listWebhooks($store), true)); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if ($input->getOption('delete')) { |
|
68
|
|
|
$this->webhookCreator->deleteAllWebhooks($store); |
|
69
|
|
|
$output->writeln('Webhooks deleted'); |
|
70
|
|
|
|
|
71
|
|
|
return; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (empty($this->topics)) { |
|
75
|
|
|
throw new \LogicException('No webhook topics configured'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->webhookCreator->createWebhooks($store, $this->topics); |
|
79
|
|
|
|
|
80
|
|
|
$output->writeln('Webhooks created'); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|