-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Baseurl.php
143 lines (128 loc) · 4.37 KB
/
Baseurl.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
135
136
137
138
139
140
141
142
143
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\AdminNotification\Model\System\Message;
use Magento\Store\Model\Store;
/**
* @deprecated 100.1.0
*/
class Baseurl implements \Magento\Framework\Notification\MessageInterface
{
/**
* @var \Magento\Framework\UrlInterface
*/
protected $_urlBuilder;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_config;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* @var \Magento\Framework\App\Config\ValueFactory
*/
protected $_configValueFactory;
/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\App\Config\ValueFactory $configValueFactory
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\App\Config\ValueFactory $configValueFactory
) {
$this->_urlBuilder = $urlBuilder;
$this->_config = $config;
$this->_storeManager = $storeManager;
$this->_configValueFactory = $configValueFactory;
}
/**
* Get url for config settings where base url option can be changed
*
* @return string
*/
protected function _getConfigUrl()
{
$output = '';
$defaultUnsecure = $this->_config->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default');
$defaultSecure = $this->_config->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default');
if ($defaultSecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER ||
$defaultUnsecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER
) {
$output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web']);
} else {
/** @var $dataCollection \Magento\Config\Model\ResourceModel\Config\Data\Collection */
$dataCollection = $this->_configValueFactory->create()->getCollection();
$dataCollection->addValueFilter(\Magento\Store\Model\Store::BASE_URL_PLACEHOLDER);
/** @var $data \Magento\Framework\App\Config\ValueInterface */
foreach ($dataCollection as $data) {
if ($data->getScope() == 'stores') {
$code = $this->_storeManager->getStore($data->getScopeId())->getCode();
$output = $this->_urlBuilder->getUrl(
'adminhtml/system_config/edit',
['section' => 'web', 'store' => $code]
);
break;
} elseif ($data->getScope() == 'websites') {
$code = $this->_storeManager->getWebsite($data->getScopeId())->getCode();
$output = $this->_urlBuilder->getUrl(
'adminhtml/system_config/edit',
['section' => 'web', 'website' => $code]
);
break;
}
}
}
return $output;
}
/**
* Retrieve unique message identity
*
* @return string
*/
public function getIdentity()
{
// md5() here is not for cryptographic use.
// phpcs:ignore Magento2.Security.InsecureFunction
return md5('BASE_URL' . $this->_getConfigUrl());
}
/**
* Check whether
*
* @return bool
*/
public function isDisplayed()
{
return (bool)$this->_getConfigUrl();
}
/**
* Retrieve message text
*
* @return \Magento\Framework\Phrase
*/
public function getText()
{
return __(
'{{base_url}} is not recommended to use in a production environment to declare the Base Unsecure '
. 'URL / Base Secure URL. We highly recommend changing this value in your Magento '
. '<a href="%1">configuration</a>.',
$this->_getConfigUrl()
);
}
/**
* Retrieve message severity
*
* @return int
*/
public function getSeverity()
{
return self::SEVERITY_CRITICAL;
}
}