From 1149017be574c93f93f8e1debdb4570eb8a1dc14 Mon Sep 17 00:00:00 2001 From: Ankur Kaneria Date: Tue, 26 Apr 2016 09:42:55 -0500 Subject: [PATCH 1/3] MAGETWO-52187: Magento re-install with minimum admin access breaks installation - Added a check to detect attempt to reinstall on top of prior successful installation --- .../src/Magento/Setup/Controller/Install.php | 25 ++++++++++++++++- .../Test/Unit/Controller/InstallTest.php | 27 +++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php index 2eea8c52bef87..1f863624e2cf5 100644 --- a/setup/src/Magento/Setup/Controller/Install.php +++ b/setup/src/Magento/Setup/Controller/Install.php @@ -20,6 +20,7 @@ use Zend\View\Model\ViewModel; use Magento\Setup\Console\Command\InstallCommand; use Magento\SampleData; +use Magento\Framework\App\DeploymentConfig; /** * Install controller @@ -48,6 +49,11 @@ class Install extends AbstractActionController */ protected $sampleDataState; + /** + * @var \Magento\Framework\App\DeploymentConfig + */ + private $deploymentConfig; + /** * Default Constructor * @@ -55,17 +61,20 @@ class Install extends AbstractActionController * @param InstallerFactory $installerFactory * @param ProgressFactory $progressFactory * @param \Magento\Framework\Setup\SampleData\State $sampleDataState + * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig */ public function __construct( WebLogger $logger, InstallerFactory $installerFactory, ProgressFactory $progressFactory, - \Magento\Framework\Setup\SampleData\State $sampleDataState + \Magento\Framework\Setup\SampleData\State $sampleDataState, + DeploymentConfig $deploymentConfig ) { $this->log = $logger; $this->installer = $installerFactory->create($logger); $this->progressFactory = $progressFactory; $this->sampleDataState = $sampleDataState; + $this->deploymentConfig = $deploymentConfig; } /** @@ -89,6 +98,7 @@ public function startAction() $this->log->clear(); $json = new JsonModel; try { + $this->checkForPriorInstall(); $data = array_merge( $this->importDeploymentConfigForm(), $this->importUserConfigForm(), @@ -106,6 +116,7 @@ public function startAction() $json->setVariable('messages', $this->installer->getInstallInfo()[Installer::INFO_MESSAGE]); } catch (\Exception $e) { $this->log->logError($e); + $json->setVariable('messages', $e->getMessage()); $json->setVariable('success', false); } return $json; @@ -145,6 +156,18 @@ public function progressAction() return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]); } + /** + * Checks for prior install + * + * @throws \Magento\Setup\Exception + */ + private function checkForPriorInstall() + { + if ($this->deploymentConfig->isAvailable()) { + throw new \Magento\Setup\Exception('Magento application is already installed.'); + } + } + /** * Maps data from request to format of deployment config model * diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php index b2ec9a6f86300..37f40675856a7 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php @@ -35,6 +35,11 @@ class InstallTest extends \PHPUnit_Framework_TestCase */ private $sampleDataState; + /** + * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject + */ + private $deploymentConfig; + public function setUp() { $this->webLogger = $this->getMock('\Magento\Setup\Model\WebLogger', [], [], '', false); @@ -42,6 +47,7 @@ public function setUp() $this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false); $this->progressFactory = $this->getMock('\Magento\Setup\Model\Installer\ProgressFactory', [], [], '', false); $this->sampleDataState = $this->getMock('\Magento\Framework\Setup\SampleData\State', [], [], '', false); + $this->deploymentConfig = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false); $installerFactory->expects($this->once())->method('create')->with($this->webLogger) ->willReturn($this->installer); @@ -49,7 +55,8 @@ public function setUp() $this->webLogger, $installerFactory, $this->progressFactory, - $this->sampleDataState + $this->sampleDataState, + $this->deploymentConfig ); } @@ -65,6 +72,7 @@ public function testStartAction() $this->webLogger->expects($this->once())->method('clear'); $this->installer->expects($this->once())->method('install'); $this->installer->expects($this->exactly(2))->method('getInstallInfo'); + $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false); $jsonModel = $this->controller->startAction(); $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); $variables = $jsonModel->getVariables(); @@ -74,9 +82,23 @@ public function testStartAction() $this->assertTrue($variables['success']); } - public function testStartActionException() + public function testStartActionPrioInstallException() + { + $this->webLogger->expects($this->once())->method('clear'); + $this->installer->expects($this->never())->method('install'); + $this->installer->expects($this->never())->method('getInstallInfo'); + $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true); + $jsonModel = $this->controller->startAction(); + $this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel); + $variables = $jsonModel->getVariables(); + $this->assertArrayHasKey('success', $variables); + $this->assertArrayHasKey('messages', $variables); + $this->assertFalse($variables['success']); + } + public function testStartActionInstallException() { $this->webLogger->expects($this->once())->method('clear'); + $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false); $this->installer->expects($this->once())->method('install') ->willThrowException($this->getMock('\Exception')); $jsonModel = $this->controller->startAction(); @@ -87,6 +109,7 @@ public function testStartActionWithSampleDataError() { $this->webLogger->expects($this->once())->method('clear'); $this->webLogger->expects($this->never())->method('logError'); + $this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false); $this->installer->method('install'); $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true); $jsonModel = $this->controller->startAction(); From 3eea09b49b7b3fe97d2d7b8aea55736b196c1749 Mon Sep 17 00:00:00 2001 From: Ankur Kaneria Date: Tue, 26 Apr 2016 13:23:16 -0500 Subject: [PATCH 2/3] MAGETWO-52187: Magento re-install with minimum admin access breaks installation - Minor update to docblock to fix static test failure --- setup/src/Magento/Setup/Controller/Install.php | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/src/Magento/Setup/Controller/Install.php b/setup/src/Magento/Setup/Controller/Install.php index 1f863624e2cf5..647ba4e59f7d0 100644 --- a/setup/src/Magento/Setup/Controller/Install.php +++ b/setup/src/Magento/Setup/Controller/Install.php @@ -159,6 +159,7 @@ public function progressAction() /** * Checks for prior install * + * @return void * @throws \Magento\Setup\Exception */ private function checkForPriorInstall() From d1f57d96fbbbf3c57ff500e3bede542d08686ac5 Mon Sep 17 00:00:00 2001 From: Ankur Kaneria Date: Tue, 26 Apr 2016 16:56:45 -0500 Subject: [PATCH 3/3] MAGETWO-52187: Magento re-install with minimum admin access breaks installation - Minor code update based on review. Fixed a typo in unit test function name --- setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php index 37f40675856a7..121621075a138 100644 --- a/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php @@ -82,7 +82,7 @@ public function testStartAction() $this->assertTrue($variables['success']); } - public function testStartActionPrioInstallException() + public function testStartActionPriorInstallException() { $this->webLogger->expects($this->once())->method('clear'); $this->installer->expects($this->never())->method('install');