/** * Check DB connection * * @return void * @throws \Magento\Framework\Exception\SessionException */ protected function checkConnection() { if (!$this->_write) { throw new SessionException(new Phrase('Write DB connection is not available')); } if (!$this->_write->isTableExists($this->_sessionTable)) { throw new SessionException(new Phrase('DB storage table does not exist')); } }
/** * Check DB connection * * @return void * @throws \Magento\Framework\Session\SaveHandlerException */ protected function checkConnection() { if (!$this->_write) { throw new \Magento\Framework\Session\SaveHandlerException('Write DB connection is not available'); } if (!$this->_write->isTableExists($this->_sessionTable)) { throw new \Magento\Framework\Session\SaveHandlerException('DB storage table does not exist'); } }
/** * Test for create() and drop() methods * * @return void */ public function testCreateAndDrop() { /** @var \Magento\Framework\Mview\View\Changelog $model */ $model = $this->objectManager->create('Magento\\Framework\\Mview\\View\\Changelog', ['resource' => $this->resource]); $model->setViewId('test_view_id_2'); $changelogName = $this->resource->getTableName($model->getName()); $this->assertFalse($this->connection->isTableExists($changelogName)); $model->create(); $this->assertTrue($this->connection->isTableExists($changelogName)); $model->drop(); $this->assertFalse($this->connection->isTableExists($changelogName)); }
/** * 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); } }
/** * Check is flat table for store exists * * @param int $storeId * @return bool */ protected function _isFlatTableExists($storeId) { if (!isset($this->_flatTablesExist[$storeId])) { $tableName = $this->_productIndexerHelper->getFlatTableName($storeId); $isTableExists = $this->_connection->isTableExists($tableName); $this->_flatTablesExist[$storeId] = $isTableExists ? true : false; } return $this->_flatTablesExist[$storeId]; }
/** * Get maximum version_id from changelog * * @return int * @throws \Exception */ public function getVersion() { $changelogTableName = $this->resource->getTableName($this->getName()); if (!$this->connection->isTableExists($changelogTableName)) { throw new \Exception("Table {$changelogTableName} does not exist"); } $row = $this->connection->fetchRow('SHOW TABLE STATUS LIKE ?', [$changelogTableName]); if (isset($row['Auto_increment'])) { return (int) $row['Auto_increment'] - 1; } else { throw new \Exception("Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id."); } }
/** * @param AdapterInterface $connection * @param string $tableName * @return void */ private function dropTable(AdapterInterface $connection, $tableName) { if ($connection->isTableExists($tableName)) { $connection->dropTable($tableName); } }
/** * Create table 'flag' * * @param SchemaSetupInterface $setup * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection * @return void */ private function setupFlagTable( SchemaSetupInterface $setup, \Magento\Framework\DB\Adapter\AdapterInterface $connection ) { if (!$connection->isTableExists($setup->getTable('flag'))) { $table = $connection->newTable( $setup->getTable('flag') )->addColumn( 'flag_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 'Flag Id' )->addColumn( 'flag_code', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, 255, ['nullable' => false], 'Flag Code' )->addColumn( 'state', \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, null, ['unsigned' => true, 'nullable' => false, 'default' => '0'], 'Flag State' )->addColumn( 'flag_data', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, '64k', [], 'Flag Data' )->addColumn( 'last_update', \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE], 'Date of Last Flag Update' )->addIndex( $setup->getIdxName('flag', ['last_update']), ['last_update'] )->setComment( 'Flag' ); $connection->createTable($table); } }
/** * @param AdapterInterface $adapter * @param string $tableName * @return void */ private function dropTable(AdapterInterface $adapter, $tableName) { if ($adapter->isTableExists($tableName)) { $adapter->dropTable($tableName); } }