Skip to content

Commit 12efdf6

Browse files
author
He, Robert(rohe)
committed
Merge pull request #587 from magento-ogre/MAGETWO-52187-user-noaccess
[Ogre] MAGETWO-52187: Magento re-install with minimum admin access breaks installation
2 parents ee61591 + ef00b9c commit 12efdf6

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

setup/src/Magento/Setup/Controller/Install.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Zend\View\Model\ViewModel;
2121
use Magento\Setup\Console\Command\InstallCommand;
2222
use Magento\SampleData;
23+
use Magento\Framework\App\DeploymentConfig;
2324

2425
/**
2526
* Install controller
@@ -48,24 +49,32 @@ class Install extends AbstractActionController
4849
*/
4950
protected $sampleDataState;
5051

52+
/**
53+
* @var \Magento\Framework\App\DeploymentConfig
54+
*/
55+
private $deploymentConfig;
56+
5157
/**
5258
* Default Constructor
5359
*
5460
* @param WebLogger $logger
5561
* @param InstallerFactory $installerFactory
5662
* @param ProgressFactory $progressFactory
5763
* @param \Magento\Framework\Setup\SampleData\State $sampleDataState
64+
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
5865
*/
5966
public function __construct(
6067
WebLogger $logger,
6168
InstallerFactory $installerFactory,
6269
ProgressFactory $progressFactory,
63-
\Magento\Framework\Setup\SampleData\State $sampleDataState
70+
\Magento\Framework\Setup\SampleData\State $sampleDataState,
71+
DeploymentConfig $deploymentConfig
6472
) {
6573
$this->log = $logger;
6674
$this->installer = $installerFactory->create($logger);
6775
$this->progressFactory = $progressFactory;
6876
$this->sampleDataState = $sampleDataState;
77+
$this->deploymentConfig = $deploymentConfig;
6978
}
7079

7180
/**
@@ -89,6 +98,7 @@ public function startAction()
8998
$this->log->clear();
9099
$json = new JsonModel;
91100
try {
101+
$this->checkForPriorInstall();
92102
$data = array_merge(
93103
$this->importDeploymentConfigForm(),
94104
$this->importUserConfigForm(),
@@ -106,6 +116,7 @@ public function startAction()
106116
$json->setVariable('messages', $this->installer->getInstallInfo()[Installer::INFO_MESSAGE]);
107117
} catch (\Exception $e) {
108118
$this->log->logError($e);
119+
$json->setVariable('messages', $e->getMessage());
109120
$json->setVariable('success', false);
110121
}
111122
return $json;
@@ -145,6 +156,19 @@ public function progressAction()
145156
return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
146157
}
147158

159+
/**
160+
* Checks for prior install
161+
*
162+
* @return void
163+
* @throws \Magento\Setup\Exception
164+
*/
165+
private function checkForPriorInstall()
166+
{
167+
if ($this->deploymentConfig->isAvailable()) {
168+
throw new \Magento\Setup\Exception('Magento application is already installed.');
169+
}
170+
}
171+
148172
/**
149173
* Maps data from request to format of deployment config model
150174
*

setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,28 @@ class InstallTest extends \PHPUnit_Framework_TestCase
3535
*/
3636
private $sampleDataState;
3737

38+
/**
39+
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $deploymentConfig;
42+
3843
public function setUp()
3944
{
4045
$this->webLogger = $this->getMock('\Magento\Setup\Model\WebLogger', [], [], '', false);
4146
$installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false);
4247
$this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false);
4348
$this->progressFactory = $this->getMock('\Magento\Setup\Model\Installer\ProgressFactory', [], [], '', false);
4449
$this->sampleDataState = $this->getMock('\Magento\Framework\Setup\SampleData\State', [], [], '', false);
50+
$this->deploymentConfig = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
4551

4652
$installerFactory->expects($this->once())->method('create')->with($this->webLogger)
4753
->willReturn($this->installer);
4854
$this->controller = new Install(
4955
$this->webLogger,
5056
$installerFactory,
5157
$this->progressFactory,
52-
$this->sampleDataState
58+
$this->sampleDataState,
59+
$this->deploymentConfig
5360
);
5461
}
5562

@@ -65,6 +72,7 @@ public function testStartAction()
6572
$this->webLogger->expects($this->once())->method('clear');
6673
$this->installer->expects($this->once())->method('install');
6774
$this->installer->expects($this->exactly(2))->method('getInstallInfo');
75+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
6876
$jsonModel = $this->controller->startAction();
6977
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
7078
$variables = $jsonModel->getVariables();
@@ -74,9 +82,23 @@ public function testStartAction()
7482
$this->assertTrue($variables['success']);
7583
}
7684

77-
public function testStartActionException()
85+
public function testStartActionPriorInstallException()
86+
{
87+
$this->webLogger->expects($this->once())->method('clear');
88+
$this->installer->expects($this->never())->method('install');
89+
$this->installer->expects($this->never())->method('getInstallInfo');
90+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
91+
$jsonModel = $this->controller->startAction();
92+
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
93+
$variables = $jsonModel->getVariables();
94+
$this->assertArrayHasKey('success', $variables);
95+
$this->assertArrayHasKey('messages', $variables);
96+
$this->assertFalse($variables['success']);
97+
}
98+
public function testStartActionInstallException()
7899
{
79100
$this->webLogger->expects($this->once())->method('clear');
101+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
80102
$this->installer->expects($this->once())->method('install')
81103
->willThrowException($this->getMock('\Exception'));
82104
$jsonModel = $this->controller->startAction();
@@ -87,6 +109,7 @@ public function testStartActionWithSampleDataError()
87109
{
88110
$this->webLogger->expects($this->once())->method('clear');
89111
$this->webLogger->expects($this->never())->method('logError');
112+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
90113
$this->installer->method('install');
91114
$this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
92115
$jsonModel = $this->controller->startAction();

0 commit comments

Comments
 (0)