1 | <?php |
||||
2 | declare(strict_types=1); |
||||
3 | /** |
||||
4 | */ |
||||
5 | |||||
6 | namespace CommerceLeague\ActiveCampaign\Console\Command; |
||||
7 | |||||
8 | use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
||||
9 | use CommerceLeague\ActiveCampaign\MessageQueue\Topics; |
||||
10 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory; |
||||
0 ignored issues
–
show
|
|||||
11 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer\Collection as CustomerCollection; |
||||
12 | use Magento\Framework\Console\Cli; |
||||
13 | use Magento\Framework\MessageQueue\PublisherInterface; |
||||
14 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Subscriber\CollectionFactory as SubscriberCollectionFactory; |
||||
0 ignored issues
–
show
The type
CommerceLeague\ActiveCam...riber\CollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||||
15 | use CommerceLeague\ActiveCampaign\Model\ResourceModel\Subscriber\Collection as SubscriberCollection; |
||||
16 | use Symfony\Component\Console\Exception\RuntimeException; |
||||
17 | use Symfony\Component\Console\Helper\ProgressBarFactory; |
||||
0 ignored issues
–
show
The type
Symfony\Component\Consol...lper\ProgressBarFactory was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||||
18 | use Symfony\Component\Console\Input\InputInterface; |
||||
19 | use Symfony\Component\Console\Input\InputOption; |
||||
20 | use Symfony\Component\Console\Output\OutputInterface; |
||||
21 | |||||
22 | /** |
||||
23 | * Class ExportContactCommand |
||||
24 | */ |
||||
25 | class ExportContactCommand extends AbstractExportCommand |
||||
26 | { |
||||
27 | private const NAME = 'activecampaign:export:contact'; |
||||
28 | private const OPTION_EMAIL = 'email'; |
||||
29 | private const OPTION_OMITTED = 'omitted'; |
||||
30 | private const OPTION_ALL = 'all'; |
||||
31 | |||||
32 | /** |
||||
33 | * @var CustomerCollectionFactory |
||||
34 | */ |
||||
35 | private $customerCollectionFactory; |
||||
36 | |||||
37 | /** |
||||
38 | * @var SubscriberCollectionFactory |
||||
39 | */ |
||||
40 | private $subscriberCollectionFactory; |
||||
41 | |||||
42 | /** |
||||
43 | * @param ConfigHelper $configHelper |
||||
44 | * @param CustomerCollectionFactory $customerCollectionFactory |
||||
45 | * @param SubscriberCollectionFactory $subscriberCollectionFactory |
||||
46 | * @param ProgressBarFactory $progressBarFactory |
||||
47 | * @param PublisherInterface $publisher |
||||
48 | */ |
||||
49 | public function __construct( |
||||
50 | ConfigHelper $configHelper, |
||||
51 | CustomerCollectionFactory $customerCollectionFactory, |
||||
52 | SubscriberCollectionFactory $subscriberCollectionFactory, |
||||
53 | ProgressBarFactory $progressBarFactory, |
||||
54 | PublisherInterface $publisher |
||||
55 | ) { |
||||
56 | $this->customerCollectionFactory = $customerCollectionFactory; |
||||
57 | $this->subscriberCollectionFactory = $subscriberCollectionFactory; |
||||
58 | parent::__construct($configHelper, $progressBarFactory, $publisher); |
||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * @inheritDoc |
||||
63 | */ |
||||
64 | protected function configure() |
||||
65 | { |
||||
66 | $this->setName(self::NAME) |
||||
67 | ->setDescription('Export contacts') |
||||
68 | ->addOption( |
||||
69 | self::OPTION_EMAIL, |
||||
70 | null, |
||||
71 | InputOption::VALUE_REQUIRED, |
||||
72 | 'The contact email' |
||||
73 | ) |
||||
74 | ->addOption( |
||||
75 | self::OPTION_OMITTED, |
||||
76 | null, |
||||
77 | InputOption::VALUE_NONE, |
||||
78 | 'Only export omitted contacts' |
||||
79 | ) |
||||
80 | ->addOption( |
||||
81 | self::OPTION_ALL, |
||||
82 | null, |
||||
83 | InputOption::VALUE_NONE, |
||||
84 | 'Export all contacts' |
||||
85 | ); |
||||
86 | } |
||||
87 | |||||
88 | /** |
||||
89 | * @inheritDoc |
||||
90 | */ |
||||
91 | protected function interact(InputInterface $input, OutputInterface $output) |
||||
92 | { |
||||
93 | if (!$this->configHelper->isEnabled() || !$this->configHelper->isContactExportEnabled()) { |
||||
94 | throw new RuntimeException('Export disabled by system configuration'); |
||||
95 | } |
||||
96 | |||||
97 | $email = $input->getOption(self::OPTION_EMAIL); |
||||
98 | $omitted = $input->getOption(self::OPTION_OMITTED); |
||||
99 | $all = $input->getOption(self::OPTION_ALL); |
||||
100 | |||||
101 | if ($email === null && $omitted === false && $all === false) { |
||||
102 | throw new RuntimeException('Please provide at least one option'); |
||||
103 | } |
||||
104 | |||||
105 | if ($email !== null && ($omitted === true || $all === true)) { |
||||
106 | throw new RuntimeException('You cannot use --email together with another option'); |
||||
107 | } |
||||
108 | |||||
109 | if ($omitted === true && $all === true) { |
||||
110 | throw new RuntimeException('You cannot use --omitted and --all together'); |
||||
111 | } |
||||
112 | } |
||||
113 | |||||
114 | /** |
||||
115 | * @inheritDoc |
||||
116 | */ |
||||
117 | protected function execute(InputInterface $input, OutputInterface $output) |
||||
118 | { |
||||
119 | $customerIds = $this->getCustomerIds($input); |
||||
120 | $customerIdsCount = count($customerIds); |
||||
121 | $subscriberEmails = $this->getSubscriberEmails($input); |
||||
122 | $subscriberEmailsCount = count($subscriberEmails); |
||||
123 | |||||
124 | if (($customerIdsCount + $subscriberEmailsCount) === 0) { |
||||
125 | $output->writeln('<error>No contact(s) found matching your criteria</error>'); |
||||
126 | return Cli::RETURN_FAILURE; |
||||
127 | } |
||||
128 | |||||
129 | if ($customerIdsCount > 0) { |
||||
130 | $progressBar = $this->createProgressBar( |
||||
131 | $output, |
||||
132 | $customerIdsCount, |
||||
133 | 'Customer(s)' |
||||
134 | ); |
||||
135 | |||||
136 | foreach ($customerIds as $customerId) { |
||||
137 | $this->publisher->publish( |
||||
138 | Topics::CUSTOMER_CONTACT_EXPORT, |
||||
139 | json_encode(['magento_customer_id' => $customerId]) |
||||
0 ignored issues
–
show
json_encode(array('magen...er_id' => $customerId)) of type string is incompatible with the type array|object expected by parameter $data of Magento\Framework\Messag...herInterface::publish() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
140 | ); |
||||
141 | |||||
142 | $progressBar->advance(); |
||||
143 | } |
||||
144 | |||||
145 | $output->writeln(''); |
||||
146 | } |
||||
147 | |||||
148 | if ($subscriberEmailsCount > 0) { |
||||
149 | $progressBar = $this->createProgressBar( |
||||
150 | $output, |
||||
151 | $subscriberEmailsCount, |
||||
152 | 'Subscriber(s)' |
||||
153 | ); |
||||
154 | |||||
155 | foreach ($subscriberEmails as $subscriberEmail) { |
||||
156 | $this->publisher->publish( |
||||
157 | Topics::NEWSLETTER_CONTACT_EXPORT, |
||||
158 | json_encode(['email' => $subscriberEmail]) |
||||
159 | ); |
||||
160 | |||||
161 | $progressBar->advance(); |
||||
162 | } |
||||
163 | |||||
164 | $output->writeln(''); |
||||
165 | } |
||||
166 | |||||
167 | $output->writeln(sprintf( |
||||
168 | '<info>%s contact(s) have been scheduled for export.</info>', |
||||
169 | ($customerIdsCount + $subscriberEmailsCount) |
||||
170 | )); |
||||
171 | |||||
172 | return Cli::RETURN_SUCCESS; |
||||
173 | } |
||||
174 | |||||
175 | /** |
||||
176 | * @param InputInterface $input |
||||
177 | * @return array |
||||
178 | */ |
||||
179 | private function getCustomerIds(InputInterface $input): array |
||||
180 | { |
||||
181 | /** @var CustomerCollection $customerCollection */ |
||||
182 | $customerCollection = $this->customerCollectionFactory->create(); |
||||
183 | |||||
184 | if (($email = $input->getOption(self::OPTION_EMAIL)) !== null) { |
||||
185 | $customerCollection->addEmailFilter($email); |
||||
186 | } |
||||
187 | |||||
188 | if ($input->getOption(self::OPTION_OMITTED)) { |
||||
189 | $customerCollection->addContactOmittedFilter(); |
||||
190 | } |
||||
191 | |||||
192 | return $customerCollection->getAllIds(); |
||||
193 | } |
||||
194 | |||||
195 | /** |
||||
196 | * @param InputInterface $input |
||||
197 | * @return array |
||||
198 | */ |
||||
199 | private function getSubscriberEmails(InputInterface $input): array |
||||
200 | { |
||||
201 | /** @var SubscriberCollection $subscriberCollection */ |
||||
202 | $subscriberCollection = $this->subscriberCollectionFactory->create(); |
||||
203 | $subscriberCollection->excludeCustomers(); |
||||
204 | |||||
205 | if (($email = $input->getOption(self::OPTION_EMAIL)) !== null) { |
||||
206 | $subscriberCollection->addEmailFilter($email); |
||||
207 | } |
||||
208 | |||||
209 | if ($input->getOption(self::OPTION_OMITTED)) { |
||||
210 | $subscriberCollection->addContactOmittedFilter(); |
||||
211 | } |
||||
212 | |||||
213 | return $subscriberCollection->getAllEmails(); |
||||
214 | } |
||||
215 | } |
||||
216 |
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