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