Skip to content

Commit

Permalink
Do not store null for channel options (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Jul 15, 2024
2 parents 1bd9f93 + 1079dc6 commit b377ae1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions application/forms/ChannelForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function editChannel(): void
$storedValues = $this->fetchDbValues();

$channel['config'] = json_encode($this->filterConfig($channel['config']));
$storedValues['config'] = json_encode($this->filterConfig($storedValues['config']));
$storedValues['config'] = json_encode($storedValues['config']);

if (! empty(array_diff_assoc($channel, $storedValues))) {
$channel['changed_at'] = time() * 1000;
Expand Down Expand Up @@ -397,17 +397,19 @@ protected function fromCurrentLocale(array $localeMap): ?string
*/
private function filterConfig(array $config): array
{
return array_filter(
$config,
function ($configItem, $key) {
if (isset($this->defaultChannelOptions[$key])) {
return $this->defaultChannelOptions[$key] !== $configItem;
foreach ($config as $key => $value) {
if (isset($this->defaultChannelOptions[$key])) {
if ($value === null) {
$config[$key] = '';
} elseif ($this->defaultChannelOptions[$key] === $value) {
unset($config[$key]);
}
} elseif ($value === null) {
unset($config[$key]);
}
}

return $configItem !== null;
},
ARRAY_FILTER_USE_BOTH
);
return $config;
}

/**
Expand Down

0 comments on commit b377ae1

Please sign in to comment.