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 CommerceLeague\ActiveCampaign\Model\ResourceModel\Magento\CustomerCollectionFactory; |
|
|
|
|
10
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Magento\CustomerCollection; |
11
|
|
|
use Magento\Framework\Console\Cli; |
12
|
|
|
use Magento\Framework\MessageQueue\PublisherInterface; |
13
|
|
|
use Symfony\Component\Console\Exception\RuntimeException; |
14
|
|
|
use Symfony\Component\Console\Helper\ProgressBarFactory; |
|
|
|
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ExportCustomerCommand |
21
|
|
|
*/ |
22
|
|
|
class ExportCustomerCommand extends AbstractExportCommand |
23
|
|
|
{ |
24
|
|
|
private const NAME = 'activecampaign:export:customer'; |
25
|
|
|
private const OPTION_EMAIL = 'email'; |
26
|
|
|
private const OPTION_OMITTED = 'omitted'; |
27
|
|
|
private const OPTION_ALL = 'all'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var CustomerCollectionFactory |
31
|
|
|
*/ |
32
|
|
|
private $customerCollectionFactory; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param CustomerCollectionFactory $customerCollectionFactory |
36
|
|
|
* @param PublisherInterface $publisher |
37
|
|
|
* @param ProgressBarFactory $progressBarFactory |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
CustomerCollectionFactory $customerCollectionFactory, |
41
|
|
|
PublisherInterface $publisher, |
42
|
|
|
ProgressBarFactory $progressBarFactory |
43
|
|
|
) { |
44
|
|
|
$this->customerCollectionFactory = $customerCollectionFactory; |
45
|
|
|
parent::__construct($progressBarFactory, $publisher); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritDoc |
50
|
|
|
*/ |
51
|
|
|
protected function configure() |
52
|
|
|
{ |
53
|
|
|
$this->setName(self::NAME) |
54
|
|
|
->setDescription('Export customers') |
55
|
|
|
->addOption( |
56
|
|
|
self::OPTION_EMAIL, |
57
|
|
|
null, |
58
|
|
|
InputOption::VALUE_REQUIRED, |
59
|
|
|
'The customer email' |
60
|
|
|
) |
61
|
|
|
->addOption( |
62
|
|
|
self::OPTION_OMITTED, |
63
|
|
|
null, |
64
|
|
|
InputOption::VALUE_NONE, |
65
|
|
|
'Only export omitted customers' |
66
|
|
|
) |
67
|
|
|
->addOption( |
68
|
|
|
self::OPTION_ALL, |
69
|
|
|
null, |
70
|
|
|
InputOption::VALUE_NONE, |
71
|
|
|
'Export all customers' |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritDoc |
77
|
|
|
*/ |
78
|
|
|
protected function interact(InputInterface $input, OutputInterface $output) |
79
|
|
|
{ |
80
|
|
|
$email = $input->getOption(self::OPTION_EMAIL); |
81
|
|
|
$omitted = $input->getOption(self::OPTION_OMITTED); |
82
|
|
|
$all = $input->getOption(self::OPTION_ALL); |
83
|
|
|
|
84
|
|
|
if ($email === null && $omitted === false && $all === false) { |
85
|
|
|
throw new RuntimeException('Please provide at least one option'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($email !== null && ($omitted === true || $all === true)) { |
89
|
|
|
throw new RuntimeException('You cannot use --email together with another option'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($omitted === true && $all === true) { |
93
|
|
|
throw new RuntimeException('You cannot use --omitted and --all together'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritDoc |
99
|
|
|
*/ |
100
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
101
|
|
|
{ |
102
|
|
|
$customerIds = $this->getCustomerIds($input); |
103
|
|
|
$customerIdsCount = count($customerIds); |
104
|
|
|
|
105
|
|
|
if ($customerIdsCount === 0) { |
106
|
|
|
$output->writeln('<error>No customer(s) found matching your criteria</error>'); |
107
|
|
|
return Cli::RETURN_FAILURE; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$progressBar = $this->createProgressBar( |
111
|
|
|
$output, |
112
|
|
|
count($customerIds), |
113
|
|
|
'Customer(s)' |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
foreach ($customerIds as $customerId) { |
117
|
|
|
$this->publisher->publish( |
118
|
|
|
Topics::CUSTOMER_CUSTOMER_EXPORT, |
119
|
|
|
json_encode(['magento_customer_id' => $customerId]) |
|
|
|
|
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
$progressBar->advance(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$output->writeln(''); |
126
|
|
|
$output->writeln(sprintf( |
127
|
|
|
'<info>%s customers(s) have been scheduled for export.</info>', |
128
|
|
|
(count($customerIds))) |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
return Cli::RETURN_SUCCESS; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param InputInterface $input |
136
|
|
|
* @return array |
137
|
|
|
*/ |
138
|
|
|
private function getCustomerIds(InputInterface $input): array |
139
|
|
|
{ |
140
|
|
|
/** @var CustomerCollection $customerCollection */ |
141
|
|
|
$customerCollection = $this->customerCollectionFactory->create(); |
142
|
|
|
|
143
|
|
|
if (($email = $input->getOption(self::OPTION_EMAIL)) !== null) { |
144
|
|
|
$customerCollection->addEmailFilter($email); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if ($input->getOption(self::OPTION_OMITTED)) { |
148
|
|
|
$customerCollection->addOmittedFilter(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $customerCollection->getAllIds(); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
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