Skip to content

Commit

Permalink
Merge pull request #587 from magento-ogre/MAGETWO-52187-user-noaccess
Browse files Browse the repository at this point in the history
[Ogre] MAGETWO-52187: Magento re-install with minimum admin access breaks installation
  • Loading branch information
He, Robert(rohe) committed May 2, 2016
2 parents ee61591 + ef00b9c commit 12efdf6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
26 changes: 25 additions & 1 deletion setup/src/Magento/Setup/Controller/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,24 +49,32 @@ class Install extends AbstractActionController
*/
protected $sampleDataState;

/**
* @var \Magento\Framework\App\DeploymentConfig
*/
private $deploymentConfig;

/**
* Default Constructor
*
* @param WebLogger $logger
* @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;
}

/**
Expand All @@ -89,6 +98,7 @@ public function startAction()
$this->log->clear();
$json = new JsonModel;
try {
$this->checkForPriorInstall();
$data = array_merge(
$this->importDeploymentConfigForm(),
$this->importUserConfigForm(),
Expand All @@ -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;
Expand Down Expand Up @@ -145,6 +156,19 @@ public function progressAction()
return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
}

/**
* Checks for prior install
*
* @return void
* @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
*
Expand Down
27 changes: 25 additions & 2 deletions setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@ 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);
$installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false);
$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);
$this->controller = new Install(
$this->webLogger,
$installerFactory,
$this->progressFactory,
$this->sampleDataState
$this->sampleDataState,
$this->deploymentConfig
);
}

Expand All @@ -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();
Expand All @@ -74,9 +82,23 @@ public function testStartAction()
$this->assertTrue($variables['success']);
}

public function testStartActionException()
public function testStartActionPriorInstallException()
{
$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();
Expand All @@ -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();
Expand Down

0 comments on commit 12efdf6

Please sign in to comment.