fix(config): correctly detect v1 vs v2 config and preserve versions node

- Determine config version by presence of "system" and "template" nodes
  instead of "versions", since a v2 config can also include "versions"
  and was previously being skipped from merging as a result.
- Preserve the "versions" node after merging a v1 config, since
  PortalConfigReader.MergeConfigs does not carry it forward.
This commit is contained in:
jkdevito 2026-07-07 16:55:43 -05:00
parent 2f7789b374
commit 47e186d8f4

View file

@ -135,12 +135,14 @@ namespace PepperDash.Essentials.Core.Config
{
var parsedConfig = JObject.Parse(fs.ReadToEnd());
// Check if it's a v2 config (check for "version" node)
// this means it's already merged by the Portal API
// from the v2 config tool
var isV2Config = parsedConfig["versions"] != null;
if (isV2Config)
// A config is v1 if it has separate "system" and "template" nodes that
// need to be merged. A v2 config is already merged by the Portal API and
// will not have "system"/"template" nodes. This is independent of whether
// a "versions" node is present, which only carries version metadata and
// can appear on either a v1 or v2 config.
var isV1Config = parsedConfig["system"] != null && parsedConfig["template"] != null;
if (!isV1Config)
{
Debug.LogMessage(LogEventLevel.Information, "Config file is a v2 format, no merge necessary.");
ConfigObject = parsedConfig.ToObject<EssentialsConfig>();
@ -148,6 +150,8 @@ namespace PepperDash.Essentials.Core.Config
return true;
}
Debug.LogMessage(LogEventLevel.Information, "Config file is a v1 format, merging system and template.");
// Extract SystemUrl and TemplateUrl into final config output
ConfigObject = PortalConfigReader.MergeConfigs(parsedConfig).ToObject<EssentialsConfig>();
@ -160,6 +164,13 @@ namespace PepperDash.Essentials.Core.Config
{
ConfigObject.TemplateUrl = parsedConfig["template_url"].Value<string>();
}
// MergeConfigs does not carry the "versions" node forward, so it must be
// applied separately to ensure it's preserved in the merged config.
if (parsedConfig["versions"] != null)
{
ConfigObject.Versions = parsedConfig["versions"].ToObject<VersionData>();
}
}
Debug.LogMessage(LogEventLevel.Information, "Successfully Loaded Merged Config");