1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Catalog_Model_Url
35: {
36: 37: 38: 39: 40:
41: const MAX_REQUEST_PATH_LENGTH = 240;
42:
43: 44: 45: 46: 47: 48:
49: const ALLOWED_REQUEST_PATH_OVERFLOW = 10;
50:
51: 52: 53: 54: 55:
56: protected $_resourceModel;
57:
58: 59: 60: 61: 62:
63: protected $_categories = array();
64:
65: 66: 67: 68: 69:
70: protected $_rootCategories = array();
71:
72: 73: 74: 75: 76:
77: protected $_rewrites = array();
78:
79: 80: 81: 82: 83:
84: protected $_rewrite;
85:
86: 87: 88: 89: 90:
91: protected $_productUrlSuffix = array();
92:
93: 94: 95: 96: 97:
98: protected $_categoryUrlSuffix = array();
99:
100: 101: 102: 103: 104:
105: protected $_saveRewritesHistory = null;
106:
107: 108: 109: 110: 111:
112: static protected $_categoryForUrlPath;
113:
114: 115: 116: 117: 118: 119: 120: 121: 122:
123: protected function _addCategoryUrlPath($category)
124: {
125: if (!($category instanceof Varien_Object) || $category->getUrlPath()) {
126: return;
127: }
128:
129:
130:
131: if ($category->getLevel() <= 1) {
132: $category->setUrlPath('');
133: return;
134: }
135:
136: if (self::$_categoryForUrlPath === null) {
137: self::$_categoryForUrlPath = Mage::getModel('catalog/category');
138: }
139:
140:
141: $urlPath = self::$_categoryForUrlPath
142: ->setData($category->getData())
143: ->getUrlPath();
144: $category->setUrlPath($urlPath);
145: }
146:
147: 148: 149: 150: 151: 152:
153: public function getStores($storeId = null)
154: {
155: return $this->getResource()->getStores($storeId);
156: }
157:
158: 159: 160: 161: 162:
163: public function getResource()
164: {
165: if (is_null($this->_resourceModel)) {
166: $this->_resourceModel = Mage::getResourceModel('catalog/url');
167: }
168: return $this->_resourceModel;
169: }
170:
171: 172: 173: 174: 175:
176: public function getCategoryModel()
177: {
178: return $this->getResource()->getCategoryModel();
179: }
180:
181: 182: 183: 184: 185:
186: public function getProductModel()
187: {
188: return $this->getResource()->getProductModel();
189: }
190:
191: 192: 193: 194: 195: 196:
197: public function getStoreRootCategory($storeId) {
198: if (!array_key_exists($storeId, $this->_rootCategories)) {
199: $category = null;
200: $store = $this->getStores($storeId);
201: if ($store) {
202: $rootCategoryId = $store->getRootCategoryId();
203: $category = $this->getResource()->getCategory($rootCategoryId, $storeId);
204: }
205: $this->_rootCategories[$storeId] = $category;
206: }
207: return $this->_rootCategories[$storeId];
208: }
209:
210: 211: 212: 213: 214: 215: 216:
217: public function setShouldSaveRewritesHistory($flag)
218: {
219: $this->_saveRewritesHistory = (bool)$flag;
220: return $this;
221: }
222:
223: 224: 225: 226: 227: 228:
229: public function getShouldSaveRewritesHistory($storeId = null)
230: {
231: if ($this->_saveRewritesHistory !== null) {
232: return $this->_saveRewritesHistory;
233: }
234: return Mage::helper('catalog')->shouldSaveUrlRewritesHistory($storeId);
235: }
236:
237: 238: 239: 240: 241: 242: 243:
244: public function refreshRewrites($storeId = null)
245: {
246: if (is_null($storeId)) {
247: foreach ($this->getStores() as $store) {
248: $this->refreshRewrites($store->getId());
249: }
250: return $this;
251: }
252:
253: $this->clearStoreInvalidRewrites($storeId);
254: $this->refreshCategoryRewrite($this->getStores($storeId)->getRootCategoryId(), $storeId, false);
255: $this->refreshProductRewrites($storeId);
256: $this->getResource()->clearCategoryProduct($storeId);
257:
258: return $this;
259: }
260:
261: 262: 263: 264: 265: 266: 267: 268:
269: protected function _refreshCategoryRewrites(Varien_Object $category, $parentPath = null, $refreshProducts = true)
270: {
271: if ($category->getId() != $this->getStores($category->getStoreId())->getRootCategoryId()) {
272: if ($category->getUrlKey() == '') {
273: $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName());
274: }
275: else {
276: $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey());
277: }
278:
279: $idPath = $this->generatePath('id', null, $category);
280: $targetPath = $this->generatePath('target', null, $category);
281: $requestPath = $this->getCategoryRequestPath($category, $parentPath);
282:
283: $rewriteData = array(
284: 'store_id' => $category->getStoreId(),
285: 'category_id' => $category->getId(),
286: 'product_id' => null,
287: 'id_path' => $idPath,
288: 'request_path' => $requestPath,
289: 'target_path' => $targetPath,
290: 'is_system' => 1
291: );
292:
293: $this->getResource()->saveRewrite($rewriteData, $this->_rewrite);
294:
295: if ($this->getShouldSaveRewritesHistory($category->getStoreId())) {
296: $this->_saveRewriteHistory($rewriteData, $this->_rewrite);
297: }
298:
299: if ($category->getUrlKey() != $urlKey) {
300: $category->setUrlKey($urlKey);
301: $this->getResource()->saveCategoryAttribute($category, 'url_key');
302: }
303: if ($category->getUrlPath() != $requestPath) {
304: $category->setUrlPath($requestPath);
305: $this->getResource()->saveCategoryAttribute($category, 'url_path');
306: }
307: }
308: else {
309: if ($category->getUrlPath() != '') {
310: $category->setUrlPath('');
311: $this->getResource()->saveCategoryAttribute($category, 'url_path');
312: }
313: }
314:
315: if ($refreshProducts) {
316: $this->_refreshCategoryProductRewrites($category);
317: }
318:
319: foreach ($category->getChilds() as $child) {
320: $this->_refreshCategoryRewrites($child, $category->getUrlPath() . '/', $refreshProducts);
321: }
322:
323: return $this;
324: }
325:
326: 327: 328: 329: 330: 331: 332:
333: protected function _refreshProductRewrite(Varien_Object $product, Varien_Object $category)
334: {
335: if ($category->getId() == $category->getPath()) {
336: return $this;
337: }
338: if ($product->getUrlKey() == '') {
339: $urlKey = $this->getProductModel()->formatUrlKey($product->getName());
340: }
341: else {
342: $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
343: }
344:
345: $idPath = $this->generatePath('id', $product, $category);
346: $targetPath = $this->generatePath('target', $product, $category);
347: $requestPath = $this->getProductRequestPath($product, $category);
348:
349: $categoryId = null;
350: $updateKeys = true;
351: if ($category->getLevel() > 1) {
352: $categoryId = $category->getId();
353: $updateKeys = false;
354: }
355:
356: $rewriteData = array(
357: 'store_id' => $category->getStoreId(),
358: 'category_id' => $categoryId,
359: 'product_id' => $product->getId(),
360: 'id_path' => $idPath,
361: 'request_path' => $requestPath,
362: 'target_path' => $targetPath,
363: 'is_system' => 1
364: );
365:
366: $this->getResource()->saveRewrite($rewriteData, $this->_rewrite);
367:
368: if ($this->getShouldSaveRewritesHistory($category->getStoreId())) {
369: $this->_saveRewriteHistory($rewriteData, $this->_rewrite);
370: }
371:
372: if ($updateKeys && $product->getUrlKey() != $urlKey) {
373: $product->setUrlKey($urlKey);
374: $this->getResource()->saveProductAttribute($product, 'url_key');
375: }
376: if ($updateKeys && $product->getUrlPath() != $requestPath) {
377: $product->setUrlPath($requestPath);
378: $this->getResource()->saveProductAttribute($product, 'url_path');
379: }
380:
381: return $this;
382: }
383:
384: 385: 386: 387: 388: 389:
390: protected function _refreshCategoryProductRewrites(Varien_Object $category)
391: {
392: $originalRewrites = $this->_rewrites;
393: $process = true;
394: $lastEntityId = 0;
395: $firstIteration = true;
396: while ($process == true) {
397: $products = $this->getResource()->getProductsByCategory($category, $lastEntityId);
398: if (!$products) {
399: if ($firstIteration) {
400: $this->getResource()->deleteCategoryProductStoreRewrites(
401: $category->getId(),
402: array(),
403: $category->getStoreId()
404: );
405: }
406: $process = false;
407: break;
408: }
409:
410:
411: $rootCategory = $this->getStoreRootCategory($category->getStoreId());
412: $categoryIds = array($category->getId(), $rootCategory->getId());
413: $this->_rewrites = $this->getResource()->prepareRewrites(
414: $category->getStoreId(),
415: $categoryIds,
416: array_keys($products)
417: );
418:
419: foreach ($products as $product) {
420:
421: $this->_refreshProductRewrite($product, $rootCategory);
422: $this->_refreshProductRewrite($product, $category);
423: }
424: $firstIteration = false;
425: unset($products);
426: }
427: $this->_rewrites = $originalRewrites;
428: return $this;
429: }
430:
431: 432: 433: 434: 435: 436: 437: 438: 439:
440: public function refreshCategoryRewrite($categoryId, $storeId = null, $refreshProducts = true)
441: {
442: if (is_null($storeId)) {
443: foreach ($this->getStores() as $store) {
444: $this->refreshCategoryRewrite($categoryId, $store->getId(), $refreshProducts);
445: }
446: return $this;
447: }
448:
449: $category = $this->getResource()->getCategory($categoryId, $storeId);
450: if (!$category) {
451: return $this;
452: }
453:
454:
455: $category = $this->getResource()->loadCategoryChilds($category);
456: $categoryIds = array($category->getId());
457: if ($category->getAllChilds()) {
458: $categoryIds = array_merge($categoryIds, array_keys($category->getAllChilds()));
459: }
460: $this->_rewrites = $this->getResource()->prepareRewrites($storeId, $categoryIds);
461: $this->_refreshCategoryRewrites($category, null, $refreshProducts);
462:
463: unset($category);
464: $this->_rewrites = array();
465:
466: return $this;
467: }
468:
469: 470: 471: 472: 473: 474: 475: 476:
477: public function refreshProductRewrite($productId, $storeId = null)
478: {
479: if (is_null($storeId)) {
480: foreach ($this->getStores() as $store) {
481: $this->refreshProductRewrite($productId, $store->getId());
482: }
483: return $this;
484: }
485:
486: $product = $this->getResource()->getProduct($productId, $storeId);
487: if ($product) {
488: $store = $this->getStores($storeId);
489: $storeRootCategoryId = $store->getRootCategoryId();
490:
491:
492: $categories = $this->getResource()->getCategories($product->getCategoryIds(), $storeId);
493: $this->_rewrites = $this->getResource()->prepareRewrites($storeId, '', $productId);
494:
495:
496:
497:
498: if (!isset($categories[$storeRootCategoryId])) {
499: $categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId);
500: }
501:
502:
503: foreach ($categories as $category) {
504: $this->_refreshProductRewrite($product, $category);
505: }
506:
507:
508: $excludeCategoryIds = array_keys($categories);
509: $this->getResource()->clearProductRewrites($productId, $storeId, $excludeCategoryIds);
510:
511: unset($categories);
512: unset($product);
513: } else {
514:
515: $this->getResource()->clearProductRewrites($productId, $storeId, array());
516: }
517:
518: return $this;
519: }
520:
521: 522: 523: 524: 525: 526:
527: public function refreshProductRewrites($storeId)
528: {
529: $this->_categories = array();
530: $storeRootCategoryId = $this->getStores($storeId)->getRootCategoryId();
531: $storeRootCategoryPath = $this->getStores($storeId)->getRootCategoryPath();
532: $this->_categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId);
533:
534: $lastEntityId = 0;
535: $process = true;
536:
537: while ($process == true) {
538: $products = $this->getResource()->getProductsByStore($storeId, $lastEntityId);
539: if (!$products) {
540: $process = false;
541: break;
542: }
543:
544: $this->_rewrites = $this->getResource()->prepareRewrites($storeId, false, array_keys($products));
545:
546: $loadCategories = array();
547: foreach ($products as $product) {
548: foreach ($product->getCategoryIds() as $categoryId) {
549: if (!isset($this->_categories[$categoryId])) {
550: $loadCategories[$categoryId] = $categoryId;
551: }
552: }
553: }
554:
555: if ($loadCategories) {
556: foreach ($this->getResource()->getCategories($loadCategories, $storeId) as $category) {
557: $this->_categories[$category->getId()] = $category;
558: }
559: }
560:
561: foreach ($products as $product) {
562: $this->_refreshProductRewrite($product, $this->_categories[$storeRootCategoryId]);
563: foreach ($product->getCategoryIds() as $categoryId) {
564: if ($categoryId != $storeRootCategoryId && isset($this->_categories[$categoryId])) {
565: if (strpos($this->_categories[$categoryId]['path'], $storeRootCategoryPath . '/') !== 0) {
566: continue;
567: }
568: $this->_refreshProductRewrite($product, $this->_categories[$categoryId]);
569: }
570: }
571: }
572:
573: unset($products);
574: $this->_rewrites = array();
575: }
576:
577: $this->_categories = array();
578: return $this;
579: }
580:
581: 582: 583: 584: 585: 586:
587: public function clearStoreInvalidRewrites($storeId = null)
588: {
589: if (is_null($storeId)) {
590: foreach ($this->getStores() as $store) {
591: $this->clearStoreInvalidRewrites($store->getId());
592: }
593: return $this;
594: }
595:
596: $this->getResource()->clearStoreInvalidRewrites($storeId);
597: return $this;
598: }
599:
600: 601: 602: 603: 604: 605: 606: 607: 608: 609:
610: public function getUnusedPath($storeId, $requestPath, $idPath)
611: {
612: if (strpos($idPath, 'product') !== false) {
613: $suffix = $this->getProductUrlSuffix($storeId);
614: } else {
615: $suffix = $this->getCategoryUrlSuffix($storeId);
616: }
617: if (empty($requestPath)) {
618: $requestPath = '-';
619: } elseif ($requestPath == $suffix) {
620: $requestPath = '-' . $suffix;
621: }
622:
623: 624: 625:
626: if (strlen($requestPath) > self::MAX_REQUEST_PATH_LENGTH + self::ALLOWED_REQUEST_PATH_OVERFLOW) {
627: $requestPath = substr($requestPath, 0, self::MAX_REQUEST_PATH_LENGTH);
628: }
629:
630: if (isset($this->_rewrites[$idPath])) {
631: $this->_rewrite = $this->_rewrites[$idPath];
632: if ($this->_rewrites[$idPath]->getRequestPath() == $requestPath) {
633: return $requestPath;
634: }
635: }
636: else {
637: $this->_rewrite = null;
638: }
639:
640: $rewrite = $this->getResource()->getRewriteByRequestPath($requestPath, $storeId);
641: if ($rewrite && $rewrite->getId()) {
642: if ($rewrite->getIdPath() == $idPath) {
643: $this->_rewrite = $rewrite;
644: return $requestPath;
645: }
646:
647: $match = array();
648: $regularExpression = '#^([0-9a-z/-]+?)(-([0-9]+))?('.preg_quote($suffix).')?$#i';
649: if (!preg_match($regularExpression, $requestPath, $match)) {
650: return $this->getUnusedPath($storeId, '-', $idPath);
651: }
652: $match[1] = $match[1] . '-';
653: $match[4] = isset($match[4]) ? $match[4] : '';
654:
655: $lastRequestPath = $this->getResource()
656: ->getLastUsedRewriteRequestIncrement($match[1], $match[4], $storeId);
657: if ($lastRequestPath) {
658: $match[3] = $lastRequestPath;
659: }
660: return $match[1]
661: . (isset($match[3]) ? ($match[3]+1) : '1')
662: . $match[4];
663: }
664: else {
665: return $requestPath;
666: }
667: }
668:
669: 670: 671: 672: 673: 674:
675: public function getProductUrlSuffix($storeId)
676: {
677: return Mage::helper('catalog/product')->getProductUrlSuffix($storeId);
678: }
679:
680: 681: 682: 683: 684: 685:
686: public function getCategoryUrlSuffix($storeId)
687: {
688: return Mage::helper('catalog/category')->getCategoryUrlSuffix($storeId);
689: }
690:
691: 692: 693: 694: 695: 696: 697:
698: public function getCategoryRequestPath($category, $parentPath)
699: {
700: $storeId = $category->getStoreId();
701: $idPath = $this->generatePath('id', null, $category);
702: $suffix = $this->getCategoryUrlSuffix($storeId);
703:
704: if (isset($this->_rewrites[$idPath])) {
705: $this->_rewrite = $this->_rewrites[$idPath];
706: $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
707: }
708:
709: if ($category->getUrlKey() == '') {
710: $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName());
711: }
712: else {
713: $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey());
714: }
715:
716: $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId());
717: if (null === $parentPath) {
718: $parentPath = $this->getResource()->getCategoryParentPath($category);
719: }
720: elseif ($parentPath == '/') {
721: $parentPath = '';
722: }
723: $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath,
724: true, $category->getStoreId());
725:
726: $requestPath = $parentPath . $urlKey . $categoryUrlSuffix;
727: if (isset($existingRequestPath) && $existingRequestPath == $requestPath . $suffix) {
728: return $existingRequestPath;
729: }
730:
731: if ($this->_deleteOldTargetPath($requestPath, $idPath, $storeId)) {
732: return $requestPath;
733: }
734:
735: return $this->getUnusedPath($category->getStoreId(), $requestPath,
736: $this->generatePath('id', null, $category)
737: );
738: }
739:
740: 741: 742: 743: 744: 745: 746: 747:
748: protected function _deleteOldTargetPath($requestPath, $idPath, $storeId)
749: {
750: $finalOldTargetPath = $this->getResource()->findFinalTargetPath($requestPath, $storeId);
751: if ($finalOldTargetPath && $finalOldTargetPath == $idPath) {
752: $this->getResource()->deleteRewriteRecord($requestPath, $storeId, true);
753: return true;
754: }
755:
756: return false;
757: }
758:
759: 760: 761: 762: 763: 764: 765:
766: public function getProductRequestPath($product, $category)
767: {
768: if ($product->getUrlKey() == '') {
769: $urlKey = $this->getProductModel()->formatUrlKey($product->getName());
770: } else {
771: $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
772: }
773: $storeId = $category->getStoreId();
774: $suffix = $this->getProductUrlSuffix($storeId);
775: $idPath = $this->generatePath('id', $product, $category);
776: 777: 778:
779: if ($category->getLevel() > 1) {
780:
781: $this->_addCategoryUrlPath($category);
782: $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(),
783: false, $storeId);
784: $requestPath = $categoryUrl . '/' . $urlKey;
785: } else {
786: $requestPath = $urlKey;
787: }
788:
789: if (strlen($requestPath) > self::MAX_REQUEST_PATH_LENGTH + self::ALLOWED_REQUEST_PATH_OVERFLOW) {
790: $requestPath = substr($requestPath, 0, self::MAX_REQUEST_PATH_LENGTH);
791: }
792:
793: $this->_rewrite = null;
794: 795: 796:
797: if (isset($this->_rewrites[$idPath])) {
798: $this->_rewrite = $this->_rewrites[$idPath];
799: $existingRequestPath = $this->_rewrites[$idPath]->getRequestPath();
800:
801: if ($existingRequestPath == $requestPath . $suffix) {
802: return $existingRequestPath;
803: }
804:
805: $existingRequestPath = preg_replace('/' . preg_quote($suffix, '/') . '$/', '', $existingRequestPath);
806: 807: 808:
809: if ($product->getUrlKey() == '' && !empty($requestPath)
810: && strpos($existingRequestPath, $requestPath) === 0
811: ) {
812: $existingRequestPath = preg_replace(
813: '/^' . preg_quote($requestPath, '/') . '/', '', $existingRequestPath
814: );
815: if (preg_match('#^-([0-9]+)$#i', $existingRequestPath)) {
816: return $this->_rewrites[$idPath]->getRequestPath();
817: }
818: }
819:
820: $fullPath = $requestPath.$suffix;
821: if ($this->_deleteOldTargetPath($fullPath, $idPath, $storeId)) {
822: return $fullPath;
823: }
824: }
825: 826: 827:
828: $validatedPath = $this->getResource()->checkRequestPaths(
829: array($requestPath.$suffix, $requestPath.'-'.$product->getId().$suffix),
830: $storeId
831: );
832:
833: if ($validatedPath) {
834: return $validatedPath;
835: }
836: 837: 838:
839: return $this->getUnusedPath($storeId, $requestPath.$suffix, $idPath);
840: }
841:
842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855:
856: public function generatePath($type = 'target', $product = null, $category = null, $parentPath = null)
857: {
858: if (!$product && !$category) {
859: Mage::throwException(Mage::helper('core')->__('Please specify either a category or a product, or both.'));
860: }
861:
862:
863: if ('id' === $type) {
864: if (!$product) {
865: return 'category/' . $category->getId();
866: }
867: if ($category && $category->getLevel() > 1) {
868: return 'product/' . $product->getId() . '/' . $category->getId();
869: }
870: return 'product/' . $product->getId();
871: }
872:
873:
874: if ('request' === $type) {
875:
876: if (!$product) {
877: if ($category->getUrlKey() == '') {
878: $urlKey = $this->getCategoryModel()->formatUrlKey($category->getName());
879: }
880: else {
881: $urlKey = $this->getCategoryModel()->formatUrlKey($category->getUrlKey());
882: }
883:
884: $categoryUrlSuffix = $this->getCategoryUrlSuffix($category->getStoreId());
885: if (null === $parentPath) {
886: $parentPath = $this->getResource()->getCategoryParentPath($category);
887: }
888: elseif ($parentPath == '/') {
889: $parentPath = '';
890: }
891: $parentPath = Mage::helper('catalog/category')->getCategoryUrlPath($parentPath,
892: true, $category->getStoreId());
893:
894: return $this->getUnusedPath($category->getStoreId(), $parentPath . $urlKey . $categoryUrlSuffix,
895: $this->generatePath('id', null, $category)
896: );
897: }
898:
899:
900: if (!$category) {
901: Mage::throwException(Mage::helper('core')->__('A category object is required for determining the product request path.'));
902: }
903:
904: if ($product->getUrlKey() == '') {
905: $urlKey = $this->getProductModel()->formatUrlKey($product->getName());
906: }
907: else {
908: $urlKey = $this->getProductModel()->formatUrlKey($product->getUrlKey());
909: }
910: $productUrlSuffix = $this->getProductUrlSuffix($category->getStoreId());
911: if ($category->getLevel() > 1) {
912:
913: $this->_addCategoryUrlPath($category);
914: $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(),
915: false, $category->getStoreId());
916: return $this->getUnusedPath($category->getStoreId(), $categoryUrl . '/' . $urlKey . $productUrlSuffix,
917: $this->generatePath('id', $product, $category)
918: );
919: }
920:
921:
922: return $this->getUnusedPath($category->getStoreId(), $urlKey . $productUrlSuffix,
923: $this->generatePath('id', $product)
924: );
925: }
926:
927:
928: if (!$product) {
929: return 'catalog/category/view/id/' . $category->getId();
930: }
931: if ($category && $category->getLevel() > 1) {
932: return 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId();
933: }
934: return 'catalog/product/view/id/' . $product->getId();
935: }
936:
937: 938: 939: 940: 941:
942: public function generateUniqueIdPath()
943: {
944: return str_replace('0.', '', str_replace(' ', '_', microtime()));
945: }
946:
947: 948: 949: 950: 951: 952: 953: 954:
955: protected function _saveRewriteHistory($rewriteData, $rewrite)
956: {
957: if ($rewrite instanceof Varien_Object && $rewrite->getId()) {
958: $rewriteData['target_path'] = $rewriteData['request_path'];
959: $rewriteData['request_path'] = $rewrite->getRequestPath();
960: $rewriteData['id_path'] = $this->generateUniqueIdPath();
961: $rewriteData['is_system'] = 0;
962: $rewriteData['options'] = 'RP';
963: $this->getResource()->saveRewriteHistory($rewriteData);
964: }
965:
966: return $this;
967: }
968: }
969: