/**
  * @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['attribute_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');
     $urlKeyExpr = $schema->getUseFilterLabels() ? $core->isManadevLayeredNavigationInstalled() ? $this->_seoify('`f`.`name`', $schema) : $this->_seoify('COALESCE(`l`.`value`, `a`.`frontend_label`)', $schema) : "REPLACE(LOWER(`a`.`attribute_code`), '_', '-')";
     $fields = array('url_key' => new Zend_Db_Expr($urlKeyExpr), 'internal_name' => new Zend_Db_Expr('`a`.`attribute_code`'), 'position' => new Zend_Db_Expr($core->isManadevSeoLayeredNavigationInstalled() ? '`f`.`url_position`' : ($core->isManadevLayeredNavigationInstalled() ? '`f`.`position`' : '`ca`.`position`')), 'filter_display' => new Zend_Db_Expr($core->isManadevLayeredNavigationInstalled() ? '`f`.`display`' : 'NULL'), 'type' => new Zend_Db_Expr("IF(a.backend_type = 'decimal', " . "'" . Mana_Seo_Model_ParsedUrl::PARAMETER_PRICE . "', " . "'" . Mana_Seo_Model_ParsedUrl::PARAMETER_ATTRIBUTE . "')"), '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()), 'attribute_id' => new Zend_Db_Expr('`a`.`attribute_id`'), 'unique_key' => new Zend_Db_Expr("CONCAT(`a`.`attribute_id`, '-', {$urlKeyExpr})"), 'status' => new Zend_Db_Expr("'" . Mana_Seo_Model_Url::STATUS_ACTIVE . "'"), 'description' => new Zend_Db_Expr("CONCAT('{$this->seoHelper()->__('Attribute')} \\'', " . "COALESCE(`l`.`value`, `a`.`frontend_label`), '\\' ({$this->seoHelper()->__('code')} \\'', " . "`a`.`attribute_code`, '\\'). ', IF(a.backend_type = 'decimal', '{$this->seoHelper()->__('Always Added before decimal value range')}', '{$this->seoHelper()->__('Added before filter/attribute value(s)/option(s) if showing filter name in URL is enabled')}'))"));
     /* @var $select Varien_Db_Select */
     $select = $this->_getFilterableAttributeSelect($db)->joinLeft(array('l' => $this->getTable('eav/attribute_label')), $db->quoteInto("`l`.`attribute_id` = `a`.`attribute_id` AND `l`.`store_id` = ?", $schema->getStoreId()), null);
     if ($core->isManadevLayeredNavigationInstalled()) {
         $select->joinInner(array('g' => $this->getTable('mana_filters/filter2')), '`g`.`code` = `a`.`attribute_code`', null)->joinInner(array('f' => $this->getTable('mana_filters/filter2_store')), $db->quoteInto("`f`.`global_id` = `g`.`id` AND `f`.`store_id` = ?", $schema->getStoreId()), null);
     }
     $obsoleteCondition = "(`schema_id` = " . $schema->getId() . ") AND (`is_parameter` = 1) AND " . "(`type` IN ('" . Mana_Seo_Model_ParsedUrl::PARAMETER_PRICE . "', '" . Mana_Seo_Model_ParsedUrl::PARAMETER_ATTRIBUTE . "'))";
     if (isset($options['attribute_id'])) {
         $select->where('`a`.`attribute_id` = ?', $options['attribute_id']);
         $obsoleteCondition .= ' AND (`attribute_id` = ' . $options['attribute_id'] . ')';
     }
     $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));
     $selectSql = $select->__toString();
     $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['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['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 string $expr
  * @param Mana_Seo_Model_Schema $schema
  * @return string
  */
 protected function _seoify($expr, $schema)
 {
     $expr = "LOWER({$expr})";
     foreach ($schema->getSortedSymbols() as $symbol) {
         $expr = "REPLACE({$expr}, {$this->_quote($symbol['symbol'])}, {$this->_quote($symbol['substitute'])})";
     }
     return $expr;
 }
 /**
  * @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);
 }
 /**
  * @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();
     foreach ($schema->getJson('toolbar_url_keys') as $urlKey) {
         $urlKeyExpr = "'" . $urlKey['name'] . "'";
         $fields = array('url_key' => new Zend_Db_Expr($urlKeyExpr), 'type' => new Zend_Db_Expr("'" . Mana_Seo_Model_ParsedUrl::PARAMETER_TOOLBAR . "'"), '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), 'internal_name' => new Zend_Db_Expr("'" . $urlKey['internal_name'] . "'"), 'position' => new Zend_Db_Expr($urlKey['position']), 'status' => new Zend_Db_Expr("'" . Mana_Seo_Model_Url::STATUS_ACTIVE . "'"), 'description' => new Zend_Db_Expr("'{$this->getDescription($urlKey['internal_name'])}'"));
         $obsoleteCondition = "(`schema_id` = " . $schema->getId() . ") AND (`is_parameter` = 1) AND (`type` = '" . Mana_Seo_Model_ParsedUrl::PARAMETER_TOOLBAR . "') AND (`internal_name` = '" . $urlKey['internal_name'] . "')";
         $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);
     }
 }
 /**
  * @param Mana_Seo_Model_Schema $schema
  */
 public function getParameterUrls($schema)
 {
     if (!isset($this->_parameterUrls[$schema->getId()])) {
         $urls = array();
         $ids = array();
         foreach ($this->getUrlCollection($schema, Mana_Seo_Resource_Url_Collection::TYPE_PARAMETER) as $url) {
             /* @var $url Mana_Seo_Model_Url */
             if (!isset($urls[$url->getInternalName()])) {
                 $urls[$url->getInternalName()] = $url;
             } else {
                 $ids[] = $url->getId();
             }
         }
         if (count($ids)) {
             /* @var $logger Mana_Core_Helper_Logger */
             $logger = Mage::helper('mana_core/logger');
             $logger->logSeoUrl(sprintf('NOTICE: Multiple parameter URL keys found for one match request, taking first one. All URL key ids: %s', implode($ids)));
         }
         $this->_parameterUrls[$schema->getId()] = $urls;
     }
     return $this->_parameterUrls[$schema->getId()];
 }
 /**
  * @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);
     }
 }
Beispiel #11
0
 public function getItemData($key, $value)
 {
     /* @var $seo Mana_Seo_Helper_Data */
     $seo = Mage::helper('mana_seo');
     $this->_schema = $seo->getActiveSchema($this->getStore()->getId());
     if ($url = $this->_getParameterUrl($key)) {
         switch ($url->getType()) {
             case Mana_Seo_Model_ParsedUrl::PARAMETER_ATTRIBUTE:
                 if ($urlKey = $this->_getValueUrlKey($value)) {
                     return array('url' => $this->_encode($urlKey['final_url_key']), 'prefix' => $urlKey['final_include_filter_name'] || in_array($url->getFilterDisplay(), array('slider', 'range', 'min_max_slider')) ? $this->_encode($url->getFinalUrlKey()) . $this->getSchema()->getFirstValueSeparator() : '', 'position' => $urlKey['position'], 'id' => $value);
                 }
                 break;
             case Mana_Seo_Model_ParsedUrl::PARAMETER_CATEGORY:
                 if ($this->getSchema()->getRedirectToSubcategory()) {
                     $url = urldecode(str_replace('+', '%2B', $seo->urlDecode(Mage::app()->getFrontController()->getRequest()->getParam('m-url'))));
                     $query = array('cat' => $value, 'm-seo-enabled' => null, 'm-show-more-cat' => null, 'm-show-more-popup' => null, 'm-url' => null);
                     /* @var $parser Mana_Seo_Helper_UrlParser */
                     $parser = Mage::helper('mana_seo/urlParser');
                     $storeUrl = Mage::app()->getStore()->isCurrentlySecure() ? $this->getUrl('', array('_secure' => true)) : $this->getUrl('');
                     $storeParsedUrl = parse_url($storeUrl);
                     $path = substr($url, strlen($storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') . $storeParsedUrl['path']));
                     //                        if (!$this->coreHelper()->startsWith($path, '/')) {
                     //                            $path = '/'.$path;
                     //                        }
                     $urlQuery = array();
                     if (($pos = strpos($path, '?')) !== false) {
                         parse_str(substr($path, $pos + 1), $urlQuery);
                         $path = substr($path, 0, $pos);
                     }
                     $storeParsedQuery = array();
                     if (isset($storeParsedUrl['query'])) {
                         parse_str($storeParsedUrl['query'], $storeParsedQuery);
                     }
                     if ($this->coreHelper()->startsWith($path, 'catalogsearch/result/')) {
                         $path = Mage::getStoreConfig('mana/seo/search_url_key') . substr($path, strlen('catalogsearch/result/'));
                     }
                     if ($parsedUrl = $parser->parse($path)) {
                         $params = array_merge($parsedUrl->getImplodedParameters(), array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure(), '_use_rewrite' => true, '_m_escape' => '', '_query' => array_merge($storeParsedQuery, $query, $urlQuery, count($parsedUrl->getQueryParameters()) ? $parsedUrl->getImplodedQueryParameters() : array())));
                         $url = Mage::helper('mana_filters')->markLayeredNavigationUrl(Mage::getUrl($parsedUrl->getRoute(), $params), $parsedUrl->getRoute(), $params);
                         return array('full_url' => $url);
                     } else {
                         throw new Exception('Not implemented');
                     }
                 } elseif ($urlKey = $this->_getCategoryUrlKeys($value)) {
                     return array('url' => $this->_encode($urlKey), 'prefix' => $this->_encode($url->getFinalUrlKey()) . $this->getSchema()->getFirstValueSeparator(), 'position' => 0, 'id' => 0);
                 }
                 break;
             case Mana_Seo_Model_ParsedUrl::PARAMETER_PRICE:
                 list($from, $to) = explode(',', $value);
                 $index = $from;
                 $range = $to;
                 if ($this->_schema->getUseRangeBounds()) {
                     $from = ($index - 1) * $range;
                     $to = $from + $range;
                     $path = $from . $this->_schema->getPriceSeparator() . $to;
                 } else {
                     $path = $index . $this->_schema->getPriceSeparator() . $range;
                 }
                 return array('url' => $path, 'prefix' => '', 'position' => 0, 'id' => 0);
             default:
                 throw new Exception('Not implemented');
         }
     }
     return $value;
 }
 /**
  * @param Mana_Seo_Model_Schema $schema
  * @return Mana_Seo_Resource_Url_Collection
  */
 public function setSchemaFilter($schema)
 {
     $this->getSelect()->where("`main_table`.`schema_id` = ?", $schema->getId());
     return $this;
 }
 protected function unaccent($s)
 {
     return $this->_schema->getData('accent_insensitive') ? $this->coreHelper()->unaccent($s) : $s;
 }
 /**
  * @param Mana_Seo_Model_Schema $row
  * @return string
  */
 public function getRowUrl($row)
 {
     return $this->adminHelper()->getStoreUrl('*/*/edit', array('id' => $row->getId()));
 }
 /**
  * @param Mana_Seo_Model_Schema $row
  * @return string
  */
 public function getRowTitle($row)
 {
     return $this->__("Edit SEO schema '%s'", $row->getName());
 }