forked from Hevelop/magento2-patches
-
Notifications
You must be signed in to change notification settings - Fork 7
/
PATCH_MDVA-4538_EE_2.1.4_v2.composer.patch
executable file
·199 lines (198 loc) · 6.27 KB
/
PATCH_MDVA-4538_EE_2.1.4_v2.composer.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
diff --git a/Model/Indexer/Source.php b/Model/Indexer/Source.php
new file mode 100644
index 0000000..2310953
--- /dev/null
+++ b/Model/Indexer/Source.php
@@ -0,0 +1,154 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Customer\Model\Indexer;
+
+use Magento\Customer\Model\ResourceModel\Customer\Indexer\Collection;
+use Magento\Framework\App\ResourceConnection\SourceProviderInterface;
+use Traversable;
+use Magento\Framework\Exception\LocalizedException;
+
+/**
+ * Customers data batch generator for customer_grid indexer
+ */
+class Source implements \IteratorAggregate, \Countable, SourceProviderInterface
+{
+ /**
+ * @var Collection
+ */
+ private $customerCollection;
+
+ /**
+ * @var int
+ */
+ private $batchSize;
+
+ /**
+ * @param \Magento\Customer\Model\ResourceModel\Customer\Indexer\CollectionFactory $collection
+ * @param int $batchSize
+ */
+ public function __construct(
+ \Magento\Customer\Model\ResourceModel\Customer\Indexer\CollectionFactory $collectionFactory,
+ $batchSize = 10000
+ ) {
+ $this->customerCollection = $collectionFactory->create();
+ $this->batchSize = $batchSize;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getMainTable()
+ {
+ return $this->customerCollection->getMainTable();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIdFieldName()
+ {
+ return $this->customerCollection->getIdFieldName();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addFieldToSelect($fieldName, $alias = null)
+ {
+ $this->customerCollection->addFieldToSelect($fieldName, $alias);
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getSelect()
+ {
+ return $this->customerCollection->getSelect();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addFieldToFilter($attribute, $condition = null)
+ {
+ $this->customerCollection->addFieldToFilter($attribute, $condition);
+ return $this;
+ }
+
+ /**
+ * @return int
+ */
+ public function count()
+ {
+ return $this->customerCollection->getSize();
+ }
+
+ /**
+ * Retrieve an iterator
+ *
+ * @return Traversable
+ */
+ public function getIterator()
+ {
+ $this->customerCollection->setPageSize($this->batchSize);
+ $lastPage = $this->customerCollection->getLastPageNumber();
+ $pageNumber = 0;
+ do {
+ $this->customerCollection->clear();
+ $this->customerCollection->setCurPage($pageNumber);
+ foreach ($this->customerCollection->getItems() as $key => $value) {
+ yield $key => $value;
+ }
+ $pageNumber++;
+ } while ($pageNumber <= $lastPage);
+ }
+
+ /**
+ * Add attribute to entities in collection
+ *
+ * If $attribute == '*' select all attributes
+ *
+ * @param array|string|integer|\Magento\Framework\App\Config\Element $attribute
+ * @param bool|string $joinType flag for joining attribute
+ * @return $this
+ * @throws LocalizedException
+ */
+ public function addAttributeToSelect($attribute, $joinType = false)
+ {
+ return $this->customerCollection->addAttributeToSelect($attribute, $joinType);
+ }
+
+ /**
+ * Add attribute from joined entity to select
+ *
+ * Examples:
+ * ('billing_firstname', 'customer_address/firstname', 'default_billing')
+ * ('billing_lastname', 'customer_address/lastname', 'default_billing')
+ * ('shipping_lastname', 'customer_address/lastname', 'default_billing')
+ * ('shipping_postalcode', 'customer_address/postalcode', 'default_shipping')
+ * ('shipping_city', $cityAttribute, 'default_shipping')
+ *
+ * Developer is encouraged to use existing instances of attributes and entities
+ * After first use of string entity name it will be cached in the collection
+ *
+ * @todo connect between joined attributes of same entity
+ * @param string $alias alias for the joined attribute
+ * @param string|\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
+ * @param string $bind attribute of the main entity to link with joined $filter
+ * @param string $filter primary key for the joined entity (entity_id default)
+ * @param string $joinType inner|left
+ * @param null $storeId
+ * @return $this
+ * @throws LocalizedException
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ * @SuppressWarnings(PHPMD.NPathComplexity)
+ */
+ public function joinAttribute($alias, $attribute, $bind, $filter = null, $joinType = 'inner', $storeId = null)
+ {
+ return $this->customerCollection->joinAttribute($alias, $attribute, $bind, $filter, $joinType, $storeId);
+ }
+}
diff --git a/Model/ResourceModel/Customer/Indexer/Collection.php b/Model/ResourceModel/Customer/Indexer/Collection.php
new file mode 100644
index 0000000..5b9716a
--- /dev/null
+++ b/Model/ResourceModel/Customer/Indexer/Collection.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Customer\Model\ResourceModel\Customer\Indexer;
+
+/**
+ * Customers collection for customer_grid indexer
+ */
+class Collection extends \Magento\Customer\Model\ResourceModel\Customer\Collection
+{
+ /**
+ * @inheritdoc
+ */
+ protected function beforeAddLoadedItem(\Magento\Framework\DataObject $item)
+ {
+ return $item;
+ }
+}
diff --git a/etc/indexer.xml b/etc/indexer.xml
index b48592c..5f64442 100644
--- a/etc/indexer.xml
+++ b/etc/indexer.xml
@@ -11,7 +11,7 @@
<title translate="true">Customer Grid</title>
<description translate="true">Rebuild Customer grid index</description>
- <fieldset name="customer" source="Magento\Customer\Model\ResourceModel\Customer\Collection"
+ <fieldset name="customer" source="Magento\Customer\Model\Indexer\Source"
provider="Magento\Customer\Model\Indexer\AttributeProvider">
<field name="name" xsi:type="searchable" dataType="text" handler="CustomerNameHandler"/>
<field name="email" xsi:type="searchable" dataType="varchar"/>