Added config file for installation

This commit is contained in:
Taras Machyshyn
2019-05-16 11:56:43 +03:00
parent 8efc395ca1
commit 471dd1ab49
4 changed files with 152 additions and 5 deletions
+2 -1
View File
@@ -15,4 +15,5 @@ npm-debug.log
/tests/integration/config.php /tests/integration/config.php
composer.phar composer.phar
vendor/ vendor/
/custom/Espo/Custom/* /custom/Espo/Custom/*
/install/config.php
+25
View File
@@ -41,6 +41,8 @@ class Installer
protected $databaseHelper = null; protected $databaseHelper = null;
protected $installerConfig;
protected $isAuth = false; protected $isAuth = false;
protected $permissionMap; protected $permissionMap;
@@ -71,6 +73,9 @@ class Installer
$user = $this->getEntityManager()->getEntity('User'); $user = $this->getEntityManager()->getEntity('User');
$this->app->getContainer()->setUser($user); $this->app->getContainer()->setUser($user);
require_once('install/core/InstallerConfig.php');
$this->installerConfig = new InstallerConfig();
require_once('install/core/SystemHelper.php'); require_once('install/core/SystemHelper.php');
$this->systemHelper = new SystemHelper(); $this->systemHelper = new SystemHelper();
@@ -127,6 +132,11 @@ class Installer
return $this->databaseHelper; return $this->databaseHelper;
} }
protected function getInstallerConfig()
{
return $this->installerConfig;
}
protected function getFileManager() protected function getFileManager()
{ {
return $this->app->getContainer()->get('fileManager'); return $this->app->getContainer()->get('fileManager');
@@ -161,6 +171,12 @@ class Installer
public function isInstalled() public function isInstalled()
{ {
$installerConfig = $this->getInstallerConfig();
if ($installerConfig->get('isInstalled')) {
return true;
}
return $this->app->isInstalled(); return $this->app->isInstalled();
} }
@@ -184,6 +200,11 @@ class Installer
return $translated; return $translated;
} }
public function getInstallerConfigData()
{
return $this->getInstallerConfig()->getAllData();
}
public function getSystemRequirementList($type, $requiredOnly = false, array $additionalData = null) public function getSystemRequirementList($type, $requiredOnly = false, array $additionalData = null)
{ {
$systemRequirementManager = new \Espo\Core\Utils\SystemRequirements($this->app->getContainer()); $systemRequirementManager = new \Espo\Core\Utils\SystemRequirements($this->app->getContainer());
@@ -419,6 +440,10 @@ class Installer
$result &= $this->executeQueries(); $result &= $this->executeQueries();
/** END: afterInstall scripts */ /** END: afterInstall scripts */
$installerConfig = $this->getInstallerConfig();
$installerConfig->set('isInstalled', true);
$installerConfig->save();
$config = $this->app->getContainer()->get('config'); $config = $this->app->getContainer()->get('config');
$config->set('isInstalled', true); $config->set('isInstalled', true);
$result &= $config->save(); $result &= $config->save();
+116
View File
@@ -0,0 +1,116 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
class InstallerConfig
{
private $data;
private $fileManager;
protected $configPath = 'install/config.php'; //full path: install/config.php
public function __construct()
{
$this->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;
}
}
+9 -4
View File
@@ -86,17 +86,21 @@ $installer = new Installer();
// check if app was installed // check if app was installed
if ($installer->isInstalled() && !isset($_SESSION['install']['installProcess'])) { 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 = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$url = preg_replace('/install\/?/', '', $url, 1); $url = preg_replace('/install\/?/', '', $url, 1);
$url = strtok($url, '#'); $url = strtok($url, '#');
$url = strtok($url, '?'); $url = strtok($url, '?');
$_SESSION['install']['redirected'] = true;
header("Location: {$url}"); header("Location: {$url}");
exit; exit;
} }
else {
// double check if infinite loop $_SESSION['install']['installProcess'] = true;
$_SESSION['install']['installProcess'] = true;
}
$smarty->caching = false; $smarty->caching = false;
$smarty->setTemplateDir('install/core/tpl'); $smarty->setTemplateDir('install/core/tpl');
@@ -142,6 +146,7 @@ $smarty->assign('action', ucfirst($action));
/** config */ /** config */
$smarty->assign('config', $config); $smarty->assign('config', $config);
$smarty->assign('installerConfig', $installer->getInstallerConfigData());
if (Utils::checkActionExists($action)) { if (Utils::checkActionExists($action)) {
include $actionFile; include $actionFile;