Exemple #1
0
 /**
  * @magentoConfigFixture global/resources/db/table_prefix prefix_
  */
 public function testGetTableName()
 {
     $tablePrefix = 'prefix_';
     $tableSuffix = 'suffix';
     $tableNameOrig = 'core_website';
     $tableName = $this->_model->getTableName(array($tableNameOrig, $tableSuffix));
     $this->assertContains($tablePrefix, $tableName);
     $this->assertContains($tableSuffix, $tableName);
     $this->assertContains($tableNameOrig, $tableName);
 }
 /**
  * Extract table names and prepare for cli rendering
  *
  * @param array $resources
  *
  * @return void
  */
 protected function prepareResourcesTables($resources)
 {
     $preparedResources = array();
     foreach ($resources as $resource) {
         try {
             $preparedResources[] = $this->coreResource->getTableName($resource);
         } catch (Mage_Core_Exception $e) {
         }
     }
     return $preparedResources;
 }
 /**
  * Get trigger action body for event
  *
  * @param int $entityEventId
  * @return string
  */
 public function getTriggerBody($entityEventId)
 {
     $select = $this->_connection->select()->reset()->from(array(), array('status' => new Zend_Db_Expr('?')))->joinInner(array('me' => $this->_resource->getTableName('enterprise_mview/metadata_event')), new Zend_Db_Expr('mm.metadata_id = me.metadata_id'), array())->where('mview_event_id = ?', $entityEventId);
     $update = $this->_connection->updateFromSelect($select, array('mm' => $this->_resource->getTableName('enterprise_mview/metadata')));
     $update = $this->_connection->quoteInto($update, Enterprise_Mview_Model_Metadata::STATUS_INVALID, null, 1);
     return $update . ';';
 }
 /**
  * Copy data from temporary to main redirects table
  *
  * @return void
  */
 protected function _copyRedirectsToMainTable()
 {
     $select = $this->_connection->select();
     $select->from(array('t' => self::TMP_TABLE_NAME), array('*'));
     $query = $select->insertFromSelect($this->_resource->getTableName('enterprise_urlrewrite/redirect'), array('identifier', 'target_path', 'store_id', 'category_id', 'product_id'), Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
     $this->_connection->query($query);
 }
 /**
  * Get action model name by index table and type
  *
  * @param string $indexTable
  * @param string $type
  * @return bool|string
  */
 public function getActionModelNameByIndexTable($indexTable, $type = 'all')
 {
     $indexers = $this->getIndexers();
     $actionModelName = false;
     foreach ($indexers as $indexer) {
         $prefixedTablrName = $this->_resource->getTableName($indexer->index_table);
         if ($prefixedTablrName == $indexTable && isset($indexer->action_model->{$type})) {
             $actionModelName = (string) $indexer->action_model->{$type};
             break;
         }
     }
     return $actionModelName;
 }
Exemple #6
0
 /**
  * Populate ACL with rules from external storage
  *
  * @param Magento_Acl $acl
  */
 public function populateAcl(Magento_Acl $acl)
 {
     $ruleTable = $this->_resource->getTableName("admin_rule");
     $adapter = $this->_resource->getConnection('read');
     $select = $adapter->select()->from(array('r' => $ruleTable));
     $rulesArr = $adapter->fetchAll($select);
     foreach ($rulesArr as $rule) {
         $role = $rule['role_type'] . $rule['role_id'];
         $resource = $rule['resource_id'];
         $privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null;
         if ($rule['permission'] == 'allow') {
             if ($resource === Mage_Backend_Model_Acl_Config::ACL_RESOURCE_ALL) {
                 $acl->allow($role, null, $privileges);
             }
             $acl->allow($role, $resource, $privileges);
         } else {
             if ($rule['permission'] == 'deny') {
                 $acl->deny($role, $resource, $privileges);
             }
         }
     }
 }
 /**
  * Create $total Magento customers with emails "customer_$i[at]test.com" and save mapping to MageId into
  * $this->_testMageCustomers & $this->_testMageCustomersReverted
  *
  * ATTENTION: There is warning "Test method "_createMageCustomers" in test class "..." is not public."
  * in case of method's visibility is 'protected' (after $total argument was added).
  *
  * @param int $total total count of the Magento customers to be created.
  */
 protected function _createMageCustomers($total = 13)
 {
     $tbl = $this->_resource->getTableName(Cfg::ENTITY_MAGE_CUSTOMER);
     for ($i = 1; $i <= $total; $i++) {
         $email = "customer_{$i}@test.com";
         $this->_conn->insert($tbl, [Cfg::E_CUSTOMER_A_EMAIL => $email]);
         $id = $this->_conn->lastInsertId($tbl);
         $this->_mapCustomerMageIdByIndex[$i] = $id;
         $this->_mapCustomerIndexByMageId[$id] = $i;
         $this->_logger->debug("New Magento customer #{$i} is added with ID={$id} ({$email}).");
     }
     $this->_logger->debug("Total {$total} customer were added to Magento.");
 }
Exemple #8
0
 /**
  * Populate ACL with roles from external storage
  *
  * @param Magento_Acl $acl
  */
 public function populateAcl(Magento_Acl $acl)
 {
     $roleTableName = $this->_resource->getTableName('admin_role');
     $adapter = $this->_resource->getConnection('read');
     $select = $adapter->select()->from($roleTableName)->order('tree_level');
     foreach ($adapter->fetchAll($select) as $role) {
         $parent = $role['parent_id'] > 0 ? Mage_User_Model_Acl_Role_Group::ROLE_TYPE . $role['parent_id'] : null;
         switch ($role['role_type']) {
             case Mage_User_Model_Acl_Role_Group::ROLE_TYPE:
                 $roleId = $role['role_type'] . $role['role_id'];
                 $acl->addRole($this->_objectFactory->getModelInstance('Mage_User_Model_Acl_Role_Group', array('roleId' => $roleId)), $parent);
                 break;
             case Mage_User_Model_Acl_Role_User::ROLE_TYPE:
                 $roleId = $role['role_type'] . $role['user_id'];
                 if (!$acl->hasRole($roleId)) {
                     $acl->addRole($this->_objectFactory->getModelInstance('Mage_User_Model_Acl_Role_User', array('roleId' => $roleId)), $parent);
                 } else {
                     $acl->addRoleParent($roleId, $parent);
                 }
                 break;
         }
     }
 }
 /**
  * Get table name for the entity
  *
  * @param string $entityName
  * @return string
  */
 public function getTable($entityName)
 {
     if (isset($this->_tables[$entityName])) {
         return $this->_tables[$entityName];
     }
     if (strpos($entityName, '/')) {
         $this->_tables[$entityName] = $this->_resources->getTableName($entityName);
     } elseif (!empty($this->_resourceModel)) {
         $this->_tables[$entityName] = $this->_resources->getTableName($this->_resourceModel . '/' . $entityName);
     } else {
         $this->_tables[$entityName] = $entityName;
     }
     return $this->_tables[$entityName];
 }
 /**
  * Extract table names and prepare for cli rendering
  *
  * @param array $resources
  *
  * @return void
  */
 protected function prepareResources(&$resources)
 {
     foreach ($resources as $key => &$resource) {
         try {
             $table = $this->coreResource->getTableName($resource);
         } catch (\Mage_Core_Exception $e) {
             // table not exists
             $table = false;
         }
         if ($table === false) {
             unset($resources[$key]);
         } else {
             $resource = $table;
         }
     }
 }
Exemple #11
0
 /**
  * Get real table name for db table, validated by db adapter
  *
  * @param string $tableName
  * @return string
  */
 public function getTable($tableName)
 {
     if (is_array($tableName)) {
         $cacheName = join('@', $tableName);
         list($tableName, $entitySuffix) = $tableName;
     } else {
         $cacheName = $tableName;
         $entitySuffix = null;
     }
     if (!is_null($entitySuffix)) {
         $tableName .= '_' . $entitySuffix;
     }
     if (!isset($this->_tables[$cacheName])) {
         $this->_tables[$cacheName] = $this->_resources->getTableName($tableName);
     }
     return $this->_tables[$cacheName];
 }
Exemple #12
0
 /**
  * Get table name for the entity, validated by db adapter
  *
  * @param string $entityName
  * @return string
  */
 public function getTable($entityName)
 {
     if (is_array($entityName)) {
         $cacheName = join('@', $entityName);
         list($entityName, $entitySuffix) = $entityName;
     } else {
         $cacheName = $entityName;
         $entitySuffix = null;
     }
     if (isset($this->_tables[$cacheName])) {
         return $this->_tables[$cacheName];
     }
     if (strpos($entityName, '/')) {
         if (!is_null($entitySuffix)) {
             $modelEntity = array($entityName, $entitySuffix);
         } else {
             $modelEntity = $entityName;
         }
         $this->_tables[$cacheName] = $this->_resources->getTableName($modelEntity);
     } else {
         if (!empty($this->_resourceModel)) {
             $entityName = sprintf('%s/%s', $this->_resourceModel, $entityName);
             if (!is_null($entitySuffix)) {
                 $modelEntity = array($entityName, $entitySuffix);
             } else {
                 $modelEntity = $entityName;
             }
             $this->_tables[$cacheName] = $this->_resources->getTableName($modelEntity);
         } else {
             if (!is_null($entitySuffix)) {
                 $entityName .= '_' . $entitySuffix;
             }
             $this->_tables[$cacheName] = $entityName;
         }
     }
     return $this->_tables[$cacheName];
 }
Exemple #13
0
 /**
  * Constructor
  *
  * @param Mage_Core_Model_Resource $resource
  */
 public function __construct(Mage_Core_Model_Resource $resource)
 {
     $this->_sessionTable = $resource->getTableName('core_session');
     $this->_write = $resource->getConnection('core_write');
 }
 protected function _construct()
 {
     $this->_resource = Mage::getSingleton('core/resource');
     $this->_connection = $this->_resource->getConnection('core_write');
     $this->_table = $this->_resource->getTableName($this->_table);
 }
 /**
  * Join url rewrite to select
  *
  * @param Varien_Db_Select $select
  * @param int $storeId
  * @return Mage_Catalog_Helper_Category_Url_Rewrite
  */
 public function joinTableToSelect(Varien_Db_Select $select, $storeId)
 {
     $select->joinLeft(array('url_rewrite' => $this->_resource->getTableName('core/url_rewrite')), 'url_rewrite.category_id=main_table.entity_id AND url_rewrite.is_system=1 AND ' . $this->_connection->quoteInto('url_rewrite.store_id = ? AND ', (int) $storeId) . $this->_connection->prepareSqlCondition('url_rewrite.id_path', array('like' => 'category/%')), array('request_path' => 'url_rewrite.request_path'));
     return $this;
 }
 /**
  * Join url rewrite to select
  *
  * @param Varien_Db_Select $select
  * @param int $storeId
  * @return Enterprise_Catalog_Helper_Category_UrlRewrite
  */
 public function joinTableToSelect(Varien_Db_Select $select, $storeId)
 {
     $requestPath = $this->_connection->getIfNullSql('url_rewrite.request_path', 'default_ur.request_path');
     $select->joinLeft(array('url_rewrite_category' => $this->_resource->getTableName('enterprise_catalog/category')), 'url_rewrite_category.category_id = main_table.entity_id' . ' AND ' . $this->_connection->quoteInto('url_rewrite_category.store_id = ?', (int) $storeId), array(''))->joinLeft(array('url_rewrite' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'url_rewrite_category.url_rewrite_id = url_rewrite.url_rewrite_id AND url_rewrite.is_system = 1', array(''))->joinLeft(array('default_urc' => $this->_resource->getTableName('enterprise_catalog/category')), 'default_urc.category_id = url_rewrite_category.category_id AND default_urc.store_id = 0', array(''))->joinLeft(array('default_ur' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'default_ur.url_rewrite_id = default_urc.url_rewrite_id  AND default_ur.is_system = 1', array('request_path' => $requestPath));
     return $this;
 }
 /**
  * Prepare url rewrite left join statement for given select instance and store_id parameter.
  *
  * @param Varien_Db_Select $select
  * @param int $storeId
  * @return Enterprise_Catalog_Helper_Product_UrlRewrite
  */
 public function joinTableToSelect(Varien_Db_Select $select, $storeId)
 {
     $requestPath = $this->_connection->getIfNullSql('url_rewrite.request_path', 'default_ur.request_path');
     $select->joinLeft(array('url_rewrite_product' => $this->_resource->getTableName('enterprise_catalog/product')), 'url_rewrite_product.product_id = main_table.entity_id ' . 'AND url_rewrite_product.store_id = ' . (int) $storeId, array('url_rewrite_product.product_id' => 'url_rewrite_product.product_id'))->joinLeft(array('url_rewrite' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'url_rewrite_product.url_rewrite_id = url_rewrite.url_rewrite_id AND url_rewrite.is_system = 1', array(''))->joinLeft(array('default_urp' => $this->_resource->getTableName('enterprise_catalog/product')), 'default_urp.product_id = main_table.entity_id AND default_urp.store_id = 0', array(''))->joinLeft(array('default_ur' => $this->_resource->getTableName('enterprise_urlrewrite/url_rewrite')), 'default_ur.url_rewrite_id = default_urp.url_rewrite_id', array('request_path' => $requestPath));
     return $this;
 }