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 #796

- fixes based on CR comments
  • Loading branch information
mazhalai authored and eddielau committed Jan 9, 2015
1 parent a95e9c7 commit 999d538
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
15 changes: 2 additions & 13 deletions setup/module/Magento/Setup/src/Controller/DatabaseCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
*/
namespace Magento\Setup\Controller;

use Magento\Framework\Filesystem;
use Magento\Setup\Model\InstallerFactory;
use Magento\Setup\Model\WebLogger;
use Zend\Json\Json;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
Expand All @@ -20,23 +18,14 @@ 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, Filesystem $filesystem)
public function __construct(InstallerFactory $installerFactory)
{
$this->installerFactory = $installerFactory;
$this->filesystem = $filesystem;
}

/**
Expand All @@ -48,7 +37,7 @@ public function indexAction()
{
$params = Json::decode($this->getRequest()->getContent(), Json::TYPE_ARRAY);
try {
$installer = $this->installerFactory->create(new WebLogger($this->filesystem));
$installer = $this->installerFactory->create();
$password = isset($params['password']) ? $params['password'] : '';
$installer->checkDatabaseConnection($params['name'], $params['host'], $params['user'], $password);
return new JsonModel(['success' => true]);
Expand Down
5 changes: 2 additions & 3 deletions setup/module/Magento/Setup/src/Model/InstallerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public function __construct(ServiceLocatorInterface $serviceLocator)
/**
* Factory method for installer object
*
* @param LoggerInterface $log
* @return Installer
*/
public function create(LoggerInterface $log)
public function create()
{
return new Installer(
$this->serviceLocator->get('Magento\Setup\Model\FilePermissions'),
Expand All @@ -43,7 +42,7 @@ public function create(LoggerInterface $log)
$this->serviceLocator->get('Magento\Framework\Module\ModuleList\Loader'),
$this->serviceLocator->get('Magento\Framework\App\Filesystem\DirectoryList'),
$this->serviceLocator->get('Magento\Setup\Model\AdminAccountFactory'),
$log,
new WebLogger($this->serviceLocator->get('Magento\Framework\Filesystem')),
$this->serviceLocator->get('Magento\Framework\Math\Random'),
$this->serviceLocator->get('Magento\Setup\Module\ConnectionFactory'),
$this->serviceLocator->get('Magento\Framework\App\MaintenanceMode'),
Expand Down
22 changes: 7 additions & 15 deletions setup/module/Magento/Setup/src/Model/WebLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class WebLogger implements LoggerInterface
/**
* Log File
*
* @var string
* @const string
*/
protected $logFile = 'install.log';
const LOG_WEB = 'install.log';

/**
* Currently open file resource
Expand All @@ -29,7 +29,6 @@ class WebLogger implements LoggerInterface
*/
protected $filesystem;


/**
* Currently open file resource
*
Expand Down Expand Up @@ -68,14 +67,7 @@ public function logSuccess($message)
public function logError(\Exception $e)
{
$this->terminateLine();
$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/>');
$this->writeToFile('<span class="text-danger">[ERROR] ' . $e . '<span><br/>');
}

/**
Expand Down Expand Up @@ -113,7 +105,7 @@ public function logMeta($message)
*/
private function writeToFile($message)
{
$this->directory->writeFile($this->logFile, $message, 'a+');
$this->directory->writeFile(self::LOG_WEB, $message, 'a+');
}

/**
Expand All @@ -123,7 +115,7 @@ private function writeToFile($message)
*/
public function get()
{
$fileContents = explode('\n', $this->directory->readFile($this->logFile));
$fileContents = explode('\n', $this->directory->readFile(self::LOG_WEB));
return $fileContents;
}

Expand All @@ -134,8 +126,8 @@ public function get()
*/
public function clear()
{
if ($this->directory->isExist($this->logFile)) {
$this->directory->delete($this->logFile);
if ($this->directory->isExist(self::LOG_WEB)) {
$this->directory->delete(self::LOG_WEB);
}
}

Expand Down

0 comments on commit 999d538

Please sign in to comment.