protected function _reindexCategoryUrlKey(Mage_Catalog_Model_Category $category, Mage_Core_Model_Store $store)
 {
     $requestPath = trim($category->getParentUrl(), '/');
     if (Mage::getStoreConfig('catalog/seo/category_use_parent_category')) {
         $requestPath = (!empty($requestPath) ? $requestPath . '/' : '') . $category->getUrlKey();
     } else {
         $requestPath = $category->getUrlKey();
     }
     $requestPath = $this->_cutRequestPath($requestPath);
     $urlKeyValue = $this->_getUrlKeyAttributeValueId($category, $store);
     if (empty($urlKeyValue) && empty($urlKeyValue['value_id'])) {
         $category = $this->_setUrlKeyForDefaultStore($category, $store);
         $urlKeyValue = $this->_getUrlKeyAttributeValueId($category, $store);
     }
     $valueId = $urlKeyValue['value_id'];
     $rewriteRow = $this->_getRewrite($requestPath, $store->getId());
     if (!$rewriteRow || $rewriteRow['value_id'] != $valueId) {
         $rewriteForValueId = $this->_getRewriteForValueId($store->getId(), $valueId);
         $suffix = trim(str_replace($requestPath, '', $category->getRequestPath()), '-');
         $requestPathIncrement = (int) $this->_getRewriteRequestIncrement($requestPath, $store);
         if (!$rewriteForValueId || !preg_match('#^(\\d)+$#', $suffix) || $suffix > $requestPathIncrement) {
             if ($rewriteRow && $rewriteRow['value_id'] != $valueId) {
                 $requestPath .= '-' . ++$requestPathIncrement;
             }
             $category = $this->_saveRewrite($category, $store, $requestPath, $valueId);
         }
     }
     $this->_indexedCategoryIds[$store->getId()][$category->getId()] = 1;
     return $category;
 }
 /**
  * Write category url_key into enterprise_url_rewrite table
  *
  * @param Mage_Catalog_Model_Category $category
  * @param Mage_Core_Model_Store $store
  * @return Mage_Catalog_Model_Category
  */
 protected function _reindexCategoryUrlKey(Mage_Catalog_Model_Category $category, Mage_Core_Model_Store $store)
 {
     $requestPath = trim($category->getParentUrl(), '/');
     $requestPath = (!empty($requestPath) ? $requestPath . '/' : '') . $category->getUrlKey();
     $requestPath = $this->_cutRequestPath($requestPath);
     $urlKeyValue = $this->_getUrlKeyAttributeValueId($category, $store);
     /*
      * if this category created on store view level, we should write default url key for this category,
      * or this category will be unaccessible from frontend
      */
     if (empty($urlKeyValue) && empty($urlKeyValue['value_id'])) {
         $category = $this->_setUrlKeyForDefaultStore($category, $store);
         //get url key value id from backend table after changes
         $urlKeyValue = $this->_getUrlKeyAttributeValueId($category, $store);
     }
     $valueId = $urlKeyValue['value_id'];
     /**
      * Check if we should insert rewrite into table
      */
     $rewriteRow = $this->_getRewrite($requestPath, $store->getId());
     if (!$rewriteRow || $rewriteRow['value_id'] != $valueId) {
         //get current url path from enterprise_url_rewrite
         $rewriteForValueId = $this->_getRewriteForValueId($store->getId(), $valueId);
         $suffix = trim(str_replace($requestPath, '', $category->getRequestPath()), '-');
         /*
          * theoretically we may face with situation when several categories have url_key like:
          * id url_key request path
          * 1  abc     abc
          * 2  abc     abc-1
          * 3  abc     abc-2
          * and we should reindex category with id 2, we can't be sure should we add prefix or not
          * so workaround with regexp cover most cases of this problem
          */
         $requestPathIncrement = (int) $this->_getRewriteRequestIncrement($requestPath, $store);
         if (!$rewriteForValueId || !preg_match('#^(\\d)+$#', $suffix) || $suffix > $requestPathIncrement) {
             if ($rewriteRow && $rewriteRow['value_id'] != $valueId) {
                 $requestPath .= '-' . ++$requestPathIncrement;
             }
             $category = $this->_saveRewrite($category, $store, $requestPath, $valueId);
             // clean full page cache for category
         }
     }
     // save id of already indexed category into list
     $this->_indexedCategoryIds[$store->getId()][$category->getId()] = 1;
     return $category;
 }