Skip to content

Commit 956bee0

Browse files
committed
MDEE-376: bubble up errors in link command
1 parent 001406c commit 956bee0

4 files changed

Lines changed: 36 additions & 59 deletions

File tree

SalesOrdersDataExporter/Console/Command/ExportOnDemand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\DataExporter\Model\Logging\CommerceDataExportLoggerInterface;
1414
use Magento\Framework\Console\Cli;
1515
use Magento\Framework\Intl\DateTimeFactory;
16-
use Magento\SalesOrdersDataExporter\Console\Command\Link;
1716
use Magento\SalesOrdersDataExporter\Model\Indexer\DateTimeRangeOrderProcessor;
1817
use Symfony\Component\Console\Command\Command;
1918
use Symfony\Component\Console\Input\InputArgument;
@@ -46,8 +45,7 @@ public function __construct(
4645
DateTimeRangeOrderProcessor $processor,
4746
DateTimeFactory $dateTimeFactory,
4847
Link $link
49-
)
50-
{
48+
) {
5149
$this->logger = $logger;
5250
$this->metadata = $metadata;
5351
$this->processor = $processor;
@@ -94,9 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9492
private function ensureAssignedUuids(DateTime $from, DateTime $to, OutputInterface $output): int
9593
{
9694
$returnCode = $this->linkCommand->
97-
prepareForExport(
95+
assignUuidsToOrderEntities(
9896
$this->metadata->getBatchSize(),
99-
$output,
10097
$from->format(DateTimeInterface::W3C),
10198
$to->format(DateTimeInterface::W3C)
10299
);

SalesOrdersDataExporter/Console/Command/Link.php

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -135,35 +135,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
135135
? (new \DateTime($input->getOption(self::OPTION_TO)))->format(\DateTimeInterface::W3C)
136136
: null;
137137

138-
return $this->prepareForExport($batchSize, $output, $from, $to, $state);
139-
} catch (\Throwable $e) {
140-
$output->writeln('<error>Failed to update UUID. Check logs</error>');
141-
$this->logger->error(
142-
sprintf('Command "%s" failed. Error message: %s', self::COMMAND_NAME, $e->getMessage())
143-
);
144-
145-
return Cli::RETURN_FAILURE;
146-
}
147-
}
148-
149-
/**
150-
* Updating UUID
151-
*
152-
* @param int $batchSize
153-
* @param OutputInterface $output
154-
* @param string $from
155-
* @param string $to
156-
* @param string $state
157-
* @return int
158-
*/
159-
public function prepareForExport(
160-
int $batchSize,
161-
OutputInterface $output,
162-
string $from = null,
163-
string $to = null,
164-
string $state = ''
165-
) {
166-
try {
167138
$output->writeln(
168139
sprintf(
169140
'<info>Start updating UUID with parameters [state=%s, from=%s, to=%s, batch_size=%s]</info>',
@@ -174,19 +145,16 @@ public function prepareForExport(
174145
)
175146
);
176147

177-
$updatedEntities = 0;
178-
foreach ($this->getOrders($state, $batchSize, $from, $to) as $type => $entityIds) {
179-
$this->uuidManager->assignBulk($entityIds, $type);
180-
$updatedEntities += count($entityIds);
181-
}
148+
$updatedEntities = $this->assignUuidsToOrderEntities($batchSize, $from, $to, $state);
149+
182150
$output->writeln(
183151
sprintf(
184152
'<info>Update completed successfully, %s entities updated</info>',
185153
$updatedEntities
186154
)
187155
);
188-
return Cli::RETURN_SUCCESS;
189156

157+
return CLI::RETURN_SUCCESS;
190158
} catch (\Throwable $e) {
191159
$output->writeln('<error>Failed to update UUID. Check logs</error>');
192160
$this->logger->error(
@@ -197,6 +165,29 @@ public function prepareForExport(
197165
}
198166
}
199167

168+
/**
169+
* Updating UUID
170+
*
171+
* @param int $batchSize
172+
* @param string|null $from
173+
* @param string|null $to
174+
* @param string $state
175+
* @return int
176+
*/
177+
public function assignUuidsToOrderEntities(
178+
int $batchSize,
179+
string $from = null,
180+
string $to = null,
181+
string $state = ''
182+
): int {
183+
$updatedEntities = 0;
184+
foreach ($this->getOrders($state, $batchSize, $from, $to) as $type => $entityIds) {
185+
$this->uuidManager->assignBulk($entityIds, $type);
186+
$updatedEntities += count($entityIds);
187+
}
188+
return $updatedEntities;
189+
}
190+
200191
/**
201192
* @param string $state
202193
* @param int $batchSize

SalesOrdersDataExporter/Model/OnDemandExportOrdersRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function countOrders(): int
3939
['count' => 'COUNT(*)']
4040
);
4141
$row = $connection->fetchRow($select);
42-
return $row['count'];
42+
return intval($row['count']);
4343
}
4444

45-
public function fetchOrders(int $batchSize = 100): Generator
45+
public function fetchOrders(): Generator
4646
{
4747
$tableName = $this->resourceConnection->getTableName($this->metadata->getFeedTableName());
4848
$connection = $this->resourceConnection->getConnection();
@@ -56,7 +56,7 @@ public function fetchOrders(int $batchSize = 100): Generator
5656
$iterator = $this->batchIteratorFactory->create(
5757
[
5858
'select' => $select,
59-
'batchSize' => $batchSize,
59+
'batchSize' => $this->metadata->getBatchSize(),
6060
'correlationName' => 'order',
6161
'rangeField' => 'id',
6262
'rangeFieldAlias' => 'id',

SalesOrdersDataExporter/Model/OnDemandOrdersExporter.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
use DateTimeInterface;
1212
use Magento\DataExporter\Model\Indexer\FeedIndexMetadata;
1313
use Magento\DataExporter\Model\Logging\CommerceDataExportLoggerInterface;
14-
use Magento\Framework\Console\Cli;
1514
use Magento\SalesOrdersDataExporter\Console\Command\Link;
1615
use Magento\SalesOrdersDataExporter\Model\Indexer\DateTimeRangeOrderProcessor;
17-
use Symfony\Component\Console\Output\NullOutput;
18-
use Symfony\Component\Console\Output\OutputInterface;
1916

2017
class OnDemandOrdersExporter
2118
{
@@ -36,23 +33,15 @@ public function __construct(
3633
$this->linkCommand = $linkCommand;
3734
}
3835

39-
public function export(DateTime $from, DateTime $to, OutputInterface $output = null): void
36+
public function export(DateTime $from, DateTime $to): void
4037
{
41-
$output = $output ?? new NullOutput();
42-
$this->ensureAssignedUuids($from, $to, $output);
43-
$this->processor->fullReindex($this->metadata, $from, $to);
44-
}
45-
46-
private function ensureAssignedUuids(DateTime $from, DateTime $to, OutputInterface $output): void
47-
{
48-
$returnCode = $this->linkCommand->prepareForExport(
38+
$this->linkCommand->assignUuidsToOrderEntities(
4939
$this->metadata->getBatchSize(),
50-
$output,
5140
$from->format(DateTimeInterface::W3C),
5241
$to->format(DateTimeInterface::W3C)
5342
);
54-
if ($returnCode != Cli::RETURN_SUCCESS) {
55-
$this->logger->error('Command "commerce-data-export:orders:link" failed.');
56-
}
43+
$this->processor->fullReindex($this->metadata, $from, $to);
44+
// TODO: would be interesting here to return the amount of orders indexed but impl needs further thinking
5745
}
46+
5847
}

0 commit comments

Comments
 (0)