Skip to content

Commit

Permalink
mvc:model:JsonKeyValueStoreField - support congfigd input without fil…
Browse files Browse the repository at this point in the history
…estream, needed for opnsense#7515

basically this just offers the option to remove the SourceFile reference and keep the configd action, the call overhead of using configd is quite low anyway and opnsense#7515 implements generic caching (which was the intend of the file handle)
  • Loading branch information
AdSchellevis committed Jun 6, 2024
1 parent 06d5077 commit a39add8
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function setConfigdPopulateTTL($value)
*/
protected function actionPostLoadingEvent()
{
$data = null;
if ($this->internalSourceFile != null) {
if ($this->internalSourceField != null) {
$sourcefile = sprintf($this->internalSourceFile, $this->internalSourceField);
Expand All @@ -135,8 +136,7 @@ protected function actionPostLoadingEvent()
$muttime = $stat['size'] == 0 ? 0 : $stat['mtime'];
if (time() - $muttime > $this->internalConfigdPopulateTTL) {
$act = $this->internalConfigdPopulateAct;
$backend = new Backend();
$response = $backend->configdRun($act, false, 20);
$response = (new Backend())->configdRun($act, false, 20);
if (!empty($response) && json_decode($response) !== null) {
// only store parsable results
fseek($sourcehandle, 0);
Expand All @@ -151,12 +151,14 @@ protected function actionPostLoadingEvent()
}
if (is_file($sourcefile)) {
$data = json_decode(file_get_contents($sourcefile), true);
if ($data != null) {
$this->internalOptionList = $data;
if ($this->internalSelectAll && $this->internalValue == "") {
$this->internalValue = implode(',', array_keys($this->internalOptionList));
}
}
}
} elseif (!empty($this->internalConfigdPopulateAct)) {
$data = json_decode((new Backend())->configdRun($this->internalConfigdPopulateAct, false, 20) ?? '', true);
}
if ($data != null) {
$this->internalOptionList = $data;
if ($this->internalSelectAll && $this->internalValue == "") {
$this->internalValue = implode(',', array_keys($this->internalOptionList));
}
}
}
Expand Down

0 comments on commit a39add8

Please sign in to comment.