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