From df5597a2e417a3ce16e3f4e31e719a3da3589414 Mon Sep 17 00:00:00 2001 From: Shcherbatykh Nikita Date: Thu, 23 Aug 2018 17:10:27 +0300 Subject: [PATCH] MAGETWO-94030: No condition in Catalog Staging MView triggers --- .../Framework/Mview/View/Subscription.php | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/internal/Magento/Framework/Mview/View/Subscription.php b/lib/internal/Magento/Framework/Mview/View/Subscription.php index 2f781dcad0abe..e464770b0540a 100644 --- a/lib/internal/Magento/Framework/Mview/View/Subscription.php +++ b/lib/internal/Magento/Framework/Mview/View/Subscription.php @@ -193,33 +193,32 @@ protected function getLinkedViews() */ protected function buildStatement($event, $changelog) { - $columns = []; - if ($this->connection->isTableExists($this->getTableName()) - && $describe = $this->connection->describeTable($this->getTableName()) - ) { - foreach ($describe as $column) { - if (in_array($column['COLUMN_NAME'], $this->ignoredUpdateColumns)) { - continue; - } - $columns[] = sprintf( - 'NEW.%1$s != OLD.%1$s', - $this->connection->quoteIdentifier($column['COLUMN_NAME']) - ); - } - } - switch ($event) { case Trigger::EVENT_INSERT: $trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);"; break; case Trigger::EVENT_UPDATE: + $tableName = $this->resource->getTableName($this->getTableName()); $trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);"; - if ($columns) { - $trigger = sprintf( - "IF (%s) THEN %s END IF;", - implode(' OR ', $columns), - $trigger - ); + if ($this->connection->isTableExists($tableName) && + $describe = $this->connection->describeTable($tableName) + ) { + $columnNames = array_column($describe, 'COLUMN_NAME'); + $columnNames = array_diff($columnNames, $this->ignoredUpdateColumns); + if ($columnNames) { + $columns = []; + foreach ($columnNames as $columnName) { + $columns[] = sprintf( + 'NEW.%1$s <=> OLD.%1$s', + $this->connection->quoteIdentifier($columnName) + ); + } + $trigger = sprintf( + "IF (%s) THEN %s END IF;", + implode(' OR ', $columns), + $trigger + ); + } } break; case Trigger::EVENT_DELETE: