EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Config:set auto type
Yurii32e32f7a7975
diff --git a/application/Espo/Classes/ConsoleCommands/SetConfigParam.php b/application/Espo/Classes/ConsoleCommands/SetConfigParam.phpindex 9e847fb62d..90b62f4f79 100644--- a/application/Espo/Classes/ConsoleCommands/SetConfigParam.php+++ b/application/Espo/Classes/ConsoleCommands/SetConfigParam.php@@ -49,6 +49,7 @@ class SetConfigParam implements Commandprivate const string TYPE_INT = 'int';private const string TYPE_FLOAT = 'float';private const string TYPE_JSON = 'json';+ private const string TYPE_AUTO = 'auto';/** @var string[] */private const array ALLOWED_TYPES = [@@ -57,6 +58,7 @@ class SetConfigParam implements Commandself::TYPE_INT,self::TYPE_FLOAT,self::TYPE_JSON,+ self::TYPE_AUTO,];public function __construct(@@ -140,6 +142,32 @@ class SetConfigParam implements Commandprivate function prepareValue(IO $io, string $value, string $type): mixed{+ if ($type === self::TYPE_AUTO) {+ $lower = strtolower($value);++ if ($lower === 'true') {+ return true;+ }++ if ($lower === 'false') {+ return false;+ }++ if ($lower === 'null') {+ return null;+ }++ if (filter_var($value, FILTER_VALIDATE_INT) !== false) {+ return (int) $value;+ }++ if (filter_var($value, FILTER_VALIDATE_FLOAT) !== false) {+ return (float) $value;+ }++ return $value;+ }+if ($type === self::TYPE_JSON) {try {return Json::decode($value);diff --git a/tests/unit/Espo/Commands/ConfigTest.php b/tests/unit/Espo/Commands/ConfigTest.phpindex 515d52fc20..9679f1f9ea 100644--- a/tests/unit/Espo/Commands/ConfigTest.php+++ b/tests/unit/Espo/Commands/ConfigTest.php@@ -364,6 +364,84 @@ class ConfigTest extends TestCase);}+ public function testSetConfigValueAutoTrue1(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: 'true',+ valueExpected: true,+ );+ }++ public function testSetConfigValueAutoTrue2(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: 'TRUE',+ valueExpected: true,+ );+ }++ public function testSetConfigValueAutoFalse1(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: 'false',+ valueExpected: false,+ );+ }++ public function testSetConfigValueAutoNull1(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: 'null',+ );+ }++ public function testSetConfigValueAutoNull2(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: 'NULL',+ );+ }++ public function testSetConfigValueAutoInt(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: '2',+ valueExpected: 2,+ );+ }++ public function testSetConfigValueAutoFloat(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: '2.0',+ valueExpected: 2.0,+ );+ }++ public function testSetConfigValueAutoString(): void+ {+ $this->internalTestSet(+ type: 'auto',+ paramName: 'test',+ value: 'value',+ valueExpected: 'value',+ );+ }+/*** @param (Closure(Config & MockObject): void)|null $hook*/