@@ -113,23 +113,16 @@ public function create()
113
113
->setEvent ($ event )
114
114
->setTable ($ this ->resource ->getTableName ($ this ->tableName ));
115
115
116
- $ trigger ->addStatement ($ this ->buildStatement ($ event , $ this ->getView ()->getChangelog ()));
116
+ $ trigger ->addStatement ($ this ->buildStatement ($ event , $ this ->getView ()->getChangelog (), $ this -> getColumnName () ));
117
117
118
118
// Add statements for linked views
119
119
foreach ($ this ->getLinkedViews () as $ view ) {
120
- // Store current column name for reverting back later.
121
- $ originalColumnName = $ this ->getColumnName ();
122
-
123
120
/** @var \Magento\Framework\Mview\ViewInterface $view */
124
121
// Use the column name from specific subscription instead of
125
122
// use from the one which is currently updated.
126
123
$ subscriptions = $ view ->getSubscriptions ();
127
124
$ subscription = $ subscriptions [$ this ->getTableName ()];
128
- $ this ->columnName = $ subscription ['column ' ];
129
- $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ->getChangelog ()));
130
-
131
- // Revert back the column name.
132
- $ this ->columnName = $ originalColumnName ;
125
+ $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ->getChangelog (), $ subscription ['column ' ]));
133
126
}
134
127
135
128
$ this ->connection ->dropTrigger ($ trigger ->getName ());
@@ -157,19 +150,12 @@ public function remove()
157
150
158
151
// Add statements for linked views
159
152
foreach ($ this ->getLinkedViews () as $ view ) {
160
- // Store current column name for reverting back later.
161
- $ originalColumnName = $ this ->columnName ;
162
-
163
153
/** @var \Magento\Framework\Mview\ViewInterface $view */
164
154
// Use the column name from specific subscription instead of
165
155
// use from the one which is currently updated.
166
156
$ subscriptions = $ view ->getSubscriptions ();
167
157
$ subscription = $ subscriptions [$ this ->getTableName ()];
168
- $ this ->columnName = $ subscription ['column ' ];
169
- $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ->getChangelog ()));
170
-
171
- // Revert back the column name.
172
- $ this ->columnName = $ originalColumnName ;
158
+ $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ->getChangelog (), $ subscription ['column ' ]));
173
159
}
174
160
175
161
$ this ->connection ->dropTrigger ($ trigger ->getName ());
@@ -216,9 +202,10 @@ protected function getLinkedViews()
216
202
*
217
203
* @param string $event
218
204
* @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
205
+ * @param string $subscriptionColumnName
219
206
* @return string
220
207
*/
221
- protected function buildStatement ($ event , $ changelog )
208
+ protected function buildStatement ($ event , $ changelog, $ subscriptionColumnName )
222
209
{
223
210
switch ($ event ) {
224
211
case Trigger::EVENT_INSERT :
@@ -258,7 +245,7 @@ protected function buildStatement($event, $changelog)
258
245
$ trigger ,
259
246
$ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
260
247
$ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
261
- $ this ->connection ->quoteIdentifier ($ this -> getColumnName () )
248
+ $ this ->connection ->quoteIdentifier ($ subscriptionColumnName )
262
249
);
263
250
}
264
251
0 commit comments