19
19
use Magento \DataExporter \Model \Batch \BatchGeneratorInterface ;
20
20
use Magento \DataExporter \Model \Batch \FeedSource \Generator as FeedSourceBatchGenerator ;
21
21
use Magento \DataExporter \Model \Logging \CommerceDataExportLoggerInterface ;
22
- use Magento \DataExporter \Status \ExportStatusCodeProvider ;
22
+ use Magento \DataExporter \Status \ExportStatusCodeProvider as ExportStatusCode ;
23
23
use Magento \Framework \App \ObjectManager ;
24
24
use Magento \Framework \App \ResourceConnection ;
25
25
use Magento \DataExporter \Export \Processor as ExportProcessor ;
35
35
*/
36
36
class FeedIndexProcessorCreateUpdate implements FeedIndexProcessorInterface
37
37
{
38
- /**
39
- * @var ResourceConnection
40
- */
41
38
private ResourceConnection $ resourceConnection ;
42
-
43
- /**
44
- * @var ExportProcessor
45
- */
46
39
private ExportProcessor $ exportProcessor ;
47
-
48
- /**
49
- * @var CommerceDataExportLoggerInterface
50
- */
51
40
private CommerceDataExportLoggerInterface $ logger ;
52
-
53
- /**
54
- * @var ExportFeedInterface
55
- */
56
- private $ exportFeedProcessor ;
57
-
58
- /**
59
- * @var FeedUpdater
60
- */
41
+ private ExportFeedInterface $ exportFeedProcessor ;
61
42
private FeedUpdater $ feedUpdater ;
62
-
63
- /**
64
- * @var FeedHashBuilder
65
- */
66
43
private FeedHashBuilder $ hashBuilder ;
67
-
68
- /**
69
- * @var SerializerInterface
70
- */
71
44
private SerializerInterface $ serializer ;
72
-
73
- /**
74
- * @var DeletedEntitiesProviderInterface
75
- */
76
45
private DeletedEntitiesProviderInterface $ deletedEntitiesProvider ;
77
-
78
- /**
79
- * @var ProcessManagerFactory
80
- */
81
46
private ProcessManagerFactory $ processManagerFactory ;
82
-
83
- /**
84
- * @var BatchGeneratorInterface
85
- */
86
47
private BatchGeneratorInterface $ batchGenerator ;
87
-
88
- /**
89
- * @var IndexStateProviderFactory
90
- */
91
48
private IndexStateProviderFactory $ indexStateProviderFactory ;
92
49
93
50
/**
@@ -330,7 +287,7 @@ private function filterFeedItems(
330
287
FeedIndexMetadata::FEED_TABLE_FIELD_PK ,
331
288
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID ,
332
289
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH ,
333
- FeedIndexMetadata::FEED_TABLE_FIELD_STATUS
290
+ FeedIndexMetadata::FEED_TABLE_FIELD_STATUS ,
334
291
]
335
292
)->where (sprintf ('f.%s IN (?) ' , FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID ), $ feedIdsValues );
336
293
@@ -340,29 +297,57 @@ private function filterFeedItems(
340
297
$ identifier = $ row [FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID ];
341
298
$ feedHash = $ row [FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH ];
342
299
343
- if ($ indexStateProvider !== null ) {
344
- $ indexStateProvider ->addProcessedHash ($ feedHash );
345
- }
300
+ $ indexStateProvider ?->addProcessedHash($ feedHash );
346
301
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
+ )) {
356
307
$ feedItems [$ identifier ][FeedIndexMetadata::FEED_TABLE_FIELD_PK ]
357
308
= $ row [FeedIndexMetadata::FEED_TABLE_FIELD_PK ];
309
+ $ feedItems [$ identifier ][FeedIndexMetadata::FEED_TABLE_FIELD_STATUS ]
310
+ = $ row [FeedIndexMetadata::FEED_TABLE_FIELD_STATUS ];
358
311
$ updates [] = $ feedItems [$ identifier ];
359
- unset($ feedItems [$ identifier ]);
360
312
}
313
+ unset($ feedItems [$ identifier ]);
361
314
}
362
315
}
363
316
return [$ feedItems , $ updates ];
364
317
}
365
318
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
+
366
351
/**
367
352
* Add hashes and modifiedAt field if it's required
368
353
*
@@ -399,7 +384,7 @@ private function addHashesAndModifiedAt(array $data, FeedIndexMetadata $metadata
399
384
'Identifier for feed item is empty. Skip sync for entity ' ,
400
385
[
401
386
'feed ' => $ metadata ->getFeedName (),
402
- 'item ' => var_export ($ row , true )
387
+ 'item ' => var_export ($ row , true ),
403
388
]
404
389
);
405
390
continue ;
@@ -409,7 +394,7 @@ private function addHashesAndModifiedAt(array $data, FeedIndexMetadata $metadata
409
394
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_ID => $ identifier ,
410
395
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH => $ hash ,
411
396
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_DATA => $ row ,
412
- FeedIndexMetadata::FEED_TABLE_FIELD_IS_DELETED => $ deleted
397
+ FeedIndexMetadata::FEED_TABLE_FIELD_IS_DELETED => $ deleted,
413
398
];
414
399
}
415
400
return $ data ;
0 commit comments