Skip to content

Commit

Permalink
21853: Send the view object and do all processing in buildStatement.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikunj committed Apr 14, 2020
1 parent 4035ec0 commit 320ced7
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/internal/Magento/Framework/Mview/View/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,12 @@ public function create()
->setEvent($event)
->setTable($this->resource->getTableName($this->tableName));

$trigger->addStatement($this->buildStatement($event, $this->getView()->getChangelog(), $this->getColumnName()));
$trigger->addStatement($this->buildStatement($event, $this->getView()));

// Add statements for linked views
foreach ($this->getLinkedViews() as $view) {
/** @var \Magento\Framework\Mview\ViewInterface $view */
// Use the column name from specific linked view instead of
// using from the one which is currently updated for all
// the views.
$subscriptions = $view->getSubscriptions();
$subscription = $subscriptions[$this->getTableName()];
$trigger->addStatement($this->buildStatement($event, $view->getChangelog(), $subscription['column']));
$trigger->addStatement($this->buildStatement($event, $view));
}

$this->connection->dropTrigger($trigger->getName());
Expand Down Expand Up @@ -152,12 +147,7 @@ public function remove()
// Add statements for linked views
foreach ($this->getLinkedViews() as $view) {
/** @var \Magento\Framework\Mview\ViewInterface $view */
// Use the column name from specific linked view instead of
// using from the one which is currently updated for all
// the views.
$subscriptions = $view->getSubscriptions();
$subscription = $subscriptions[$this->getTableName()];
$trigger->addStatement($this->buildStatement($event, $view->getChangelog(), $subscription['column']));
$trigger->addStatement($this->buildStatement($event, $view));
}

$this->connection->dropTrigger($trigger->getName());
Expand Down Expand Up @@ -203,12 +193,18 @@ protected function getLinkedViews()
* Build trigger statement for INSERT, UPDATE, DELETE events
*
* @param string $event
* @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
* @param string $subscriptionColumnName
* @param \Magento\Framework\Mview\ViewInterface $view
* @return string
*/
protected function buildStatement($event, $changelog, $subscriptionColumnName)
protected function buildStatement($event, $view)
{
// Get the subscription for the specific view and specific table.
// We will use column name from it.
$subscription = $view->getSubscriptions()[$this->getTableName()];

// Get the changelog from View to get changelog column name.
$changelog = $view->getChangelog();

switch ($event) {
case Trigger::EVENT_INSERT:
$trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
Expand Down Expand Up @@ -247,7 +243,7 @@ protected function buildStatement($event, $changelog, $subscriptionColumnName)
$trigger,
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
$this->connection->quoteIdentifier($changelog->getColumnName()),
$this->connection->quoteIdentifier($subscriptionColumnName)
$this->connection->quoteIdentifier($subscription['column'])
);
}

Expand Down

0 comments on commit 320ced7

Please sign in to comment.