Skip to content

Commit 19b7238

Browse files
authored
MDEE-848: Resend invalid feed (#441)
* MDEE-848: Resend invalid feed
1 parent 087ab68 commit 19b7238

File tree

2 files changed

+51
-62
lines changed

2 files changed

+51
-62
lines changed

DataExporter/Model/Batch/Feed/Generator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ private function getSelect(
210210
): Select {
211211
$connection = $this->resourceConnection->getConnection();
212212
$sinceTimestamp = $sinceTimestamp === '1' ? (int)$sinceTimestamp : $sinceTimestamp;
213+
$skipStatus = array_merge(
214+
ExportStatusCodeProvider::NON_RETRYABLE_HTTP_STATUS_CODE,
215+
(array)ExportStatusCodeProvider::FAILED_ITEM_ERROR
216+
);
213217

214218
$subSelect = $this->resourceConnection->getConnection()
215219
->select()
@@ -219,7 +223,7 @@ private function getSelect(
219223
);
220224
if ($isExportImmediately) {
221225
$subSelect->distinct(true);
222-
$subSelect->where('st.status NOT IN (?)', ExportStatusCodeProvider::NON_RETRYABLE_HTTP_STATUS_CODE);
226+
$subSelect->where('st.status NOT IN (?)', $skipStatus);
223227
} else {
224228
$subSelect->where('st.modified_at > ?', $sinceTimestamp);
225229
}

DataExporter/Model/Indexer/FeedIndexProcessorCreateUpdate.php

Lines changed: 46 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Magento\DataExporter\Model\Batch\BatchGeneratorInterface;
2020
use Magento\DataExporter\Model\Batch\FeedSource\Generator as FeedSourceBatchGenerator;
2121
use Magento\DataExporter\Model\Logging\CommerceDataExportLoggerInterface;
22-
use Magento\DataExporter\Status\ExportStatusCodeProvider;
22+
use Magento\DataExporter\Status\ExportStatusCodeProvider as ExportStatusCode;
2323
use Magento\Framework\App\ObjectManager;
2424
use Magento\Framework\App\ResourceConnection;
2525
use Magento\DataExporter\Export\Processor as ExportProcessor;
@@ -35,59 +35,16 @@
3535
*/
3636
class FeedIndexProcessorCreateUpdate implements FeedIndexProcessorInterface
3737
{
38-
/**
39-
* @var ResourceConnection
40-
*/
4138
private ResourceConnection $resourceConnection;
42-
43-
/**
44-
* @var ExportProcessor
45-
*/
4639
private ExportProcessor $exportProcessor;
47-
48-
/**
49-
* @var CommerceDataExportLoggerInterface
50-
*/
5140
private CommerceDataExportLoggerInterface $logger;
52-
53-
/**
54-
* @var ExportFeedInterface
55-
*/
56-
private $exportFeedProcessor;
57-
58-
/**
59-
* @var FeedUpdater
60-
*/
41+
private ExportFeedInterface $exportFeedProcessor;
6142
private FeedUpdater $feedUpdater;
62-
63-
/**
64-
* @var FeedHashBuilder
65-
*/
6643
private FeedHashBuilder $hashBuilder;
67-
68-
/**
69-
* @var SerializerInterface
70-
*/
7144
private SerializerInterface $serializer;
72-
73-
/**
74-
* @var DeletedEntitiesProviderInterface
75-
*/
7645
private DeletedEntitiesProviderInterface $deletedEntitiesProvider;
77-
78-
/**
79-
* @var ProcessManagerFactory
80-
*/
8146
private ProcessManagerFactory $processManagerFactory;
82-
83-
/**
84-
* @var BatchGeneratorInterface
85-
*/
8647
private BatchGeneratorInterface $batchGenerator;
87-
88-
/**
89-
* @var IndexStateProviderFactory
90-
*/
9148
private IndexStateProviderFactory $indexStateProviderFactory;
9249

9350
/**
@@ -330,7 +287,7 @@ private function filterFeedItems(
330287
FeedIndexMetadata::FEED_TABLE_FIELD_PK,
331288
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID,
332289
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH,
333-
FeedIndexMetadata::FEED_TABLE_FIELD_STATUS
290+
FeedIndexMetadata::FEED_TABLE_FIELD_STATUS,
334291
]
335292
)->where(sprintf('f.%s IN (?)', FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID), $feedIdsValues);
336293

@@ -340,29 +297,57 @@ private function filterFeedItems(
340297
$identifier = $row[FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID];
341298
$feedHash = $row[FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH];
342299

343-
if ($indexStateProvider !== null) {
344-
$indexStateProvider->addProcessedHash($feedHash);
345-
}
300+
$indexStateProvider?->addProcessedHash($feedHash);
346301
if (isset($feedItems[$identifier][FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH])) {
347-
if (\in_array(
348-
(int)$row[FeedIndexMetadata::FEED_TABLE_FIELD_STATUS],
349-
ExportStatusCodeProvider::NON_RETRYABLE_HTTP_STATUS_CODE,
350-
true
351-
)
352-
&& $feedHash == $feedItems[$identifier][FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH]
353-
) {
354-
unset($feedItems[$identifier]);
355-
} else {
302+
if ($this->isSendNeeded(
303+
$feedItems[$identifier][FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH],
304+
$feedHash,
305+
(int)$row[FeedIndexMetadata::FEED_TABLE_FIELD_STATUS]
306+
)) {
356307
$feedItems[$identifier][FeedIndexMetadata::FEED_TABLE_FIELD_PK]
357308
= $row[FeedIndexMetadata::FEED_TABLE_FIELD_PK];
309+
$feedItems[$identifier][FeedIndexMetadata::FEED_TABLE_FIELD_STATUS]
310+
= $row[FeedIndexMetadata::FEED_TABLE_FIELD_STATUS];
358311
$updates[] = $feedItems[$identifier];
359-
unset($feedItems[$identifier]);
360312
}
313+
unset($feedItems[$identifier]);
361314
}
362315
}
363316
return [$feedItems, $updates];
364317
}
365318

319+
/**
320+
* Determines if data should be sent based on status and feed changes.
321+
*
322+
* @example
323+
* | Status | Feed Changed = Yes | Feed Changed = No |
324+
* |--------|--------------------|--------------------|
325+
* | -1 | Send | Send |
326+
* | 0 | Send | Send |
327+
* | 1 | Send | Do not send |
328+
* | 200 | Send | Do not send |
329+
* | 400 | Send | Do not send |
330+
* | 500 | Send | Send |
331+
* | 403 | Send | Send |
332+
*
333+
* @param string $oldFeedHash
334+
* @param string $newFeedHash
335+
* @param int $feedStatus
336+
* @return bool
337+
*/
338+
private function isSendNeeded(string $oldFeedHash, string $newFeedHash, int $feedStatus): bool
339+
{
340+
return $oldFeedHash !== $newFeedHash
341+
|| (
342+
!\in_array(
343+
$feedStatus,
344+
ExportStatusCode::NON_RETRYABLE_HTTP_STATUS_CODE,
345+
true
346+
)
347+
&& $feedStatus !== ExportStatusCode::FAILED_ITEM_ERROR
348+
);
349+
}
350+
366351
/**
367352
* Add hashes and modifiedAt field if it's required
368353
*
@@ -399,7 +384,7 @@ private function addHashesAndModifiedAt(array $data, FeedIndexMetadata $metadata
399384
'Identifier for feed item is empty. Skip sync for entity',
400385
[
401386
'feed' => $metadata->getFeedName(),
402-
'item' => var_export($row, true)
387+
'item' => var_export($row, true),
403388
]
404389
);
405390
continue;
@@ -409,7 +394,7 @@ private function addHashesAndModifiedAt(array $data, FeedIndexMetadata $metadata
409394
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID => $identifier,
410395
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH => $hash,
411396
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_DATA => $row,
412-
FeedIndexMetadata::FEED_TABLE_FIELD_IS_DELETED => $deleted
397+
FeedIndexMetadata::FEED_TABLE_FIELD_IS_DELETED => $deleted,
413398
];
414399
}
415400
return $data;

0 commit comments

Comments
 (0)