当前位置: 首页>>代码示例>>PHP>>正文


PHP AdapterInterface::newTable方法代码示例

本文整理汇总了PHP中Magento\Framework\DB\Adapter\AdapterInterface::newTable方法的典型用法代码示例。如果您正苦于以下问题:PHP AdapterInterface::newTable方法的具体用法?PHP AdapterInterface::newTable怎么用?PHP AdapterInterface::newTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\DB\Adapter\AdapterInterface的用法示例。


在下文中一共展示了AdapterInterface::newTable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * Create changelog table
  *
  * @return void
  * @throws \Exception
  */
 public function create()
 {
     $changelogTableName = $this->resource->getTableName($this->getName());
     if (!$this->connection->isTableExists($changelogTableName)) {
         $table = $this->connection->newTable($changelogTableName)->addColumn('version_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 'Version ID')->addColumn($this->getColumnName(), \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['unsigned' => true, 'nullable' => false, 'default' => '0'], 'Entity ID');
         $this->connection->createTable($table);
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:Changelog.php

示例2: create

 /**
  * Create changelog table
  *
  * @return void
  * @throws \Exception
  */
 public function create()
 {
     $changelogTableName = $this->resource->getTableName($this->getName());
     if ($this->write->isTableExists($changelogTableName)) {
         throw new \Exception("Table {$changelogTableName} already exist");
     }
     $table = $this->write->newTable($changelogTableName)->addColumn('version_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), 'Version ID')->addColumn($this->getColumnName(), \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, array('unsigned' => true, 'nullable' => false, 'default' => '0'), 'Entity ID');
     $this->write->createTable($table);
 }
开发者ID:,项目名称:,代码行数:15,代码来源:

示例3: setUp

 protected function setUp()
 {
     $installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\Module\\Setup', array('resourceName' => 'core_setup', 'moduleName' => 'Magento_Core'));
     $this->_connection = $installer->getConnection();
     $this->_tableName = $installer->getTable('table_two_column_idx');
     $this->_oneColumnIdxName = $installer->getIdxName($this->_tableName, array('column1'));
     $this->_twoColumnIdxName = $installer->getIdxName($this->_tableName, array('column1', 'column2'));
     $table = $this->_connection->newTable($this->_tableName)->addColumn('id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, array('identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true), 'Id')->addColumn('column1', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER)->addColumn('column2', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER)->addIndex($this->_oneColumnIdxName, array('column1'))->addIndex($this->_twoColumnIdxName, array('column1', 'column2'));
     $this->_connection->createTable($table);
 }
开发者ID:aiesh,项目名称:magento2,代码行数:10,代码来源:InterfaceTest.php

示例4: setUp

 protected function setUp()
 {
     /** @var \Magento\Framework\Setup\ModuleDataSetupInterface $installer */
     $installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('\\Magento\\Framework\\Setup\\ModuleDataSetupInterface');
     $this->_connection = $installer->getConnection();
     $this->_tableName = $this->_connection->getTableName('table_two_column_idx');
     $this->_oneColumnIdxName = $this->_connection->getIndexName($this->_tableName, ['column1']);
     $this->_twoColumnIdxName = $this->_connection->getIndexName($this->_tableName, ['column1', 'column2']);
     $table = $this->_connection->newTable($this->_tableName)->addColumn('id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 'Id')->addColumn('column1', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER)->addColumn('column2', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER)->addIndex($this->_oneColumnIdxName, ['column1'])->addIndex($this->_twoColumnIdxName, ['column1', 'column2']);
     $this->_connection->createTable($table);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:InterfaceTest.php

示例5: createDelta

 /**
  * 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);
     }
 }
开发者ID:victor-v-rad,项目名称:data-migration-tool,代码行数:40,代码来源:Mysql.php

示例6: makeTempCategoryTreeIndex

 /**
  * Build and populate the temporary category tree index table
  *
  * Returns the name of the temporary table to use in queries.
  *
  * @return string
  */
 protected function makeTempCategoryTreeIndex()
 {
     // Note: this temporary table is per-connection, so won't conflict by prefix.
     $temporaryName = $this->getTemporaryTreeIndexTableName();
     $temporaryTable = $this->connection->newTable($temporaryName);
     $temporaryTable->addColumn('parent_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['nullable' => false, 'unsigned' => true]);
     $temporaryTable->addColumn('child_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, null, ['nullable' => false, 'unsigned' => true]);
     // Each entry will be unique.
     $temporaryTable->addIndex('idx_primary', ['parent_id', 'child_id'], ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY]);
     // Drop the temporary table in case it already exists on this (persistent?) connection.
     $this->connection->dropTemporaryTable($temporaryName);
     $this->connection->createTemporaryTable($temporaryTable);
     $this->fillTempCategoryTreeIndex($temporaryName);
     return $temporaryName;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:22,代码来源:AbstractAction.php

示例7: getFlatTableStructure

 /**
  * Return structure for flat catalog table
  *
  * @param string $tableName
  * @return \Magento\Framework\DB\Ddl\Table
  */
 protected function getFlatTableStructure($tableName)
 {
     $table = $this->connection->newTable($tableName)->setComment(sprintf("Catalog Category Flat", $tableName));
     //Adding columns
     foreach ($this->getColumns() as $fieldName => $fieldProp) {
         $default = $fieldProp['default'];
         if ($fieldProp['type'][0] == \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP && $default == 'CURRENT_TIMESTAMP') {
             $default = \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT;
         }
         $table->addColumn($fieldName, $fieldProp['type'][0], $fieldProp['type'][1], ['nullable' => $fieldProp['nullable'], 'unsigned' => $fieldProp['unsigned'], 'default' => $default, 'primary' => isset($fieldProp['primary']) ? $fieldProp['primary'] : false], $fieldProp['comment'] != '' ? $fieldProp['comment'] : ucwords(str_replace('_', ' ', $fieldName)));
     }
     // Adding indexes
     $table->addIndex($this->connection->getIndexName($tableName, ['entity_id']), ['entity_id'], ['type' => 'primary']);
     $table->addIndex($this->connection->getIndexName($tableName, ['store_id']), ['store_id'], ['type' => 'index']);
     $table->addIndex($this->connection->getIndexName($tableName, ['path']), ['path'], ['type' => 'index']);
     $table->addIndex($this->connection->getIndexName($tableName, ['level']), ['level'], ['type' => 'index']);
     return $table;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:24,代码来源:AbstractAction.php

示例8: _createTemporaryFlatTable

 /**
  * Prepare flat table for store
  *
  * @param int|string $storeId
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _createTemporaryFlatTable($storeId)
 {
     $columns = $this->_productIndexerHelper->getFlatColumns();
     $indexesNeed = $this->_productIndexerHelper->getFlatIndexes();
     $maxIndex = $this->_config->getValue(self::XML_NODE_MAX_INDEX_COUNT);
     if ($maxIndex && count($indexesNeed) > $maxIndex) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The Flat Catalog module has a limit of %2$d filterable and/or sortable attributes.' . 'Currently there are %1$d of them.' . 'Please reduce the number of filterable/sortable attributes in order to use this module', count($indexesNeed), $maxIndex));
     }
     $indexKeys = [];
     $indexProps = array_values($indexesNeed);
     $upperPrimaryKey = strtoupper(\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_PRIMARY);
     foreach ($indexProps as $i => $indexProp) {
         $indexName = $this->_connection->getIndexName($this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId)), $indexProp['fields'], $indexProp['type']);
         $indexProp['type'] = strtoupper($indexProp['type']);
         if ($indexProp['type'] == $upperPrimaryKey) {
             $indexKey = $upperPrimaryKey;
         } else {
             $indexKey = $indexName;
         }
         $indexProps[$i] = ['KEY_NAME' => $indexName, 'COLUMNS_LIST' => $indexProp['fields'], 'INDEX_TYPE' => strtolower($indexProp['type'])];
         $indexKeys[$i] = $indexKey;
     }
     $indexesNeed = array_combine($indexKeys, $indexProps);
     /** @var $table \Magento\Framework\DB\Ddl\Table */
     $table = $this->_connection->newTable($this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId)));
     foreach ($columns as $fieldName => $fieldProp) {
         $columnLength = isset($fieldProp['length']) ? $fieldProp['length'] : null;
         $columnDefinition = ['nullable' => isset($fieldProp['nullable']) ? (bool) $fieldProp['nullable'] : false, 'unsigned' => isset($fieldProp['unsigned']) ? (bool) $fieldProp['unsigned'] : false, 'default' => isset($fieldProp['default']) ? $fieldProp['default'] : false, 'primary' => false];
         $columnComment = isset($fieldProp['comment']) ? $fieldProp['comment'] : $fieldName;
         $table->addColumn($fieldName, $fieldProp['type'], $columnLength, $columnDefinition, $columnComment);
     }
     foreach ($indexesNeed as $indexProp) {
         $table->addIndex($indexProp['KEY_NAME'], $indexProp['COLUMNS_LIST'], ['type' => $indexProp['INDEX_TYPE']]);
     }
     $table->setComment("Catalog Product Flat (Store {$storeId})");
     $this->_connection->dropTable($this->_getTemporaryTableName($this->_productIndexerHelper->getFlatTableName($storeId)));
     $this->_connection->createTable($table);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:47,代码来源:FlatTableBuilder.php

示例9: _createTemporaryTable

 /**
  * Create empty temporary table with given columns list
  *
  * @param string $tableName  Table name
  * @param array $columns array('columnName' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute, ...)
  * @param string $valueFieldSuffix
  *
  * @return array
  */
 protected function _createTemporaryTable($tableName, array $columns, $valueFieldSuffix)
 {
     $valueTables = [];
     if (!empty($columns)) {
         $valueTableName = $tableName . $valueFieldSuffix;
         $temporaryTable = $this->_connection->newTable($tableName);
         $valueTemporaryTable = $this->_connection->newTable($valueTableName);
         $flatColumns = $this->_productIndexerHelper->getFlatColumns();
         $temporaryTable->addColumn('entity_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER);
         $temporaryTable->addColumn('type_id', \Magento\Framework\DB\Ddl\Table::TYPE_TEXT);
         $temporaryTable->addColumn('attribute_set_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER);
         $valueTemporaryTable->addColumn('entity_id', \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER);
         /** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
         foreach ($columns as $columnName => $attribute) {
             $attributeCode = $attribute->getAttributeCode();
             if (isset($flatColumns[$attributeCode])) {
                 $column = $flatColumns[$attributeCode];
             } else {
                 $column = $attribute->_getFlatColumnsDdlDefinition();
                 $column = $column[$attributeCode];
             }
             $temporaryTable->addColumn($columnName, $column['type'], isset($column['length']) ? $column['length'] : null);
             $columnValueName = $attributeCode . $valueFieldSuffix;
             if (isset($flatColumns[$columnValueName])) {
                 $columnValue = $flatColumns[$columnValueName];
                 $valueTemporaryTable->addColumn($columnValueName, $columnValue['type'], isset($columnValue['length']) ? $columnValue['length'] : null);
             }
         }
         $this->_connection->dropTemporaryTable($tableName);
         $this->_connection->createTemporaryTable($temporaryTable);
         if (count($valueTemporaryTable->getColumns()) > 1) {
             $this->_connection->dropTemporaryTable($valueTableName);
             $this->_connection->createTemporaryTable($valueTemporaryTable);
             $valueTables[$valueTableName] = $valueTableName;
         }
     }
     return $valueTables;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:47,代码来源:TableBuilder.php

示例10: setupFlagTable

 /**
  * 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);
     }
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:53,代码来源:Installer.php


注:本文中的Magento\Framework\DB\Adapter\AdapterInterface::newTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。