From 2f84b6816536ba85829248041e582754be8e41e5 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Mon, 15 Aug 2016 07:56:46 -0500 Subject: [PATCH 1/3] MAGETWO-56063: After upgrading from 2.0.7 to 2.1, editing a category gives a 500 error - skip loading of values for nonexistent attributes --- .../Eav/Model/ResourceModel/ReadHandler.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php b/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php index 6b32cc77188e8..72761bb0d140c 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php +++ b/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php @@ -6,6 +6,7 @@ namespace Magento\Eav\Model\ResourceModel; use Magento\Eav\Api\AttributeRepositoryInterface as AttributeRepository; +use Magento\Framework\App\ObjectManager; use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\ResourceConnection as AppResource; @@ -49,6 +50,11 @@ class ReadHandler implements AttributeInterface */ protected $scopeResolver; + /** + * @var \Psr\Log\LoggerInterface + */ + private $logger; + /** * ReadHandler constructor. * @@ -163,9 +169,30 @@ public function execute($entityType, $entityData, $arguments = []) \Magento\Framework\DB\Select::SQL_UNION_ALL ); foreach ($connection->fetchAll($unionSelect) as $attributeValue) { - $entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value']; + if (isset($attributesMap[$attributeValue['attribute_id']])) { + $entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value']; + } else { + $this->getLogger()->warning( + "Attempt to load value of nonexistent EAV attribute '{$attributeValue['attribute_id']}' + for entity type '$entityType'." + ); + } } } return $entityData; } + + /** + * Get logger + * + * @return \Psr\Log\LoggerInterface + * @deprecated + */ + private function getLogger() + { + if ($this->logger == null) { + $this->logger = ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class); + } + return $this->logger; + } } From 92b03ef7643361add5de3cf9917869ed3a56bba9 Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Tue, 16 Aug 2016 10:03:32 -0500 Subject: [PATCH 2/3] MAGETWO-56063: After upgrading from 2.0.7 to 2.1, editing a category gives a 500 error - fixed logger injection --- .../Eav/Model/ResourceModel/ReadHandler.php | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php b/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php index 72761bb0d140c..e831522aa47a4 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php +++ b/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php @@ -14,6 +14,7 @@ use Magento\Framework\Model\Entity\ScopeInterface; use Magento\Framework\EntityManager\Operation\AttributeInterface; use Magento\Eav\Model\Entity\AttributeCache; +use Psr\Log\LoggerInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -51,7 +52,7 @@ class ReadHandler implements AttributeInterface protected $scopeResolver; /** - * @var \Psr\Log\LoggerInterface + * @var LoggerInterface */ private $logger; @@ -64,6 +65,7 @@ class ReadHandler implements AttributeInterface * @param AppResource $appResource * @param ScopeResolver $scopeResolver * @param AttributeCache $attributeCache + * @param LoggerInterface $logger */ public function __construct( AttributeRepository $attributeRepository, @@ -71,7 +73,8 @@ public function __construct( SearchCriteriaBuilder $searchCriteriaBuilder, AppResource $appResource, ScopeResolver $scopeResolver, - AttributeCache $attributeCache + AttributeCache $attributeCache, + LoggerInterface $logger ) { $this->attributeRepository = $attributeRepository; $this->metadataPool = $metadataPool; @@ -79,6 +82,7 @@ public function __construct( $this->appResource = $appResource; $this->scopeResolver = $scopeResolver; $this->attributeCache = $attributeCache; + $this->logger = $logger; } /** @@ -172,7 +176,7 @@ public function execute($entityType, $entityData, $arguments = []) if (isset($attributesMap[$attributeValue['attribute_id']])) { $entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value']; } else { - $this->getLogger()->warning( + $this->logger->warning( "Attempt to load value of nonexistent EAV attribute '{$attributeValue['attribute_id']}' for entity type '$entityType'." ); @@ -181,18 +185,4 @@ public function execute($entityType, $entityData, $arguments = []) } return $entityData; } - - /** - * Get logger - * - * @return \Psr\Log\LoggerInterface - * @deprecated - */ - private function getLogger() - { - if ($this->logger == null) { - $this->logger = ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class); - } - return $this->logger; - } } From ecf51097a0a5fa341ad4c70ceb74ca762658823f Mon Sep 17 00:00:00 2001 From: Olga Kopylova Date: Tue, 16 Aug 2016 22:35:22 -0500 Subject: [PATCH 3/3] MAGETWO-56063: After upgrading from 2.0.7 to 2.1, editing a category gives a 500 error - removed unused code --- app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php b/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php index e831522aa47a4..723d05b92c512 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php +++ b/app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php @@ -6,7 +6,6 @@ namespace Magento\Eav\Model\ResourceModel; use Magento\Eav\Api\AttributeRepositoryInterface as AttributeRepository; -use Magento\Framework\App\ObjectManager; use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\App\ResourceConnection as AppResource;