Skip to content

Commit 407f321

Browse files
author
Yaroslav Voronoy
committed
Merge remote-tracking branch 'origin/MDVA-305' into 2.0.6_backlog
2 parents f2aaafa + 44e87cc commit 407f321

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class Install extends AbstractActionController
4848
*/
4949
protected $sampleDataState;
5050

51+
/**
52+
* @var \Magento\Framework\App\DeploymentConfig
53+
*/
54+
private $deploymentConfig;
55+
5156
/**
5257
* Default Constructor
5358
*
@@ -89,6 +94,7 @@ public function startAction()
8994
$this->log->clear();
9095
$json = new JsonModel;
9196
try {
97+
$this->checkForPriorInstall();
9298
$data = array_merge(
9399
$this->importDeploymentConfigForm(),
94100
$this->importUserConfigForm(),
@@ -106,6 +112,7 @@ public function startAction()
106112
$json->setVariable('messages', $this->installer->getInstallInfo()[Installer::INFO_MESSAGE]);
107113
} catch (\Exception $e) {
108114
$this->log->logError($e);
115+
$json->setVariable('messages', $e->getMessage());
109116
$json->setVariable('success', false);
110117
}
111118
return $json;
@@ -145,6 +152,19 @@ public function progressAction()
145152
return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
146153
}
147154

155+
/**
156+
* Checks for prior install
157+
*
158+
* @return void
159+
* @throws \Magento\Setup\Exception
160+
*/
161+
private function checkForPriorInstall()
162+
{
163+
if ($this->getDeploymentConfig()->isAvailable()) {
164+
throw new \Magento\Setup\Exception('Magento application is already installed.');
165+
}
166+
}
167+
148168
/**
149169
* Maps data from request to format of deployment config model
150170
*
@@ -242,4 +262,20 @@ private function importAdminUserForm()
242262
$result[AdminAccount::KEY_LAST_NAME] = $result[AdminAccount::KEY_USER];
243263
return $result;
244264
}
265+
266+
/**
267+
* Get Deployment Config
268+
*
269+
* @return \Magento\Framework\App\DeploymentConfig
270+
*
271+
* @deprecated
272+
*/
273+
private function getDeploymentConfig()
274+
{
275+
if ($this->deploymentConfig === null) {
276+
$this->deploymentConfig = $this->installer->getObjectManagerProvider()->get()
277+
->get(\Magento\Framework\App\DeploymentConfig::class);
278+
}
279+
return $this->deploymentConfig;
280+
}
245281
}

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,16 @@ public function installDeploymentConfig($data)
488488
$this->objectManagerProvider->reset();
489489
}
490490

491+
/**
492+
* Get Object Manager Provider
493+
*
494+
* @return ObjectManagerProvider
495+
*/
496+
public function getObjectManagerProvider()
497+
{
498+
return $this->objectManagerProvider;
499+
}
500+
491501
/**
492502
* Set up setup_module table to register modules' versions, skip this process if it already exists
493503
*

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ 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);
@@ -51,6 +57,11 @@ public function setUp()
5157
$this->progressFactory,
5258
$this->sampleDataState
5359
);
60+
61+
$deploymentConfigReflection = new \ReflectionClass(get_class($this->controller));
62+
$deploymentConfigReflectionProperty = $deploymentConfigReflection->getProperty('deploymentConfig');
63+
$deploymentConfigReflectionProperty->setAccessible(true);
64+
$deploymentConfigReflectionProperty->setValue($this->controller, $this->deploymentConfig);
5465
}
5566

5667
public function testIndexAction()
@@ -65,6 +76,7 @@ public function testStartAction()
6576
$this->webLogger->expects($this->once())->method('clear');
6677
$this->installer->expects($this->once())->method('install');
6778
$this->installer->expects($this->exactly(2))->method('getInstallInfo');
79+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
6880
$jsonModel = $this->controller->startAction();
6981
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
7082
$variables = $jsonModel->getVariables();
@@ -74,9 +86,23 @@ public function testStartAction()
7486
$this->assertTrue($variables['success']);
7587
}
7688

77-
public function testStartActionException()
89+
public function testStartActionPriorInstallException()
90+
{
91+
$this->webLogger->expects($this->once())->method('clear');
92+
$this->installer->expects($this->never())->method('install');
93+
$this->installer->expects($this->never())->method('getInstallInfo');
94+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
95+
$jsonModel = $this->controller->startAction();
96+
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
97+
$variables = $jsonModel->getVariables();
98+
$this->assertArrayHasKey('success', $variables);
99+
$this->assertArrayHasKey('messages', $variables);
100+
$this->assertFalse($variables['success']);
101+
}
102+
public function testStartActionInstallException()
78103
{
79104
$this->webLogger->expects($this->once())->method('clear');
105+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
80106
$this->installer->expects($this->once())->method('install')
81107
->willThrowException($this->getMock('\Exception'));
82108
$jsonModel = $this->controller->startAction();
@@ -87,6 +113,7 @@ public function testStartActionWithSampleDataError()
87113
{
88114
$this->webLogger->expects($this->once())->method('clear');
89115
$this->webLogger->expects($this->never())->method('logError');
116+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
90117
$this->installer->method('install');
91118
$this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
92119
$jsonModel = $this->controller->startAction();

0 commit comments

Comments
 (0)