@@ -113,17 +113,12 @@ 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 (), $ this -> getColumnName () ));
116
+ $ trigger ->addStatement ($ this ->buildStatement ($ event , $ this ->getView ()));
117
117
118
118
// Add statements for linked views
119
119
foreach ($ this ->getLinkedViews () as $ view ) {
120
120
/** @var \Magento\Framework\Mview\ViewInterface $view */
121
- // Use the column name from specific linked view instead of
122
- // using from the one which is currently updated for all
123
- // the views.
124
- $ subscriptions = $ view ->getSubscriptions ();
125
- $ subscription = $ subscriptions [$ this ->getTableName ()];
126
- $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ->getChangelog (), $ subscription ['column ' ]));
121
+ $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ));
127
122
}
128
123
129
124
$ this ->connection ->dropTrigger ($ trigger ->getName ());
@@ -152,12 +147,7 @@ public function remove()
152
147
// Add statements for linked views
153
148
foreach ($ this ->getLinkedViews () as $ view ) {
154
149
/** @var \Magento\Framework\Mview\ViewInterface $view */
155
- // Use the column name from specific linked view instead of
156
- // using from the one which is currently updated for all
157
- // the views.
158
- $ subscriptions = $ view ->getSubscriptions ();
159
- $ subscription = $ subscriptions [$ this ->getTableName ()];
160
- $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ->getChangelog (), $ subscription ['column ' ]));
150
+ $ trigger ->addStatement ($ this ->buildStatement ($ event , $ view ));
161
151
}
162
152
163
153
$ this ->connection ->dropTrigger ($ trigger ->getName ());
@@ -203,12 +193,18 @@ protected function getLinkedViews()
203
193
* Build trigger statement for INSERT, UPDATE, DELETE events
204
194
*
205
195
* @param string $event
206
- * @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
207
- * @param string $subscriptionColumnName
196
+ * @param \Magento\Framework\Mview\ViewInterface $view
208
197
* @return string
209
198
*/
210
- protected function buildStatement ($ event , $ changelog , $ subscriptionColumnName )
199
+ protected function buildStatement ($ event , $ view )
211
200
{
201
+ // Get the subscription for the specific view and specific table.
202
+ // We will use column name from it.
203
+ $ subscription = $ view ->getSubscriptions ()[$ this ->getTableName ()];
204
+
205
+ // Get the changelog from View to get changelog column name.
206
+ $ changelog = $ view ->getChangelog ();
207
+
212
208
switch ($ event ) {
213
209
case Trigger::EVENT_INSERT :
214
210
$ trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); " ;
@@ -247,7 +243,7 @@ protected function buildStatement($event, $changelog, $subscriptionColumnName)
247
243
$ trigger ,
248
244
$ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
249
245
$ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
250
- $ this ->connection ->quoteIdentifier ($ subscriptionColumnName )
246
+ $ this ->connection ->quoteIdentifier ($ subscription [ ' column ' ] )
251
247
);
252
248
}
253
249
0 commit comments