Skip to content

Commit df5597a

Browse files
MAGETWO-94030: No condition in Catalog Staging MView triggers
1 parent 716dca6 commit df5597a

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

lib/internal/Magento/Framework/Mview/View/Subscription.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,33 +193,32 @@ protected function getLinkedViews()
193193
*/
194194
protected function buildStatement($event, $changelog)
195195
{
196-
$columns = [];
197-
if ($this->connection->isTableExists($this->getTableName())
198-
&& $describe = $this->connection->describeTable($this->getTableName())
199-
) {
200-
foreach ($describe as $column) {
201-
if (in_array($column['COLUMN_NAME'], $this->ignoredUpdateColumns)) {
202-
continue;
203-
}
204-
$columns[] = sprintf(
205-
'NEW.%1$s != OLD.%1$s',
206-
$this->connection->quoteIdentifier($column['COLUMN_NAME'])
207-
);
208-
}
209-
}
210-
211196
switch ($event) {
212197
case Trigger::EVENT_INSERT:
213198
$trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
214199
break;
215200
case Trigger::EVENT_UPDATE:
201+
$tableName = $this->resource->getTableName($this->getTableName());
216202
$trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
217-
if ($columns) {
218-
$trigger = sprintf(
219-
"IF (%s) THEN %s END IF;",
220-
implode(' OR ', $columns),
221-
$trigger
222-
);
203+
if ($this->connection->isTableExists($tableName) &&
204+
$describe = $this->connection->describeTable($tableName)
205+
) {
206+
$columnNames = array_column($describe, 'COLUMN_NAME');
207+
$columnNames = array_diff($columnNames, $this->ignoredUpdateColumns);
208+
if ($columnNames) {
209+
$columns = [];
210+
foreach ($columnNames as $columnName) {
211+
$columns[] = sprintf(
212+
'NEW.%1$s <=> OLD.%1$s',
213+
$this->connection->quoteIdentifier($columnName)
214+
);
215+
}
216+
$trigger = sprintf(
217+
"IF (%s) THEN %s END IF;",
218+
implode(' OR ', $columns),
219+
$trigger
220+
);
221+
}
223222
}
224223
break;
225224
case Trigger::EVENT_DELETE:

0 commit comments

Comments
 (0)