|
| 1 | +commit 4ee8443a262e18c08b942aef313710b2c070a7a4 |
| 2 | +Author: Viktor Paladiichuk <vpaladiychuk@magento.com> |
| 3 | +Date: Thu Nov 16 18:55:15 2017 +0200 |
| 4 | + |
| 5 | + SET-36: Memory limit exhausted during import of customers and addresses |
| 6 | + |
| 7 | +diff --git a/vendor/magento/module-customer-import-export/Model/Import/Address.php b/vendor/magento/module-customer-import-export/Model/Import/Address.php |
| 8 | +index eb5742d24c7..70b8c34ef41 100644 |
| 9 | +--- a/vendor/magento/module-customer-import-export/Model/Import/Address.php |
| 10 | ++++ b/vendor/magento/module-customer-import-export/Model/Import/Address.php |
| 11 | +@@ -238,6 +238,11 @@ class Address extends AbstractCustomer |
| 12 | + protected $postcodeValidator; |
| 13 | + |
| 14 | + /** |
| 15 | ++ * @var array |
| 16 | ++ */ |
| 17 | ++ private $loadedAddresses; |
| 18 | ++ |
| 19 | ++ /** |
| 20 | + * @param \Magento\Framework\Stdlib\StringUtils $string |
| 21 | + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
| 22 | + * @param \Magento\ImportExport\Model\ImportFactory $importFactory |
| 23 | +@@ -368,21 +373,50 @@ class Address extends AbstractCustomer |
| 24 | + */ |
| 25 | + protected function _initAddresses() |
| 26 | + { |
| 27 | +- /** @var $address \Magento\Customer\Model\Address */ |
| 28 | +- foreach ($this->_addressCollection as $address) { |
| 29 | +- $customerId = $address->getParentId(); |
| 30 | +- if (!isset($this->_addresses[$customerId])) { |
| 31 | +- $this->_addresses[$customerId] = []; |
| 32 | ++ if ($this->_addressCollection->isLoaded()) { |
| 33 | ++ /** @var $address \Magento\Customer\Model\Address */ |
| 34 | ++ foreach ($this->_addressCollection as $address) { |
| 35 | ++ $customerId = $address->getParentId(); |
| 36 | ++ if (!isset($this->_addresses[$customerId])) { |
| 37 | ++ $this->_addresses[$customerId] = []; |
| 38 | ++ } |
| 39 | ++ $addressId = $address->getId(); |
| 40 | ++ if (!in_array($addressId, $this->_addresses[$customerId])) { |
| 41 | ++ $this->_addresses[$customerId][] = $addressId; |
| 42 | ++ } |
| 43 | + } |
| 44 | +- $addressId = $address->getId(); |
| 45 | +- if (!in_array($addressId, $this->_addresses[$customerId])) { |
| 46 | +- $this->_addresses[$customerId][] = $addressId; |
| 47 | ++ } else { |
| 48 | ++ foreach ($this->getLoadedAddresses() as $addressId => $address) { |
| 49 | ++ $customerId = $address['parent_id']; |
| 50 | ++ if (!isset($this->_addresses[$customerId])) { |
| 51 | ++ $this->_addresses[$customerId] = []; |
| 52 | ++ } |
| 53 | ++ if (!in_array($addressId, $this->_addresses[$customerId])) { |
| 54 | ++ $this->_addresses[$customerId][] = $addressId; |
| 55 | ++ } |
| 56 | + } |
| 57 | + } |
| 58 | + return $this; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | ++ * @return array |
| 63 | ++ */ |
| 64 | ++ private function getLoadedAddresses() |
| 65 | ++ { |
| 66 | ++ if (empty($this->loadedAddresses)) { |
| 67 | ++ $collection = clone $this->_addressCollection; |
| 68 | ++ $table = $collection->getMainTable(); |
| 69 | ++ $select = $collection->getSelect(); |
| 70 | ++ $select->reset('columns'); |
| 71 | ++ $select->reset('from'); |
| 72 | ++ $select->from($table, ['entity_id', 'parent_id']); |
| 73 | ++ $this->loadedAddresses = $collection->getResource()->getConnection()->fetchAssoc($select); |
| 74 | ++ } |
| 75 | ++ return $this->loadedAddresses; |
| 76 | ++ } |
| 77 | ++ |
| 78 | ++ /** |
| 79 | + * Initialize country regions hash for clever recognition |
| 80 | + * |
| 81 | + * @return $this |
| 82 | +diff --git a/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php b/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php |
| 83 | +index 4e6687bff28..359822df6d9 100644 |
| 84 | +--- a/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php |
| 85 | ++++ b/vendor/magento/module-customer-import-export/Model/ResourceModel/Import/Customer/Storage.php |
| 86 | +@@ -117,13 +117,18 @@ class Storage |
| 87 | + */ |
| 88 | + public function getCustomerId($email, $websiteId) |
| 89 | + { |
| 90 | +- // lazy loading |
| 91 | +- $this->load(); |
| 92 | ++ if (!isset($this->_customerIds[$email][$websiteId])) { |
| 93 | ++ $collection = clone $this->_customerCollection; |
| 94 | ++ $mainTable = $collection->getResource()->getEntityTable(); |
| 95 | + |
| 96 | +- if (isset($this->_customerIds[$email][$websiteId])) { |
| 97 | +- return $this->_customerIds[$email][$websiteId]; |
| 98 | +- } |
| 99 | ++ $select = $collection->getSelect(); |
| 100 | ++ $select->reset(); |
| 101 | ++ $select->from($mainTable, ['entity_id']); |
| 102 | ++ $select->where($mainTable . '.email = ?', $email); |
| 103 | ++ $select->where($mainTable . '.website_id = ?', $websiteId); |
| 104 | + |
| 105 | +- return false; |
| 106 | ++ $this->_customerIds[$email][$websiteId] = $collection->getResource()->getConnection()->fetchOne($select); |
| 107 | ++ } |
| 108 | ++ return $this->_customerIds[$email][$websiteId]; |
| 109 | + } |
| 110 | + } |
0 commit comments