Skip to content

Commit 5f421a8

Browse files
authored
[PHP 8.1]MDEE-105: Catalog Export extensions Magento 2.4.4 & PHP 8.1 compatibility (#115)
* MDEE-105: Catalog Export extensions Magento 2.4.4 & PHP 8.1 compatibility
1 parent 6595e8f commit 5f421a8

File tree

23 files changed

+97
-144
lines changed

23 files changed

+97
-144
lines changed

BundleProductDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-eav": ">=102.0.2",
2121
"magento/module-store": ">=101.0.2",

CatalogDataExporter/Model/Provider/EavAttributes/EntityEavAttributesResolver.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public function resolve(array $entitiesData, string $storeCode)
8282
$fullAttributesData = $this->eavAttributesProvider->getEavAttributesData($entityIds, $storeCode);
8383
}
8484

85-
return \array_replace($partialAttributesData, $fullAttributesData);
85+
$attributes = \array_replace($partialAttributesData, $fullAttributesData);
86+
if (empty($attributes)) {
87+
throw new UnableRetrieveData('Empty list of EAV attributes for products: ' . implode(',', $entityIds));
88+
}
89+
return $attributes;
8690
}
8791
}

CatalogDataExporter/Model/Provider/Products.php

+28-27
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function __construct(
7373
* @param array $values
7474
*
7575
* @return array
76-
*
7776
* @throws UnableRetrieveData
7877
*/
7978
public function get(array $values) : array
@@ -83,37 +82,39 @@ public function get(array $values) : array
8382
$mappedProducts = [];
8483
$attributesData = [];
8584

86-
try {
87-
foreach ($values as $value) {
88-
$scope = $value['scopeId'] ?? Store::DEFAULT_STORE_ID;
89-
$queryArguments[$scope][$value['productId']] = $value['attribute_ids'] ?? [];
90-
}
85+
foreach ($values as $value) {
86+
$scope = $value['scopeId'] ?? Store::DEFAULT_STORE_ID;
87+
$queryArguments[$scope][$value['productId']] = $value['attribute_ids'] ?? [];
88+
}
9189

92-
$connection = $this->resourceConnection->getConnection();
93-
foreach ($queryArguments as $scopeId => $productData) {
94-
$cursor = $connection->query(
95-
$this->productMainQuery->getQuery(\array_keys($productData), $scopeId ?: null)
96-
);
90+
$connection = $this->resourceConnection->getConnection();
91+
foreach ($queryArguments as $scopeId => $productData) {
92+
$cursor = $connection->query(
93+
$this->productMainQuery->getQuery(\array_keys($productData), $scopeId ?: null)
94+
);
9795

98-
while ($row = $cursor->fetch()) {
99-
$mappedProducts[$row['storeViewCode']][$row['productId']] = $row;
100-
$attributesData[$row['storeViewCode']][$row['productId']] = $productData[$row['productId']];
101-
}
96+
while ($row = $cursor->fetch()) {
97+
$mappedProducts[$row['storeViewCode']][$row['productId']] = $row;
98+
$attributesData[$row['storeViewCode']][$row['productId']] = $productData[$row['productId']];
10299
}
103-
104-
foreach ($mappedProducts as $storeCode => $products) {
105-
$output[] = \array_map(function ($row) {
106-
return $this->formatter->format($row);
107-
}, \array_replace_recursive(
108-
$products,
109-
$this->entityEavAttributesResolver->resolve($attributesData[$storeCode], $storeCode)
110-
));
111-
}
112-
} catch (\Throwable $exception) {
113-
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
114-
throw new UnableRetrieveData('Unable to retrieve product data');
100+
}
101+
if (!$mappedProducts) {
102+
$productsIds = \implode(',', \array_unique(\array_column($values, 'productId')));
103+
$scopes = \implode(',', \array_unique(\array_column($values, 'scopeId')));
104+
throw new UnableRetrieveData(
105+
\sprintf('Cannot collect product data for ids %s in scopes %s', $productsIds, $scopes)
106+
);
115107
}
116108

109+
foreach ($mappedProducts as $storeCode => $products) {
110+
$output[] = \array_map(function ($row) {
111+
return $this->formatter->format($row);
112+
}, \array_replace_recursive(
113+
$products,
114+
$this->entityEavAttributesResolver->resolve($attributesData[$storeCode], $storeCode)
115+
));
116+
}
117+
/** @phpstan-ignore-next-line */
117118
return !empty($output) ? \array_merge(...$output) : [];
118119
}
119120
}

CatalogDataExporter/Test/Integration/Category/CategoryBreadCrumbsTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function testBreadCrumbsData(): void
6868
//store 2, second store-view
6969
$data = $this->getCategoryById(402, 'custom_store_view_two');
7070

71-
7271
$this->assertContainsBreadCrumbs($data);
7372
$breadCrumbs = $data['breadcrumbs'];
7473
$expected = [
@@ -105,7 +104,7 @@ private function assertContainsSpecifiedData(array $categoryBreadCrumbs, array $
105104
{
106105
// Sort breadcrumbs by category level
107106
\usort($categoryBreadCrumbs, function ($a, $b) {
108-
return $a['categoryLevel'] > $b['categoryLevel'];
107+
return $a['categoryLevel'] <=> $b['categoryLevel'];
109108
});
110109

111110
self::assertEquals($expectedBreadCrumbs, $categoryBreadCrumbs);

CatalogDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-catalog": ">=103.0.2",
2121
"magento/module-eav": ">=102.0.2",

CatalogInventoryDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-catalog-inventory": ">=100.3.2",
2121
"magento/module-store": ">=101.0.2",

CatalogUrlRewriteDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-url-rewrite": ">=101.1.2",
2121
"magento/module-store": ">=101.0.2",

ConfigurableProductDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-configurable-product": ">=100.3.2",
2121
"magento/module-catalog": ">=103.0.2",

ConfigurationDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/framework-message-queue": ">=100.3.2",
2121
"magento/module-config": ">=101.1.2",

CustomerGroupDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.3.0||~7.4.0",
18+
"php": "~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-data-exporter": "self.version"
2121

DataExporter/Export/Extractor.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private function indexDataByArguments(array $field, array $data, bool $isRoot) :
9191
private function extractDataForNode(Info $info, Node $node, array $value)
9292
{
9393
$output = [];
94-
$isRoot = (spl_object_hash($info->getRootNode()) == spl_object_hash($node));
94+
$isRoot = (spl_object_hash($info->getRootNode()) === spl_object_hash($node));
9595
if ($node->getField()['provider']) {
9696
$key = base64_encode(json_encode($node->getField()));
9797
$providerClass = $node->getField()['provider'];
@@ -139,11 +139,13 @@ public function extract(Info $info, array $arguments = []) : array
139139
}
140140

141141
/**
142+
* Stop profiling
143+
*
142144
* @param bool $isRoot
143-
* @param $providerClass
145+
* @param string $providerClass
144146
* @param array $value
145147
*/
146-
private function profilerStop(bool $isRoot, $providerClass, array $value): void
148+
private function profilerStop(bool $isRoot, string $providerClass, array $value): void
147149
{
148150
if (!$this->profiler) {
149151
return ;
@@ -158,9 +160,11 @@ private function profilerStop(bool $isRoot, $providerClass, array $value): void
158160
}
159161

160162
/**
161-
* @return float|string
163+
* Start profiling
164+
*
165+
* @return void
162166
*/
163-
private function profilerStart()
167+
private function profilerStart(): void
164168
{
165169
if ($this->profiler) {
166170
$this->profilerTime = microtime(true);

DataExporter/Export/Processor.php

+27-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\DataExporter\Export;
99

1010
use Magento\DataExporter\Export\Request\InfoAssembler;
11+
use Magento\DataExporter\Model\Logging\CommerceDataExportLoggerInterface as LoggerInterface;
1112

1213
/**
1314
* Class Processor
@@ -36,22 +37,30 @@ class Processor
3637
*/
3738
private $rootProfileName;
3839

40+
/**
41+
* @var LoggerInterface
42+
*/
43+
private $logger;
44+
3945
/**
4046
* @param Extractor $extractor
4147
* @param Transformer $transformer
4248
* @param InfoAssembler $infoAssembler
49+
* @param LoggerInterface $logger
4350
* @param string $rootProfileName
4451
*/
4552
public function __construct(
4653
Extractor $extractor,
4754
Transformer $transformer,
4855
InfoAssembler $infoAssembler,
56+
LoggerInterface $logger,
4957
string $rootProfileName = 'Export'
5058
) {
5159
$this->extractor = $extractor;
5260
$this->transformer = $transformer;
5361
$this->infoAssembler = $infoAssembler;
5462
$this->rootProfileName = $rootProfileName;
63+
$this->logger = $logger;
5564
}
5665

5766
/**
@@ -63,8 +72,23 @@ public function __construct(
6372
*/
6473
public function process(string $fieldName, array $arguments = []) : array
6574
{
66-
$info = $this->infoAssembler->assembleFieldInfo($fieldName, $this->rootProfileName);
67-
$snapshots = $this->extractor->extract($info, $arguments);
68-
return $this->transformer->transform($info, $snapshots);
75+
try {
76+
$info = $this->infoAssembler->assembleFieldInfo($fieldName, $this->rootProfileName);
77+
$snapshots = $this->extractor->extract($info, $arguments);
78+
return $this->transformer->transform($info, $snapshots);
79+
} catch (\Throwable $exception) {
80+
$provider = empty($info) === false ? $info->getRootNode()->getField()['provider'] : '';
81+
// if error happened during data collecting we skip entire process
82+
$this->logger->error(
83+
\sprintf(
84+
'Unable to collect data for provider %s, error: %s',
85+
$provider,
86+
$exception->getMessage()
87+
),
88+
['exception' => $exception]
89+
);
90+
}
91+
92+
return [];
6993
}
7094
}

DataExporter/Model/Indexer/FeedIndexProcessorCreateUpdate.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
}
3939

4040
/**
41-
* @ingeritdoc
41+
* {@inerhitDoc}
4242
*
4343
* @param FeedIndexMetadata $metadata
4444
* @param DataSerializerInterface $serializer
@@ -50,8 +50,7 @@ public function partialReindex(
5050
DataSerializerInterface $serializer,
5151
EntityIdsProviderInterface $idsProvider,
5252
array $ids = []
53-
): void
54-
{
53+
): void {
5554
$feedIdentity = $metadata->getFeedIdentity();
5655
$arguments = [];
5756
foreach ($idsProvider->getAffectedIds($metadata, $ids) as $id) {
@@ -70,7 +69,7 @@ public function partialReindex(
7069
}
7170

7271
/**
73-
* @inheridoc
72+
* {@inerhitDoc}
7473
*
7574
* @param FeedIndexMetadata $metadata
7675
* @param DataSerializerInterface $serializer
@@ -81,8 +80,7 @@ public function fullReindex(
8180
FeedIndexMetadata $metadata,
8281
DataSerializerInterface $serializer,
8382
EntityIdsProviderInterface $idsProvider
84-
): void
85-
{
83+
): void {
8684
$this->truncateIndexTable($metadata);
8785
foreach ($idsProvider->getAllIds($metadata) as $batch) {
8886
$ids = \array_column($batch, $metadata->getFeedIdentity());

DataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-analytics": ">=100.3.2",
2121
"magento/module-query-xml": "self.version"

InventoryDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-catalog-inventory": ">=100.3.2",
2121
"magento/module-catalog": ">=103.0.2",

ParentProductDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-configurable-product": ">=100.3.2",
2121
"magento/module-catalog": ">=103.0.2",

ProductReviewDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-review": ">=100.3.2",
2121
"magento/module-store": ">=101.0.2",

ProductVariantDataExporter/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require": {
18-
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0",
18+
"php": "~7.1.3||~7.2.0||~7.3.0||~7.4.0||~8.1.0",
1919
"magento/framework": ">=102.0.2",
2020
"magento/module-data-exporter": "self.version",
2121
"magento/module-catalog": ">=103.0.2",

QueryXml/Model/Query.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function __construct(
5555
}
5656

5757
/**
58+
* Get database select object
59+
*
5860
* @return Select
5961
*/
6062
public function getSelect()
@@ -63,6 +65,8 @@ public function getSelect()
6365
}
6466

6567
/**
68+
* Get database connection name
69+
*
6670
* @return string
6771
*/
6872
public function getConnectionName()
@@ -71,6 +75,8 @@ public function getConnectionName()
7175
}
7276

7377
/**
78+
* Get array of configurations
79+
*
7480
* @return array
7581
*/
7682
public function getConfig()
@@ -79,11 +85,9 @@ public function getConfig()
7985
}
8086

8187
/**
82-
* Specify data which should be serialized to JSON
83-
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
84-
* @return mixed data which can be serialized by <b>json_encode</b>,
85-
* which is a value of any type other than a resource.
88+
* {@inerhitDoc}
8689
*/
90+
#[\ReturnTypeWillChange]
8791
public function jsonSerialize()
8892
{
8993
return [

0 commit comments

Comments
 (0)