|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Console\Command; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Topics; |
|
9
|
|
|
use Magento\Customer\Model\ResourceModel\Customer\Collection as MagentoCustomerCollection; |
|
10
|
|
|
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as MagentoCustomerCollectionFactory; |
|
|
|
|
|
|
11
|
|
|
use Magento\Framework\Console\Cli; |
|
12
|
|
|
use Magento\Framework\MessageQueue\PublisherInterface; |
|
13
|
|
|
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory as SubscriberCollectionFactory; |
|
|
|
|
|
|
14
|
|
|
use Magento\Newsletter\Model\ResourceModel\Subscriber\Collection as SubscriberCollection; |
|
15
|
|
|
use Magento\Newsletter\Model\Subscriber; |
|
16
|
|
|
use Symfony\Component\Console\Helper\ProgressBarFactory; |
|
|
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class ExportContactCommand |
|
22
|
|
|
*/ |
|
23
|
|
|
class ExportContactCommand extends AbstractExportCommand |
|
24
|
|
|
{ |
|
25
|
|
|
private const NAME = 'activecampaign:export:contact'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var MagentoCustomerCollectionFactory |
|
29
|
|
|
*/ |
|
30
|
|
|
private $magentoCustomerCollectionFactory; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var SubscriberCollectionFactory |
|
34
|
|
|
*/ |
|
35
|
|
|
private $subscriberCollectionFactory; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory |
|
39
|
|
|
* @param SubscriberCollectionFactory $subscriberCollectionFactory |
|
40
|
|
|
* @param PublisherInterface $publisher |
|
41
|
|
|
* @param ProgressBarFactory $progressBarFactory |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory, |
|
45
|
|
|
SubscriberCollectionFactory $subscriberCollectionFactory, |
|
46
|
|
|
PublisherInterface $publisher, |
|
47
|
|
|
ProgressBarFactory $progressBarFactory |
|
48
|
|
|
) { |
|
49
|
|
|
$this->magentoCustomerCollectionFactory = $magentoCustomerCollectionFactory; |
|
50
|
|
|
$this->subscriberCollectionFactory = $subscriberCollectionFactory; |
|
51
|
|
|
parent::__construct($progressBarFactory, $publisher); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @inheritDoc |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function configure() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->setName(self::NAME); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @inheritDoc |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
66
|
|
|
{ |
|
67
|
|
|
$magentoCustomerIds = $this->getMagentoCustomerIds(); |
|
68
|
|
|
|
|
69
|
|
|
$progressBar = $this->createProgressBar( |
|
70
|
|
|
$output, |
|
71
|
|
|
count($magentoCustomerIds), |
|
72
|
|
|
'Export Magento Customer(s)' |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
foreach ($magentoCustomerIds as $magentoCustomerId) { |
|
76
|
|
|
$this->publisher->publish( |
|
77
|
|
|
Topics::CUSTOMER_CONTACT_EXPORT, |
|
78
|
|
|
json_encode(['magento_customer_id' => $magentoCustomerId]) |
|
|
|
|
|
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$progressBar->advance(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$output->writeln(''); |
|
85
|
|
|
|
|
86
|
|
|
$subscriberEmails = $this->getSubscriberEmails(); |
|
87
|
|
|
|
|
88
|
|
|
$progressBar = $this->createProgressBar( |
|
89
|
|
|
$output, |
|
90
|
|
|
count($subscriberEmails), |
|
91
|
|
|
'Export Newsletter Subscriber(s)' |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
foreach ($subscriberEmails as $subscriberEmail) { |
|
95
|
|
|
$this->publisher->publish( |
|
96
|
|
|
Topics::NEWSLETTER_CONTACT_EXPORT, |
|
97
|
|
|
json_encode(['email' => $subscriberEmail]) |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$progressBar->advance(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$output->writeln(''); |
|
104
|
|
|
$output->writeln(sprintf( |
|
105
|
|
|
'<info>Exported %s contact(s)</info>', |
|
106
|
|
|
(count($magentoCustomerIds) + count($subscriberEmails))) |
|
107
|
|
|
); |
|
108
|
|
|
|
|
109
|
|
|
return Cli::RETURN_SUCCESS; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return array |
|
114
|
|
|
*/ |
|
115
|
|
|
private function getMagentoCustomerIds(): array |
|
116
|
|
|
{ |
|
117
|
|
|
/** @var MagentoCustomerCollection $magentoCustomerCollection */ |
|
118
|
|
|
$magentoCustomerCollection = $this->magentoCustomerCollectionFactory->create(); |
|
119
|
|
|
return $magentoCustomerCollection->getAllIds(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
|
private function getSubscriberEmails(): array |
|
126
|
|
|
{ |
|
127
|
|
|
/** @var SubscriberCollection $subscriberCollection */ |
|
128
|
|
|
$subscriberCollection = $this->subscriberCollectionFactory->create(); |
|
129
|
|
|
$subscriberCollection->addFieldToFilter('customer_id', 0); |
|
130
|
|
|
|
|
131
|
|
|
$subscriberEmails = []; |
|
132
|
|
|
|
|
133
|
|
|
/** @var Subscriber $subscriber */ |
|
134
|
|
|
foreach ($subscriberCollection as $subscriber) { |
|
135
|
|
|
$subscriberEmails[] = $subscriber->getEmail(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
return $subscriberEmails; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths