From 1e6b1ffcf88b0f2009ae469cafd6187726dcac77 Mon Sep 17 00:00:00 2001 From: Tammo ter Hark Date: Mon, 30 Nov 2026 12:49:58 +0100 Subject: [PATCH] feat(variants): auto-sync NEW mother option keys into variant jsons and report them (row 246) Standing rule: when the mother config.xml gains option keys that a variant json does not list yet, build.php adds them to the json as "" (inherit the mother default, skipped at apply time) and prints 'NOTE: N NEW option key(s) ... review them: ...'. Existing keys/values and legacy keys are never touched; options are rewritten in mother-config order. Runs on every build (single and build_all), so new settable keys are always surfaced to the user. README rebuild section and AGENTS.md document the rule. Verified in a /tmp sandbox: added a fake option to the mother config, built a json missing it -> key added as "" with the NOTE, existing values (#123456) and legacy key (logotopmargin) preserved; second run reports 0 new keys. php -l clean; export_public.sh exit 0. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- README.md | 9 ++++++--- variants/build.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eba1737..6167331 100644 --- a/README.md +++ b/README.md @@ -450,9 +450,12 @@ the variant's `preview.png` is identical to the mother's. set `PHP_BIN=/path/to/php` if `php` is not on PATH.) Both modes call `build.php` per picked-up variant, print a summary (`N built, M failed, K not picked up`) and exit non-zero if any variant - fails (unknown option keys fail loudly — the drift check). Then, per - (re)built variant: reset the theme in the LimeSurvey admin (Theme options → - Reset), flush assets, Ctrl+F5. `build.php` enforces the per-variant rules itself: + fails (unknown option keys fail loudly — the drift check). NEW option keys in + the mother `config.xml` are automatically added to each variant json as `""` + (inherit) and reported with a `NOTE: N NEW option key(s) ...` line, so every + new settable key is surfaced to you — review those keys in the json. + Then, per (re)built variant: reset the theme in the LimeSurvey admin + (Theme options → Reset), flush assets, Ctrl+F5. `build.php` enforces the per-variant rules itself: `files/preview.svg` is only added at first creation and never overwritten, and it warns when a variant's `preview.png` is identical to the mother's. Never edit the generated `..//` folder by hand — every build diff --git a/variants/build.php b/variants/build.php index 89f7c0e..73eb2e1 100644 --- a/variants/build.php +++ b/variants/build.php @@ -60,6 +60,9 @@ * value ("" or null) means "inherit the mother theme's default" and is skipped — * only non-empty values are written into the variant config. So a variant json * can show every key the user CAN set, while leaving unknown ones to inherit. + * Row 246: when the mother config.xml gains NEW option keys, they are added to + * the json automatically as "" and a NOTE is printed listing them, so the user + * is informed about every new settable key (existing values are never touched). * * Output: * ..//config.xml (next to this theme, in upload/themes/survey) @@ -114,6 +117,43 @@ if (!$doc->load($motherConfig)) { } $xpath = new DOMXPath($doc); +// --- row 246: keep the json in sync with the mother config — NEW option keys --- +// Standing rule: when the mother config.xml gains option keys that a variant json +// does not list yet, they are ADDED to the json as "" (inherit the mother default) +// and the user is INFORMED (notice below), so nothing settable goes unnoticed. +// Existing keys and values are never touched; legacy keys unknown to the mother +// are kept as-is at the end of the options object. +$motherOptionKeys = []; +foreach ($xpath->query('//options/*') as $opt) { + if ($opt instanceof DOMElement) { + $motherOptionKeys[] = $opt->nodeName; + } +} +if (!isset($definition['options']) || !is_array($definition['options'])) { + $definition['options'] = []; +} +$newKeys = []; +foreach ($motherOptionKeys as $k) { + if (!array_key_exists($k, $definition['options'])) { + $definition['options'][$k] = ''; + $newKeys[] = $k; + } +} +if (!empty($newKeys)) { + $ordered = []; + foreach ($motherOptionKeys as $k) { + $ordered[$k] = $definition['options'][$k]; + } + foreach ($definition['options'] as $k => $v) { + if (!in_array($k, $motherOptionKeys, true)) { + $ordered[$k] = $v; // legacy key not present in the mother config + } + } + $definition['options'] = $ordered; + file_put_contents($definitionFile, json_encode($definition, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n"); + echo "NOTE: " . count($newKeys) . " NEW option key(s) in the mother config.xml were added to $definitionFile as \"\" (inherit default) — review them: " . implode(', ', $newKeys) . "\n"; +} + $motherName = (string) $xpath->query('//metadata/name')->item(0)->textContent; // --- metadata: identify the variant, point extends to the mother theme ---