Skip to content

Commit c896a78

Browse files
author
Maksym Savich
committed
MAGETWO-31354: Magento Version Tag shows in RSS Feed
1 parent 214a270 commit c896a78

File tree

6 files changed

+57
-11
lines changed

6 files changed

+57
-11
lines changed

app/code/Magento/AdminNotification/Model/Feed.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ class Feed extends \Magento\Framework\Model\AbstractModel
5050
*/
5151
protected $_deploymentConfig;
5252

53+
/**
54+
* @var \Magento\Framework\App\ProductMetadataInterface
55+
*/
56+
protected $productMetadata;
57+
58+
/**
59+
* @var \Magento\Framework\UrlInterface
60+
*/
61+
protected $urlBuilder;
62+
5363
/**
5464
* @param \Magento\Framework\Model\Context $context
5565
* @param \Magento\Framework\Registry $registry
@@ -68,15 +78,19 @@ public function __construct(
6878
\Magento\AdminNotification\Model\InboxFactory $inboxFactory,
6979
\Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory,
7080
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
81+
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
82+
\Magento\Framework\UrlInterface $urlBuilder,
7183
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
7284
\Magento\Framework\Data\Collection\Db $resourceCollection = null,
7385
array $data = []
7486
) {
7587
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
76-
$this->_backendConfig = $backendConfig;
77-
$this->_inboxFactory = $inboxFactory;
78-
$this->curlFactory = $curlFactory;
88+
$this->_backendConfig = $backendConfig;
89+
$this->_inboxFactory = $inboxFactory;
90+
$this->curlFactory = $curlFactory;
7991
$this->_deploymentConfig = $deploymentConfig;
92+
$this->productMetadata = $productMetadata;
93+
$this->urlBuilder = $urlBuilder;
8094
}
8195

8296
/**
@@ -191,7 +205,15 @@ public function setLastUpdate()
191205
public function getFeedData()
192206
{
193207
$curl = $this->curlFactory->create();
194-
$curl->setConfig(['timeout' => 2]);
208+
$curl->setConfig(
209+
[
210+
'timeout' => 2,
211+
'useragent' => $this->productMetadata->getName()
212+
. '/' . $this->productMetadata->getVersion()
213+
. ' (' . $this->productMetadata->getEdition() . ')',
214+
'referer' => $this->urlBuilder->getUrl('*/*/*')
215+
]
216+
);
195217
$curl->write(\Zend_Http_Client::GET, $this->getFeedUrl(), '1.0');
196218
$data = $curl->read();
197219
if ($data === false) {

app/code/Magento/Version/Controller/Index/Index.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
class Index extends Action
1717
{
18-
const PRODUCT_NAME = "Magento";
19-
2018
/**
2119
* @var ProductMetadataInterface
2220
*/
@@ -40,7 +38,7 @@ public function __construct(Context $context, ProductMetadataInterface $productM
4038
public function execute()
4139
{
4240
$this->getResponse()->setBody(
43-
self::PRODUCT_NAME . '/' .
41+
$this->productMetadata->getName() . '/' .
4442
$this->productMetadata->getVersion() . ' (' .
4543
$this->productMetadata->getEdition() . ')'
4644
);

dev/tests/unit/testsuite/Magento/Framework/App/ProductMetadataTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ public function testGetEdition()
3434
$productEdition = $this->productMetadata->getEdition();
3535
$this->assertNotEmpty($productEdition, 'Empty product edition');
3636
}
37+
38+
public function testGetName()
39+
{
40+
$productName = $this->productMetadata->getName();
41+
$this->assertNotEmpty($productName, 'Empty product name');
42+
}
3743
}

lib/internal/Magento/Framework/App/ProductMetadata.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class ProductMetadata implements ProductMetadataInterface
1313
{
1414
const EDITION_NAME = 'Community';
15+
const PRODUCT_NAME = 'Magento';
1516

1617
/**
1718
* Get Product version
@@ -32,4 +33,14 @@ public function getEdition()
3233
{
3334
return self::EDITION_NAME;
3435
}
36+
37+
/**
38+
* Get Product name
39+
*
40+
* @return string
41+
*/
42+
public function getName()
43+
{
44+
return self::PRODUCT_NAME;
45+
}
3546
}

lib/internal/Magento/Framework/App/ProductMetadataInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ public function getVersion();
2222
* @return string
2323
*/
2424
public function getEdition();
25+
26+
/**
27+
* Get Product name
28+
*
29+
* @return string
30+
*/
31+
public function getName();
2532
}

lib/internal/Magento/Framework/HTTP/Adapter/Curl.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ class Curl implements \Zend_Http_Client_Adapter_Interface
3535
* @var array
3636
*/
3737
protected $_allowedParams = [
38-
'timeout' => CURLOPT_TIMEOUT,
38+
'timeout' => CURLOPT_TIMEOUT,
3939
'maxredirects' => CURLOPT_MAXREDIRS,
40-
'proxy' => CURLOPT_PROXY,
41-
'ssl_cert' => CURLOPT_SSLCERT,
42-
'userpwd' => CURLOPT_USERPWD,
40+
'proxy' => CURLOPT_PROXY,
41+
'ssl_cert' => CURLOPT_SSLCERT,
42+
'userpwd' => CURLOPT_USERPWD,
43+
'useragent' => CURLOPT_USERAGENT,
44+
'referer' => CURLOPT_REFERER
4345
];
4446

4547
/**

0 commit comments

Comments
 (0)