@@ -113,17 +113,12 @@ public function create()
113113 ->setEvent ($ event )
114114 ->setTable ($ this ->resource ->getTableName ($ this ->tableName ));
115115
116- $ trigger ->addStatement ($ this ->buildStatement ($ event , $ this ->getView ()-> getChangelog (), $ this -> getColumnName () ));
116+ $ trigger ->addStatement ($ this ->buildStatement ($ event , $ this ->getView ()));
117117
118118 // Add statements for linked views
119119 foreach ($ this ->getLinkedViews () as $ view ) {
120120 /** @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 ));
127122 }
128123
129124 $ this ->connection ->dropTrigger ($ trigger ->getName ());
@@ -152,12 +147,7 @@ public function remove()
152147 // Add statements for linked views
153148 foreach ($ this ->getLinkedViews () as $ view ) {
154149 /** @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 ));
161151 }
162152
163153 $ this ->connection ->dropTrigger ($ trigger ->getName ());
@@ -203,12 +193,18 @@ protected function getLinkedViews()
203193 * Build trigger statement for INSERT, UPDATE, DELETE events
204194 *
205195 * @param string $event
206- * @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
207- * @param string $subscriptionColumnName
196+ * @param \Magento\Framework\Mview\ViewInterface $view
208197 * @return string
209198 */
210- protected function buildStatement ($ event , $ changelog , $ subscriptionColumnName )
199+ protected function buildStatement ($ event , $ view )
211200 {
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+
212208 switch ($ event ) {
213209 case Trigger::EVENT_INSERT :
214210 $ trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); " ;
@@ -247,7 +243,7 @@ protected function buildStatement($event, $changelog, $subscriptionColumnName)
247243 $ trigger ,
248244 $ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
249245 $ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
250- $ this ->connection ->quoteIdentifier ($ subscriptionColumnName )
246+ $ this ->connection ->quoteIdentifier ($ subscription [ ' column ' ] )
251247 );
252248 }
253249
0 commit comments