From 27e593e6e1e0a3e3ceb4aa493b460572fcf026c3 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 29 Nov 2016 23:06:33 -0800 Subject: testing check for cache invalidation to after values are decoded --- system/db/config.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'system/db') diff --git a/system/db/config.go b/system/db/config.go index edd4234..8bcf16b 100644 --- a/system/db/config.go +++ b/system/db/config.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "net/url" + "strings" "time" "github.com/bosssauce/ponzu/system/admin/config" @@ -25,6 +26,27 @@ func SetConfig(data url.Values) error { err := store.Update(func(tx *bolt.Tx) error { b := tx.Bucket([]byte("_config")) + // check for any multi-value fields (ex. checkbox fields) + // and correctly format for db storage. Essentially, we need + // fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2} + var discardKeys []string + for k, v := range data { + if strings.Contains(k, ".") { + key := strings.Split(k, ".")[0] + + if data.Get(key) == "" { + data.Set(key, v[0]) + discardKeys = append(discardKeys, k) + } else { + data.Add(key, v[0]) + } + } + } + + for _, discardKey := range discardKeys { + data.Del(discardKey) + } + cfg := &config.Config{} dec := schema.NewDecoder() dec.SetAliasTag("json") // allows simpler struct tagging when creating a content type -- cgit v1.2.3