Skip to content

Commit 01e20d2

Browse files
author
Anton Evers
committed
prevent unit tests from failing add documentation and increase readability
1 parent 0028ce6 commit 01e20d2

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ class Subscription implements SubscriptionInterface
5252
*/
5353
protected $linkedViews = [];
5454

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+
5563
/**
5664
* @var Resource
5765
*/
@@ -175,62 +183,54 @@ protected function getLinkedViews()
175183
}
176184

177185
/**
178-
* Build trigger statement for INSER, UPDATE, DELETE events
186+
* Build trigger statement for INSERT, UPDATE, DELETE events
179187
*
180188
* @param string $event
181189
* @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
182190
* @return string
183191
*/
184192
protected function buildStatement($event, $changelog)
185193
{
186-
$skipColumns = ['updated_at'];
187-
$describe = $this->connection->describeTable($this->getTableName());
188194
$columns = [];
189-
if (is_array($describe)) {
195+
if ($describe = $this->connection->describeTable($this->getTableName())) {
190196
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;
194199
}
200+
$columns[] = sprintf(
201+
'NEW.%1$s != OLD.%1$s',
202+
$this->connection->quoteIdentifier($column['COLUMN_NAME'])
203+
);
195204
}
196205
}
197206

198207
switch ($event) {
199208
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;
206211
case Trigger::EVENT_UPDATE:
212+
$trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
207213
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;",
210216
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
214218
);
215219
}
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;
223221
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;
231224
default:
232225
return '';
226+
233227
}
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+
);
234234
}
235235

236236
/**

0 commit comments

Comments
 (0)