/** * Add price indexes for catalog product flat table * * @param Varien_Object $object * @return Mage_CatalogIndex_Model_Mysql4_Indexer */ public function prepareCatalogProductFlatIndexes(Varien_Object $object) { $indexes = $object->getIndexes(); foreach (Mage::getSingleton('catalogindex/retreiver')->getCustomerGroups() as $group) { $columnName = 'display_price_group_' . $group->getId(); $indexName = 'IDX_DISPLAY_PRICE_GROUP_' . $group->getId(); $indexes[$indexName] = array('type' => 'index', 'fields' => array($columnName)); } $object->setIndexes($indexes); return $this; }
/** * Retrieve catalog product flat table indexes array * * @return array */ public function getFlatIndexes() { if (is_null($this->_indexes)) { $this->_indexes = array(); if ($this->getFlatHelper()->isAddChildData()) { $this->_indexes['PRIMARY'] = array('type' => 'primary', 'fields' => array('entity_id', 'child_id')); $this->_indexes['IDX_CHILD'] = array('type' => 'index', 'fields' => array('child_id')); $this->_indexes['IDX_IS_CHILD'] = array('type' => 'index', 'fields' => array('entity_id', 'is_child')); } else { $this->_indexes['PRIMARY'] = array('type' => 'primary', 'fields' => array('entity_id')); } $this->_indexes['IDX_TYPE_ID'] = array('type' => 'index', 'fields' => array('type_id')); $this->_indexes['IDX_ATRRIBUTE_SET'] = array('type' => 'index', 'fields' => array('attribute_set_id')); foreach ($this->getAttributes() as $attribute) { /* @var $attribute Mage_Eav_Model_Entity_Attribute */ $indexes = $attribute->setFlatAddFilterableAttributes($this->getFlatHelper()->isAddFilterableAttributes())->setFlatAddChildData($this->getFlatHelper()->isAddChildData())->getFlatIndexes(); if (is_null($indexes)) { continue; } $this->_indexes = array_merge($this->_indexes, $indexes); } $indexesObject = new Varien_Object(); $indexesObject->setIndexes($this->_indexes); Mage::dispatchEvent('catalog_product_flat_prepare_indexes', array('indexes' => $indexesObject)); $this->_indexes = $indexesObject->getIndexes(); } return $this->_indexes; }
/** * @param Varien_Object $context * @param Varien_Simplexml_Element $module * @param Varien_Simplexml_Element $entity * @param Varien_Simplexml_Element $scope */ public function _endTableScript($context, $module, $entity, $scope) { $scope = $scope; if (!empty($scope->unique)) { /* @var $resource Mage_Core_Model_Mysql4_Resource */ $resource = Mage::getResourceSingleton('core/resource'); $indexes = $context->getIndexes(); foreach ($scope->unique->children() as $unique) { $index = (object) array('unique' => 1, 'name' => 'unique_' . $unique->getName(), 'indexed_fields' => array()); $includeUniqueIndex = false; foreach ($unique->children() as $field => $def) { if ((string) $def['module'] == $this->getModuleName() && (string) $def['version'] == $this->getVersion()) { $includeUniqueIndex = true; $index->indexed_fields[] = $field; } else { $installedVersion = $resource->getDbVersion((string) $def['module'] . '_setup'); if ($installedVersion && version_compare($installedVersion, (string) $def['version']) >= 0) { $index->indexed_fields[] = $field; } } } if ($includeUniqueIndex) { if (!((string) $scope->unique['module'] == $this->getModuleName() && (string) $scope->unique['version'] == $this->getVersion())) { $index->rebuild = true; } $indexes[] = $index; } } $context->setIndexes($indexes); } $sql = $context->getSql(); $context->setTable($this->getTable((string) $module->name . '/' . (string) $entity->name . '/' . (string) $scope->name)); if ((string) $scope['module'] != $this->getModuleName() || (string) $scope['version'] != $this->getVersion()) { foreach ($context->getFields() as $field) { $sql .= "ALTER TABLE `{$context->getTable()}` ADD COLUMN ( "; $sql .= $this->_renderField($field); $sql .= ");\n"; } foreach ($context->getIndexes() as $index) { if (!empty($index->rebuild)) { $sql .= "ALTER TABLE `{$context->getTable()}` DROP KEY `" . (string) $index->name . "`"; $sql .= ";\n"; } $sql .= "ALTER TABLE `{$context->getTable()}` ADD "; $sql .= $this->_renderIndex($index); $sql .= ";\n"; } } else { if (count($context->getFields()) || count($context->getIndexes())) { $sql .= "DROP TABLE IF EXISTS `{$context->getTable()}`;\n"; $sql .= "CREATE TABLE `{$context->getTable()}` ( \n"; $sep = false; foreach ($context->getFields() as $field) { if ($sep) { $sql .= ", \n"; } else { $sep = true; } $sql .= " " . $this->_renderField($field); } foreach ($context->getIndexes() as $index) { if ($sep) { $sql .= ", \n"; } else { $sep = true; } $sql .= " " . $this->_renderIndex($index); } $sql .= "\n"; $sql .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='';\n"; } } foreach ($context->getConstraints() as $constraint) { $sql .= "ALTER TABLE `{$context->getTable()}` ADD CONSTRAINT "; $sql .= $this->_renderConstraint($context, $constraint); $sql .= ";\n"; } $context->setSql($sql); }
/** * Retrieve catalog product flat table indexes array * * @return array */ public function getFlatIndexes() { if (is_null($this->_indexes)) { $this->_indexes = array('PRIMARY' => array('type' => 'primary', 'fields' => array('entity_id', 'child_id')), 'IDX_CHILD_ID' => array('type' => 'index', 'fields' => array('child_id')), 'IDX_IS_CHILD' => array('type' => 'index', 'fields' => array('entity_id', 'is_child')), 'IDX_TYPE_ID' => array('type' => 'index', 'fields' => array('type_id')), 'IDX_ATRRIBUTE_SET' => array('type' => 'index', 'fields' => array('attribute_set_id'))); foreach ($this->getAttributes() as $attribute) { /* @var $attribute Mage_Eav_Model_Entity_Attribute */ if (is_null($attribute->getFlatColumns())) { continue; } $this->_indexes = array_merge($this->_indexes, $attribute->getFlatIndexes()); } $indexesObject = new Varien_Object(); $indexesObject->setIndexes($this->_indexes); AO::dispatchEvent('catalog_product_flat_prepare_indexes', array('indexes' => $indexesObject)); $this->_indexes = $indexesObject->getIndexes(); } return $this->_indexes; }
/** * Retrieve catalog product flat table indexes array * * @return array */ public function getFlatIndexes() { if ($this->_indexes === null) { $this->_indexes = array(); if ($this->getFlatHelper()->isAddChildData()) { $this->_indexes['PRIMARY'] = array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY, 'fields' => array('entity_id', 'child_id')); $this->_indexes['IDX_CHILD'] = array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, 'fields' => array('child_id')); $this->_indexes['IDX_IS_CHILD'] = array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, 'fields' => array('entity_id', 'is_child')); } else { $this->_indexes['PRIMARY'] = array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_PRIMARY, 'fields' => array('entity_id')); } $this->_indexes['IDX_TYPE_ID'] = array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, 'fields' => array('type_id')); $this->_indexes['IDX_ATTRIBUTE_SET'] = array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX, 'fields' => array('attribute_set_id')); foreach ($this->getAttributes() as $attribute) { /** @var $attribute Mage_Eav_Model_Entity_Attribute */ $indexes = $attribute->setFlatAddFilterableAttributes($this->getFlatHelper()->isAddFilterableAttributes())->setFlatAddChildData($this->getFlatHelper()->isAddChildData())->getFlatIndexes(); if ($indexes !== null && !empty($indexes)) { $this->_indexes = array_merge($this->_indexes, $indexes); } } $indexesObject = new Varien_Object(); $indexesObject->setIndexes($this->_indexes); Mage::dispatchEvent('enterprise_catalog_product_flat_prepare_indexes', array('indexes' => $indexesObject)); $this->_indexes = $indexesObject->getIndexes(); } return $this->_indexes; }