Skip to content

Commit

Permalink
MAGETWO-94030: No condition in Catalog Staging MView triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-shcherbatykh committed Aug 23, 2018
1 parent 716dca6 commit df5597a
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions lib/internal/Magento/Framework/Mview/View/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit df5597a

Please sign in to comment.