Skip to content

Commit 38741f7

Browse files
committed
Configuration page patch.
Add the ability to remove orphaned data from the configuration file.
1 parent 1cf80d5 commit 38741f7

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

assets/default/_config.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
<tr>
1515
<td class="ng1">
1616
<div class="s">{tip_see_the_documentation}<hr /><em>{label_active_config_file} <span class="txtRd">{ActiveConfigFile}</span></em><hr /></div>
17-
<div class="bNav"><input type="submit" value="{field_update}" /></div>
17+
<div class="bNav">
18+
<input type="submit" value="{field_update}" /><br />
19+
<br />
20+
<input type="checkbox" name="orphaned" id="orphaned" class="auto" /><label class="s" for="orphaned">{checkbox_delete_orphaned_values}</label>
21+
</div>
1822
</td>
1923
</tr>
2024
</table>
2125
{ConfigFields}
22-
<table>
23-
<tr><td class="ng1"><div class="bNav"><input type="submit" value="{field_update}" /></div></td></tr>
24-
</table>
2526
</form>
2627
</td>
2728
</tr>

assets/fullmoon/_config.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
<tr>
1010
<td class="ng1">
1111
<div class="s">{tip_see_the_documentation}<hr /><em>{label_active_config_file} <span class="txtRd">{ActiveConfigFile}</span></em><hr /></div>
12-
<div class="bNav"><input type="submit" value="{field_update}" /></div>
12+
<div class="bNav">
13+
<input type="submit" value="{field_update}" /><br />
14+
<br />
15+
<input type="checkbox" name="orphaned" id="orphaned" class="auto" /><label class="s" for="orphaned">{checkbox_delete_orphaned_values}</label>
16+
</div>
1317
</td>
1418
</tr>
1519
</table>
1620
{ConfigFields}
17-
<table><tr><td class="ng1"><div class="bNav"><input type="submit" value="{field_update}" /></div></td></tr></table>
1821
</form>

src/FrontEnd.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,11 @@ public function view(string $Page = ''): void
10381038
/** For required extensions, classes, etc. */
10391039
$ReqsLookupCache = [];
10401040

1041+
/** Rebuilding in order to strip out orphaned data. */
1042+
if (isset($_POST['orphaned'])) {
1043+
$NewConfig = [];
1044+
}
1045+
10411046
/** Iterate through configuration defaults. */
10421047
foreach ($this->Loader->ConfigurationDefaults as $CatKey => $CatValue) {
10431048
if (!is_array($CatValue)) {
@@ -1553,6 +1558,14 @@ public function view(string $Page = ''): void
15531558
$this->Loader->L10N->Data,
15541559
$this->Loader->parse($ThisDir, $ConfigurationRow)
15551560
);
1561+
1562+
/** Rebuilding in order to strip out orphaned data. */
1563+
if (isset($NewConfig)) {
1564+
if (!isset($NewConfig[$CatKey])) {
1565+
$NewConfig[$CatKey] = [];
1566+
}
1567+
$NewConfig[$CatKey][$DirKey] = $this->Loader->Configuration[$CatKey][$DirKey];
1568+
}
15561569
}
15571570
$CatKeyFriendly = $this->Loader->L10N->getString('config_' . $CatKey . '_label') ?: $CatKey;
15581571
$FE['Indexes'] .= sprintf(
@@ -1567,7 +1580,17 @@ public function view(string $Page = ''): void
15671580
unset($ReqsLookupCache);
15681581

15691582
/** Update the currently active configuration file if any changes were made. */
1570-
if ($ConfigurationModified) {
1583+
if ($ConfigurationModified || isset($NewConfig)) {
1584+
if (isset($NewConfig)) {
1585+
foreach ($this->Loader->Configuration as $CatKey => $CatValue) {
1586+
if (substr($CatKey, 0, 5) !== 'user.') {
1587+
continue;
1588+
}
1589+
$NewConfig[$CatKey] = $CatValue;
1590+
}
1591+
$this->Loader->Configuration = $NewConfig;
1592+
unset($NewConfig);
1593+
}
15711594
if ($this->Loader->updateConfiguration()) {
15721595
$FE['state_msg'] = $this->Loader->L10N->getString('response_configuration_updated');
15731596
} else {

0 commit comments

Comments
 (0)