/**
  * Creates a progress indicator from log contents
  *
  * @param WebLogger $logger
  * @return Progress
  */
 public function createFromLog(WebLogger $logger)
 {
     $total = 1;
     $current = 0;
     $contents = implode('', $logger->get());
     if (preg_match_all(Installer::PROGRESS_LOG_REGEX, $contents, $matches, PREG_SET_ORDER)) {
         $last = array_pop($matches);
         list(, $current, $total) = $last;
     }
     $progress = new Progress($total, $current);
     return $progress;
 }
Esempio n. 2
0
 /**
  * Checks progress of installation
  *
  * @return JsonModel
  */
 public function progressAction()
 {
     $percent = 0;
     $success = false;
     $contents = [];
     $json = new JsonModel();
     // Depending upon the install environment and network latency, there is a possibility that
     // "progress" check request may arrive before the Install POST request. In that case
     // "install.log" file may not be created yet. Check the "install.log" is created before
     // trying to read from it.
     if (!$this->log->logfileExists()) {
         return $json->setVariables(['progress' => $percent, 'success' => true, 'console' => $contents]);
     }
     try {
         $progress = $this->progressFactory->createFromLog($this->log);
         $percent = sprintf('%d', $progress->getRatio() * 100);
         $success = true;
         $contents = $this->log->get();
         if ($this->sampleDataState->hasError()) {
             $json->setVariable('isSampleDataError', true);
         }
     } catch (\Exception $e) {
         $contents = [(string) $e];
     }
     return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
 }
Esempio n. 3
0
 public function testProgressAction()
 {
     $someNumber = 42;
     $consoleMessages = ['key1' => 'log message 1', 'key2' => 'log message 2'];
     $progress = $this->getMock('\\Magento\\Setup\\Model\\Installer\\Progress', [], [], '', false);
     $this->progressFactory->expects($this->once())->method('createFromLog')->with($this->webLogger)->willReturn($progress);
     $progress->expects($this->once())->method('getRatio')->willReturn($someNumber);
     $this->webLogger->expects($this->once())->method('get')->willReturn($consoleMessages);
     $jsonModel = $this->controller->progressAction();
     $this->assertInstanceOf('\\Zend\\View\\Model\\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('progress', $variables);
     $this->assertArrayHasKey('success', $variables);
     $this->assertArrayHasKey('console', $variables);
     $this->assertSame($consoleMessages, $variables['console']);
     $this->assertTrue($variables['success']);
     $this->assertSame(sprintf('%d', $someNumber * 100), $variables['progress']);
 }
Esempio n. 4
0
 public function testProgressActionNoInstallLogFile()
 {
     $this->webLogger->expects($this->once())->method('logfileExists')->willReturn(false);
     $jsonModel = $this->controller->progressAction();
     $this->assertInstanceOf('\\Zend\\View\\Model\\JsonModel', $jsonModel);
     $variables = $jsonModel->getVariables();
     $this->assertArrayHasKey('success', $variables);
     $this->assertArrayHasKey('console', $variables);
     $this->assertTrue($variables['success']);
     $this->assertEmpty($variables['console']);
     $this->assertSame(0, $variables['progress']);
 }
Esempio n. 5
0
 /**
  * Checks progress of installation
  *
  * @return JsonModel
  */
 public function progressAction()
 {
     $percent = 0;
     $success = false;
     try {
         $progress = $this->progressFactory->createFromLog($this->log);
         $percent = sprintf('%d', $progress->getRatio() * 100);
         $success = true;
         $contents = $this->log->get();
     } catch (\Exception $e) {
         $contents = [(string) $e];
     }
     return new JsonModel(['progress' => $percent, 'success' => $success, 'console' => $contents]);
 }
Esempio n. 6
0
 /**
  * Checks progress of installation
  *
  * @return JsonModel
  */
 public function progressAction()
 {
     $percent = 0;
     $success = false;
     $json = new JsonModel();
     try {
         $progress = $this->progressFactory->createFromLog($this->log);
         $percent = sprintf('%d', $progress->getRatio() * 100);
         $success = true;
         $contents = $this->log->get();
     } catch (\Exception $e) {
         $contents = [(string)$e];
         if ($e instanceof \Magento\Setup\SampleDataException) {
             $json->setVariable('isSampleDataError', true);
         }
     }
     return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
 }
 public function testClearNotExist()
 {
     $this->directoryWriteMock->expects($this->never())->method('delete');
     $this->webLogger->clear();
 }