9
9
use Magento \Customer \Model \ResourceModel \Customer \CollectionFactory as CustomerCollectionFactory ;
10
10
use Magento \Framework \DataObject ;
11
11
use Magento \Framework \DB \Select ;
12
- use Magento \ImportExport \Model \ResourceModel \CollectionByPagesIterator ;
13
- use Magento \ImportExport \Model \ResourceModel \CollectionByPagesIteratorFactory ;
14
12
15
13
/**
16
14
* Storage to check existing customers.
@@ -38,13 +36,6 @@ class Storage
38
36
*/
39
37
protected $ _pageSize ;
40
38
41
- /**
42
- * Collection by pages iterator.
43
- *
44
- * @var CollectionByPagesIterator
45
- */
46
- protected $ _byPagesIterator ;
47
-
48
39
/**
49
40
* @var CustomerCollectionFactory
50
41
*/
@@ -71,21 +62,16 @@ class Storage
71
62
72
63
/**
73
64
* @param CustomerCollectionFactory $collectionFactory
74
- * @param CollectionByPagesIteratorFactory $colIteratorFactory
75
65
* @param array $data
76
66
*/
77
67
public function __construct (
78
68
CustomerCollectionFactory $ collectionFactory ,
79
- CollectionByPagesIteratorFactory $ colIteratorFactory ,
80
69
array $ data = []
81
70
) {
82
71
$ this ->_customerCollection = isset (
83
72
$ data ['customer_collection ' ]
84
73
) ? $ data ['customer_collection ' ] : $ collectionFactory ->create ();
85
- $ this ->_pageSize = isset ($ data ['page_size ' ]) ? $ data ['page_size ' ] : 0 ;
86
- $ this ->_byPagesIterator = isset (
87
- $ data ['collection_by_pages_iterator ' ]
88
- ) ? $ data ['collection_by_pages_iterator ' ] : $ colIteratorFactory ->create ();
74
+ $ this ->_pageSize = isset ($ data ['page_size ' ]) ? (int ) $ data ['page_size ' ] : 0 ;
89
75
$ this ->customerCollectionFactory = $ collectionFactory ;
90
76
}
91
77
@@ -95,21 +81,20 @@ public function __construct(
95
81
* @param array $customerIdentifiers With keys "email" and "website_id".
96
82
* @return void
97
83
*/
98
- private function loadCustomersData (array $ customerIdentifiers )
84
+ private function loadCustomersData (array $ customerIdentifiers ): void
99
85
{
100
- $ this ->_pageSize ;
101
-
102
86
/** @var CustomerCollection $collection */
103
87
$ collection = $ this ->customerCollectionFactory ->create ();
104
88
$ collection ->removeAttributeToSelect ();
105
89
$ select = $ collection ->getSelect ();
106
90
$ customerTableId = array_keys ($ select ->getPart (Select::FROM ))[0 ];
107
91
108
- $ getChuck = function (int $ offset ) use ($ customerIdentifiers ) {
109
- return array_slice ($ customerIdentifiers , $ offset , $ this ->_pageSize );
92
+ $ pageSize = $ this ->_pageSize ?: count ($ customerIdentifiers );
93
+ $ getChuck = function (int $ offset ) use ($ customerIdentifiers , $ pageSize ) {
94
+ return array_slice ($ customerIdentifiers , $ offset , $ pageSize );
110
95
};
111
96
$ offset = 0 ;
112
- for ($ chunk = $ getChuck ($ offset ); !empty ($ chunk ); $ offset += $ this -> _pageSize , $ chunk = $ getChuck ($ offset )) {
97
+ for ($ chunk = $ getChuck ($ offset ); !empty ($ chunk ); $ offset += $ pageSize , $ chunk = $ getChuck ($ offset )) {
113
98
$ emails = array_column ($ chunk , 'email ' );
114
99
$ chunkSelect = clone $ select ;
115
100
$ chunkSelect ->where ($ customerTableId . '.email IN (?) ' , $ emails );
0 commit comments