Skip to content

Commit

Permalink
MAGETWO-31850: [GITHUB] install.log can not be created with open_base…
Browse files Browse the repository at this point in the history
…dir restriction

- moved install.log to var/log
  • Loading branch information
mazhalai authored and eddielau committed Jan 9, 2015
1 parent 24a7e92 commit a95e9c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 57 deletions.
14 changes: 12 additions & 2 deletions setup/module/Magento/Setup/src/Controller/DatabaseCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
namespace Magento\Setup\Controller;

use Magento\Framework\Filesystem;
use Magento\Setup\Model\InstallerFactory;
use Magento\Setup\Model\WebLogger;
use Zend\Json\Json;
Expand All @@ -19,14 +20,23 @@ class DatabaseCheck extends AbstractActionController
*/
private $installerFactory;

/**
* Filesystem to access log
*
* @var Filesystem
*/
private $filesystem;

/**
* Constructor
*
* @param InstallerFactory $installerFactory
* @param Filesystem $filesystem
*/
public function __construct(InstallerFactory $installerFactory)
public function __construct(InstallerFactory $installerFactory, Filesystem $filesystem)
{
$this->installerFactory = $installerFactory;
$this->filesystem = $filesystem;
}

/**
Expand All @@ -38,7 +48,7 @@ public function indexAction()
{
$params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
try {
$installer = $this->installerFactory->create(new WebLogger());
$installer = $this->installerFactory->create(new WebLogger($this->filesystem));
$password = isset($params['password']) ? $params['password'] : '';
$installer->checkDatabaseConnection($params['name'], $params['host'], $params['user'], $password);
return new JsonModel(['success' => true]);
Expand Down
80 changes: 25 additions & 55 deletions setup/module/Magento/Setup/src/Model/WebLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Magento\Setup\Model;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;

/**
* Web UI Logger
*
Expand All @@ -22,16 +25,17 @@ class WebLogger implements LoggerInterface
/**
* Currently open file resource
*
* @var resource
* @var Filesystem
*/
protected $resource;
protected $filesystem;


/**
* Whether the log contains an error message
* Currently open file resource
*
* @var bool
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
*/
protected $hasError = false;
protected $directory;

/**
* Indicator of whether inline output is started
Expand All @@ -42,31 +46,11 @@ class WebLogger implements LoggerInterface

/**
* Constructor
* @param Filesystem $filesystem
*/
public function __construct()
{
$this->logFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $this->logFile;
}

/**
* Opens log file in the specified mode
*
* @param string $mode
* @return void
*/
private function open($mode)
{
$this->resource = fopen($this->logFile, $mode);
}

/**
* Closes the log file
*
* @return void
*/
private function close()
public function __construct(Filesystem $filesystem)
{
fclose($this->resource);
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::LOG);
}

/**
Expand All @@ -84,7 +68,14 @@ public function logSuccess($message)
public function logError(\Exception $e)
{
$this->terminateLine();
$this->writeToFile('<span class="text-danger">[ERROR] ' . $e . '<span><br/>');
$stackTrace = $e->getTrace();
$this->writeToFile('<span class="text-danger">[ERROR] ' . $e->getMessage() . '<br/>');
foreach ($stackTrace as $errorLine) {
if (isset($errorLine['file'])) {
$this->writeToFile($errorLine['file'] . ' ' . $errorLine['line'] . '<br/>');
}
}
$this->writeToFile('<span><br/>');
}

/**
Expand Down Expand Up @@ -122,19 +113,7 @@ public function logMeta($message)
*/
private function writeToFile($message)
{
$this->open('a+');
fwrite($this->resource, $message);
$this->close();
}

/**
* Whether there is an error in the log
*
* @return bool
*/
public function hasError()
{
return $this->hasError;
$this->directory->writeFile($this->logFile, $message, 'a+');
}

/**
Expand All @@ -144,17 +123,8 @@ public function hasError()
*/
public function get()
{
$this->open('r+');
fseek($this->resource, 0);
$messages = [];
while (($string = fgets($this->resource)) !== false) {
if (strpos($string, '[ERROR]') !== false) {
$this->hasError = true;
}
$messages[] = $string;
}
$this->close();
return $messages;
$fileContents = explode('\n', $this->directory->readFile($this->logFile));
return $fileContents;
}

/**
Expand All @@ -164,8 +134,8 @@ public function get()
*/
public function clear()
{
if (file_exists($this->logFile)) {
unlink($this->logFile);
if ($this->directory->isExist($this->logFile)) {
$this->directory->delete($this->logFile);
}
}

Expand Down

0 comments on commit a95e9c7

Please sign in to comment.