Skip to content

Commit 8769eff

Browse files
committed
Merge remote-tracking branch 'ogresCE/MAGETWO-44713-install-log-error' into PR_Branch
2 parents 4e0b27f + e4d6f25 commit 8769eff

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ public function progressAction()
120120
{
121121
$percent = 0;
122122
$success = false;
123+
$contents = [];
123124
$json = new JsonModel();
125+
126+
// Depending upon the install environment and network latency, there is a possibility that
127+
// "progress" check request may arrive before the Install POST request. In that case
128+
// "install.log" file may not be created yet. Check the "install.log" is created before
129+
// trying to read from it.
130+
if (!$this->log->logfileExists()) {
131+
return $json->setVariables(['progress' => $percent, 'success' => true, 'console' => $contents]);
132+
}
133+
124134
try {
125135
$progress = $this->progressFactory->createFromLog($this->log);
126136
$percent = sprintf('%d', $progress->getRatio() * 100);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ public function clear()
137137
}
138138
}
139139

140+
/**
141+
* Checks existence of install.log file
142+
*
143+
* @return bool
144+
*/
145+
public function logfileExists()
146+
{
147+
return ($this->directory->isExist($this->logFile));
148+
}
149+
140150
/**
141151
* Terminates line if the inline logging is started
142152
*

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function setUp()
4242
$this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false);
4343
$this->progressFactory = $this->getMock('\Magento\Setup\Model\Installer\ProgressFactory', [], [], '', false);
4444
$this->sampleDataState = $this->getMock('\Magento\Framework\Setup\SampleData\State', [], [], '', false);
45+
4546
$installerFactory->expects($this->once())->method('create')->with($this->webLogger)
4647
->willReturn($this->installer);
4748
$this->controller = new Install(
@@ -100,6 +101,8 @@ public function testProgressAction()
100101
{
101102
$numValue = 42;
102103
$consoleMessages = ['key1' => 'log message 1', 'key2' => 'log message 2'];
104+
105+
$this->webLogger->expects($this->once())->method('logfileExists')->willReturn(true);
103106
$progress = $this->getMock('\Magento\Setup\Model\Installer\Progress', [], [], '', false);
104107
$this->progressFactory->expects($this->once())->method('createFromLog')->with($this->webLogger)
105108
->willReturn($progress);
@@ -119,6 +122,7 @@ public function testProgressAction()
119122
public function testProgressActionWithError()
120123
{
121124
$e = 'Some exception message';
125+
$this->webLogger->expects($this->once())->method('logfileExists')->willReturn(true);
122126
$this->progressFactory->expects($this->once())->method('createFromLog')
123127
->will($this->throwException(new \LogicException($e)));
124128
$jsonModel = $this->controller->progressAction();
@@ -134,6 +138,7 @@ public function testProgressActionWithError()
134138
public function testProgressActionWithSampleDataError()
135139
{
136140
$numValue = 42;
141+
$this->webLogger->expects($this->once())->method('logfileExists')->willReturn(true);
137142
$progress = $this->getMock('\Magento\Setup\Model\Installer\Progress', [], [], '', false);
138143
$progress->expects($this->once())->method('getRatio')->willReturn($numValue);
139144
$this->progressFactory->expects($this->once())->method('createFromLog')->willReturn($progress);
@@ -148,6 +153,19 @@ public function testProgressActionWithSampleDataError()
148153
$this->assertSame(sprintf('%d', $numValue * 100), $variables['progress']);
149154
}
150155

156+
public function testProgressActionNoInstallLogFile()
157+
{
158+
$this->webLogger->expects($this->once())->method('logfileExists')->willReturn(false);
159+
$jsonModel = $this->controller->progressAction();
160+
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
161+
$variables = $jsonModel->getVariables();
162+
$this->assertArrayHasKey('success', $variables);
163+
$this->assertArrayHasKey('console', $variables);
164+
$this->assertTrue($variables['success']);
165+
$this->assertEmpty($variables['console']);
166+
$this->assertSame(0, $variables['progress']);
167+
}
168+
151169
public function testDispatch()
152170
{
153171
$request = $this->getMock('\Zend\Http\PhpEnvironment\Request', [], [], '', false);

0 commit comments

Comments
 (0)