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 <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-30 12:49:58 +01:00
commit 1e6b1ffcf8
2 changed files with 46 additions and 3 deletions

View file

@ -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 set `PHP_BIN=/path/to/php` if `php` is not on PATH.) Both modes call
`build.php` per picked-up variant, print a summary `build.php` per picked-up variant, print a summary
(`N built, M failed, K not picked up`) and exit non-zero if any variant (`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 fails (unknown option keys fail loudly — the drift check). NEW option keys in
(re)built variant: reset the theme in the LimeSurvey admin (Theme options → the mother `config.xml` are automatically added to each variant json as `""`
Reset), flush assets, Ctrl+F5. `build.php` enforces the per-variant rules itself: (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, `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. and it warns when a variant's `preview.png` is identical to the mother's.
Never edit the generated `../<client>/` folder by hand — every build Never edit the generated `../<client>/` folder by hand — every build

View file

@ -60,6 +60,9 @@
* value ("" or null) means "inherit the mother theme's default" and is skipped — * 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 * 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. * 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: * Output:
* ../<variantName>/config.xml (next to this theme, in upload/themes/survey) * ../<variantName>/config.xml (next to this theme, in upload/themes/survey)
@ -114,6 +117,43 @@ if (!$doc->load($motherConfig)) {
} }
$xpath = new DOMXPath($doc); $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; $motherName = (string) $xpath->query('//metadata/name')->item(0)->textContent;
// --- metadata: identify the variant, point extends to the mother theme --- // --- metadata: identify the variant, point extends to the mother theme ---