Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Subscription Class Reference
Inheritance diagram for Subscription:
SubscriptionInterface

Public Member Functions

 __construct (ResourceConnection $resource, \Magento\Framework\DB\Ddl\TriggerFactory $triggerFactory, \Magento\Framework\Mview\View\CollectionInterface $viewCollection, \Magento\Framework\Mview\ViewInterface $view, $tableName, $columnName, $ignoredUpdateColumns=[])
 
 getView ()
 
 getTableName ()
 
 getColumnName ()
 
- Public Member Functions inherited from SubscriptionInterface
 create ()
 
 remove ()
 

Protected Member Functions

 buildStatement ($event, $changelog)
 

Protected Attributes

 $connection
 
 $triggerFactory
 
 $viewCollection
 
 $view
 
 $tableName
 
 $columnName
 
 $linkedViews = []
 
 $resource
 

Detailed Description

Definition at line 18 of file Subscription.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ResourceConnection  $resource,
\Magento\Framework\DB\Ddl\TriggerFactory  $triggerFactory,
\Magento\Framework\Mview\View\CollectionInterface  $viewCollection,
\Magento\Framework\Mview\ViewInterface  $view,
  $tableName,
  $columnName,
  $ignoredUpdateColumns = [] 
)
Parameters
ResourceConnection$resource
\Magento\Framework\DB\Ddl\TriggerFactory$triggerFactory
\Magento\Framework\Mview\View\CollectionInterface$viewCollection
\Magento\Framework\Mview\ViewInterface$view
string$tableName
string$columnName
array$ignoredUpdateColumns

Definition at line 81 of file Subscription.php.

89  {
90  $this->connection = $resource->getConnection();
91  $this->triggerFactory = $triggerFactory;
92  $this->viewCollection = $viewCollection;
93  $this->view = $view;
94  $this->tableName = $tableName;
95  $this->columnName = $columnName;
96  $this->resource = $resource;
97  $this->ignoredUpdateColumns = $ignoredUpdateColumns;
98  }

Member Function Documentation

◆ buildStatement()

buildStatement (   $event,
  $changelog 
)
protected

Build trigger statement for INSERT, UPDATE, DELETE events

Parameters
string$event
\Magento\Framework\Mview\View\ChangelogInterface$changelog
Returns
string

Definition at line 199 of file Subscription.php.

200  {
201  switch ($event) {
202  case Trigger::EVENT_INSERT:
203  $trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
204  break;
205  case Trigger::EVENT_UPDATE:
206  $tableName = $this->resource->getTableName($this->getTableName());
207  $trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
208  if ($this->connection->isTableExists($tableName) &&
209  $describe = $this->connection->describeTable($tableName)
210  ) {
211  $columnNames = array_column($describe, 'COLUMN_NAME');
212  $columnNames = array_diff($columnNames, $this->ignoredUpdateColumns);
213  if ($columnNames) {
214  $columns = [];
215  foreach ($columnNames as $columnName) {
216  $columns[] = sprintf(
217  'NEW.%1$s <=> OLD.%1$s',
218  $this->connection->quoteIdentifier($columnName)
219  );
220  }
221  $trigger = sprintf(
222  "IF (%s) THEN %s END IF;",
223  implode(' OR ', $columns),
224  $trigger
225  );
226  }
227  }
228  break;
229  case Trigger::EVENT_DELETE:
230  $trigger = "INSERT IGNORE INTO %s (%s) VALUES (OLD.%s);";
231  break;
232  default:
233  return '';
234  }
235  return sprintf(
236  $trigger,
237  $this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
238  $this->connection->quoteIdentifier($changelog->getColumnName()),
239  $this->connection->quoteIdentifier($this->getColumnName())
240  );
241  }
$columns
Definition: default.phtml:15
$trigger
Definition: trigger.php:27

◆ getColumnName()

getColumnName ( )

Retrieve table column name

Returns
string @codeCoverageIgnore

Implements SubscriptionInterface.

Definition at line 287 of file Subscription.php.

◆ getTableName()

getTableName ( )

Retrieve table name

Returns
string @codeCoverageIgnore

Implements SubscriptionInterface.

Definition at line 276 of file Subscription.php.

◆ getView()

getView ( )

Retrieve View related to subscription

Returns
\Magento\Framework\Mview\ViewInterface @codeCoverageIgnore

Implements SubscriptionInterface.

Definition at line 265 of file Subscription.php.

Field Documentation

◆ $columnName

$columnName
protected

Definition at line 50 of file Subscription.php.

◆ $connection

$connection
protected

Definition at line 25 of file Subscription.php.

◆ $linkedViews

$linkedViews = []
protected

Definition at line 57 of file Subscription.php.

◆ $resource

$resource
protected

Definition at line 70 of file Subscription.php.

◆ $tableName

$tableName
protected

Definition at line 45 of file Subscription.php.

◆ $triggerFactory

$triggerFactory
protected

Definition at line 30 of file Subscription.php.

◆ $view

$view
protected

Definition at line 40 of file Subscription.php.

◆ $viewCollection

$viewCollection
protected

Definition at line 35 of file Subscription.php.


The documentation for this class was generated from the following file: