/**
  * @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);
 }
Example #2
0
 /**
  * Apply price grant on price index select
  *
  * @param Varien_Object $data
  * @param int $customerGroupId
  * @return Enterprise_CatalogPermissions_Model_Mysql4_Permission_Index
  */
 public function applyPriceGrantToPriceIndex($data, $customerGroupId)
 {
     $select = $data->getSelect();
     $parts = $select->getPart(Zend_Db_Select::FROM);
     if (!isset($parts['permission_index_product'])) {
         $select->joinLeft(array('permission_index_product' => $this->getTable('permission_index_product')), 'permission_index_product.category_id IS NULL AND
              permission_index_product.product_id = ' . $data->getTable() . '.entity_id AND
              permission_index_product.store_id = ' . (int) $data->getStoreId() . ' AND
              permission_index_product.customer_group_id = ' . (int) $customerGroupId, array());
     }
     if (!Mage::helper('enterprise_catalogpermissions')->isAllowedProductPrice()) {
         $select->where('permission_index_product.grant_catalog_product_price = ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_ALLOW);
     } else {
         $select->where('permission_index_product.grant_catalog_product_price != ' . Enterprise_CatalogPermissions_Model_Permission::PERMISSION_DENY . '
                  OR permission_index_product.grant_catalog_product_price IS NULL');
     }
     return $this;
 }