Skip to content

Commit a483374

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-67054-PR-9094' into MAGETWO-67501-PR-9264
2 parents 31b63be + 01fe5d7 commit a483374

File tree

10 files changed

+175
-20
lines changed

10 files changed

+175
-20
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
/.settings
66
atlassian*
77
/nbproject
8+
/robots.txt
9+
/pub/robots.txt
810
/sitemap
911
/sitemap.xml
12+
/pub/sitemap
13+
/pub/sitemap.xml
1014
/.idea
1115
/.gitattributes
1216
/app/config_sandbox

app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*/
1010
namespace Magento\Config\Model\Config\Backend\Admin;
1111

12-
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
13+
use Magento\Framework\App\ObjectManager;
1314

1415
class Robots extends \Magento\Framework\App\Config\Value
1516
{
@@ -32,6 +33,7 @@ class Robots extends \Magento\Framework\App\Config\Value
3233
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
3334
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
3435
* @param array $data
36+
* @param DocumentRoot $documentRoot
3537
*/
3638
public function __construct(
3739
\Magento\Framework\Model\Context $context,
@@ -41,10 +43,13 @@ public function __construct(
4143
\Magento\Framework\Filesystem $filesystem,
4244
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
4345
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
44-
array $data = []
46+
array $data = [],
47+
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null
4548
) {
4649
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
47-
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
50+
51+
$documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
52+
$this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
4853
$this->_file = 'robots.txt';
4954
}
5055

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Config\Model\Config\Reader\Source\Deployed;
8+
9+
use Magento\Framework\Config\ConfigOptionsListConstants;
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\App\DeploymentConfig;
12+
13+
/**
14+
* Class DocumentRoot
15+
* @package Magento\Config\Model\Config\Reader\Source\Deployed
16+
*/
17+
class DocumentRoot
18+
{
19+
/**
20+
* @var DeploymentConfig
21+
*/
22+
private $config;
23+
24+
/**
25+
* DocumentRoot constructor.
26+
* @param DeploymentConfig $config
27+
*/
28+
public function __construct(DeploymentConfig $config)
29+
{
30+
$this->config = $config;
31+
}
32+
33+
/**
34+
* A shortcut to load the document root path from the DirectoryList based on the
35+
* deployment configuration.
36+
*
37+
* @return string
38+
*/
39+
public function getPath()
40+
{
41+
return $this->isPub() ? DirectoryList::PUB : DirectoryList::ROOT;
42+
}
43+
44+
/**
45+
* Returns whether the deployment configuration specifies that the document root is
46+
* in the pub/ folder. This affects ares such as sitemaps and robots.txt (and will
47+
* likely be extended to control other areas).
48+
*
49+
* @return bool
50+
*/
51+
public function isPub()
52+
{
53+
return (bool)$this->config->get(ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB);
54+
}
55+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Model\Config\Reader\Source\Deployed;
7+
8+
use Magento\Config\Model\Config\Reader;
9+
use Magento\Framework\App\Config;
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\Config\ConfigOptionsListConstants;
13+
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
14+
15+
/**
16+
* Test class for checking settings that defined in config file
17+
*/
18+
class DocumentRootTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $configMock;
24+
25+
/**
26+
* @var DocumentRoot
27+
*/
28+
private $documentRoot;
29+
30+
public function setUp()
31+
{
32+
$this->configMock = $this->getMockBuilder(DeploymentConfig::class)
33+
->disableOriginalConstructor()
34+
->getMock();
35+
36+
$this->documentRoot = new DocumentRoot($this->configMock);
37+
}
38+
39+
/**
40+
* Ensures that the path returned matches the pub/ path.
41+
*/
42+
public function testGetPath()
43+
{
44+
$this->configMockSetForDocumentRootIsPub();
45+
46+
$this->assertSame(DirectoryList::PUB, $this->documentRoot->getPath());
47+
}
48+
49+
/**
50+
* Ensures that the deployment configuration returns the mocked value for
51+
* the pub/ folder.
52+
*/
53+
public function testIsPub()
54+
{
55+
$this->configMockSetForDocumentRootIsPub();
56+
57+
$this->assertSame(true, $this->documentRoot->isPub());
58+
}
59+
60+
private function configMockSetForDocumentRootIsPub()
61+
{
62+
$this->configMock->expects($this->any())
63+
->method('get')
64+
->willReturnMap([
65+
[
66+
ConfigOptionsListConstants::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB,
67+
null,
68+
true
69+
],
70+
]);
71+
}
72+
}

app/code/Magento/Sitemap/Block/Adminhtml/Grid/Renderer/Link.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
namespace Magento\Sitemap\Block\Adminhtml\Grid\Renderer;
1212

1313
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
15+
use Magento\Framework\App\ObjectManager;
1416

1517
class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
1618
{
@@ -24,20 +26,29 @@ class Link extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRe
2426
*/
2527
protected $_sitemapFactory;
2628

29+
/**
30+
* @var DocumentRoot
31+
*/
32+
protected $documentRoot;
33+
2734
/**
2835
* @param \Magento\Backend\Block\Context $context
2936
* @param \Magento\Sitemap\Model\SitemapFactory $sitemapFactory
3037
* @param \Magento\Framework\Filesystem $filesystem
3138
* @param array $data
39+
* @param DocumentRoot $documentRoot
3240
*/
3341
public function __construct(
3442
\Magento\Backend\Block\Context $context,
3543
\Magento\Sitemap\Model\SitemapFactory $sitemapFactory,
3644
\Magento\Framework\Filesystem $filesystem,
37-
array $data = []
45+
array $data = [],
46+
DocumentRoot $documentRoot = null
3847
) {
3948
$this->_sitemapFactory = $sitemapFactory;
4049
$this->_filesystem = $filesystem;
50+
$this->documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
51+
4152
parent::__construct($context, $data);
4253
}
4354

@@ -54,7 +65,8 @@ public function render(\Magento\Framework\DataObject $row)
5465
$url = $this->escapeHtml($sitemap->getSitemapUrl($row->getSitemapPath(), $row->getSitemapFilename()));
5566

5667
$fileName = preg_replace('/^\//', '', $row->getSitemapPath() . $row->getSitemapFilename());
57-
$directory = $this->_filesystem->getDirectoryRead(DirectoryList::ROOT);
68+
$documentRootPath = $this->documentRoot->getPath();
69+
$directory = $this->_filesystem->getDirectoryRead($documentRootPath);
5870
if ($directory->isFile($fileName)) {
5971
return sprintf('<a href="%1$s">%1$s</a>', $url);
6072
}

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// @codingStandardsIgnoreFile
88

99
namespace Magento\Sitemap\Model;
10-
11-
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
11+
use Magento\Framework\App\ObjectManager;
1212

1313
/**
1414
* Sitemap model
@@ -147,21 +147,24 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel
147147
protected $dateTime;
148148

149149
/**
150+
* Initialize dependencies.
151+
*
150152
* @param \Magento\Framework\Model\Context $context
151153
* @param \Magento\Framework\Registry $registry
152154
* @param \Magento\Framework\Escaper $escaper
153155
* @param \Magento\Sitemap\Helper\Data $sitemapData
154156
* @param \Magento\Framework\Filesystem $filesystem
155-
* @param \Magento\Sitemap\Model\ResourceModel\Catalog\CategoryFactory $categoryFactory
156-
* @param \Magento\Sitemap\Model\ResourceModel\Catalog\ProductFactory $productFactory
157-
* @param \Magento\Sitemap\Model\ResourceModel\Cms\PageFactory $cmsFactory
157+
* @param ResourceModel\Catalog\CategoryFactory $categoryFactory
158+
* @param ResourceModel\Catalog\ProductFactory $productFactory
159+
* @param ResourceModel\Cms\PageFactory $cmsFactory
158160
* @param \Magento\Framework\Stdlib\DateTime\DateTime $modelDate
159161
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
160162
* @param \Magento\Framework\App\RequestInterface $request
161163
* @param \Magento\Framework\Stdlib\DateTime $dateTime
162-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
163-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
164+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
165+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
164166
* @param array $data
167+
* @param DocumentRoot|null $documentRoot
165168
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
166169
*/
167170
public function __construct(
@@ -179,11 +182,13 @@ public function __construct(
179182
\Magento\Framework\Stdlib\DateTime $dateTime,
180183
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
181184
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
182-
array $data = []
185+
array $data = [],
186+
\Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot $documentRoot = null
183187
) {
184188
$this->_escaper = $escaper;
185189
$this->_sitemapData = $sitemapData;
186-
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
190+
$documentRoot = $documentRoot ?: ObjectManager::getInstance()->get(DocumentRoot::class);
191+
$this->_directory = $filesystem->getDirectoryWrite($documentRoot->getPath());
187192
$this->_categoryFactory = $categoryFactory;
188193
$this->_productFactory = $productFactory;
189194
$this->_cmsFactory = $cmsFactory;

app/code/Magento/Sitemap/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"magento/module-backend": "100.2.*",
1111
"magento/module-catalog-url-rewrite": "100.2.*",
1212
"magento/module-media-storage": "100.2.*",
13-
"magento/framework": "100.2.*"
13+
"magento/framework": "100.2.*",
14+
"magento/module-config": "100.2.*"
1415
},
1516
"suggest": {
1617
"magento/module-config": "100.2.*"

dev/tests/integration/testsuite/Magento/Config/Model/Config/Backend/Admin/RobotsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Config\Model\Config\Backend\Admin;
77

8-
use Magento\Framework\App\Filesystem\DirectoryList;
8+
use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot;
99

1010
/**
1111
* @magentoAppArea adminhtml
@@ -33,11 +33,11 @@ protected function setUp()
3333
$this->model = $objectManager->create(\Magento\Config\Model\Config\Backend\Admin\Robots::class);
3434
$this->model->setPath('design/search_engine_robots/custom_instructions');
3535
$this->model->afterLoad();
36+
37+
$documentRootPath = $objectManager->get(DocumentRoot::class)->getPath();
3638
$this->rootDirectory = $objectManager->get(
3739
\Magento\Framework\Filesystem::class
38-
)->getDirectoryRead(
39-
DirectoryList::ROOT
40-
);
40+
)->getDirectoryRead($documentRootPath);
4141
}
4242

4343
/**

generated/.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Order deny,allow
2-
Deny from all
2+
Deny from all

lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ConfigOptionsListConstants
3030
const CONFIG_PATH_DB = 'db';
3131
const CONFIG_PATH_RESOURCE = 'resource';
3232
const CONFIG_PATH_CACHE_TYPES = 'cache_types';
33+
const CONFIG_PATH_DOCUMENT_ROOT_IS_PUB = 'directories/document_root_is_pub';
3334
const CONFIG_PATH_DB_LOGGER_OUTPUT = 'db_logger/output';
3435
const CONFIG_PATH_DB_LOGGER_LOG_EVERYTHING = 'db_logger/log_everything';
3536
const CONFIG_PATH_DB_LOGGER_QUERY_TIME_THRESHOLD = 'db_logger/query_time_threshold';

0 commit comments

Comments
 (0)