Skip to content

Commit 983e1a3

Browse files
authored
MDEE-1041: Persist x-request-id from response (#485)
1 parent bd62660 commit 983e1a3

File tree

9 files changed

+68
-3
lines changed

9 files changed

+68
-3
lines changed

CatalogDataExporter/Test/Integration/ProductDataSerializerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Magento\DataExporter\Status\ExportStatusCodeProvider;
2525
use Magento\TestFramework\Helper\Bootstrap;
2626
use Magento\DataExporter\Model\FeedExportStatusBuilder;
27+
use Magento\DataExporter\Model\Indexer\FeedIndexMetadata;
2728

2829
class ProductDataSerializerTest extends AbstractProductTestHelper
2930
{
@@ -255,6 +256,7 @@ private function prepareExpectedData(
255256
'is_deleted' => $feed['deleted'],
256257
'status' => $failedSkuPosition ? $finalStatus : $status,
257258
'errors' => $failedSkuPosition ? $errors : $exportStatus->getReasonPhrase(),
259+
FeedIndexMetadata::FEED_TABLE_FIELD_METADATA => $exportStatus->getMetadata(),
258260
'feed_data' => $this->jsonSerializer->serialize($feed),
259261
'feed_hash' => $item['feed_hash'],
260262
'feed_id' => $item['feed_id'],

CatalogDataExporter/etc/db_schema.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
nullable="true"
7676
comment="Errors"
7777
/>
78+
<column
79+
xsi:type="text"
80+
name="metadata"
81+
nullable="true"
82+
comment="metadata info"
83+
/>
7884
<constraint xsi:type="primary" referenceId="PRIMARY">
7985
<column name="id"/>
8086
</constraint>
@@ -151,6 +157,12 @@
151157
nullable="true"
152158
comment="Errors"
153159
/>
160+
<column
161+
xsi:type="text"
162+
name="metadata"
163+
nullable="true"
164+
comment="metadata info"
165+
/>
154166
<constraint xsi:type="primary" referenceId="PRIMARY">
155167
<column name="id"/>
156168
</constraint>
@@ -227,6 +239,12 @@
227239
nullable="true"
228240
comment="Errors"
229241
/>
242+
<column
243+
xsi:type="text"
244+
name="metadata"
245+
nullable="true"
246+
comment="metadata info"
247+
/>
230248
<constraint xsi:type="primary" referenceId="PRIMARY">
231249
<column name="id"/>
232250
</constraint>

DataExporter/Model/FeedExportStatus.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace Magento\DataExporter\Model;
1818

1919
use Magento\DataExporter\Status\ExportStatusCode;
20+
use Magento\Framework\App\ObjectManager;
21+
use Magento\Framework\Serialize\Serializer\Json;
2022

2123
/**
2224
* DTO class to handle result of feed export
@@ -26,20 +28,29 @@ class FeedExportStatus
2628
private ExportStatusCode $status;
2729
private string $reasonPhrase;
2830
private array $failedItems;
31+
private array $metadata;
32+
private Json $jsonSerializer;
2933

3034
/**
3135
* @param ExportStatusCode $status
3236
* @param string $reasonPhrase
3337
* @param array $failedItems
38+
* @param Json $jsonSerializer
39+
* @param array $metadata
3440
*/
3541
public function __construct(
3642
ExportStatusCode $status,
3743
string $reasonPhrase,
38-
array $failedItems
44+
array $failedItems,
45+
?Json $jsonSerializer = null,
46+
?array $metadata = []
3947
) {
4048
$this->status = $status;
4149
$this->reasonPhrase = $reasonPhrase;
4250
$this->failedItems = $failedItems;
51+
$this->metadata = $metadata;
52+
$this->jsonSerializer = $jsonSerializer
53+
?? ObjectManager::getInstance()->get(Json::class);
4354
}
4455

4556
/**
@@ -71,4 +82,14 @@ public function getStatus(): ExportStatusCode
7182
{
7283
return $this->status;
7384
}
85+
86+
/**
87+
* Get metadata
88+
*
89+
* @return string
90+
*/
91+
public function getMetadata(): string
92+
{
93+
return $this->jsonSerializer->serialize($this->metadata);
94+
}
7495
}

DataExporter/Model/FeedExportStatusBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,22 @@ public function __construct(
5858
* @param int $status
5959
* @param string $reasonPhrase
6060
* @param array $failedItems
61+
* @param array $metadata
6162
* @return FeedExportStatus
6263
*/
6364
public function build(
6465
int $status,
6566
string $reasonPhrase = '',
66-
array $failedItems = []
67+
array $failedItems = [],
68+
array $metadata = []
6769
) : FeedExportStatus {
6870
try {
6971
return $this->feedExportStatusFactory->create(
7072
[
7173
'status' => $this->buildStatusCode($status),
7274
'reasonPhrase' => $reasonPhrase,
73-
'failedItems' => $failedItems
75+
'failedItems' => $failedItems,
76+
'metadata' => $metadata
7477
]
7578
);
7679

DataExporter/Model/Indexer/DataSerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private function serializeForImmediateExport(
165165
$outputRow[FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH] = $row[
166166
FeedIndexMetadata::FEED_TABLE_FIELD_FEED_HASH
167167
];
168+
$outputRow[FeedIndexMetadata::FEED_TABLE_FIELD_METADATA] = $exportStatus->getMetadata();
168169
if (IndexStateProvider::isUpdate($row)) {
169170
$outputRow[FeedIndexMetadata::FEED_TABLE_FIELD_PK] = $row[FeedIndexMetadata::FEED_TABLE_FIELD_PK];
170171
$output[IndexStateProvider::UPDATE_OPERATION][] = $outputRow;

DataExporter/Model/Indexer/FeedIndexMetadata.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class FeedIndexMetadata
3434
public const FEED_TABLE_FIELD_FEED_DATA = 'feed_data';
3535
public const FEED_TABLE_FIELD_STATUS = 'status';
3636
public const FEED_TABLE_FIELD_ERRORS = 'errors';
37+
public const FEED_TABLE_FIELD_METADATA = 'metadata';
3738
/**
3839
* Default columns that must be updated each time when feed persisted to storage
3940
*/
@@ -44,6 +45,7 @@ class FeedIndexMetadata
4445
self::FEED_TABLE_FIELD_FEED_HASH => self::FEED_TABLE_FIELD_FEED_HASH,
4546
self::FEED_TABLE_FIELD_STATUS => self::FEED_TABLE_FIELD_STATUS,
4647
self::FEED_TABLE_FIELD_ERRORS => self::FEED_TABLE_FIELD_ERRORS,
48+
self::FEED_TABLE_FIELD_METADATA => self::FEED_TABLE_FIELD_METADATA,
4749
self::FEED_TABLE_FIELD_MODIFIED_AT => self::FEED_TABLE_FIELD_MODIFIED_AT
4850
];
4951

InventoryDataExporter/etc/db_schema.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
nullable="true"
7575
comment="Errors"
7676
/>
77+
<column
78+
xsi:type="text"
79+
name="metadata"
80+
nullable="true"
81+
comment="metadata info"
82+
/>
7783
<constraint xsi:type="primary" referenceId="PRIMARY">
7884
<column name="id"/>
7985
</constraint>

ProductPriceDataExporter/etc/db_schema.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
nullable="true"
7676
comment="Errors"
7777
/>
78+
<column
79+
xsi:type="text"
80+
name="metadata"
81+
nullable="true"
82+
comment="metadata info"
83+
/>
7884
<constraint xsi:type="primary" referenceId="PRIMARY">
7985
<column name="id"/>
8086
</constraint>

ProductVariantDataExporter/etc/db_schema.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
nullable="true"
7676
comment="Errors"
7777
/>
78+
<column
79+
xsi:type="text"
80+
name="metadata"
81+
nullable="true"
82+
comment="metadata info"
83+
/>
7884
<constraint xsi:type="primary" referenceId="PRIMARY">
7985
<column name="id"/>
8086
</constraint>

0 commit comments

Comments
 (0)