snapshot of https://github.com/espocrm/espocrm.git (master, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
This commit is contained in:
215
application/Espo/Core/Utils/Config/Access.php
Normal file
215
application/Espo/Core/Utils/Config/Access.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\FieldUtil;
|
||||
use Espo\Entities\Settings;
|
||||
use Espo\ORM\Defs\Params\FieldParam;
|
||||
|
||||
class Access
|
||||
{
|
||||
/** Logged-in users can read. Admin can write. */
|
||||
public const LEVEL_DEFAULT = 'default';
|
||||
/** No one can read/write. */
|
||||
public const LEVEL_SYSTEM = 'system';
|
||||
/** No one can read, admin can write. */
|
||||
public const LEVEL_INTERNAL = 'internal';
|
||||
/** Only super-admin can read/write. */
|
||||
public const LEVEL_SUPER_ADMIN = 'superAdmin';
|
||||
/** Only admin can read/write. */
|
||||
public const LEVEL_ADMIN = 'admin';
|
||||
/** Even not logged-in can read. Admin can write. */
|
||||
public const LEVEL_GLOBAL = 'global';
|
||||
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private Metadata $metadata,
|
||||
private FieldUtil $fieldUtil
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get read-only parameters.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getReadOnlyParamList(): array
|
||||
{
|
||||
$itemList = [];
|
||||
|
||||
$fieldDefs = $this->metadata->get(['entityDefs', Settings::ENTITY_TYPE, 'fields']);
|
||||
|
||||
foreach ($fieldDefs as $field => $fieldParams) {
|
||||
if (empty($fieldParams[FieldParam::READ_ONLY])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->fieldUtil->getAttributeList(Settings::ENTITY_TYPE, $field) as $attribute) {
|
||||
$itemList[] = $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
$params = $this->metadata->get(['app', 'config', 'params']) ?? [];
|
||||
|
||||
foreach ($params as $name => $item) {
|
||||
if ($item['readOnly'] ?? false) {
|
||||
$itemList[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($itemList));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAdminParamList(): array
|
||||
{
|
||||
$itemList = $this->config->get('adminItems') ?? [];
|
||||
|
||||
$fieldDefs = $this->metadata->get(['entityDefs', Settings::ENTITY_TYPE, 'fields']);
|
||||
|
||||
foreach ($fieldDefs as $field => $fieldParams) {
|
||||
if (empty($fieldParams['onlyAdmin'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->fieldUtil->getAttributeList(Settings::ENTITY_TYPE, $field) as $attribute) {
|
||||
$itemList[] = $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(
|
||||
array_merge(
|
||||
$itemList,
|
||||
$this->getParamListByLevel(self::LEVEL_ADMIN)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getInternalParamList(): array
|
||||
{
|
||||
return $this->getParamListByLevel(self::LEVEL_INTERNAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSystemParamList(): array
|
||||
{
|
||||
$itemList = $this->config->get('systemItems') ?? [];
|
||||
|
||||
$fieldDefs = $this->metadata->get(['entityDefs', Settings::ENTITY_TYPE, 'fields']);
|
||||
|
||||
foreach ($fieldDefs as $field => $fieldParams) {
|
||||
if (empty($fieldParams['onlySystem'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->fieldUtil->getAttributeList(Settings::ENTITY_TYPE, $field) as $attribute) {
|
||||
$itemList[] = $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(
|
||||
array_merge(
|
||||
$itemList,
|
||||
$this->getParamListByLevel(self::LEVEL_SYSTEM)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getGlobalParamList(): array
|
||||
{
|
||||
$itemList = $this->config->get('globalItems', []);
|
||||
|
||||
$fieldDefs = $this->metadata->get(['entityDefs', Settings::ENTITY_TYPE, 'fields']);
|
||||
|
||||
foreach ($fieldDefs as $field => $fieldParams) {
|
||||
if (empty($fieldParams['global'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($this->fieldUtil->getAttributeList(Settings::ENTITY_TYPE, $field) as $attribute) {
|
||||
$itemList[] = $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(
|
||||
array_merge(
|
||||
$itemList,
|
||||
$this->getParamListByLevel(self::LEVEL_GLOBAL)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSuperAdminParamList(): array
|
||||
{
|
||||
return array_values(
|
||||
array_merge(
|
||||
$this->config->get('superAdminItems') ?? [],
|
||||
$this->getParamListByLevel(self::LEVEL_SUPER_ADMIN)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param self::LEVEL_* $level
|
||||
* @return string[]
|
||||
*/
|
||||
private function getParamListByLevel(string $level): array
|
||||
{
|
||||
$itemList = [];
|
||||
|
||||
$params = $this->metadata->get(['app', 'config', 'params']) ?? [];
|
||||
|
||||
foreach ($params as $name => $item) {
|
||||
$levelItem = $item['level'] ?? null;
|
||||
|
||||
if ($levelItem !== $level) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$itemList[] = $name;
|
||||
}
|
||||
|
||||
return $itemList;
|
||||
}
|
||||
}
|
||||
83
application/Espo/Core/Utils/Config/ApplicationConfig.php
Normal file
83
application/Espo/Core/Utils/Config/ApplicationConfig.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
/**
|
||||
* @since 9.0.0
|
||||
*/
|
||||
class ApplicationConfig
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
) {}
|
||||
|
||||
public function getSiteUrl(): string
|
||||
{
|
||||
return rtrim($this->config->get('siteUrl') ?? '', '/');
|
||||
}
|
||||
|
||||
public function getDateFormat(): string
|
||||
{
|
||||
return $this->config->get('dateFormat') ?? 'DD.MM.YYYY';
|
||||
}
|
||||
|
||||
public function getTimeFormat(): string
|
||||
{
|
||||
return $this->config->get('timeFormat') ?? 'HH:mm';
|
||||
}
|
||||
|
||||
public function getTimeZone(): string
|
||||
{
|
||||
return $this->config->get('timeZone') ?? 'UTC';
|
||||
}
|
||||
|
||||
public function getLanguage(): string
|
||||
{
|
||||
return $this->config->get('language') ?? 'en_US';
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 9.2.0
|
||||
*/
|
||||
public function getRecordsPerPage(): int
|
||||
{
|
||||
return (int) $this->config->get('recordsPerPage');
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 10.1.0
|
||||
*/
|
||||
public function getApplicationName(): string
|
||||
{
|
||||
return $this->config->get('applicationName', 'EspoCRM');
|
||||
}
|
||||
}
|
||||
101
application/Espo/Core/Utils/Config/ConfigFileManager.php
Normal file
101
application/Espo/Core/Utils/Config/ConfigFileManager.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class ConfigFileManager
|
||||
{
|
||||
protected FileManager $fileManager;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->fileManager = new FileManager();
|
||||
}
|
||||
|
||||
public function setConfig(Config $config): void
|
||||
{
|
||||
$this->fileManager = new FileManager(
|
||||
$config->get('defaultPermissions')
|
||||
);
|
||||
}
|
||||
|
||||
public function isFile(string $filePath): bool
|
||||
{
|
||||
return $this->fileManager->isFile($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function putPhpContentsInternal(string $path, array $data, bool $useRenaming = false): void
|
||||
{
|
||||
$result = $this->fileManager->putPhpContents($path, $data, true, $useRenaming);
|
||||
|
||||
if ($result === false) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function putPhpContents(string $path, array $data): void
|
||||
{
|
||||
$this->putPhpContentsInternal($path, $data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function putPhpContentsNoRenaming(string $path, array $data): void
|
||||
{
|
||||
$this->putPhpContentsInternal($path, $data, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getPhpContents(string $path): array
|
||||
{
|
||||
$data = $this->fileManager->getPhpContents($path);
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new RuntimeException("Bad data stored in '{$path}.");
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
260
application/Espo/Core/Utils/Config/ConfigWriter.php
Normal file
260
application/Espo/Core/Utils/Config/ConfigWriter.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Writes into the config.
|
||||
*/
|
||||
class ConfigWriter
|
||||
{
|
||||
/** @var array<string, mixed> */
|
||||
private $changedData = [];
|
||||
/** @var string[] */
|
||||
private $removeParamList = [];
|
||||
/** @var string[] */
|
||||
protected $associativeArrayAttributeList = [
|
||||
'currencyRates',
|
||||
'database',
|
||||
'logger',
|
||||
'defaultPermissions',
|
||||
];
|
||||
|
||||
private string $cacheTimestampParam = 'cacheTimestamp';
|
||||
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private ConfigWriterFileManager $fileManager,
|
||||
private ConfigWriterHelper $helper,
|
||||
private InternalConfigHelper $internalConfigHelper
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Set a parameter.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function set(string $name, $value): void
|
||||
{
|
||||
if (in_array($name, $this->associativeArrayAttributeList) && is_object($value)) {
|
||||
$value = (array) $value;
|
||||
}
|
||||
|
||||
$this->changedData[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set multiple parameters.
|
||||
*
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
public function setMultiple(array $params): void
|
||||
{
|
||||
foreach ($params as $name => $value) {
|
||||
$this->set($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a parameter.
|
||||
*/
|
||||
public function remove(string $name): void
|
||||
{
|
||||
$this->removeParamList[] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save config changes to the file.
|
||||
*/
|
||||
public function save(): void
|
||||
{
|
||||
$changedData = $this->changedData;
|
||||
|
||||
if (!isset($changedData[$this->cacheTimestampParam])) {
|
||||
$changedData[$this->cacheTimestampParam] = $this->generateCacheTimestamp();
|
||||
}
|
||||
|
||||
$configPath = $this->config->getConfigPath();
|
||||
$internalConfigPath = $this->config->getInternalConfigPath();
|
||||
$stateConfigPath = $this->config->getStateConfigPath();
|
||||
|
||||
if (!$this->fileManager->isFile($configPath)) {
|
||||
throw new RuntimeException("Config file '$configPath' not found.");
|
||||
}
|
||||
|
||||
$data = $this->fileManager->getPhpContents($configPath);
|
||||
|
||||
$dataInternal = $this->fileManager->isFile($internalConfigPath) ?
|
||||
$this->fileManager->getPhpContents($internalConfigPath) : [];
|
||||
|
||||
$dataState = $this->fileManager->isFile($stateConfigPath) ?
|
||||
$this->fileManager->getPhpContents($stateConfigPath) : [];
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new RuntimeException("Could not read config.");
|
||||
}
|
||||
|
||||
if (!is_array($dataInternal)) {
|
||||
throw new RuntimeException("Could not read config-internal.");
|
||||
}
|
||||
|
||||
if (!is_array($dataState)) {
|
||||
throw new RuntimeException("Could not read state.");
|
||||
}
|
||||
|
||||
$toSaveInternal = false;
|
||||
$toSaveState = false;
|
||||
$toSaveMain = false;
|
||||
|
||||
foreach (array_merge(array_keys($changedData), $this->removeParamList) as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
$toSaveMain = true;
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $dataInternal)) {
|
||||
$toSaveInternal = true;
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $dataState)) {
|
||||
$toSaveState = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($changedData as $key => $value) {
|
||||
if ($this->internalConfigHelper->isParamForStateConfig($key)) {
|
||||
$dataState[$key] = $value;
|
||||
|
||||
unset($data[$key]);
|
||||
unset($dataInternal[$key]);
|
||||
|
||||
$toSaveState = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->internalConfigHelper->isParamForInternalConfig($key)) {
|
||||
$dataInternal[$key] = $value;
|
||||
|
||||
unset($data[$key]);
|
||||
unset($dataState[$key]);
|
||||
|
||||
$toSaveInternal = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[$key] = $value;
|
||||
|
||||
unset($dataState[$key]);
|
||||
unset($dataInternal[$key]);
|
||||
|
||||
$toSaveMain = true;
|
||||
}
|
||||
|
||||
foreach ($this->removeParamList as $key) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $dataInternal)) {
|
||||
unset($dataInternal[$key]);
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $dataState)) {
|
||||
unset($dataState[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($toSaveInternal) {
|
||||
$this->saveData($internalConfigPath, $dataInternal, 'microtimeInternal');
|
||||
}
|
||||
|
||||
if ($toSaveMain) {
|
||||
$this->saveData($configPath, $data, 'microtime');
|
||||
}
|
||||
|
||||
if ($toSaveState) {
|
||||
$this->saveData($stateConfigPath, $dataState, 'microtimeState');
|
||||
}
|
||||
|
||||
$this->changedData = [];
|
||||
$this->removeParamList = [];
|
||||
|
||||
$this->config->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private function saveData(string $path, array &$data, string $timeParam): void
|
||||
{
|
||||
$data[$timeParam] = $microtime = $this->helper->generateMicrotime();
|
||||
|
||||
try {
|
||||
$this->fileManager->putPhpContents($path, $data);
|
||||
} catch (Exception) {
|
||||
throw new RuntimeException("Could not save config.");
|
||||
}
|
||||
|
||||
$reloadedData = $this->fileManager->getPhpContents($path);
|
||||
|
||||
if (
|
||||
is_array($reloadedData) &&
|
||||
$microtime === ($reloadedData[$timeParam] ?? null)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->fileManager->putPhpContentsNoRenaming($path, $data);
|
||||
} catch (Exception) {
|
||||
throw new RuntimeException("Could not save config.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the cache timestamp.
|
||||
*
|
||||
* @todo Remove? Saving re-writes the cache timestamp anyway.
|
||||
*/
|
||||
public function updateCacheTimestamp(): void
|
||||
{
|
||||
$this->set($this->cacheTimestampParam, $this->generateCacheTimestamp());
|
||||
}
|
||||
|
||||
protected function generateCacheTimestamp(): int
|
||||
{
|
||||
return $this->helper->generateCacheTimestamp();
|
||||
}
|
||||
}
|
||||
122
application/Espo/Core/Utils/Config/ConfigWriterFileManager.php
Normal file
122
application/Espo/Core/Utils/Config/ConfigWriterFileManager.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class ConfigWriterFileManager
|
||||
{
|
||||
private FileManager $fileManager;
|
||||
|
||||
/**
|
||||
* @param ?array{
|
||||
* dir: string|int|null,
|
||||
* file: string|int|null,
|
||||
* user: string|int|null,
|
||||
* group: string|int|null,
|
||||
* } $defaultPermissions
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?array $defaultPermissions = null)
|
||||
{
|
||||
$defaultPermissionsToSet = null;
|
||||
|
||||
if ($defaultPermissions) {
|
||||
$defaultPermissionsToSet = $defaultPermissions;
|
||||
} else if ($config) {
|
||||
$defaultPermissionsToSet = $config->get('defaultPermissions');
|
||||
}
|
||||
|
||||
$this->fileManager = new FileManager($defaultPermissionsToSet);
|
||||
}
|
||||
|
||||
public function setConfig(Config $config): void
|
||||
{
|
||||
$this->fileManager = new FileManager(
|
||||
$config->get('defaultPermissions')
|
||||
);
|
||||
}
|
||||
|
||||
public function isFile(string $filePath): bool
|
||||
{
|
||||
return $this->fileManager->isFile($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
protected function putPhpContentsInternal(string $path, array $data, bool $useRenaming = false): void
|
||||
{
|
||||
$result = $this->fileManager->putPhpContents($path, $data, true, $useRenaming);
|
||||
|
||||
if ($result === false) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data $data
|
||||
*/
|
||||
public function putPhpContents(string $path, array $data): void
|
||||
{
|
||||
$this->putPhpContentsInternal($path, $data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function putPhpContentsNoRenaming(string $path, array $data): void
|
||||
{
|
||||
$this->putPhpContentsInternal($path, $data, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Supposed to return array. False means the file is being written or corrupted.
|
||||
* @return array<string, mixed>|false
|
||||
*/
|
||||
public function getPhpContents(string $path)
|
||||
{
|
||||
try {
|
||||
$data = $this->fileManager->getPhpContents($path);
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
43
application/Espo/Core/Utils/Config/ConfigWriterHelper.php
Normal file
43
application/Espo/Core/Utils/Config/ConfigWriterHelper.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
class ConfigWriterHelper
|
||||
{
|
||||
public function generateCacheTimestamp(): int
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public function generateMicrotime(): float
|
||||
{
|
||||
return microtime(true);
|
||||
}
|
||||
}
|
||||
73
application/Espo/Core/Utils/Config/InternalConfigHelper.php
Normal file
73
application/Espo/Core/Utils/Config/InternalConfigHelper.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
|
||||
class InternalConfigHelper
|
||||
{
|
||||
/** @var string[] */
|
||||
private array $stateParamList = [
|
||||
'appTimestamp',
|
||||
'cacheTimestamp',
|
||||
'version',
|
||||
'latestVersion',
|
||||
'latestExtensionVersions',
|
||||
'currencyRates',
|
||||
];
|
||||
|
||||
public function __construct(private Config $config, private Metadata $metadata)
|
||||
{}
|
||||
|
||||
public function isParamForStateConfig(string $name): bool
|
||||
{
|
||||
return in_array($name, $this->stateParamList);
|
||||
}
|
||||
|
||||
public function isParamForInternalConfig(string $name): bool
|
||||
{
|
||||
if ($this->config->isInternal($name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in_array($name, $this->config->get('systemItems') ?? [])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$level = $this->metadata->get(['app', 'config', 'params', $name, 'level']);
|
||||
|
||||
if ($level === Access::LEVEL_SYSTEM || $level === Access::LEVEL_INTERNAL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class MissingDefaultParamsSaver
|
||||
{
|
||||
private string $defaultConfigPath = 'application/Espo/Resources/defaults/config.php';
|
||||
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private ConfigWriter $configWriter,
|
||||
private FileManager $fileManager
|
||||
) {}
|
||||
|
||||
public function process(): void
|
||||
{
|
||||
$data = $this->fileManager->getPhpSafeContents($this->defaultConfigPath);
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $data */
|
||||
|
||||
$newData = [];
|
||||
|
||||
foreach ($data as $param => $value) {
|
||||
if ($this->config->has($param)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newData[$param] = $value;
|
||||
}
|
||||
|
||||
if (!count($newData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->configWriter->setMultiple($newData);
|
||||
$this->configWriter->save();
|
||||
}
|
||||
}
|
||||
56
application/Espo/Core/Utils/Config/Populator.php
Normal file
56
application/Espo/Core/Utils/Config/Populator.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
|
||||
use Espo\Core\Utils\File\Manager;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @since 10.0.0
|
||||
*/
|
||||
class Populator
|
||||
{
|
||||
private string $configFile = 'data/config.php';
|
||||
|
||||
public function __construct(
|
||||
private Manager $fileManager,
|
||||
private MissingDefaultParamsSaver $missingDefaultParamsSaver,
|
||||
) {}
|
||||
|
||||
public function populate(): void
|
||||
{
|
||||
if (!$this->fileManager->exists($this->configFile)) {
|
||||
$this->fileManager->putPhpContents($this->configFile, []);
|
||||
}
|
||||
|
||||
$this->missingDefaultParamsSaver->process();
|
||||
}
|
||||
}
|
||||
47
application/Espo/Core/Utils/Config/StateConfig.php
Normal file
47
application/Espo/Core/Utils/Config/StateConfig.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
/**
|
||||
* @since 10.1.0
|
||||
*/
|
||||
class StateConfig
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
) {}
|
||||
|
||||
public function getCacheTimestamp(): int
|
||||
{
|
||||
return $this->config->get('cacheTimestamp') ?? 0;
|
||||
}
|
||||
}
|
||||
52
application/Espo/Core/Utils/Config/StateConfigDirect.php
Normal file
52
application/Espo/Core/Utils/Config/StateConfigDirect.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @since 10.1.0
|
||||
*/
|
||||
class StateConfigDirect
|
||||
{
|
||||
private string $stateConfigPath = 'data/state.php';
|
||||
|
||||
private const string CACHE_TIMESTAMP_KEY = 'cacheTimestamp';
|
||||
|
||||
public function __construct(
|
||||
private ConfigFileManager $configFileManager,
|
||||
) {}
|
||||
|
||||
public function getCacheTimestamp(): int
|
||||
{
|
||||
$data = $this->configFileManager->getPhpContents($this->stateConfigPath);
|
||||
|
||||
return $data[self::CACHE_TIMESTAMP_KEY] ?? 0;
|
||||
}
|
||||
}
|
||||
81
application/Espo/Core/Utils/Config/SystemConfig.php
Normal file
81
application/Espo/Core/Utils/Config/SystemConfig.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://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 Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Config;
|
||||
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
/**
|
||||
* @since 9.1.0
|
||||
*/
|
||||
class SystemConfig
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
) {}
|
||||
|
||||
public function useCache(): bool
|
||||
{
|
||||
return (bool) $this->config->get('useCache');
|
||||
}
|
||||
|
||||
public function getVersion(): string
|
||||
{
|
||||
return (string) $this->config->get('version');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is restricted mode.
|
||||
*
|
||||
* @since 9.1.8
|
||||
*/
|
||||
public function isRestrictedMode(): bool
|
||||
{
|
||||
return (bool) $this->config->get('restrictedMode');
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 10.0.0
|
||||
*/
|
||||
public function isCronEnabled(): bool
|
||||
{
|
||||
return !$this->config->get('cronDisabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* A maintenance mode. Only admin can log in.
|
||||
*
|
||||
* @since 10.1.0
|
||||
*/
|
||||
public function isMaintenanceMode(): bool
|
||||
{
|
||||
return (bool) $this->config->get('maintenanceMode');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user