Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/code/Magento/Eav/Model/AttributeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Eav\Model;

Expand Down Expand Up @@ -52,7 +53,7 @@ public function __construct(
* Returns array of fields
*
* @param string $entityType
* @return array
* @return string[]
* @throws \Exception
*/
public function getAttributes($entityType)
Expand All @@ -66,6 +67,7 @@ public function getAttributes($entityType)
foreach ($searchResult->getItems() as $attribute) {
$attributes[] = $attribute->getAttributeCode();
}

return $attributes;
}
}
5 changes: 4 additions & 1 deletion lib/internal/Magento/Framework/Model/EntitySnapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Model;

Expand Down Expand Up @@ -44,6 +45,8 @@ public function __construct(
}

/**
* Register snapshot of entity data.
*
* @param string $entityType
* @param object $entity
* @return void
Expand All @@ -55,7 +58,7 @@ public function registerSnapshot($entityType, $entity)
$entityData = $hydrator->extract($entity);
$attributes = $this->attributeProvider->getAttributes($entityType);
$this->snapshotData[$entityType][$entityData[$metadata->getIdentifierField()]]
= array_intersect_key($entityData, $attributes);
= array_intersect(\array_keys($entityData), $attributes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Model\EntitySnapshot;

Expand Down Expand Up @@ -53,31 +54,29 @@ public function __construct(
* Returns array of fields
*
* @param string $entityType
* @return array
* @return string[]
* @throws \Exception
*/
public function getAttributes($entityType)
{
if (!isset($this->registry[$entityType])) {
$metadata = $this->metadataPool->getMetadata($entityType);
$this->registry[$entityType] = $metadata->getEntityConnection()->describeTable($metadata->getEntityTable());
if ($metadata->getLinkField() != $metadata->getIdentifierField()) {
unset($this->registry[$entityType][$metadata->getLinkField()]);
}
$providers = [];
if (isset($this->providers[$entityType])) {
$providers = $this->providers[$entityType];
} elseif (isset($this->providers['default'])) {
$providers = $this->providers['default'];
$entityDescription = $metadata->getEntityConnection()->describeTable($metadata->getEntityTable());
if ($metadata->getLinkField() !== $metadata->getIdentifierField()) {
unset($entityDescription[$metadata->getLinkField()]);
}
$attributes = [];
$attributes[] = \array_keys($entityDescription);

$providers = $this->providers[$entityType] ?? $this->providers['default'] ?? [];
foreach ($providers as $providerClass) {
$provider = $this->objectManager->get($providerClass);
$this->registry[$entityType] = array_merge(
$this->registry[$entityType],
$provider->getAttributes($entityType)
);
$attributes[] = $provider->getAttributes($entityType);
}

$this->registry[$entityType] = \array_merge(...$attributes);
}

return $this->registry[$entityType];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Model\EntitySnapshot;

Expand All @@ -12,8 +13,10 @@
interface AttributeProviderInterface
{
/**
* Returns array of fields
*
* @param string $entityType
* @return array
* @return string[]
*/
public function getAttributes($entityType);
}