コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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;
 }