From 999d53836c5837ceebb14a55bc3bbce6c9856496 Mon Sep 17 00:00:00 2001 From: Maddy Chellathurai Date: Mon, 22 Dec 2014 11:31:10 -0600 Subject: [PATCH] MAGETWO-31850: [GITHUB] install.log can not be created with open_basedir restriction #796 - fixes based on CR comments --- .../Setup/src/Controller/DatabaseCheck.php | 15 ++----------- .../Setup/src/Model/InstallerFactory.php | 5 ++--- .../Magento/Setup/src/Model/WebLogger.php | 22 ++++++------------- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/setup/module/Magento/Setup/src/Controller/DatabaseCheck.php b/setup/module/Magento/Setup/src/Controller/DatabaseCheck.php index 34284da0a7e6f..4e7286c8d5b1d 100644 --- a/setup/module/Magento/Setup/src/Controller/DatabaseCheck.php +++ b/setup/module/Magento/Setup/src/Controller/DatabaseCheck.php @@ -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; @@ -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; } /** @@ -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]); diff --git a/setup/module/Magento/Setup/src/Model/InstallerFactory.php b/setup/module/Magento/Setup/src/Model/InstallerFactory.php index 84b8b76bb0321..b2fca6118b1a1 100644 --- a/setup/module/Magento/Setup/src/Model/InstallerFactory.php +++ b/setup/module/Magento/Setup/src/Model/InstallerFactory.php @@ -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'), @@ -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'), diff --git a/setup/module/Magento/Setup/src/Model/WebLogger.php b/setup/module/Magento/Setup/src/Model/WebLogger.php index 328d8823df51c..133c932c50e27 100644 --- a/setup/module/Magento/Setup/src/Model/WebLogger.php +++ b/setup/module/Magento/Setup/src/Model/WebLogger.php @@ -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 @@ -29,7 +29,6 @@ class WebLogger implements LoggerInterface */ protected $filesystem; - /** * Currently open file resource * @@ -68,14 +67,7 @@ public function logSuccess($message) public function logError(\Exception $e) { $this->terminateLine(); - $stackTrace = $e->getTrace(); - $this->writeToFile('[ERROR] ' . $e->getMessage() . '
'); - foreach ($stackTrace as $errorLine) { - if (isset($errorLine['file'])) { - $this->writeToFile($errorLine['file'] . ' ' . $errorLine['line'] . '
'); - } - } - $this->writeToFile('
'); + $this->writeToFile('[ERROR] ' . $e . '
'); } /** @@ -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+'); } /** @@ -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; } @@ -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); } }