@@ -52,6 +52,14 @@ class Subscription implements SubscriptionInterface
52
52
*/
53
53
protected $ linkedViews = [];
54
54
55
+ /**
56
+ * List of columns that can be updated in a subscribed table
57
+ * without creating a new change log entry
58
+ *
59
+ * @var array
60
+ */
61
+ protected $ ignoredUpdateColumns = ['updated_at ' ];
62
+
55
63
/**
56
64
* @var Resource
57
65
*/
@@ -175,62 +183,54 @@ protected function getLinkedViews()
175
183
}
176
184
177
185
/**
178
- * Build trigger statement for INSER , UPDATE, DELETE events
186
+ * Build trigger statement for INSERT , UPDATE, DELETE events
179
187
*
180
188
* @param string $event
181
189
* @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
182
190
* @return string
183
191
*/
184
192
protected function buildStatement ($ event , $ changelog )
185
193
{
186
- $ skipColumns = ['updated_at ' ];
187
- $ describe = $ this ->connection ->describeTable ($ this ->getTableName ());
188
194
$ columns = [];
189
- if (is_array ( $ describe )) {
195
+ if ($ describe = $ this -> connection -> describeTable ( $ this -> getTableName () )) {
190
196
foreach ($ describe as $ column ) {
191
- if (!in_array ($ column ['COLUMN_NAME ' ], $ skipColumns )) {
192
- $ columns [] = sprintf ('NEW.%1$s != OLD.%1$s ' ,
193
- $ this ->connection ->quoteIdentifier ($ column ['COLUMN_NAME ' ]));
197
+ if (in_array ($ column ['COLUMN_NAME ' ], $ this ->ignoredUpdateColumns )) {
198
+ continue ;
194
199
}
200
+ $ columns [] = sprintf (
201
+ 'NEW.%1$s != OLD.%1$s ' ,
202
+ $ this ->connection ->quoteIdentifier ($ column ['COLUMN_NAME ' ])
203
+ );
195
204
}
196
205
}
197
206
198
207
switch ($ event ) {
199
208
case Trigger::EVENT_INSERT :
200
- return sprintf (
201
- "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); " ,
202
- $ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
203
- $ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
204
- $ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
205
- );
209
+ $ trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); " ;
210
+ break ;
206
211
case Trigger::EVENT_UPDATE :
212
+ $ trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); " ;
207
213
if ($ columns ) {
208
- return sprintf (
209
- "IF (%s) THEN INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); END IF; " ,
214
+ $ trigger = sprintf (
215
+ "IF (%s) THEN %s END IF; " ,
210
216
implode (' OR ' , $ columns ),
211
- $ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
212
- $ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
213
- $ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
217
+ $ trigger
214
218
);
215
219
}
216
- return sprintf (
217
- "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); " ,
218
- $ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
219
- $ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
220
- $ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
221
- );
222
-
220
+ break ;
223
221
case Trigger::EVENT_DELETE :
224
- return sprintf (
225
- "INSERT IGNORE INTO %s (%s) VALUES (OLD.%s); " ,
226
- $ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
227
- $ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
228
- $ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
229
- );
230
-
222
+ $ trigger = "INSERT IGNORE INTO %s (%s) VALUES (OLD.%s); " ;
223
+ break ;
231
224
default :
232
225
return '' ;
226
+
233
227
}
228
+ return sprintf (
229
+ $ trigger ,
230
+ $ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
231
+ $ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
232
+ $ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
233
+ );
234
234
}
235
235
236
236
/**
0 commit comments