@@ -186,10 +186,12 @@ protected function buildStatement($event, $changelog)
186
186
$ skipColumns = ['updated_at ' ];
187
187
$ describe = $ this ->connection ->describeTable ($ this ->getTableName ());
188
188
$ columns = [];
189
- foreach ($ describe as $ column ) {
190
- if (!in_array ($ column ['COLUMN_NAME ' ], $ skipColumns )) {
191
- $ columns [] = sprintf ('NEW.%1$s <> OLD.%1$s ' ,
192
- $ this ->connection ->quoteIdentifier ($ column ['COLUMN_NAME ' ]));
189
+ if (is_array ($ describe )) {
190
+ 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 ' ]));
194
+ }
193
195
}
194
196
}
195
197
@@ -202,9 +204,17 @@ protected function buildStatement($event, $changelog)
202
204
$ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
203
205
);
204
206
case Trigger::EVENT_UPDATE :
207
+ if ($ columns ) {
208
+ return sprintf (
209
+ "IF (%s) THEN INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); END IF; " ,
210
+ implode (' OR ' , $ columns ),
211
+ $ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
212
+ $ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
213
+ $ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
214
+ );
215
+ }
205
216
return sprintf (
206
- "IF (%s) THEN INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); END IF; " ,
207
- implode (' OR ' , $ columns ),
217
+ "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s); " ,
208
218
$ this ->connection ->quoteIdentifier ($ this ->resource ->getTableName ($ changelog ->getName ())),
209
219
$ this ->connection ->quoteIdentifier ($ changelog ->getColumnName ()),
210
220
$ this ->connection ->quoteIdentifier ($ this ->getColumnName ())
0 commit comments