Merge branch 'hotfix/4.8.2'
This commit is contained in:
@@ -111,6 +111,31 @@ class Container
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadLog()
|
||||
{
|
||||
$config = $this->get('config');
|
||||
|
||||
$path = $config->get('logger.path', 'data/logs/espo.log');
|
||||
$rotation = $config->get('logger.rotation', true);
|
||||
|
||||
$log = new \Espo\Core\Utils\Log('Espo');
|
||||
$levelCode = $log->getLevelCode($config->get('logger.level', 'WARNING'));
|
||||
|
||||
if ($rotation) {
|
||||
$maxFileNumber = $config->get('logger.maxFileNumber', 30);
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($path, $maxFileNumber, $levelCode);
|
||||
} else {
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\StreamHandler($path, $levelCode);
|
||||
}
|
||||
$log->pushHandler($handler);
|
||||
|
||||
$errorHandler = new \Monolog\ErrorHandler($log);
|
||||
$errorHandler->registerExceptionHandler(null, false);
|
||||
$errorHandler->registerErrorHandler(array(), false);
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
protected function loadFileManager()
|
||||
{
|
||||
return new \Espo\Core\Utils\File\Manager(
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2017 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://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.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
class Log extends Base
|
||||
{
|
||||
public function load()
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
$path = $config->get('logger.path', 'data/logs/espo.log');
|
||||
$rotation = $config->get('logger.rotation', true);
|
||||
|
||||
$log = new \Espo\Core\Utils\Log('Espo');
|
||||
$levelCode = $log->getLevelCode($config->get('logger.level', 'WARNING'));
|
||||
|
||||
if ($rotation) {
|
||||
$maxFileNumber = $config->get('logger.maxFileNumber', 30);
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\RotatingFileHandler($path, $maxFileNumber, $levelCode);
|
||||
} else {
|
||||
$handler = new \Espo\Core\Utils\Log\Monolog\Handler\StreamHandler($path, $levelCode);
|
||||
}
|
||||
$log->pushHandler($handler);
|
||||
|
||||
$errorHandler = new \Monolog\ErrorHandler($log);
|
||||
$errorHandler->registerExceptionHandler(null, false);
|
||||
$errorHandler->registerErrorHandler(array(), false);
|
||||
|
||||
return $log;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,5 +602,18 @@ class Util
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array keys exists
|
||||
*
|
||||
* @param array $keys
|
||||
* @param array $array
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
static public function arrayKeysExists(array $keys, array $array)
|
||||
{
|
||||
return !array_diff_key(array_flip($keys), $array);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ return array ( 'defaultPermissions' =>
|
||||
'smtpPassword',
|
||||
'cron',
|
||||
'authenticationMethod',
|
||||
'adminPanelIframeUrl',
|
||||
'ldapHost',
|
||||
'ldapPort',
|
||||
'ldapSecurity',
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"tooltips": {
|
||||
"assignmentPermission": "Allows to restrict an ability to assign records and post messages to other users.\n\nall - no restriction\n\nteam - can assign and post only to teammates\n\nno - can assign and post only to self",
|
||||
"userPermission": "Allows to restrict an ability for users to view activities, calendar and stream of other users.\n\nall - can view all\n\nteam - can view activities of teammates only\n\nno - can't view",
|
||||
"portalPermission": "Defines an access to portal information, ability to convert contacts to portal users and post messages to portal users."
|
||||
"portalPermission": "Defines an access to portal information, ability to post messages to portal users."
|
||||
},
|
||||
"labels": {
|
||||
"Access": "Access",
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"tooltips": {
|
||||
"assignmentPermission": "Allows to restrict an ability to assign records and post messages to other users.\n\nall - no restriction\n\nteam - can assign and post only to teammates\n\nno - can assign and post only to self",
|
||||
"userPermission": "Allows to restrict an ability for users to view activities, calendar and stream of other users.\n\nall - can view all\n\nteam - can view activities of teammates only\n\nno - can't view",
|
||||
"portalPermission": "Defines an access to portal information, ability to convert contacts to portal users and post messages to portal users."
|
||||
"portalPermission": "Defines an access to portal information, ability to post messages to portal users."
|
||||
},
|
||||
"labels": {
|
||||
"Access": "Access",
|
||||
|
||||
@@ -40,7 +40,7 @@ Espo.define('views/admin/index', 'view', function (Dep) {
|
||||
|
||||
setup: function () {
|
||||
this.links = this.getMetadata().get('app.adminPanel');
|
||||
this.iframeUrl = this.getConfig().get('adminPanelIframeUrl') || '//espocrm.com/news';
|
||||
this.iframeUrl = this.getConfig().get('adminPanelIframeUrl') || 'https://s.espocrm.com/';
|
||||
},
|
||||
|
||||
updatePageTitle: function () {
|
||||
|
||||
+398
-398
@@ -33,424 +33,424 @@ use Espo\Core\Utils\Config;
|
||||
|
||||
class Installer
|
||||
{
|
||||
protected $app = null;
|
||||
protected $language = null;
|
||||
|
||||
protected $systemHelper = null;
|
||||
|
||||
protected $isAuth = false;
|
||||
|
||||
protected $permissionMap;
|
||||
|
||||
protected $permissionError;
|
||||
|
||||
private $passwordHash;
|
||||
|
||||
protected $settingList = array(
|
||||
'dateFormat',
|
||||
'timeFormat',
|
||||
'timeZone',
|
||||
'weekStart',
|
||||
'defaultCurrency' => array(
|
||||
'currencyList', 'defaultCurrency',
|
||||
),
|
||||
'smtpSecurity',
|
||||
'language',
|
||||
);
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$this->app = new \Espo\Core\Application();
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User');
|
||||
$this->app->getContainer()->setUser($user);
|
||||
|
||||
require_once('install/core/SystemHelper.php');
|
||||
$this->systemHelper = new SystemHelper();
|
||||
protected $app = null;
|
||||
protected $language = null;
|
||||
|
||||
protected $systemHelper = null;
|
||||
|
||||
protected $isAuth = false;
|
||||
|
||||
protected $permissionMap;
|
||||
|
||||
protected $permissionError;
|
||||
|
||||
private $passwordHash;
|
||||
|
||||
protected $settingList = array(
|
||||
'dateFormat',
|
||||
'timeFormat',
|
||||
'timeZone',
|
||||
'weekStart',
|
||||
'defaultCurrency' => array(
|
||||
'currencyList', 'defaultCurrency',
|
||||
),
|
||||
'smtpSecurity',
|
||||
'language',
|
||||
);
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$this->app = new \Espo\Core\Application();
|
||||
|
||||
$user = $this->getEntityManager()->getEntity('User');
|
||||
$this->app->getContainer()->setUser($user);
|
||||
|
||||
require_once('install/core/SystemHelper.php');
|
||||
$this->systemHelper = new SystemHelper();
|
||||
|
||||
$configPath = $this->getConfig()->getConfigPath();
|
||||
$this->permissionMap = $this->getConfig()->get('permissionMap');
|
||||
$this->permissionMap['writable'][] = $configPath;
|
||||
$configPath = $this->getConfig()->getConfigPath();
|
||||
$this->permissionMap = $this->getConfig()->get('permissionMap');
|
||||
$this->permissionMap['writable'][] = $configPath;
|
||||
}
|
||||
|
||||
if (!file_exists($configPath)) {
|
||||
$configData = $this->getConfig()->getDefaults();
|
||||
$this->getConfig()->set($configData);
|
||||
$this->getConfig()->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
$fileManager = new FileManager();
|
||||
$config = new Config($fileManager);
|
||||
$configPath = $config->getConfigPath();
|
||||
|
||||
if (!file_exists($configPath)) {
|
||||
$fileManager->putPhpContents($configPath, array());
|
||||
|
||||
$configData = $config->getDefaults();
|
||||
$config->set($configData);
|
||||
$config->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->app->getContainer();
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
protected function getConfig()
|
||||
{
|
||||
return $this->app->getContainer()->get('config');
|
||||
}
|
||||
|
||||
protected function getSystemHelper()
|
||||
{
|
||||
return $this->systemHelper;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->app->getContainer()->get('fileManager');
|
||||
}
|
||||
|
||||
protected function getPasswordHash()
|
||||
{
|
||||
if (!isset($this->passwordHash)) {
|
||||
$config = $this->getConfig();
|
||||
$this->passwordHash = new \Espo\Core\Utils\PasswordHash($config);
|
||||
}
|
||||
|
||||
return $this->passwordHash;
|
||||
}
|
||||
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->getConfig()->get('version');
|
||||
}
|
||||
|
||||
protected function auth()
|
||||
{
|
||||
if (!$this->isAuth) {
|
||||
$auth = new \Espo\Core\Utils\Auth($this->app->getContainer());
|
||||
$auth->useNoAuth();
|
||||
|
||||
$this->isAuth = true;
|
||||
}
|
||||
|
||||
return $this->isAuth;
|
||||
}
|
||||
|
||||
public function isInstalled()
|
||||
{
|
||||
return $this->app->isInstalled();
|
||||
}
|
||||
|
||||
protected function getLanguage()
|
||||
{
|
||||
if (!isset($this->language)) {
|
||||
$this->language = $this->app->getContainer()->get('language');
|
||||
}
|
||||
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
public function getLanguageList()
|
||||
{
|
||||
$config = $this->app->getContainer()->get('config');
|
||||
|
||||
$languageList = $config->get('languageList');
|
||||
|
||||
$translated = $this->getLanguage()->translate('language', 'options', 'Global', $languageList);
|
||||
|
||||
return $translated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data
|
||||
*
|
||||
* @param array $database
|
||||
* array (
|
||||
* 'driver' => 'pdo_mysql',
|
||||
* 'host' => 'localhost',
|
||||
* 'dbname' => 'espocrm_test',
|
||||
* 'user' => 'root',
|
||||
* 'password' => '',
|
||||
* ),
|
||||
* @param string $language
|
||||
* @return bool
|
||||
*/
|
||||
public function saveData($database, $language)
|
||||
{
|
||||
$initData = include('install/core/afterInstall/config.php');
|
||||
|
||||
$siteUrl = $this->getSystemHelper()->getBaseUrl();
|
||||
|
||||
$data = array(
|
||||
'database' => $database,
|
||||
'language' => $language,
|
||||
'siteUrl' => $siteUrl,
|
||||
'passwordSalt' => $this->getPasswordHash()->generateSalt(),
|
||||
'cryptKey' => $this->getContainer()->get('crypt')->generateKey()
|
||||
);
|
||||
|
||||
$owner = $this->getFileManager()->getPermissionUtils()->getDefaultOwner(true);
|
||||
$group = $this->getFileManager()->getPermissionUtils()->getDefaultGroup(true);
|
||||
|
||||
if (!empty($owner)) {
|
||||
$data['defaultPermissions']['user'] = $owner;
|
||||
}
|
||||
if (!empty($group)) {
|
||||
$data['defaultPermissions']['group'] = $group;
|
||||
}
|
||||
|
||||
$data = array_merge($data, $initData);
|
||||
$result = $this->saveConfig($data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function saveConfig($data)
|
||||
{
|
||||
$config = $this->app->getContainer()->get('config');
|
||||
|
||||
$config->set($data);
|
||||
$result = $config->save();
|
||||
|
||||
return $result;
|
||||
}
|
||||
protected function initialize()
|
||||
{
|
||||
$fileManager = new FileManager();
|
||||
$config = new Config($fileManager);
|
||||
$configPath = $config->getConfigPath();
|
||||
|
||||
if (!file_exists($configPath)) {
|
||||
$fileManager->putPhpContents($configPath, array());
|
||||
}
|
||||
|
||||
$data = include('data/config.php');
|
||||
$defaultData = $config->getDefaults();
|
||||
|
||||
//save default data if not exists, check by keys
|
||||
if (!Util::arrayKeysExists(array_keys($defaultData), $data)) {
|
||||
$defaultData = array_replace_recursive($defaultData, $data);
|
||||
$config->set($defaultData);
|
||||
$config->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->app->getContainer();
|
||||
}
|
||||
|
||||
protected function getEntityManager()
|
||||
{
|
||||
return $this->getContainer()->get('entityManager');
|
||||
}
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->app->getContainer()->get('config');
|
||||
}
|
||||
|
||||
protected function getSystemHelper()
|
||||
{
|
||||
return $this->systemHelper;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->app->getContainer()->get('fileManager');
|
||||
}
|
||||
|
||||
protected function getPasswordHash()
|
||||
{
|
||||
if (!isset($this->passwordHash)) {
|
||||
$config = $this->getConfig();
|
||||
$this->passwordHash = new \Espo\Core\Utils\PasswordHash($config);
|
||||
}
|
||||
|
||||
return $this->passwordHash;
|
||||
}
|
||||
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->getConfig()->get('version');
|
||||
}
|
||||
|
||||
protected function auth()
|
||||
{
|
||||
if (!$this->isAuth) {
|
||||
$auth = new \Espo\Core\Utils\Auth($this->app->getContainer());
|
||||
$auth->useNoAuth();
|
||||
|
||||
$this->isAuth = true;
|
||||
}
|
||||
|
||||
return $this->isAuth;
|
||||
}
|
||||
|
||||
public function isInstalled()
|
||||
{
|
||||
return $this->app->isInstalled();
|
||||
}
|
||||
|
||||
protected function getLanguage()
|
||||
{
|
||||
if (!isset($this->language)) {
|
||||
$this->language = $this->app->getContainer()->get('language');
|
||||
}
|
||||
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
public function getLanguageList()
|
||||
{
|
||||
$config = $this->app->getContainer()->get('config');
|
||||
|
||||
$languageList = $config->get('languageList');
|
||||
|
||||
$translated = $this->getLanguage()->translate('language', 'options', 'Global', $languageList);
|
||||
|
||||
return $translated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save data
|
||||
*
|
||||
* @param array $database
|
||||
* array (
|
||||
* 'driver' => 'pdo_mysql',
|
||||
* 'host' => 'localhost',
|
||||
* 'dbname' => 'espocrm_test',
|
||||
* 'user' => 'root',
|
||||
* 'password' => '',
|
||||
* ),
|
||||
* @param string $language
|
||||
* @return bool
|
||||
*/
|
||||
public function saveData($database, $language)
|
||||
{
|
||||
$initData = include('install/core/afterInstall/config.php');
|
||||
|
||||
$siteUrl = $this->getSystemHelper()->getBaseUrl();
|
||||
|
||||
$data = array(
|
||||
'database' => $database,
|
||||
'language' => $language,
|
||||
'siteUrl' => $siteUrl,
|
||||
'passwordSalt' => $this->getPasswordHash()->generateSalt(),
|
||||
'cryptKey' => $this->getContainer()->get('crypt')->generateKey()
|
||||
);
|
||||
|
||||
$owner = $this->getFileManager()->getPermissionUtils()->getDefaultOwner(true);
|
||||
$group = $this->getFileManager()->getPermissionUtils()->getDefaultGroup(true);
|
||||
|
||||
if (!empty($owner)) {
|
||||
$data['defaultPermissions']['user'] = $owner;
|
||||
}
|
||||
if (!empty($group)) {
|
||||
$data['defaultPermissions']['group'] = $group;
|
||||
}
|
||||
|
||||
$data = array_merge($data, $initData);
|
||||
$result = $this->saveConfig($data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function saveConfig($data)
|
||||
{
|
||||
$config = $this->app->getContainer()->get('config');
|
||||
|
||||
$config->set($data);
|
||||
$result = $config->save();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function buildDatabase()
|
||||
{
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $this->app->getContainer()->get('schema')->rebuild();
|
||||
} catch (\Exception $e) {
|
||||
$this->auth();
|
||||
$result = $this->app->getContainer()->get('schema')->rebuild();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setPreferences($preferences)
|
||||
{
|
||||
$currencyList = $this->getConfig()->get('currencyList', array());
|
||||
if (isset($preferences['defaultCurrency']) && !in_array($preferences['defaultCurrency'], $currencyList)) {
|
||||
|
||||
$preferences['currencyList'] = array($preferences['defaultCurrency']);
|
||||
$preferences['baseCurrency'] = $preferences['defaultCurrency'];
|
||||
}
|
||||
|
||||
$res = $this->saveConfig($preferences);
|
||||
|
||||
/*save these settings for admin*/
|
||||
$this->setAdminPreferences($preferences);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
protected function createRecords()
|
||||
{
|
||||
$records = include('install/core/afterInstall/records.php');
|
||||
|
||||
$result = true;
|
||||
foreach ($records as $entityName => $recordList) {
|
||||
foreach ($recordList as $data) {
|
||||
$result &= $this->createRecord($entityName, $data);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function createRecord($entityName, $data)
|
||||
{
|
||||
if (isset($data['id'])) {
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
|
||||
|
||||
if (!isset($entity)) {
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$sql = "SELECT id FROM `".Util::toUnderScore($entityName)."` WHERE `id` = '".$data['id']."'";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
public function buildDatabase()
|
||||
{
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
$result = $this->app->getContainer()->get('schema')->rebuild();
|
||||
} catch (\Exception $e) {
|
||||
$this->auth();
|
||||
$result = $this->app->getContainer()->get('schema')->rebuild();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function setPreferences($preferences)
|
||||
{
|
||||
$currencyList = $this->getConfig()->get('currencyList', array());
|
||||
if (isset($preferences['defaultCurrency']) && !in_array($preferences['defaultCurrency'], $currencyList)) {
|
||||
|
||||
$preferences['currencyList'] = array($preferences['defaultCurrency']);
|
||||
$preferences['baseCurrency'] = $preferences['defaultCurrency'];
|
||||
}
|
||||
|
||||
$res = $this->saveConfig($preferences);
|
||||
|
||||
/*save these settings for admin*/
|
||||
$this->setAdminPreferences($preferences);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
protected function createRecords()
|
||||
{
|
||||
$records = include('install/core/afterInstall/records.php');
|
||||
|
||||
$result = true;
|
||||
foreach ($records as $entityName => $recordList) {
|
||||
foreach ($recordList as $data) {
|
||||
$result &= $this->createRecord($entityName, $data);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function createRecord($entityName, $data)
|
||||
{
|
||||
if (isset($data['id'])) {
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
|
||||
|
||||
if (!isset($entity)) {
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$sql = "SELECT id FROM `".Util::toUnderScore($entityName)."` WHERE `id` = '".$data['id']."'";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
|
||||
$deletedEntity = $sth->fetch(\PDO::FETCH_ASSOC);
|
||||
$deletedEntity = $sth->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
if ($deletedEntity) {
|
||||
$sql = "UPDATE `".Util::toUnderScore($entityName)."` SET deleted = '0' WHERE `id` = '".$data['id']."'";
|
||||
$pdo->prepare($sql)->execute();
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($deletedEntity) {
|
||||
$sql = "UPDATE `".Util::toUnderScore($entityName)."` SET deleted = '0' WHERE `id` = '".$data['id']."'";
|
||||
$pdo->prepare($sql)->execute();
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity($entityName, $data['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($entity)) {
|
||||
$entity = $this->getEntityManager()->getEntity($entityName);
|
||||
}
|
||||
if (!isset($entity)) {
|
||||
$entity = $this->getEntityManager()->getEntity($entityName);
|
||||
}
|
||||
|
||||
$entity->set($data);
|
||||
$entity->set($data);
|
||||
|
||||
$id = $this->getEntityManager()->saveEntity($entity);
|
||||
$id = $this->getEntityManager()->saveEntity($entity);
|
||||
|
||||
return is_string($id);
|
||||
}
|
||||
return is_string($id);
|
||||
}
|
||||
|
||||
public function createUser($userName, $password)
|
||||
{
|
||||
$this->auth();
|
||||
public function createUser($userName, $password)
|
||||
{
|
||||
$this->auth();
|
||||
|
||||
$user = array(
|
||||
'id' => '1',
|
||||
'userName' => $userName,
|
||||
'password' => $this->getPasswordHash()->hash($password),
|
||||
'lastName' => 'Admin',
|
||||
'isAdmin' => '1',
|
||||
);
|
||||
$user = array(
|
||||
'id' => '1',
|
||||
'userName' => $userName,
|
||||
'password' => $this->getPasswordHash()->hash($password),
|
||||
'lastName' => 'Admin',
|
||||
'isAdmin' => '1',
|
||||
);
|
||||
|
||||
$result = $this->createRecord('User', $user);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function setAdminPreferences($preferences)
|
||||
{
|
||||
$allowedPreferences = array(
|
||||
'dateFormat',
|
||||
'timeFormat',
|
||||
'timeZone',
|
||||
'weekStart',
|
||||
'defaultCurrency',
|
||||
'thousandSeparator',
|
||||
'decimalMark',
|
||||
'language',
|
||||
);
|
||||
$result = $this->createRecord('User', $user);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function setAdminPreferences($preferences)
|
||||
{
|
||||
$allowedPreferences = array(
|
||||
'dateFormat',
|
||||
'timeFormat',
|
||||
'timeZone',
|
||||
'weekStart',
|
||||
'defaultCurrency',
|
||||
'thousandSeparator',
|
||||
'decimalMark',
|
||||
'language',
|
||||
);
|
||||
|
||||
$data = array_intersect_key($preferences, array_flip($allowedPreferences));
|
||||
if (empty($data)) {
|
||||
return true;
|
||||
}
|
||||
$data = array_intersect_key($preferences, array_flip($allowedPreferences));
|
||||
if (empty($data)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', '1');
|
||||
if ($entity) {
|
||||
$entity->set($data);
|
||||
return $this->getEntityManager()->saveEntity($entity);
|
||||
}
|
||||
$entity = $this->getEntityManager()->getEntity('Preferences', '1');
|
||||
if ($entity) {
|
||||
$entity->set($data);
|
||||
return $this->getEntityManager()->saveEntity($entity);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkPermission()
|
||||
{
|
||||
return $this->getFileManager()->getPermissionUtils()->setMapPermission();
|
||||
}
|
||||
public function checkPermission()
|
||||
{
|
||||
return $this->getFileManager()->getPermissionUtils()->setMapPermission();
|
||||
}
|
||||
|
||||
public function getLastPermissionError()
|
||||
{
|
||||
return $this->getFileManager()->getPermissionUtils()->getLastErrorRules();
|
||||
}
|
||||
|
||||
public function setSuccess()
|
||||
{
|
||||
$this->auth();
|
||||
|
||||
/** afterInstall scripts */
|
||||
$result = $this->createRecords();
|
||||
$result &= $this->executeQueries();
|
||||
/** END: afterInstall scripts */
|
||||
|
||||
$config = $this->app->getContainer()->get('config');
|
||||
$config->set('isInstalled', true);
|
||||
$result &= $config->save();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getSettingDefaults()
|
||||
{
|
||||
$defaults = array();
|
||||
|
||||
$settingDefs = $this->app->getMetadata()->get('entityDefs.Settings.fields');
|
||||
|
||||
foreach ($this->settingList as $fieldName => $field) {
|
||||
|
||||
if (is_array($field)) {
|
||||
$fieldDefaults = array();
|
||||
foreach ($field as $subField) {
|
||||
if (isset($settingDefs[$subField])) {
|
||||
$fieldDefaults = array_merge($fieldDefaults, $this->translateSetting($subField, $settingDefs[$subField]));
|
||||
}
|
||||
}
|
||||
$defaults[$fieldName] = $fieldDefaults;
|
||||
|
||||
} else if (isset($settingDefs[$field])) {
|
||||
|
||||
$defaults[$field] = $this->translateSetting($field, $settingDefs[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($defaults['language'])) {
|
||||
$defaults['language']['options'] = $this->getLanguageList();
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
protected function translateSetting($name, array $settingDefs)
|
||||
{
|
||||
if (isset($settingDefs['options'])) {
|
||||
$optionLabel = $this->getLanguage()->translate($name, 'options', 'Settings', $settingDefs['options']);
|
||||
|
||||
if ($optionLabel == $name) {
|
||||
$optionLabel = $this->getLanguage()->translate($name, 'options', 'Global', $settingDefs['options']);
|
||||
}
|
||||
|
||||
if ($optionLabel == $name) {
|
||||
$optionLabel = array();
|
||||
foreach ($settingDefs['options'] as $key => $value) {
|
||||
$optionLabel[$value] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$settingDefs['options'] = $optionLabel;
|
||||
}
|
||||
|
||||
return $settingDefs;
|
||||
}
|
||||
|
||||
public function getCronMessage()
|
||||
{
|
||||
return $this->getContainer()->get('scheduledJob')->getSetupMessage();
|
||||
}
|
||||
|
||||
protected function executeQueries()
|
||||
{
|
||||
$queries = include('install/core/afterInstall/queries.php');
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
public function getLastPermissionError()
|
||||
{
|
||||
return $this->getFileManager()->getPermissionUtils()->getLastErrorRules();
|
||||
}
|
||||
|
||||
public function setSuccess()
|
||||
{
|
||||
$this->auth();
|
||||
|
||||
/** afterInstall scripts */
|
||||
$result = $this->createRecords();
|
||||
$result &= $this->executeQueries();
|
||||
/** END: afterInstall scripts */
|
||||
|
||||
$config = $this->app->getContainer()->get('config');
|
||||
$config->set('isInstalled', true);
|
||||
$result &= $config->save();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getSettingDefaults()
|
||||
{
|
||||
$defaults = array();
|
||||
|
||||
$settingDefs = $this->app->getMetadata()->get('entityDefs.Settings.fields');
|
||||
|
||||
foreach ($this->settingList as $fieldName => $field) {
|
||||
|
||||
if (is_array($field)) {
|
||||
$fieldDefaults = array();
|
||||
foreach ($field as $subField) {
|
||||
if (isset($settingDefs[$subField])) {
|
||||
$fieldDefaults = array_merge($fieldDefaults, $this->translateSetting($subField, $settingDefs[$subField]));
|
||||
}
|
||||
}
|
||||
$defaults[$fieldName] = $fieldDefaults;
|
||||
|
||||
} else if (isset($settingDefs[$field])) {
|
||||
|
||||
$defaults[$field] = $this->translateSetting($field, $settingDefs[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($defaults['language'])) {
|
||||
$defaults['language']['options'] = $this->getLanguageList();
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
protected function translateSetting($name, array $settingDefs)
|
||||
{
|
||||
if (isset($settingDefs['options'])) {
|
||||
$optionLabel = $this->getLanguage()->translate($name, 'options', 'Settings', $settingDefs['options']);
|
||||
|
||||
if ($optionLabel == $name) {
|
||||
$optionLabel = $this->getLanguage()->translate($name, 'options', 'Global', $settingDefs['options']);
|
||||
}
|
||||
|
||||
if ($optionLabel == $name) {
|
||||
$optionLabel = array();
|
||||
foreach ($settingDefs['options'] as $key => $value) {
|
||||
$optionLabel[$value] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$settingDefs['options'] = $optionLabel;
|
||||
}
|
||||
|
||||
return $settingDefs;
|
||||
}
|
||||
|
||||
public function getCronMessage()
|
||||
{
|
||||
return $this->getContainer()->get('scheduledJob')->getSetupMessage();
|
||||
}
|
||||
|
||||
protected function executeQueries()
|
||||
{
|
||||
$queries = include('install/core/afterInstall/queries.php');
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
$result = true;
|
||||
$result = true;
|
||||
|
||||
foreach ($queries as $query) {
|
||||
$sth = $pdo->prepare($query);
|
||||
$result =& $sth->execute();
|
||||
}
|
||||
foreach ($queries as $query) {
|
||||
$sth = $pdo->prepare($query);
|
||||
$result =& $sth->execute();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ class SystemHelper extends \Espo\Core\Utils\System
|
||||
{
|
||||
protected $config;
|
||||
|
||||
protected $mainConfig;
|
||||
|
||||
protected $requirements;
|
||||
|
||||
protected $apiPath;
|
||||
@@ -45,10 +47,23 @@ class SystemHelper extends \Espo\Core\Utils\System
|
||||
{
|
||||
$this->config = include('config.php');
|
||||
|
||||
if (file_exists('data/config.php')) {
|
||||
$this->mainConfig = include('data/config.php');
|
||||
}
|
||||
|
||||
$this->requirements = $this->config['requirements'];
|
||||
$this->apiPath = $this->config['apiPath'];
|
||||
}
|
||||
|
||||
protected function getMainConfig($optionName, $returns = null)
|
||||
{
|
||||
if (isset($this->mainConfig[$optionName])) {
|
||||
return $this->mainConfig[$optionName];
|
||||
}
|
||||
|
||||
return $returns;
|
||||
}
|
||||
|
||||
public function initWritable()
|
||||
{
|
||||
if (is_writable($this->writableDir)) {
|
||||
@@ -199,11 +214,34 @@ class SystemHelper extends \Espo\Core\Utils\System
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getPdoConnection($hostName, $port, $dbUserName, $dbUserPass, $dbName)
|
||||
protected function getPdoConnection($hostName, $port, $dbUserName, $dbUserPass, $dbName)
|
||||
{
|
||||
$params = $this->getMainConfig('database', array());
|
||||
|
||||
$port = empty($port) ? '' : 'port=' . $port . ';';
|
||||
$platform = !empty($params['platform']) ? strtolower($params['platform']) : 'mysql';
|
||||
|
||||
$options = array();
|
||||
|
||||
if (isset($params['sslCA'])) {
|
||||
$options[PDO::MYSQL_ATTR_SSL_CA] = $params['sslCA'];
|
||||
}
|
||||
if (isset($params['sslCert'])) {
|
||||
$options[PDO::MYSQL_ATTR_SSL_CERT] = $params['sslCert'];
|
||||
}
|
||||
if (isset($params['sslKey'])) {
|
||||
$options[PDO::MYSQL_ATTR_SSL_KEY] = $params['sslKey'];
|
||||
}
|
||||
if (isset($params['sslCAPath'])) {
|
||||
$options[PDO::MYSQL_ATTR_SSL_CAPATH] = $params['sslCAPath'];
|
||||
}
|
||||
if (isset($params['sslCipher'])) {
|
||||
$options[PDO::MYSQL_ATTR_SSL_CIPHER] = $params['sslCipher'];
|
||||
}
|
||||
|
||||
try {
|
||||
$dsn = "mysql:host={$hostName};" . ((!empty($port)) ? "port={$port};" : '') . "dbname={$dbName}";
|
||||
$dbh = new PDO($dsn, $dbUserName, $dbUserPass);
|
||||
$dsn = $platform . ':host='.$hostName.';'.$port.'dbname=' . $dbName;
|
||||
$dbh = new PDO($dsn, $dbUserName, $dbUserPass, $options);
|
||||
} catch (PDOException $e) {
|
||||
return $e;
|
||||
}
|
||||
|
||||
@@ -25,20 +25,21 @@
|
||||
*
|
||||
* 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.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
$config = $installer->getConfig();
|
||||
|
||||
$fields = array(
|
||||
'user-lang' => array(
|
||||
'default' => (isset($settingsDefaults['language']['default'])) ? $settingsDefaults['language']['default'] : 'en_US',
|
||||
'default' => $config->get('language', 'en_US'),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
if (isset($_SESSION['install'][$fieldName])) {
|
||||
$fields[$fieldName]['value'] = $_SESSION['install'][$fieldName];
|
||||
}
|
||||
else {
|
||||
$fields[$fieldName]['value'] = (isset($fields[$fieldName]['default']))? $fields[$fieldName]['default'] : '';
|
||||
} else {
|
||||
$fields[$fieldName]['value'] = (isset($field['default']))? $field['default'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,23 +27,35 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
$config = $installer->getConfig();
|
||||
|
||||
$fields = array(
|
||||
'db-name' => array(),
|
||||
'host-name' => array(
|
||||
'default' => (isset($langs['labels']['localhost']))? $langs['labels']['localhost'] : '',),
|
||||
'port' => array(),
|
||||
'db-user-name' => array(),
|
||||
'db-user-password' => array(),
|
||||
'db-driver' => array()
|
||||
'db-driver' => array(
|
||||
'default' => $config->get('database.driver', ''),
|
||||
),
|
||||
'db-name' => array(
|
||||
'default' => $config->get('database.dbname', ''),
|
||||
),
|
||||
'host-name' => array(
|
||||
'default' => $config->get('database.host', ''),
|
||||
),
|
||||
'port' => array(
|
||||
'default' => $config->get('database.port', ''),
|
||||
),
|
||||
'db-user-name' => array(
|
||||
'default' => $config->get('database.user', ''),
|
||||
),
|
||||
'db-user-password' => array(
|
||||
'default' => $config->get('database.password', ''),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
if (isset($_SESSION['install'][$fieldName])) {
|
||||
$fields[$fieldName]['value'] = $_SESSION['install'][$fieldName];
|
||||
}
|
||||
else {
|
||||
$fields[$fieldName]['value'] = (isset($fields[$fieldName]['default']))? $fields[$fieldName]['default'] : '';
|
||||
}
|
||||
if (isset($_SESSION['install'][$fieldName])) {
|
||||
$fields[$fieldName]['value'] = $_SESSION['install'][$fieldName];
|
||||
} else {
|
||||
$fields[$fieldName]['value'] = isset($field['default']) ? $field['default'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
$smarty->assign('fields', $fields);
|
||||
@@ -25,35 +25,42 @@
|
||||
*
|
||||
* 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.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
$config = $installer->getConfig();
|
||||
|
||||
$fields = array(
|
||||
'dateFormat' =>array (
|
||||
'default' => (isset($settingsDefaults['dateFormat']['default'])) ? $settingsDefaults['dateFormat']['default'] : '',
|
||||
),
|
||||
'default' => $config->get('dateFormat', ''),
|
||||
),
|
||||
'timeFormat' => array(
|
||||
'default'=> (isset($settingsDefaults['timeFormat']['default'])) ? $settingsDefaults['timeFormat']['default'] : ''),
|
||||
'timeZone' => array(),
|
||||
'weekStart' => array((isset($settingsDefaults['weekStart']['default'])) ? $settingsDefaults['weekStart']['default'] : ''),
|
||||
'default'=> $config->get('timeFormat', ''),
|
||||
),
|
||||
'timeZone' => array(
|
||||
'default'=> $config->get('timeZone', 'UTC'),
|
||||
),
|
||||
'weekStart' => array(
|
||||
'default'=> $config->get('weekStart', 0),
|
||||
),
|
||||
'defaultCurrency' => array(
|
||||
'default' => (isset($settingsDefaults['defaultCurrency']['default'])) ? $settingsDefaults['defaultCurrency']['default'] : ''),
|
||||
'default' => $config->get('defaultCurrency', 'USD'),
|
||||
),
|
||||
'thousandSeparator' => array(
|
||||
'default' => ',',
|
||||
'default' => $config->get('thousandSeparator', ','),
|
||||
),
|
||||
'decimalMark' =>array(
|
||||
'default' => '.',
|
||||
'default' => $config->get('decimalMark', '.'),
|
||||
),
|
||||
'language' => array(
|
||||
'default'=> (!empty($_SESSION['install']['user-lang'])) ? $_SESSION['install']['user-lang'] : 'en_US'
|
||||
'default'=> (!empty($_SESSION['install']['user-lang'])) ? $_SESSION['install']['user-lang'] : $config->get('language', 'en_US'),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
if (isset($_SESSION['install'][$fieldName])) {
|
||||
$fields[$fieldName]['value'] = $_SESSION['install'][$fieldName];
|
||||
}
|
||||
else {
|
||||
$fields[$fieldName]['value'] = (isset($fields[$fieldName]['default']))? $fields[$fieldName]['default'] : '';
|
||||
} else {
|
||||
$fields[$fieldName]['value'] = isset($field['default']) ? $field['default'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,31 +25,46 @@
|
||||
*
|
||||
* 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.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
$config = $installer->getConfig();
|
||||
|
||||
$fields = array(
|
||||
'smtpServer' => array(),
|
||||
'smtpPort' => array(
|
||||
'default' => '25',
|
||||
),
|
||||
'smtpAuth' => array(),
|
||||
'smtpSecurity' => array(
|
||||
'default' => (isset($settingsDefaults['smtpSecurity']['default'])) ? $settingsDefaults['smtpSecurity']['default'] : ''),
|
||||
'smtpUsername' => array(),
|
||||
'smtpPassword' => array(),
|
||||
|
||||
'outboundEmailFromName' => array(),
|
||||
'outboundEmailFromAddress' => array(),
|
||||
'outboundEmailIsShared' => array(),
|
||||
'smtpServer' => array(
|
||||
'default' => $config->get('smtpServer', ''),
|
||||
),
|
||||
'smtpPort' => array(
|
||||
'default' => $config->get('smtpPort', 25),
|
||||
),
|
||||
'smtpAuth' => array(
|
||||
'default' => $config->get('smtpAuth', ''),
|
||||
),
|
||||
'smtpSecurity' => array(
|
||||
'default' => $config->get('smtpSecurity', ''),
|
||||
),
|
||||
'smtpUsername' => array(
|
||||
'default' => $config->get('smtpUsername', ''),
|
||||
),
|
||||
'smtpPassword' => array(
|
||||
'default' => $config->get('smtpPassword', ''),
|
||||
),
|
||||
'outboundEmailFromName' => array(
|
||||
'default' => $config->get('outboundEmailFromName', ''),
|
||||
),
|
||||
'outboundEmailFromAddress' => array(
|
||||
'default' => $config->get('outboundEmailFromAddress', ''),
|
||||
),
|
||||
'outboundEmailIsShared' => array(
|
||||
'default' => $config->get('outboundEmailIsShared', ''),
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
if (isset($_SESSION['install'][$fieldName])) {
|
||||
$fields[$fieldName]['value'] = $_SESSION['install'][$fieldName];
|
||||
}
|
||||
else {
|
||||
$fields[$fieldName]['value'] = (isset($fields[$fieldName]['default']))? $fields[$fieldName]['default'] : '';
|
||||
}
|
||||
if (isset($_SESSION['install'][$fieldName])) {
|
||||
$fields[$fieldName]['value'] = $_SESSION['install'][$fieldName];
|
||||
} else {
|
||||
$fields[$fieldName]['value'] = isset($field['default']) ? $field['default'] : '';
|
||||
}
|
||||
}
|
||||
|
||||
$smarty->assign('fields', $fields);
|
||||
|
||||
Reference in New Issue
Block a user