From 471dd1ab49464121a6b0909cb3278ccb6a951491 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Thu, 16 May 2019 11:56:43 +0300 Subject: [PATCH] Added config file for installation --- .gitignore | 3 +- install/core/Installer.php | 25 +++++++ install/core/InstallerConfig.php | 116 +++++++++++++++++++++++++++++++ install/index.php | 13 ++-- 4 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 install/core/InstallerConfig.php diff --git a/.gitignore b/.gitignore index 565cdfcdf4..5508c4a81e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ npm-debug.log /tests/integration/config.php composer.phar vendor/ -/custom/Espo/Custom/* \ No newline at end of file +/custom/Espo/Custom/* +/install/config.php \ No newline at end of file diff --git a/install/core/Installer.php b/install/core/Installer.php index 89285b18d1..daa2c2a513 100644 --- a/install/core/Installer.php +++ b/install/core/Installer.php @@ -41,6 +41,8 @@ class Installer protected $databaseHelper = null; + protected $installerConfig; + protected $isAuth = false; protected $permissionMap; @@ -71,6 +73,9 @@ class Installer $user = $this->getEntityManager()->getEntity('User'); $this->app->getContainer()->setUser($user); + require_once('install/core/InstallerConfig.php'); + $this->installerConfig = new InstallerConfig(); + require_once('install/core/SystemHelper.php'); $this->systemHelper = new SystemHelper(); @@ -127,6 +132,11 @@ class Installer return $this->databaseHelper; } + protected function getInstallerConfig() + { + return $this->installerConfig; + } + protected function getFileManager() { return $this->app->getContainer()->get('fileManager'); @@ -161,6 +171,12 @@ class Installer public function isInstalled() { + $installerConfig = $this->getInstallerConfig(); + + if ($installerConfig->get('isInstalled')) { + return true; + } + return $this->app->isInstalled(); } @@ -184,6 +200,11 @@ class Installer return $translated; } + public function getInstallerConfigData() + { + return $this->getInstallerConfig()->getAllData(); + } + public function getSystemRequirementList($type, $requiredOnly = false, array $additionalData = null) { $systemRequirementManager = new \Espo\Core\Utils\SystemRequirements($this->app->getContainer()); @@ -419,6 +440,10 @@ class Installer $result &= $this->executeQueries(); /** END: afterInstall scripts */ + $installerConfig = $this->getInstallerConfig(); + $installerConfig->set('isInstalled', true); + $installerConfig->save(); + $config = $this->app->getContainer()->get('config'); $config->set('isInstalled', true); $result &= $config->save(); diff --git a/install/core/InstallerConfig.php b/install/core/InstallerConfig.php new file mode 100644 index 0000000000..15434bc0a7 --- /dev/null +++ b/install/core/InstallerConfig.php @@ -0,0 +1,116 @@ +fileManager = new \Espo\Core\Utils\File\Manager(); + } + + protected function getFileManager() + { + return $this->fileManager; + } + + protected function getContainer() + { + return $this->container; + } + + protected function loadData() + { + if (file_exists($this->configPath)) { + $data = include($this->configPath); + if (is_array($data)) { + return $data; + } + } + + return []; + } + + public function getAllData() + { + if (!$this->data) { + $this->data = $this->loadData(); + } + + return $this->data; + } + + public function get($name, $default = []) + { + if (!$this->data) { + $this->data = $this->loadData(); + } + + if (array_key_exists($name, $this->data)) { + return $this->data[$name]; + } + + return $default; + } + + public function set($name, $value = null) + { + if (!is_array($name)) { + $name = array($name => $value); + } + + foreach ($name as $key => $value) { + $this->data[$key] = $value; + } + } + + public function save() + { + $data = $this->loadData(); + + if (is_array($this->data)) { + foreach ($this->data as $key => $value) { + $data[$key] = $value; + } + } + + $result = $this->getFileManager()->putPhpContents($this->configPath, $data); + + if ($result) { + $this->data = null; + } + + return $result; + } +} diff --git a/install/index.php b/install/index.php index c328720615..7d882c66d0 100644 --- a/install/index.php +++ b/install/index.php @@ -86,17 +86,21 @@ $installer = new Installer(); // check if app was installed if ($installer->isInstalled() && !isset($_SESSION['install']['installProcess'])) { + if (isset($_SESSION['install']['redirected']) && $_SESSION['install']['redirected']) { + die('The installation is disabled. It can be enabled in config files.'); + } + $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $url = preg_replace('/install\/?/', '', $url, 1); $url = strtok($url, '#'); $url = strtok($url, '?'); + + $_SESSION['install']['redirected'] = true; header("Location: {$url}"); exit; } -else { - // double check if infinite loop - $_SESSION['install']['installProcess'] = true; -} + +$_SESSION['install']['installProcess'] = true; $smarty->caching = false; $smarty->setTemplateDir('install/core/tpl'); @@ -142,6 +146,7 @@ $smarty->assign('action', ucfirst($action)); /** config */ $smarty->assign('config', $config); +$smarty->assign('installerConfig', $installer->getInstallerConfigData()); if (Utils::checkActionExists($action)) { include $actionFile;