From df0a65b7c1feb9c8e0cb36ff60e8a99e107ee45e Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Mon, 14 Apr 2014 16:15:54 +0300 Subject: [PATCH] improved installer --- application/Espo/Core/Utils/File/Manager.php | 31 ++++---------------- install/core/SystemHelper.php | 20 +++++++++---- install/index.php | 2 +- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/application/Espo/Core/Utils/File/Manager.php b/application/Espo/Core/Utils/File/Manager.php index 42fed01763..ad30a0dba1 100644 --- a/application/Espo/Core/Utils/File/Manager.php +++ b/application/Espo/Core/Utils/File/Manager.php @@ -221,8 +221,8 @@ class Manager { $fileContent = $this->getContents($path); - $savedDataArray= $this->getArrayData($fileContent); - $newDataArray= $this->getArrayData($content); + $savedDataArray = Utils\Json::getArrayData($fileContent); + $newDataArray = Utils\Json::getArrayData($content); $data= Utils\Util::merge($savedDataArray, $newDataArray); if ($isJSON) { @@ -245,8 +245,8 @@ class Manager { $fileContent = $this->getContents($path); - $savedDataArray= $this->getArrayData($fileContent); - $newDataArray= $this->getArrayData($content); + $savedDataArray = Utils\Json::getArrayData($fileContent); + $newDataArray = Utils\Json::getArrayData($content); if ($onlyFirstLevel) { foreach($newDataArray as $key => $val) { @@ -288,7 +288,7 @@ class Manager return false; } - $currentDataArray = $this->getArrayData($currentData); + $currentDataArray = Utils\Json::getArrayData($currentData); $unsettedData = Utils\Util::unsetInArray($currentDataArray, $unsets); @@ -505,27 +505,6 @@ class Manager return $result; } - - /** //TODO remove - * Get an array data (if JSON convert to array) - * - * @param mixed $data - can be JSON, array - * - * @return array - */ - protected function getArrayData($data) - { - if (is_array($data)) { - return $data; - } - else if (Utils\Json::isJSON($data)) { - return Utils\Json::decode($data, true); - } - - return array(); - } - - /** * Get a filename without the file extension * diff --git a/install/core/SystemHelper.php b/install/core/SystemHelper.php index a2b48b27ef..1c42605e47 100644 --- a/install/core/SystemHelper.php +++ b/install/core/SystemHelper.php @@ -35,21 +35,29 @@ class SystemHelper protected $modRewriteUrl = '/api/v1/Metadata'; - protected $writableDir = 'data'; + protected $systemConfig = 'data/config.php'; public function initWritable() { - if (is_writable($this->writableDir)) { - return true; + $pathInfo = pathinfo($this->systemConfig); + + if (!is_writable($pathInfo['dirname'])) { + return false; } - return false; + if (!@touch($this->systemConfig)) { + return false; + } + + return true; } - public function getWritableDir() + public function getSystemDir() { - return $this->writableDir; + $pathInfo = pathinfo($this->systemConfig); + + return $pathInfo['dirname']; } diff --git a/install/index.php b/install/index.php index 51c4ecb04f..7f25a57ebb 100644 --- a/install/index.php +++ b/install/index.php @@ -39,7 +39,7 @@ require_once 'core/SystemHelper.php'; $systemHelper = new SystemHelper(); if (!$systemHelper->initWritable()) { - $dir = $systemHelper->getWritableDir(); + $dir = $systemHelper->getSystemDir(); $message = $langs['Bad init Permission']; $message = str_replace('{*}', $dir, $message);