1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Console\Command; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Service\ExportCustomerService; |
9
|
|
|
use Magento\Customer\Model\Customer; |
10
|
|
|
use Magento\Customer\Model\MagentoCustomerFactory; |
|
|
|
|
11
|
|
|
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as MagentoCustomerCollectionFactory; |
|
|
|
|
12
|
|
|
use Magento\Customer\Model\ResourceModel\Customer\Collection as MagentoCustomerCollection; |
13
|
|
|
use Magento\Framework\Console\Cli; |
14
|
|
|
use Magento\Framework\Model\ResourceModel\Iterator as ResourceIterator; |
15
|
|
|
use Symfony\Component\Console\Command\Command; |
16
|
|
|
use Symfony\Component\Console\Helper\ProgressBarFactory; |
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class ExportContactCommand |
23
|
|
|
*/ |
24
|
|
|
class ExportCustomerCommand extends Command |
25
|
|
|
{ |
26
|
|
|
private const NAME = 'activecampaign:export:customer'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var MagentoCustomerCollectionFactory |
30
|
|
|
*/ |
31
|
|
|
private $magentoCustomerCollectionFactory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var MagentoCustomerFactory |
35
|
|
|
*/ |
36
|
|
|
private $magentoCustomerFactory; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var ProgressBarFactory |
40
|
|
|
*/ |
41
|
|
|
private $progressBarFactory; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var ResourceIterator |
45
|
|
|
*/ |
46
|
|
|
private $resourceIterator; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var ExportCustomerService |
50
|
|
|
*/ |
51
|
|
|
private $exportCustomerService; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var int |
55
|
|
|
*/ |
56
|
|
|
private $exportMessages = 0; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory |
60
|
|
|
* @param MagentoCustomerFactory $magentoCustomerFactory |
61
|
|
|
* @param ProgressBarFactory $progressBarFactory |
62
|
|
|
* @param ResourceIterator $resourceIterator |
63
|
|
|
* @param ExportCustomerService $exportContactService |
64
|
|
|
*/ |
65
|
|
|
public function __construct( |
66
|
|
|
MagentoCustomerCollectionFactory $magentoCustomerCollectionFactory, |
67
|
|
|
MagentoCustomerFactory $magentoCustomerFactory, |
68
|
|
|
ProgressBarFactory $progressBarFactory, |
69
|
|
|
ResourceIterator $resourceIterator, |
70
|
|
|
ExportCustomerService $exportContactService |
71
|
|
|
) { |
72
|
|
|
$this->magentoCustomerCollectionFactory = $magentoCustomerCollectionFactory; |
73
|
|
|
$this->magentoCustomerFactory = $magentoCustomerFactory; |
74
|
|
|
$this->progressBarFactory = $progressBarFactory; |
75
|
|
|
$this->resourceIterator = $resourceIterator; |
76
|
|
|
$this->exportCustomerService = $exportContactService; |
77
|
|
|
parent::__construct(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @inheritDoc |
82
|
|
|
*/ |
83
|
|
|
protected function configure() |
84
|
|
|
{ |
85
|
|
|
$this->setName(self::NAME); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @inheritDoc |
90
|
|
|
*/ |
91
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
92
|
|
|
{ |
93
|
|
|
/** @var MagentoCustomerCollection $magentoCustomerCollection */ |
94
|
|
|
$magentoCustomerCollection = $this->magentoCustomerCollectionFactory->create(); |
95
|
|
|
|
96
|
|
|
if ($magentoCustomerCollection->getSize() === 0) { |
97
|
|
|
$output->writeln('<error>No valid magento customers found</error>'); |
98
|
|
|
return Cli::RETURN_FAILURE; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** @var ProgressBar $progressBar */ |
102
|
|
|
$progressBar = $this->progressBarFactory->create(['output' => $output]); |
103
|
|
|
$progressBar->setFormat('<comment>%message%</comment> %current% [%bar%] %elapsed%'); |
104
|
|
|
$progressBar->setMessage('Export Message(s)'); |
105
|
|
|
|
106
|
|
|
$this->resourceIterator->walk( |
107
|
|
|
$magentoCustomerCollection->getSelect(), |
108
|
|
|
[[$this, 'callbackExportMagentoCustomer']], |
109
|
|
|
[ |
110
|
|
|
'magentoCustomer' => $this->magentoCustomerFactory->create(), |
111
|
|
|
'progressBar' => $progressBar |
112
|
|
|
] |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$output->writeln(''); |
116
|
|
|
$output->writeln('<info>Created ' . $this->exportMessages . ' export message(s)</info>'); |
117
|
|
|
|
118
|
|
|
return Cli::RETURN_SUCCESS; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param array $args |
123
|
|
|
*/ |
124
|
|
|
public function callbackExportMagentoCustomer(array $args): void |
125
|
|
|
{ |
126
|
|
|
/** @var Customer $magentoCustomer */ |
127
|
|
|
$magentoCustomer = clone $args['magentoCustomer']; |
128
|
|
|
$magentoCustomer->setData($args['row']); |
129
|
|
|
|
130
|
|
|
/** @var ProgressBar $progressBar */ |
131
|
|
|
$progressBar = $args['progressBar']; |
132
|
|
|
$progressBar->advance(); |
133
|
|
|
|
134
|
|
|
$this->exportCustomerService->export($magentoCustomer); |
135
|
|
|
$this->exportMessages++; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
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