From 8b6c7b82ca420c85df61967d9ce078470133b50b Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 5 Jul 2017 14:21:23 -0400 Subject: [PATCH] Make config writer smarter about arrays. --- module/VuFind/src/VuFind/Config/Writer.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/module/VuFind/src/VuFind/Config/Writer.php b/module/VuFind/src/VuFind/Config/Writer.php index 16eac6f366d..dc56420cf43 100644 --- a/module/VuFind/src/VuFind/Config/Writer.php +++ b/module/VuFind/src/VuFind/Config/Writer.php @@ -120,6 +120,13 @@ class Writer } else if (strstr($content, '=')) { $contentParts = explode('=', $content, 2); $key = trim($contentParts[0]); + // If the key we are trying to set is already present as an array, + // we need to clear out the multiple existing values before writing + // in a new one: + if ($key == $setting . '[]') { + continue; + } + // Standard case for match on section + key: if ($currentSection == $section && $key == $setting) { $settingSet = true; if ($value === null) { @@ -231,6 +238,18 @@ class Writer $tabStr .= ' '; } + // Special case: if value is an array, we need to adjust the key + // accordingly: + if (is_array($value)) { + $retVal = ''; + foreach ($value as $current) { + $retVal .= $key . '[]' . $tabStr . " = " + . $this->buildContentValue($current); + } + return $retVal; + } + + // Standard case: value is not an array: return $key . $tabStr . " = " . $this->buildContentValue($value); } -- GitLab