Пример #1
0
 /**
  * Create delta for specified table
  *
  * @param string $documentName
  * @param string $deltaLogName
  * @param string $idKey
  * @return void
  */
 public function createDelta($documentName, $deltaLogName, $idKey)
 {
     if (!$this->resourceAdapter->isTableExists($deltaLogName)) {
         $triggerTable = $this->resourceAdapter->newTable($deltaLogName)->addColumn($idKey, \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['nullable' => false, 'primary' => true])->addColumn('operation', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT)->addColumn('processed', \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN, null, ['nullable' => false, 'default' => 0]);
         $this->resourceAdapter->createTable($triggerTable);
     } else {
         $this->deleteAllRecords($deltaLogName);
     }
     foreach (Trigger::getListOfEvents() as $event) {
         $triggerName = $this->resourceAdapter->getTableName('trg_' . $documentName . '_after_' . strtolower($event));
         $statement = $this->buildStatement($event, $idKey, $deltaLogName);
         $trigger = $this->triggerFactory->create()->setTime(Trigger::TIME_AFTER)->setEvent($event)->setTable($documentName);
         $triggerKey = $documentName . $event . Trigger::TIME_AFTER;
         $triggerExists = $this->isTriggerExist($triggerKey);
         if ($triggerExists) {
             $triggerName = $this->triggers[$triggerKey]['trigger_name'];
             $oldTriggerStatement = $this->triggers[$triggerKey]['action_statement'];
             if (strpos($oldTriggerStatement, $statement) !== false) {
                 unset($trigger);
                 continue;
             }
             $trigger->addStatement($oldTriggerStatement);
             $this->resourceAdapter->dropTrigger($triggerName);
         }
         $trigger->addStatement($statement)->setName($triggerName);
         $this->resourceAdapter->createTrigger($trigger);
         if (!$triggerExists) {
             $this->triggers[$triggerKey] = 1;
         }
         unset($trigger);
     }
 }
Пример #2
0
 /**
  * Remove subscription
  *
  * @return \Magento\Framework\Mview\View\SubscriptionInterface
  */
 public function remove()
 {
     foreach (Trigger::getListOfEvents() as $event) {
         $triggerName = $this->getAfterEventTriggerName($event);
         /** @var Trigger $trigger */
         $trigger = $this->triggerFactory->create()->setName($triggerName)->setTime(Trigger::TIME_AFTER)->setEvent($event)->setTable($this->resource->getTableName($this->getTableName()));
         // Add statements for linked views
         foreach ($this->getLinkedViews() as $view) {
             /** @var \Magento\Framework\Mview\ViewInterface $view */
             $trigger->addStatement($this->buildStatement($event, $view->getChangelog()));
         }
         $this->connection->dropTrigger($trigger->getName());
         // Re-create trigger if trigger used by linked views
         if ($trigger->getStatements()) {
             $this->connection->createTrigger($trigger);
         }
     }
     return $this;
 }