Skip to content

Commit

Permalink
mvc:JsonKeyValueStoreField - restore support for json input data with…
Browse files Browse the repository at this point in the history
…out configd callout, closes #8180

partially reverts 525481c
  • Loading branch information
AdSchellevis committed Jan 5, 2025
1 parent b962ccd commit 83be9bb
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,18 @@ public function setConfigdPopulateTTL($value)
protected function actionPostLoadingEvent()
{
$data = null;
if ($this->internalSourceFile != null && $this->internalSourceField != null) {
$sourcefile = sprintf($this->internalSourceFile, $this->internalSourceField);
} else {
$sourcefile = $this->internalSourceFile;
}
$cachename = $sourcefile != null ? $sourcefile : $this->internalConfigdPopulateAct;
if (!empty($this->internalConfigdPopulateAct)) {
if (isset(static::$internalStaticContent[$this->internalConfigdPopulateAct])) {
if (isset(static::$internalStaticContent[$cachename])) {
/* cached for the lifetime of this session */
$data = static::$internalStaticContent[$this->internalConfigdPopulateAct];
} elseif ($this->internalSourceFile != null) {
$data = static::$internalStaticContent[$cachename];
} elseif ($sourcefile != null) {
/* use a file cache for the configd call*/
if ($this->internalSourceField != null) {
$sourcefile = sprintf($this->internalSourceFile, $this->internalSourceField);
} else {
$sourcefile = $this->internalSourceFile;
}
if (is_file($sourcefile)) {
$sourcehandle = fopen($sourcefile, "r+");
} else {
Expand Down Expand Up @@ -166,12 +167,18 @@ protected function actionPostLoadingEvent()
true
);
}
if ($data != null) {
static::$internalStaticContent[$this->internalConfigdPopulateAct] = $data;
$this->internalOptionList = $data;
if ($this->internalSelectAll && $this->internalValue == "") {
$this->internalValue = implode(',', array_keys($this->internalOptionList));
}
} elseif ($sourcefile != null && isfile($sourcefile)) {

This comment has been minimized.

Copy link
@swhite2

swhite2 Jan 6, 2025

Member

@AdSchellevis is_file()?

Fatal error: Uncaught Error: Call to undefined function OPNsense\Base\FieldTypes\isfile() in /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/JsonKeyValueStoreField.php:170

This comment has been minimized.

Copy link
@AdSchellevis

AdSchellevis Jan 6, 2025

Author Member

@swhite2 (face-palm) let me force-push a change, nothing else has been pushed yet

if (isset(static::$internalStaticContent[$cachename])) {
$data = static::$internalStaticContent[$cachename];
} else {
$data = json_decode(file_get_contents($sourcefile), true) ?? [];
}
}
if ($data != null) {
static::$internalStaticContent[$cachename] = $data;
$this->internalOptionList = $data;
if ($this->internalSelectAll && $this->internalValue == "") {
$this->internalValue = implode(',', array_keys($this->internalOptionList));
}
}
}
Expand Down

0 comments on commit 83be9bb

Please sign in to comment.