Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bugs for admin save base urls #2800

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@
*/
class Mage_Adminhtml_Model_System_Config_Backend_Baseurl extends Mage_Core_Model_Config_Data
{
/**
* @return $this
* @throws Mage_Core_Exception
*/
protected function _beforeSave()
{
$value = $this->getValue();
$value = str_replace(' ', '', $this->getValue());

if ($value === '') {
$label = $this->getFieldConfig()->descend('label');
Mage::throwException(Mage::helper('core')->__('"%s" is a required value.', $label));
}

if (!preg_match('#^{{((un)?secure_)?base_url}}#', $value)) {
$value = Mage::helper('core/url')->encodePunycode($value);
Expand Down Expand Up @@ -64,9 +73,7 @@ protected function _afterSave()
}

/**
* Processing object after load data
*
* @return Mage_Core_Model_Abstract
* @inheritDoc
*/
protected function _afterLoad()
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Model/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getSecure()
if ($this->hasData('secure_is_forced')) {
return $this->getData('secure');
}
return Mage::getStoreConfigFlag('web/secure/use_in_adminhtml');
return Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_SECURE_IN_ADMINHTML);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Controller/Varien/Router/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function _noRouteShouldBeApplied()
protected function _shouldBeSecure($path)
{
return substr((string)Mage::getConfig()->getNode('default/web/unsecure/base_url'), 0, 5) === 'https'
|| Mage::getStoreConfigFlag('web/secure/use_in_adminhtml', Mage_Core_Model_App::ADMIN_STORE_ID)
|| Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_SECURE_IN_ADMINHTML, Mage_Core_Model_App::ADMIN_STORE_ID)
&& substr((string)Mage::getConfig()->getNode('default/web/secure/base_url'), 0, 5) === 'https';
}

Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ protected function _getCurrentSecureUrl($request)
*/
protected function _shouldBeSecure($path)
{
return substr(Mage::getStoreConfig('web/unsecure/base_url'), 0, 5) === 'https'
|| Mage::getStoreConfigFlag('web/secure/use_in_frontend')
&& substr(Mage::getStoreConfig('web/secure/base_url'), 0, 5) == 'https'
return substr(Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL), 0, 5) === 'https'
|| Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND)
&& substr(Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL), 0, 5) == 'https'
&& Mage::getConfig()->shouldUrlBeSecure($path);
}
}
8 changes: 4 additions & 4 deletions app/code/core/Mage/Core/Model/Source/Email/Variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function __construct()
{
$this->_configVariables = [
[
'value' => Mage_Core_Model_Url::XML_PATH_UNSECURE_URL,
'value' => Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL,
'label' => Mage::helper('core')->__('Base Unsecure URL')
],
[
'value' => Mage_Core_Model_Url::XML_PATH_SECURE_URL,
'value' => Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL,
'label' => Mage::helper('core')->__('Base Secure URL')
],
[
Expand Down Expand Up @@ -79,11 +79,11 @@ public function __construct()
'label' => Mage::helper('core')->__('Custom2 Contact Email')
],
[
'value' => 'general/store_information/name',
'value' => Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME,
'label' => Mage::helper('core')->__('Store Name')
],
[
'value' => 'general/store_information/phone',
'value' => Mage_Core_Model_Store::XML_PATH_STORE_STORE_PHONE,
'label' => Mage::helper('core')->__('Store Contact Telephone')
],
[
Expand Down
74 changes: 23 additions & 51 deletions app/code/core/Mage/Core/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,58 +56,30 @@ class Mage_Core_Model_Store extends Mage_Core_Model_Abstract
*/
public const ENTITY = 'core_store';

/**
/**#@+
* Configuration pathes
* @var string
*/
public const XML_PATH_STORE_STORE_NAME = 'general/store_information/name';
/**
*
*/
public const XML_PATH_STORE_STORE_PHONE = 'general/store_information/phone';
/**
*
*/
public const XML_PATH_STORE_STORE_HOURS = 'general/store_information/hours';
/**
*
*/
public const XML_PATH_STORE_IN_URL = 'web/url/use_store';
/**
*
*/
public const XML_PATH_USE_REWRITES = 'web/seo/use_rewrites';
/**
*
*/
public const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';
/**
*
*/
public const XML_PATH_SECURE_BASE_URL = 'web/secure/base_url';
/**
*
*/
public const XML_PATH_SECURE_IN_FRONTEND = 'web/secure/use_in_frontend';
/**
*
*/
public const XML_PATH_SECURE_IN_ADMINHTML = 'web/secure/use_in_adminhtml';
/**
*
*/
public const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
/**
*
*/
public const XML_PATH_UNSECURE_BASE_LINK_URL = 'web/unsecure/base_link_url';
/**
*
*/
public const XML_PATH_OFFLOADER_HEADER = 'web/secure/offloader_header';
/**
*
*/
public const XML_PATH_PRICE_SCOPE = 'catalog/price/scope';
public const XML_PATH_STORE_STORE_NAME = 'general/store_information/name';
public const XML_PATH_STORE_STORE_PHONE = 'general/store_information/phone';
public const XML_PATH_STORE_STORE_HOURS = 'general/store_information/hours';
public const XML_PATH_STORE_IN_URL = 'web/url/use_store';
public const XML_PATH_USE_REWRITES = 'web/seo/use_rewrites';
public const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';
public const XML_PATH_UNSECURE_BASE_JS_URL = 'web/unsecure/base_js_url';
public const XML_PATH_UNSECURE_BASE_LINK_URL = 'web/unsecure/base_link_url';
public const XML_PATH_UNSECURE_BASE_MEDIA_URL = 'web/unsecure/base_media_url';
public const XML_PATH_UNSECURE_BASE_SKIN_URL = 'web/unsecure/base_skin_url';
public const XML_PATH_SECURE_BASE_URL = 'web/secure/base_url';
public const XML_PATH_SECURE_BASE_JS_URL = 'web/secure/base_js_url';
public const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
public const XML_PATH_SECURE_BASE_MEDIA_URL = 'web/secure/base_media_url';
public const XML_PATH_SECURE_BASE_SKIN_URL = 'web/secure/base_skin_url';
public const XML_PATH_SECURE_IN_FRONTEND = 'web/secure/use_in_frontend';
public const XML_PATH_SECURE_IN_ADMINHTML = 'web/secure/use_in_adminhtml';
public const XML_PATH_OFFLOADER_HEADER = 'web/secure/offloader_header';
public const XML_PATH_PRICE_SCOPE = 'catalog/price/scope';
/**#@-*/

/**
* Price scope constants
Expand Down Expand Up @@ -1283,7 +1255,7 @@ public function isReadOnly($value = null)
public function getFrontendName()
{
if (is_null($this->_frontendName)) {
$storeGroupName = (string) Mage::getStoreConfig('general/store_information/name', $this);
$storeGroupName = (string) Mage::getStoreConfig(self::XML_PATH_STORE_STORE_NAME, $this);
$this->_frontendName = (!empty($storeGroupName)) ? $storeGroupName : $this->getGroup()->getName();
}
return $this->_frontendName;
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Model/Url/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ public function rewrite(Zend_Controller_Request_Http $request = null, Zend_Contr
}
$isRedirectOption = $this->hasOption('R');
if ($isRedirectOption || $isPermanentRedirectOption) {
if (Mage::getStoreConfig('web/url/use_store') && $storeCode = Mage::app()->getStore()->getCode()) {
if (Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL) && $storeCode = Mage::app()->getStore()->getCode()) {
$targetUrl = $request->getBaseUrl() . '/' . $storeCode . '/' . $this->getTargetPath();
}

$this->_sendRedirectHeaders($targetUrl, $isPermanentRedirectOption);
}

if (Mage::getStoreConfig('web/url/use_store') && $storeCode = Mage::app()->getStore()->getCode()) {
if (Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL) && $storeCode = Mage::app()->getStore()->getCode()) {
$targetUrl = $request->getBaseUrl() . '/' . $storeCode . '/' . $this->getTargetPath();
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Url/Rewrite/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected function _processRedirectOptions()
$targetUrl = $this->_request->getBaseUrl() . '/' . $this->_rewrite->getTargetPath();

$storeCode = $this->_app->getStore()->getCode();
if (Mage::getStoreConfig('web/url/use_store') && !empty($storeCode)) {
if (Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL) && !empty($storeCode)) {
$targetUrl = $this->_request->getBaseUrl() . '/' . $storeCode . '/' . $this->_rewrite->getTargetPath();
}

Expand Down
10 changes: 10 additions & 0 deletions app/code/core/Mage/Core/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<validate>required-entry</validate>
</base_url>
<base_link_url translate="label">
<label>Base Link URL</label>
Expand All @@ -1390,6 +1391,7 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<validate>required-entry</validate>
</base_link_url>
<base_skin_url translate="label">
<label>Base Skin URL</label>
Expand All @@ -1398,6 +1400,7 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<validate>required-entry</validate>
</base_skin_url>
<base_media_url translate="label">
<label>Base Media URL</label>
Expand All @@ -1406,6 +1409,7 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<validate>required-entry</validate>
</base_media_url>
<base_js_url translate="label comment">
<label>Base JavaScript URL</label>
Expand All @@ -1415,6 +1419,7 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[<strong style="color:red">Warning!</strong> When using CDN, in some cases JavaScript may not run properly if CDN is not in your subdomain]]></comment>
<validate>required-entry</validate>
</base_js_url>
</fields>
</unsecure>
Expand All @@ -1433,6 +1438,7 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Make sure that base URL ends with '/' (slash), e.g. http://yourdomain/magento/</comment>
<validate>required-entry</validate>
</base_url>
<base_link_url translate="label comment">
<label>Base Link URL</label>
Expand All @@ -1442,6 +1448,7 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Make sure that base URL ends with '/' (slash), e.g. http://yourdomain/magento/</comment>
<validate>required-entry</validate>
</base_link_url>
<base_skin_url translate="label">
<label>Base Skin URL</label>
Expand All @@ -1450,6 +1457,7 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<validate>required-entry</validate>
</base_skin_url>
<base_media_url translate="label">
<label>Base Media URL</label>
Expand All @@ -1458,6 +1466,7 @@
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<validate>required-entry</validate>
</base_media_url>
<base_js_url translate="label comment">
<label>Base JavaScript URL</label>
Expand All @@ -1467,6 +1476,7 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[<strong style="color:red">Warning!</strong> When using CDN, in some cases JavaScript may not run properly if CDN is not in your subdomain]]></comment>
<validate>required-entry</validate>
</base_js_url>
<use_in_frontend translate="label">
<label>Use Secure URLs in Frontend</label>
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Page/Block/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getPrintLogoUrl()

// buld url
if (!empty($logo)) {
$logo = Mage::getStoreConfig('web/unsecure/base_media_url') . $logo;
$logo = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_MEDIA_URL) . $logo;
} else {
$logo = '';
}
Expand Down