Baseurl.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AdminNotification\Model\System\Message;
  7. use Magento\Store\Model\Store;
  8. /**
  9. * @deprecated 100.1.0
  10. */
  11. class Baseurl implements \Magento\Framework\Notification\MessageInterface
  12. {
  13. /**
  14. * @var \Magento\Framework\UrlInterface
  15. */
  16. protected $_urlBuilder;
  17. /**
  18. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  19. */
  20. protected $_config;
  21. /**
  22. * @var \Magento\Store\Model\StoreManagerInterface
  23. */
  24. protected $_storeManager;
  25. /**
  26. * @var \Magento\Framework\App\Config\ValueFactory
  27. */
  28. protected $_configValueFactory;
  29. /**
  30. * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  31. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  32. * @param \Magento\Framework\UrlInterface $urlBuilder
  33. * @param \Magento\Framework\App\Config\ValueFactory $configValueFactory
  34. */
  35. public function __construct(
  36. \Magento\Framework\App\Config\ScopeConfigInterface $config,
  37. \Magento\Store\Model\StoreManagerInterface $storeManager,
  38. \Magento\Framework\UrlInterface $urlBuilder,
  39. \Magento\Framework\App\Config\ValueFactory $configValueFactory
  40. ) {
  41. $this->_urlBuilder = $urlBuilder;
  42. $this->_config = $config;
  43. $this->_storeManager = $storeManager;
  44. $this->_configValueFactory = $configValueFactory;
  45. }
  46. /**
  47. * Get url for config settings where base url option can be changed
  48. *
  49. * @return string
  50. */
  51. protected function _getConfigUrl()
  52. {
  53. $output = '';
  54. $defaultUnsecure = $this->_config->getValue(Store::XML_PATH_UNSECURE_BASE_URL, 'default');
  55. $defaultSecure = $this->_config->getValue(Store::XML_PATH_SECURE_BASE_URL, 'default');
  56. if ($defaultSecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER ||
  57. $defaultUnsecure == \Magento\Store\Model\Store::BASE_URL_PLACEHOLDER
  58. ) {
  59. $output = $this->_urlBuilder->getUrl('adminhtml/system_config/edit', ['section' => 'web']);
  60. } else {
  61. /** @var $dataCollection \Magento\Config\Model\ResourceModel\Config\Data\Collection */
  62. $dataCollection = $this->_configValueFactory->create()->getCollection();
  63. $dataCollection->addValueFilter(\Magento\Store\Model\Store::BASE_URL_PLACEHOLDER);
  64. /** @var $data \Magento\Framework\App\Config\ValueInterface */
  65. foreach ($dataCollection as $data) {
  66. if ($data->getScope() == 'stores') {
  67. $code = $this->_storeManager->getStore($data->getScopeId())->getCode();
  68. $output = $this->_urlBuilder->getUrl(
  69. 'adminhtml/system_config/edit',
  70. ['section' => 'web', 'store' => $code]
  71. );
  72. break;
  73. } elseif ($data->getScope() == 'websites') {
  74. $code = $this->_storeManager->getWebsite($data->getScopeId())->getCode();
  75. $output = $this->_urlBuilder->getUrl(
  76. 'adminhtml/system_config/edit',
  77. ['section' => 'web', 'website' => $code]
  78. );
  79. break;
  80. }
  81. }
  82. }
  83. return $output;
  84. }
  85. /**
  86. * Retrieve unique message identity
  87. *
  88. * @return string
  89. */
  90. public function getIdentity()
  91. {
  92. return md5('BASE_URL' . $this->_getConfigUrl());
  93. }
  94. /**
  95. * Check whether
  96. *
  97. * @return bool
  98. */
  99. public function isDisplayed()
  100. {
  101. return (bool)$this->_getConfigUrl();
  102. }
  103. /**
  104. * Retrieve message text
  105. *
  106. * @return \Magento\Framework\Phrase
  107. */
  108. public function getText()
  109. {
  110. return __(
  111. '{{base_url}} is not recommended to use in a production environment to declare the Base Unsecure '
  112. . 'URL / Base Secure URL. We highly recommend changing this value in your Magento '
  113. . '<a href="%1">configuration</a>.',
  114. $this->_getConfigUrl()
  115. );
  116. }
  117. /**
  118. * Retrieve message severity
  119. *
  120. * @return int
  121. */
  122. public function getSeverity()
  123. {
  124. return self::SEVERITY_CRITICAL;
  125. }
  126. }