Add unit tests for EconomicCustomerModel parsing and validation
This commit is contained in:
@@ -71,7 +71,7 @@ trait module_config_variable
|
||||
*/
|
||||
static function isVariableSet(string $module, string $variable): bool
|
||||
{
|
||||
global $db;
|
||||
$db = self::getModuleConfigDatabase();
|
||||
$module = $db->escape_string($module);
|
||||
$variable = $db->escape_string($variable);
|
||||
$sql = "SELECT value FROM module_config WHERE module = '$module' AND variable = '$variable'";
|
||||
@@ -87,7 +87,7 @@ trait module_config_variable
|
||||
*/
|
||||
function insertVariableValue(string $module, string $variable, mixed $value): void
|
||||
{
|
||||
global $db;
|
||||
$db = self::getModuleConfigDatabase();
|
||||
$module = $db->escape_string($module);
|
||||
$variable = $db->escape_string($variable);
|
||||
$value = $db->escape_string((string)$value);
|
||||
@@ -126,7 +126,7 @@ trait module_config_variable
|
||||
*/
|
||||
function getVariableValue(): mixed
|
||||
{
|
||||
global $db;
|
||||
$db = self::getModuleConfigDatabase();
|
||||
$module = $db->escape_string($this->module_name);
|
||||
$variable = $db->escape_string($this->config_variable);
|
||||
$sql = "SELECT value FROM module_config WHERE module = '$module' AND variable = '$variable'";
|
||||
@@ -242,7 +242,7 @@ trait module_config_variable
|
||||
*/
|
||||
static function updateVariableValue(string $module, string $variable, mixed $value): void
|
||||
{
|
||||
global $db;
|
||||
$db = self::getModuleConfigDatabase();
|
||||
$module = $db->escape_string($module);
|
||||
$variable = $db->escape_string($variable);
|
||||
$value = $db->escape_string((string)$value);
|
||||
@@ -251,6 +251,57 @@ trait module_config_variable
|
||||
system_search_cache::markDirtyTable('module_config');
|
||||
}
|
||||
|
||||
private static function getModuleConfigDatabase(): \classes\db
|
||||
{
|
||||
global $db, $CONFIG_DB;
|
||||
|
||||
if ($db instanceof \classes\db) {
|
||||
return $db;
|
||||
}
|
||||
|
||||
if (!is_array($CONFIG_DB) || $CONFIG_DB === []) {
|
||||
$CONFIG_DB = self::readDatabaseConfigFromEnvironment();
|
||||
}
|
||||
|
||||
if (!is_array($CONFIG_DB) || $CONFIG_DB === []) {
|
||||
throw new Exception('Database configuration is not available');
|
||||
}
|
||||
|
||||
$db = new \classes\db($CONFIG_DB);
|
||||
$db->connect();
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
||||
private static function readDatabaseConfigFromEnvironment(): array
|
||||
{
|
||||
$readEnv = static function (string $key, string $default = ''): string {
|
||||
$value = $_ENV[$key] ?? getenv($key);
|
||||
if ($value === false || $value === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return trim((string)$value);
|
||||
};
|
||||
|
||||
$host = $readEnv('CONFIG_DB_HOST');
|
||||
$user = $readEnv('CONFIG_DB_USER');
|
||||
$database = $readEnv('CONFIG_DB_DATABASE');
|
||||
|
||||
if ($host === '' || $user === '' || $database === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'host' => $host,
|
||||
'user' => $user,
|
||||
'password' => $readEnv('CONFIG_DB_PASSWORD'),
|
||||
'database' => $database,
|
||||
'port' => (int)($readEnv('CONFIG_DB_PORT', '3306') ?: '3306'),
|
||||
'ssl_mode' => $readEnv('CONFIG_DB_SSL_MODE', 'DISABLED') ?: 'DISABLED',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config variable as a JSON string
|
||||
* @return string
|
||||
|
||||
Reference in New Issue
Block a user