/
Redirect.php
executable file
·134 lines (123 loc) · 3.4 KB
/
Redirect.php
1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Magento Enterprise Edition
*
* NOTICE OF LICENSE
*
* This source file is subject to the Magento Enterprise Edition End User License Agreement
* that is bundled with this package in the file LICENSE_EE.txt.
* It is also available through the world-wide-web at this URL:
* http://www.magento.com/license/enterprise-edition
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magento.com for more information.
*
* @category Enterprise
* @package Enterprise_UrlRewrite
* @copyright Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
* @license http://www.magento.com/license/enterprise-edition
*/
/**
* UrlRewrite redirect model
*
* @category Enterprise
* @package Enterprise_UrlRewrite
* @author Magento Core Team <core@magentocommerce.com>
*/
class Enterprise_UrlRewrite_Model_Redirect extends Mage_Core_Model_Abstract
{
/**
* Url Rewrite Entity Type
*/
const URL_REWRITE_ENTITY_TYPE = 1;
/**
* Prefix of model events names
*
* @var string
*/
protected $_eventPrefix = 'redirect';
/**
* Parameter name in event
*
* In observe method you can use $observer->getEvent()->getObject() in this case
*
* @var string
*/
protected $_eventObject = 'redirect';
/**
* Initialize resources
*/
protected function _construct()
{
$this->_init('enterprise_urlrewrite/redirect');
}
/**
* Validate identifier and target path
*
* @return bool
*/
public function validate()
{
return Mage::helper('core/url_rewrite')->validateRequestPath($this->getIdentifier());
}
/**
* Make validation before saving
*
* @return Mage_Core_Model_Abstract
*/
protected function _beforeSave()
{
$this->validate();
return parent::_beforeSave();
}
/**
* Load rewrite object by request path
*
* @param string $requestPath
* @param int $storeId
* @return Enterprise_UrlRewrite_Model_Redirect
*/
public function loadByRequestPath($requestPath, $storeId)
{
$this->setId(null);
$this->_getResource()->loadByRequestPath($this, $requestPath, $storeId);
$this->_afterLoad();
$this->setOrigData();
$this->_hasDataChanges = false;
return $this;
}
/**
* Detect circular redirects
*
* @return bool
*/
public function isCircular($circularChain = array())
{
$circularChain[] = $this->getIdentifier();
$redirect = Mage::getModel('enterprise_urlrewrite/redirect')->loadByRequestPath(
$this->getTargetPath(), $this->getStoreId()
);
if (!$redirect->getId()) {
return false;
}
if (in_array($redirect->getTargetPath(), $circularChain)) {
return true;
}
return $redirect->isCircular($circularChain);
}
/**
* Check whether redirect record exists.
*
* @return bool
*/
public function exists()
{
return $this->_getResource()->exists($this);
}
}