/** * @param Mana_Seo_Model_UrlIndexer $indexer * @param Mana_Seo_Model_Schema $schema * @param array $options */ public function process($indexer, $schema, $options) { if (!isset($options['cms_page_id']) && !isset($options['store_id']) && !isset($options['schema_global_id']) && !isset($options['schema_store_id']) && !$options['reindex_all']) { return; } $db = $this->_getWriteAdapter(); $fields = array('url_key' => new Zend_Db_Expr('`p`.`identifier`'), 'type' => new Zend_Db_Expr("'cms_page'"), 'is_page' => new Zend_Db_Expr('1'), 'is_parameter' => new Zend_Db_Expr('0'), 'is_attribute_value' => new Zend_Db_Expr('0'), 'is_category_value' => new Zend_Db_Expr('0'), 'schema_id' => new Zend_Db_Expr($schema->getId()), 'cms_page_id' => new Zend_Db_Expr('`p`.`page_id`'), 'unique_key' => new Zend_Db_Expr("CONCAT(`p`.`page_id`, '-', `p`.`identifier`)"), 'status' => new Zend_Db_Expr("IF(`p`.`is_active`, '" . Mana_Seo_Model_Url::STATUS_ACTIVE . "', '" . Mana_Seo_Model_Url::STATUS_DISABLED . "')"), 'description' => new Zend_Db_Expr("CONCAT('{$this->seoHelper()->__('CMS page')} \\'', " . "`p`.`title`, '\\' (ID ', `p`.`page_id`, ')')")); /* @var $select Varien_Db_Select */ $select = $db->select()->distinct()->from(array('p' => $this->getTable('cms/page_tree')), null)->columns($fields)->where('`p`.`store_id` = ? OR `p`.`store_id` = 0', $schema->getStoreId())->where('`p`.`identifier` <> \'\''); $obsoleteCondition = "(`schema_id` = " . $schema->getId() . ") AND (`is_page` = 1) AND (`type` = 'cms_page')"; if (isset($options['cms_page_id'])) { $select->where('`p`.`page_id` = ?', $options['cms_page_id']); $obsoleteCondition .= ' AND (`cms_page_id` = ' . $options['cms_page_id'] . ')'; } // convert SELECT into UPDATE which acts as INSERT on DUPLICATE unique keys $this->logger()->logUrlIndexer('-----------------------------'); $this->logger()->logUrlIndexer(get_class($this)); $this->logger()->logUrlIndexer($select->__toString()); $this->logger()->logUrlIndexer($schema->getId()); $this->logger()->logUrlIndexer($obsoleteCondition); $this->logger()->logUrlIndexer(json_encode($options)); $sql = $select->insertFromSelect($this->getTargetTableName(), array_keys($fields)); // run the statement $this->makeAllRowsObsolete($options, $obsoleteCondition); $db->exec($sql); }
/** * @param Mana_Seo_Model_UrlIndexer $indexer * @param Mana_Seo_Model_Schema $schema * @param array $options */ public function process($indexer, $schema, $options) { if (!isset($options['category_id']) && !isset($options['store_id']) && !isset($options['schema_global_id']) && !isset($options['schema_store_id']) && !$options['reindex_all']) { return; } /* @var $db Varien_Db_Adapter_Pdo_Mysql */ $db = $this->_getWriteAdapter(); /* @var $core Mana_Core_Helper_Data */ $core = Mage::helper('mana_core'); if ($core->isEnterpriseUrlRewriteInstalled()) { $categoryIdExpr = "SUBSTRING(`r`.`target_path`, CHAR_LENGTH('catalog/category/view/id/') + 1)"; $fields = array('url_key' => new Zend_Db_Expr('`r`.`request_path`'), 'type' => new Zend_Db_Expr("'category'"), 'is_page' => new Zend_Db_Expr('1'), 'is_parameter' => new Zend_Db_Expr('0'), 'is_attribute_value' => new Zend_Db_Expr('0'), 'is_category_value' => new Zend_Db_Expr('0'), 'schema_id' => new Zend_Db_Expr($schema->getId()), 'category_id' => new Zend_Db_Expr("CAST({$categoryIdExpr} AS unsigned)"), 'unique_key' => new Zend_Db_Expr("CONCAT({$categoryIdExpr}, '-', `r`.`is_system`)"), 'status' => new Zend_Db_Expr("'" . Mana_Seo_Model_Url::STATUS_ACTIVE . "'"), 'description' => new Zend_Db_Expr("CONCAT('{$this->seoHelper()->__('Category')} ID ', " . "CAST({$categoryIdExpr} AS unsigned), ' {$this->seoHelper()->__('page')}')")); /* @var $select Varien_Db_Select */ $select = $db->select()->from(array('r' => $this->getTable('enterprise_urlrewrite/url_rewrite')), null)->joinLeft(array('rel' => $this->getTable('enterprise_urlrewrite/redirect_rewrite')), "rel.url_rewrite_id = r.url_rewrite_id", null)->columns($fields)->where("`r`.`target_path` LIKE 'catalog/category/view/id/%'")->where('rel.url_rewrite_id IS NULL')->where("`r`.`store_id` = ?", $schema->getStoreId()); if (isset($options['category_id'])) { $categoryIds = $this->_getChildCategoryIds($options['category_id'], $options['category_path']); $paths = array(); foreach ($categoryIds as $categoryId) { $paths[] = 'catalog/category/view/id/' . $categoryId; } $select->where('`r`.`target_path` IN (?)', $paths); } // convert SELECT into UPDATE which acts as INSERT on DUPLICATE unique keys $this->logger()->logUrlIndexer('-----------------------------'); $this->logger()->logUrlIndexer(get_class($this)); $this->logger()->logUrlIndexer($select->__toString()); $this->logger()->logUrlIndexer($schema->getId()); $this->logger()->logUrlIndexer(json_encode($options)); $sql = $select->insertFromSelect($this->getTargetTableName(), array_keys($fields)); // run the statement $db->exec($sql); } }
/** * @param Mana_Seo_Model_UrlIndexer $indexer * @param Mana_Seo_Model_Schema $schema * @param array $options */ public function process($indexer, $schema, $options) { if (!isset($options['store_id']) && !isset($options['process_category_filter']) && !isset($options['schema_global_id']) && !isset($options['schema_store_id']) && !$options['reindex_all']) { return; } $db = $this->_getWriteAdapter(); Mage::app()->getLocale()->emulate($schema->getStoreId()); $defaultLabel = Mage::helper('catalog')->__('Category'); Mage::app()->getLocale()->revert(); /* @var $core Mana_Core_Helper_Data */ $core = Mage::helper('mana_core'); $urlKeyExpr = $core->isManadevLayeredNavigationInstalled() ? $schema->getUseFilterLabels() ? $this->_seoify('`f`.`name`', $schema) : "'category'" : ($schema->getUseFilterLabels() ? $this->_seoify($defaultLabel, $schema) : "'category'"); $fields = array('url_key' => new Zend_Db_Expr($urlKeyExpr), 'internal_name' => new Zend_Db_Expr("'cat'"), 'position' => new Zend_Db_Expr($core->isManadevSeoLayeredNavigationInstalled() ? '`f`.`url_position`' : ($core->isManadevLayeredNavigationInstalled() ? '`f`.`position`' : "-1")), 'type' => new Zend_Db_Expr("'" . Mana_Seo_Model_ParsedUrl::PARAMETER_CATEGORY . "'"), 'is_page' => new Zend_Db_Expr('0'), 'is_parameter' => new Zend_Db_Expr('1'), 'is_attribute_value' => new Zend_Db_Expr('0'), 'is_category_value' => new Zend_Db_Expr('0'), 'schema_id' => new Zend_Db_Expr($schema->getId()), 'unique_key' => new Zend_Db_Expr($urlKeyExpr), 'status' => new Zend_Db_Expr("'" . Mana_Seo_Model_Url::STATUS_ACTIVE . "'"), 'description' => new Zend_Db_Expr("'{$this->seoHelper()->__('When filtering by category is enabled (Redirect to subcategory = No), this URL key is added before applied category name to distinguish filtering by category from subcategory pages and from attribute values')}'")); $obsoleteCondition = "(`schema_id` = " . $schema->getId() . ") AND (`is_parameter` = 1) AND (`type` = '" . Mana_Seo_Model_ParsedUrl::PARAMETER_CATEGORY . "')"; if ($core->isManadevLayeredNavigationInstalled()) { /* @var $select Varien_Db_Select */ $select = $db->select()->from(array('g' => $this->getTable('mana_filters/filter2')), null)->joinInner(array('f' => $this->getTable('mana_filters/filter2_store')), $db->quoteInto("`f`.`global_id` = `g`.`id` AND `f`.`store_id` = ?", $schema->getStoreId()), null)->where("`g`.`type` = ?", 'category'); $select->columns($fields); // convert SELECT into UPDATE which acts as INSERT on DUPLICATE unique keys $this->logger()->logUrlIndexer('-----------------------------'); $this->logger()->logUrlIndexer(get_class($this)); $this->logger()->logUrlIndexer($select->__toString()); $this->logger()->logUrlIndexer($schema->getId()); $this->logger()->logUrlIndexer($obsoleteCondition); $this->logger()->logUrlIndexer(json_encode($options)); $sql = $select->insertFromSelect($this->getTargetTableName(), array_keys($fields)); } else { $sql = $this->insert($this->getTargetTableName(), $fields); } // run the statement $this->makeAllRowsObsolete($options, $obsoleteCondition); $db->exec($sql); }
/** * @param Mana_Seo_Model_UrlIndexer $indexer * @param Mana_Seo_Model_Schema $schema * @param array $options */ public function process($indexer, $schema, $options) { if (!isset($options['category_id']) && !isset($options['store_id']) && !isset($options['schema_global_id']) && !isset($options['schema_store_id']) && !$options['reindex_all']) { return; } $db = $this->_getWriteAdapter(); /* @var $core Mana_Core_Helper_Data */ $core = Mage::helper('mana_core'); $urlKeyAttribute = $core->getAttribute('catalog_category', 'url_key', array('attribute_id', 'backend_type', 'backend_table')); $urlKeyAttributeTable = $core->getAttributeTable($urlKeyAttribute); $isActiveAttribute = $core->getAttribute('catalog_category', 'is_active', array('attribute_id', 'backend_type', 'backend_table')); $isActiveAttributeTable = $core->getAttributeTable($isActiveAttribute); $nameAttribute = $core->getAttribute('catalog_category', 'name', array('attribute_id', 'backend_type', 'backend_table')); $nameAttributeTable = $core->getAttributeTable($nameAttribute); /* @var $rootCategory Mage_Catalog_Model_Category */ $rootCategory = Mage::getModel('catalog/category'); $rootCategory->setStoreId($schema->getStoreId())->load(Mage::app()->getStore($schema->getStoreId())->getRootCategoryId()); /** @noinspection PhpUndefinedMethodInspection */ $pathPattern = $rootCategory->getPath() . '/%'; $urlKeyExpr = "COALESCE(`us`.`value`, `ug`.`value`)"; $fields = array('url_key' => new Zend_Db_Expr($urlKeyExpr), 'type' => new Zend_Db_Expr("'category'"), 'is_page' => new Zend_Db_Expr('0'), 'is_parameter' => new Zend_Db_Expr('0'), 'is_attribute_value' => new Zend_Db_Expr('0'), 'is_category_value' => new Zend_Db_Expr('1'), 'schema_id' => new Zend_Db_Expr($schema->getId()), 'category_id' => new Zend_Db_Expr('`e`.`entity_id`'), 'unique_key' => new Zend_Db_Expr("CONCAT(`e`.`entity_id`, '-', {$urlKeyExpr})"), 'status' => new Zend_Db_Expr("IF (COALESCE(`as`.`value`, `ag`.`value`) = 1, " . "'" . Mana_Seo_Model_Url::STATUS_ACTIVE . "', " . "'" . Mana_Seo_Model_Url::STATUS_DISABLED . "')"), 'description' => new Zend_Db_Expr("CONCAT('{$this->seoHelper()->__('Filtered by category')} \\'', " . "COALESCE(`ns`.`value`, `ng`.`value`), '\\' (ID ', `e`.`entity_id`, ')')")); /* @var $select Varien_Db_Select */ $select = $db->select()->from(array('e' => $this->getTable('catalog/category')), null)->joinLeft(array('ug' => $urlKeyAttributeTable), "`ug`.`entity_id` = `e`.`entity_id`" . $db->quoteInto(" AND `ug`.`attribute_id` = ?", $urlKeyAttribute['attribute_id']) . " AND `ug`.`store_id` = 0", null)->joinLeft(array('us' => $urlKeyAttributeTable), "`us`.`entity_id` = `e`.`entity_id`" . $db->quoteInto(" AND `us`.`attribute_id` = ?", $urlKeyAttribute['attribute_id']) . $db->quoteInto(" AND `us`.`store_id` = ?", $schema->getStoreId()), null)->joinLeft(array('ag' => $isActiveAttributeTable), "`ag`.`entity_id` = `e`.`entity_id`" . $db->quoteInto(" AND `ag`.`attribute_id` = ?", $isActiveAttribute['attribute_id']) . " AND `ag`.`store_id` = 0", null)->joinLeft(array('as' => $isActiveAttributeTable), "`as`.`entity_id` = `e`.`entity_id`" . $db->quoteInto(" AND `as`.`attribute_id` = ?", $isActiveAttribute['attribute_id']) . $db->quoteInto(" AND `as`.`store_id` = ?", $schema->getStoreId()), null)->joinLeft(array('ng' => $nameAttributeTable), "`ng`.`entity_id` = `e`.`entity_id`" . $db->quoteInto(" AND `ng`.`attribute_id` = ?", $nameAttribute['attribute_id']) . " AND `ng`.`store_id` = 0", null)->joinLeft(array('ns' => $nameAttributeTable), "`ns`.`entity_id` = `e`.`entity_id`" . $db->quoteInto(" AND `ns`.`attribute_id` = ?", $nameAttribute['attribute_id']) . $db->quoteInto(" AND `ns`.`store_id` = ?", $schema->getStoreId()), null)->columns($fields)->where('`e`.`path` LIKE ?', $pathPattern); $obsoleteCondition = "(`schema_id` = " . $schema->getId() . ") AND (`is_category_value` = 1) AND (`type` = 'category')"; if (isset($options['category_id'])) { $categoryIds = $this->_getChildCategoryIds($options['category_id'], $options['category_path']); $select->where('`e`.`entity_id` IN (?)', $categoryIds); $obsoleteCondition .= ' AND (`category_id` IN (' . implode(',', $categoryIds) . '))'; } // convert SELECT into UPDATE which acts as INSERT on DUPLICATE unique keys $this->logger()->logUrlIndexer('-----------------------------'); $this->logger()->logUrlIndexer(get_class($this)); $this->logger()->logUrlIndexer($select->__toString()); $this->logger()->logUrlIndexer($schema->getId()); $this->logger()->logUrlIndexer($obsoleteCondition); $this->logger()->logUrlIndexer(json_encode($options)); $sql = $select->insertFromSelect($this->getTargetTableName(), array_keys($fields)); // run the statement $this->makeAllRowsObsolete($options, $obsoleteCondition); $db->exec("SET SQL_BIG_SELECTS=1"); $db->exec($sql); }
/** * @param Mana_Seo_Model_UrlIndexer $indexer * @param Mana_Seo_Model_Schema $schema * @param array $options */ public function process($indexer, $schema, $options) { if (!isset($options['category_id']) && !isset($options['store_id']) && !isset($options['schema_global_id']) && !isset($options['schema_store_id']) && !$options['reindex_all']) { return; } $db = $this->_getWriteAdapter(); /* @var $core Mana_Core_Helper_Data */ $core = Mage::helper('mana_core'); /* @var $mbstring Mana_Core_Helper_Mbstring */ $mbstring = Mage::helper('mana_core/mbstring'); /* @var $categoryHelper Mage_Catalog_Helper_Category */ $categoryHelper = Mage::helper('catalog/category'); $suffix = $core->addDotToSuffix($categoryHelper->getCategoryUrlSuffix($schema->getStoreId())); $nameAttribute = $core->getAttribute('catalog_category', 'name', array('attribute_id', 'backend_type', 'backend_table')); $nameAttributeTable = $core->getAttributeTable($nameAttribute); $fields = array('url_key' => new Zend_Db_Expr('SUBSTRING(`r`.`request_path`, 1, CHAR_LENGTH(`r`.`request_path`) - ' . $mbstring->strlen($suffix) . ')'), 'type' => new Zend_Db_Expr("'category'"), 'is_page' => new Zend_Db_Expr('1'), 'is_parameter' => new Zend_Db_Expr('0'), 'is_attribute_value' => new Zend_Db_Expr('0'), 'is_category_value' => new Zend_Db_Expr('0'), 'schema_id' => new Zend_Db_Expr($schema->getId()), 'category_id' => new Zend_Db_Expr('`r`.`category_id`'), 'unique_key' => new Zend_Db_Expr("CONCAT(`r`.`id_path`, '-', `r`.`is_system`)"), 'status' => new Zend_Db_Expr("IF(`r`.`options` = '' OR `r`.`options` IS NULL, '" . Mana_Seo_Model_Url::STATUS_ACTIVE . "', '" . Mana_Seo_Model_Url::STATUS_OBSOLETE . "')"), 'description' => new Zend_Db_Expr("CONCAT('{$this->seoHelper()->__('Category')} \\'', " . "COALESCE(`ns`.`value`, `ng`.`value`), '\\' (ID ', `r`.`category_id`, ') {$this->seoHelper()->__('page')}')")); /* @var $select Varien_Db_Select */ $select = $db->select()->from(array('r' => $this->getTable('core/url_rewrite')), null)->joinInner(array('cat' => $this->getTable('catalog/category')), "cat.entity_id = `r`.`category_id`", null)->joinLeft(array('ng' => $nameAttributeTable), "`ng`.`entity_id` = `r`.`category_id`" . $db->quoteInto(" AND `ng`.`attribute_id` = ?", $nameAttribute['attribute_id']) . " AND `ng`.`store_id` = 0", null)->joinLeft(array('ns' => $nameAttributeTable), "`ns`.`entity_id` = `r`.`category_id`" . $db->quoteInto(" AND `ns`.`attribute_id` = ?", $nameAttribute['attribute_id']) . $db->quoteInto(" AND `ns`.`store_id` = ?", $schema->getStoreId()), null)->columns($fields)->where('`r`.`category_id` IS NOT NULL')->where('`r`.`store_id` = ?', $schema->getStoreId())->where('`r`.`product_id` IS NULL'); $obsoleteCondition = "(`schema_id` = " . $schema->getId() . ") AND (`is_page` = 1) AND (`type` = 'category')"; if (isset($options['category_id'])) { $categoryIds = $this->_getChildCategoryIds($options['category_id'], $options['category_path']); $select->where('`r`.`category_id` IN (?)', $categoryIds); $obsoleteCondition .= ' AND (`category_id` IN (' . implode(',', $categoryIds) . '))'; } // convert SELECT into UPDATE which acts as INSERT on DUPLICATE unique keys $this->logger()->logUrlIndexer('-----------------------------'); $this->logger()->logUrlIndexer(get_class($this)); $this->logger()->logUrlIndexer($select->__toString()); $this->logger()->logUrlIndexer($schema->getId()); $this->logger()->logUrlIndexer($obsoleteCondition); $this->logger()->logUrlIndexer(json_encode($options)); $sql = $select->insertFromSelect($this->getTargetTableName(), array_keys($fields)); // run the statement $this->makeAllRowsObsolete($options, $obsoleteCondition); if (!$core->isEnterpriseUrlRewriteInstalled()) { $db->exec($sql); } }
/** * @param Mana_Seo_Model_UrlIndexer $indexer * @param Mana_Seo_Model_Schema $schema * @param array $options */ public function process($indexer, $schema, $options) { if (!isset($options['store_id']) && !isset($options['schema_global_id']) && !isset($options['schema_store_id']) && !$options['reindex_all']) { return; } $db = $this->_getWriteAdapter(); $urlKeyExpr = "'" . Mage::getStoreConfig('mana/seo/search_url_key', $schema->getStoreId()) . "'"; $fields = array('url_key' => new Zend_Db_Expr($urlKeyExpr), 'type' => new Zend_Db_Expr("'search'"), 'is_page' => new Zend_Db_Expr('1'), 'is_parameter' => new Zend_Db_Expr('0'), 'is_attribute_value' => new Zend_Db_Expr('0'), 'is_category_value' => new Zend_Db_Expr('0'), 'schema_id' => new Zend_Db_Expr($schema->getId()), 'unique_key' => new Zend_Db_Expr($urlKeyExpr), 'status' => new Zend_Db_Expr("'" . Mana_Seo_Model_Url::STATUS_ACTIVE . "'"), 'description' => new Zend_Db_Expr("'{$this->seoHelper()->__('Quick search result page')}'")); $obsoleteCondition = "(`schema_id` = " . $schema->getId() . ") AND (`is_page` = 1) AND (`type` = 'search')"; $this->logger()->logUrlIndexer('-----------------------------'); $this->logger()->logUrlIndexer(get_class($this)); $this->logger()->logUrlIndexer($schema->getId()); $this->logger()->logUrlIndexer($obsoleteCondition); $this->logger()->logUrlIndexer(json_encode($options)); $sql = $this->insert($this->getTargetTableName(), $fields); // run the statement $this->makeAllRowsObsolete($options, $obsoleteCondition); $db->exec($sql); }