|
8 | 8 | namespace Magento\SalesOrdersDataExporter\Console\Command; |
9 | 9 |
|
10 | 10 | use Magento\DataExporter\Model\Logging\CommerceDataExportLoggerInterface; |
11 | | -use Magento\DataExporter\Uuid\UuidManager; |
12 | | -use Magento\Framework\App\ResourceConnection; |
13 | 11 | use Magento\Framework\Console\Cli; |
14 | | -use Magento\Framework\DB\Query\BatchIteratorFactory; |
| 12 | +use Magento\SalesOrdersDataExporter\Model\OrderUuidManager; |
| 13 | +use Symfony\Component\Console\Command\Command; |
15 | 14 | use Symfony\Component\Console\Input\InputInterface; |
16 | 15 | use Symfony\Component\Console\Input\InputOption; |
17 | 16 | use Symfony\Component\Console\Output\OutputInterface; |
18 | 17 |
|
19 | 18 | /** |
20 | 19 | * Command provides possibility to full export system configuration |
21 | 20 | */ |
22 | | -class Link extends \Symfony\Component\Console\Command\Command |
| 21 | +class Link extends Command |
23 | 22 | { |
24 | 23 | private const COMMAND_NAME = 'commerce-data-export:orders:link'; |
25 | 24 | private const OPTION_STATE = 'state'; |
26 | 25 | private const OPTION_FROM = 'from'; |
27 | 26 | private const OPTION_TO = 'to'; |
28 | 27 | private const OPTION_BATCH_SIZE = 'batch-size'; |
29 | 28 |
|
30 | | - private $uuidManager; |
31 | | - private $resourceConnection; |
32 | | - private $batchIteratorFactory; |
33 | | - |
34 | | - private $mapTypes = [ |
35 | | - 'order' => [ |
36 | | - 'table' => 'sales_order', |
37 | | - 'id_column' => 'entity_id', |
38 | | - 'link_column' => 'entity_id' |
39 | | - ], |
40 | | - 'order_item' => [ |
41 | | - 'table' => 'sales_order_item', |
42 | | - 'id_column' => 'item_id', |
43 | | - 'link_column' => 'order_id' |
44 | | - ], |
45 | | - 'credit_memo' => [ |
46 | | - 'table' => 'sales_creditmemo', |
47 | | - 'id_column' => 'entity_id', |
48 | | - 'link_column' => 'order_id' |
49 | | - ], |
50 | | - 'order_shipment' => [ |
51 | | - 'table' => 'sales_shipment', |
52 | | - 'id_column' => 'entity_id', |
53 | | - 'link_column' => 'order_id' |
54 | | - ] |
55 | | - ]; |
| 29 | + /** |
| 30 | + * @var OrderUuidManager |
| 31 | + */ |
| 32 | + private $orderUuidManager; |
56 | 33 |
|
57 | 34 | /** |
58 | 35 | * @var CommerceDataExportLoggerInterface |
59 | 36 | */ |
60 | 37 | private $logger; |
61 | 38 |
|
62 | 39 | /** |
63 | | - * @param ResourceConnection $resourceConnection |
64 | | - * @param UuidManager $uuidManager |
65 | | - * @param BatchIteratorFactory $batchIteratorFactory |
| 40 | + * @param OrderUuidManager $orderUuidManager |
| 41 | + * @param CommerceDataExportLoggerInterface $logger |
66 | 42 | */ |
67 | 43 | public function __construct( |
68 | | - ResourceConnection $resourceConnection, |
69 | | - UuidManager $uuidManager, |
70 | | - BatchIteratorFactory $batchIteratorFactory, |
| 44 | + OrderUuidManager $orderUuidManager, |
71 | 45 | CommerceDataExportLoggerInterface $logger |
72 | 46 | ) { |
73 | | - $this->uuidManager = $uuidManager; |
74 | | - $this->resourceConnection = $resourceConnection; |
75 | | - $this->batchIteratorFactory = $batchIteratorFactory; |
76 | 47 | $this->logger = $logger; |
| 48 | + $this->orderUuidManager = $orderUuidManager; |
77 | 49 | parent::__construct(); |
78 | 50 | } |
79 | 51 |
|
@@ -175,74 +147,6 @@ public function assignUuidsToOrderEntities( |
175 | 147 | string $to = null, |
176 | 148 | string $state = '' |
177 | 149 | ): int { |
178 | | - $updatedEntities = 0; |
179 | | - foreach ($this->getOrders($state, $batchSize, $from, $to) as $type => $entityIds) { |
180 | | - $this->uuidManager->assignBulk($entityIds, $type); |
181 | | - $updatedEntities += count($entityIds); |
182 | | - } |
183 | | - return $updatedEntities; |
184 | | - } |
185 | | - |
186 | | - /** |
187 | | - * @param string $state |
188 | | - * @param int $batchSize |
189 | | - * @param string|null $from |
190 | | - * @param string|null $to |
191 | | - * @return \Generator |
192 | | - */ |
193 | | - private function getOrders(string $state, int $batchSize, string $from = null, string $to = null): \Generator |
194 | | - { |
195 | | - |
196 | | - $mapTypes = array_map(function ($type) { |
197 | | - $type['table'] = $this->resourceConnection->getTableName($type['table']); |
198 | | - return $type; |
199 | | - }, $this->mapTypes); |
200 | | - |
201 | | - $connection = $this->resourceConnection->getConnection(); |
202 | | - $uuidTableName = $this->resourceConnection->getTableName('data_exporter_uuid'); |
203 | | - $orderTableName = $mapTypes['order']['table']; |
204 | | - |
205 | | - foreach ($mapTypes as $type => $data) { |
206 | | - $select = $connection->select() |
207 | | - ->from( |
208 | | - ['order' => $orderTableName], |
209 | | - [] |
210 | | - ) |
211 | | - ->joinInner( |
212 | | - ['child' => $data['table']], |
213 | | - "order.entity_id = child.{$data['link_column']}", |
214 | | - "child.{$data['id_column']} AS entity_id" |
215 | | - ) |
216 | | - ->joinLeft( |
217 | | - ['uuid' => $uuidTableName], |
218 | | - "child.{$data['id_column']} = uuid.entity_id and uuid.type = '{$type}'", |
219 | | - [] |
220 | | - ) |
221 | | - ->where('uuid.uuid IS NULL'); |
222 | | - |
223 | | - if (!empty($state)) { |
224 | | - $select->where('order.state = ?', $state); |
225 | | - } |
226 | | - if (!empty($from)) { |
227 | | - $select->where('order.created_at >= ?', $from); |
228 | | - } |
229 | | - if (!empty($to)) { |
230 | | - $select->where('order.created_at <= ?', $to); |
231 | | - } |
232 | | - |
233 | | - $iterator = $this->batchIteratorFactory->create( |
234 | | - [ |
235 | | - 'select' => $select, |
236 | | - 'batchSize' => $batchSize, |
237 | | - 'correlationName' => 'child', |
238 | | - 'rangeField' => $data['id_column'], |
239 | | - 'rangeFieldAlias' => 'entity_id' |
240 | | - ] |
241 | | - ); |
242 | | - |
243 | | - foreach ($iterator as $batchSelect) { |
244 | | - yield $type => $connection->fetchCol($batchSelect); |
245 | | - } |
246 | | - } |
| 150 | + return $this->orderUuidManager->assignByDate($batchSize, $from, $to, $state); |
247 | 151 | } |
248 | 152 | } |
0 commit comments