Skip to content

Commit e7c3e29

Browse files
committed
MAGETWO-90808: [Performance] Customer Import check data does not complete
1 parent c2c0abf commit e7c3e29

File tree

9 files changed

+78
-100
lines changed

9 files changed

+78
-100
lines changed

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class Address extends AbstractCustomer
169169
protected $_attributeCollection;
170170

171171
/**
172+
* Collection of existent addresses
173+
*
174+
* @var \Magento\Customer\Model\ResourceModel\Address\Collection
172175
* @deprecated
173176
*/
174177
protected $_addressCollection;
@@ -227,7 +230,7 @@ class Address extends AbstractCustomer
227230
protected $postcodeValidator;
228231

229232
/**
230-
* @deprecated
233+
* @var CountryWithWebsitesSource
231234
*/
232235
private $countryWithWebsites;
233236

@@ -319,9 +322,6 @@ public function __construct(
319322
$data
320323
);
321324

322-
$this->_addressCollection = isset(
323-
$data['address_collection']
324-
) ? $data['address_collection'] : $addressColFactory->create();
325325
$this->_entityTable = isset(
326326
$data['entity_table']
327327
) ? $data['entity_table'] : $addressFactory->create()->getResource()->getEntityTable();
@@ -459,18 +459,17 @@ protected function _initCountryRegions()
459459
*
460460
* @return void
461461
*/
462-
public function prepareCustomerData($rows)
462+
public function prepareCustomerData($rows): void
463463
{
464464
$customersPresent = [];
465465
foreach ($rows as $rowData) {
466-
$email = isset($rowData[static::COLUMN_EMAIL])
467-
? $rowData[static::COLUMN_EMAIL] : null;
466+
$email = $rowData[static::COLUMN_EMAIL] ?? null;
468467
$websiteId = isset($rowData[static::COLUMN_WEBSITE])
469468
? $this->getWebsiteId($rowData[static::COLUMN_WEBSITE]) : false;
470469
if ($email && $websiteId !== false) {
471470
$customersPresent[] = [
472471
'email' => $email,
473-
'website_id' => $websiteId
472+
'website_id' => $websiteId,
474473
];
475474
}
476475
}
@@ -917,7 +916,7 @@ protected function _validateRowForDelete(array $rowData, $rowNumber)
917916
if (!strlen($addressId)) {
918917
$this->addRowError(self::ERROR_ADDRESS_ID_IS_EMPTY, $rowNumber);
919918
} elseif (!$this->addressStorage->doesExist(
920-
$addressId,
919+
(string)$addressId,
921920
(string)$customerId
922921
)) {
923922
$this->addRowError(self::ERROR_ADDRESS_NOT_FOUND, $rowNumber);

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,26 +347,23 @@ protected function _getNextEntityId()
347347
}
348348

349349
/**
350-
* Pre-loading customers for existing customers checks in order
351-
* to perform mass validation/import efficiently.
350+
* Prepare customers data for existing customers checks to perform mass validation/import efficiently.
352351
*
353352
* @param array|AbstractSource $rows
354-
* and website code.
355353
*
356354
* @return void
357355
*/
358-
public function prepareCustomerData($rows)
356+
public function prepareCustomerData($rows): void
359357
{
360358
$customersPresent = [];
361359
foreach ($rows as $rowData) {
362-
$email = isset($rowData[static::COLUMN_EMAIL])
363-
? $rowData[static::COLUMN_EMAIL] : null;
360+
$email = $rowData[static::COLUMN_EMAIL] ?? null;
364361
$websiteId = isset($rowData[static::COLUMN_WEBSITE])
365362
? $this->getWebsiteId($rowData[static::COLUMN_WEBSITE]) : false;
366363
if ($email && $websiteId !== false) {
367364
$customersPresent[] = [
368365
'email' => $email,
369-
'website_id' => $websiteId
366+
'website_id' => $websiteId,
370367
];
371368
}
372369
}

app/code/Magento/CustomerImportExport/Model/Import/CustomerComposite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function validateData()
300300
foreach ($source as $row) {
301301
$rows[] = [
302302
Address::COLUMN_EMAIL => $row[Customer::COLUMN_EMAIL],
303-
Address::COLUMN_WEBSITE => $row[Customer::COLUMN_WEBSITE]
303+
Address::COLUMN_WEBSITE => $row[Customer::COLUMN_WEBSITE],
304304
];
305305
}
306306
$source->rewind();

app/code/Magento/CustomerImportExport/Model/ResourceModel/Import/Address/Storage.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ public function __construct(
6767
*
6868
* @return void
6969
*/
70-
private function addRecord(string $customerId, string $addressId)
70+
private function addRecord(string $customerId, string $addressId): void
7171
{
7272
if (!$customerId || !$addressId) {
7373
return;
7474
}
75-
$customerId = (string)$customerId;
76-
$addressId = (string)$addressId;
7775
if (!array_key_exists($customerId, $this->addresses)) {
7876
$this->addresses[$customerId] = [];
7977
}
@@ -89,9 +87,8 @@ private function addRecord(string $customerId, string $addressId)
8987
* @param string[] $customerIds
9088
*
9189
* @return void
92-
* @throws \Zend_Db_Select_Exception
9390
*/
94-
private function loadAddresses(array $customerIds)
91+
private function loadAddresses(array $customerIds): void
9592
{
9693
/** @var AddressCollection $collection */
9794
$collection = $this->addressCollectionFactory->create();
@@ -122,7 +119,7 @@ public function doesExist(string $addressId, string $forCustomerId): bool
122119
{
123120
return array_key_exists($forCustomerId, $this->addresses)
124121
&& in_array(
125-
(string)$addressId,
122+
$addressId,
126123
$this->addresses[$forCustomerId],
127124
true
128125
);
@@ -133,9 +130,8 @@ public function doesExist(string $addressId, string $forCustomerId): bool
133130
*
134131
* @param string[] $forCustomersIds
135132
* @return void
136-
* @throws \Zend_Db_Select_Exception
137133
*/
138-
public function prepareAddresses(array $forCustomersIds)
134+
public function prepareAddresses(array $forCustomersIds): void
139135
{
140136
if (!$forCustomersIds) {
141137
return;

app/code/Magento/CustomerImportExport/Model/ResourceModel/Import/Customer/Storage.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CustomerImportExport\Model\ResourceModel\Import\Customer;
77

8+
use Magento\CustomerImportExport\Test\Unit\Model\Import\CustomerCompositeTest;
89
use Magento\Framework\DataObject;
910
use Magento\Framework\DB\Select;
1011
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
@@ -15,11 +16,17 @@
1516
class Storage
1617
{
1718
/**
19+
* Flag to not load collection more than one time
20+
*
21+
* @var bool
1822
* @deprecated
1923
*/
2024
protected $_isCollectionLoaded = false;
2125

2226
/**
27+
* Customer collection
28+
*
29+
* @var \Magento\Customer\Model\ResourceModel\Customer\Collection
2330
* @deprecated
2431
*/
2532
protected $_customerCollection;
@@ -78,8 +85,9 @@ public function __construct(
7885
}
7986

8087
/**
81-
* @return void
88+
* Load needed data from customer collection
8289
*
90+
* @return void
8391
* @deprecated
8492
* @see prepareCustomers
8593
*/
@@ -104,7 +112,6 @@ public function load()
104112
* @param array[] $customerIdentifiers With keys "email" and "website_id".
105113
*
106114
* @return CustomerCollection
107-
* @throws \Zend_Db_Select_Exception
108115
*/
109116
private function prepareCollection(array $customerIdentifiers): CustomerCollection
110117
{
@@ -132,7 +139,6 @@ function (array $customer) {
132139
* @param array $customerIdentifiers With keys "email" and "website_id".
133140
*
134141
* @return void
135-
* @throws \Zend_Db_Select_Exception
136142
*/
137143
private function loadCustomersData(array $customerIdentifiers)
138144
{
@@ -147,7 +153,7 @@ private function loadCustomersData(array $customerIdentifiers)
147153
* @param array $customer
148154
* @return $this
149155
*/
150-
public function addCustomerByArray(array $customer): self
156+
public function addCustomerByArray(array $customer): Storage
151157
{
152158
$email = strtolower(trim($customer['email']));
153159
if (!isset($this->_customerIds[$email])) {
@@ -165,7 +171,7 @@ public function addCustomerByArray(array $customer): self
165171
* @param DataObject $customer
166172
* @return $this
167173
*/
168-
public function addCustomer(DataObject $customer): self
174+
public function addCustomer(DataObject $customer): Storage
169175
{
170176
$customerData = $customer->toArray();
171177
if (!isset($customerData['entity_id']) && isset($customer['id'])) {
@@ -182,7 +188,6 @@ public function addCustomer(DataObject $customer): self
182188
* @param string $email
183189
* @param int $websiteId
184190
* @return bool|int
185-
* @throws \Zend_Db_Select_Exception
186191
*/
187192
public function getCustomerId(string $email, int $websiteId)
188193
{
@@ -205,9 +210,8 @@ public function getCustomerId(string $email, int $websiteId)
205210
*
206211
* @param array[] $customersToFind With keys: email, website_id.
207212
* @return void
208-
* @throws \Zend_Db_Select_Exception
209213
*/
210-
public function prepareCustomers(array $customersToFind)
214+
public function prepareCustomers(array $customersToFind): void
211215
{
212216
$identifiers = [];
213217
foreach ($customersToFind as $customerToFind) {
@@ -221,7 +225,7 @@ public function prepareCustomers(array $customersToFind)
221225
$uniqueKey = $email .'_' .$websiteId;
222226
$identifiers[$uniqueKey] = [
223227
'email' => $email,
224-
'website_id' => $websiteId
228+
'website_id' => $websiteId,
225229
];
226230
//Recording that we've searched for a customer.
227231
if (!array_key_exists($email, $this->_customerIds)) {

app/code/Magento/CustomerImportExport/Test/Unit/Model/Import/AddressTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ protected function _createCustomerStorageMock()
261261
->willReturnCallback(
262262
function ($email, $websiteId) {
263263
foreach ($this->_customers as $customerData) {
264-
if ($customerData['email'] == $email
265-
&& $customerData['website_id'] == $websiteId
264+
if ($customerData['email'] === $email
265+
&& $customerData['website_id'] === $websiteId
266266
) {
267267
return $customerData['entity_id'];
268268
}
@@ -334,7 +334,6 @@ public function iterate(\Magento\Framework\Data\Collection $collection, $pageSiz
334334
* Create mock for custom behavior test
335335
*
336336
* @return Address|\PHPUnit_Framework_MockObject_MockObject
337-
* @throws \ReflectionException
338337
*/
339338
protected function _getModelMockForTestImportDataWithCustomBehaviour()
340339
{

0 commit comments

Comments
 (0)