Skip to content

Commit f47e46f

Browse files
committed
MAGETWO-51929: Web Setup Wizard does not work when Magento is installed in pub
- Do not show setup wizard when document root is pub
1 parent 135f967 commit f47e46f

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Model\Setup;
7+
8+
use Magento\Backend\Model\Menu;
9+
use Magento\Backend\Model\Menu\Builder;
10+
use Magento\Framework\App\DocRoot;
11+
12+
/**
13+
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified.
14+
*/
15+
class MenuBuilder
16+
{
17+
18+
/**
19+
* @var DocRoot
20+
*/
21+
protected $docRoot;
22+
23+
/**
24+
* MenuBuilder constructor.
25+
*
26+
* @param DocRoot $docRoot
27+
*/
28+
public function __construct(DocRoot $docRoot)
29+
{
30+
$this->docRoot = $docRoot;
31+
}
32+
33+
/**
34+
* Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified.
35+
*
36+
* @param Builder $subject
37+
* @param Menu $menu
38+
* @return Menu
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function afterGetResult(Builder $subject, Menu $menu)
42+
{
43+
if ($this->docRoot->hasThisSubDir('pub', 'setup')) {
44+
$menu->remove('Magento_Backend::setup_wizard');
45+
}
46+
return $menu;
47+
}
48+
}

app/code/Magento/Backend/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,7 @@
214214
</argument>
215215
</arguments>
216216
</type>
217+
<type name="Magento\Backend\Model\Menu\Builder">
218+
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
219+
</type>
217220
</config>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem\Directory\ReadFactory;
11+
12+
/**
13+
* This class calculates if document root is set to pub
14+
*/
15+
class DocRoot
16+
{
17+
/**
18+
* @var RequestInterface
19+
*/
20+
private $request;
21+
22+
/**
23+
* @var ReadFactory
24+
*/
25+
private $readFactory;
26+
27+
/**
28+
* @param RequestInterface $request
29+
* @param ReadFactory $readFactory
30+
*/
31+
public function __construct(RequestInterface $request, ReadFactory $readFactory) {
32+
$this->request = $request;
33+
$this->readFactory = $readFactory;
34+
}
35+
36+
/**
37+
* Returns true if doc root is pub/ and not BP
38+
*
39+
* @return string
40+
*/
41+
public function hasThisSubDir($dirToCheck, $missingDir)
42+
{
43+
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
44+
$readDirectory = $this->readFactory->create(DirectoryList::ROOT);
45+
return strpos($rootBasePath, $dirToCheck) && !$readDirectory->isExist($rootBasePath + $missingDir);
46+
}
47+
}

0 commit comments

Comments
 (0)