2020-10-19 14:55:20 +02:00
|
|
|
package sqlstore
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
import (
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
2022-03-22 16:24:34 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2021-10-22 12:48:53 +02:00
|
|
|
)
|
|
|
|
|
2021-11-11 18:01:43 +02:00
|
|
|
func (s *SQLStore) getSystemSetting(db sq.BaseRunner, key string) (string, error) {
|
|
|
|
scanner := s.getQueryBuilder(db).
|
|
|
|
Select("value").
|
|
|
|
From(s.tablePrefix + "system_settings").
|
|
|
|
Where(sq.Eq{"id": key}).
|
|
|
|
QueryRow()
|
|
|
|
|
|
|
|
var result string
|
|
|
|
err := scanner.Scan(&result)
|
2022-04-20 17:02:12 +02:00
|
|
|
if err != nil && !model.IsErrNotFound(err) {
|
2021-11-11 18:01:43 +02:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
func (s *SQLStore) getSystemSettings(db sq.BaseRunner) (map[string]string, error) {
|
|
|
|
query := s.getQueryBuilder(db).Select("*").From(s.tablePrefix + "system_settings")
|
2020-10-19 14:55:20 +02:00
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
rows, err := query.Query()
|
2020-10-19 14:55:20 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2020-10-19 14:55:20 +02:00
|
|
|
|
|
|
|
results := map[string]string{}
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var id string
|
|
|
|
var value string
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-19 14:55:20 +02:00
|
|
|
err := rows.Scan(&id, &value)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-19 14:55:20 +02:00
|
|
|
results[id] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, nil
|
|
|
|
}
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
func (s *SQLStore) setSystemSetting(db sq.BaseRunner, id, value string) error {
|
|
|
|
query := s.getQueryBuilder(db).Insert(s.tablePrefix+"system_settings").Columns("id", "value").Values(id, value)
|
2020-10-19 14:55:20 +02:00
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
if s.dbType == model.MysqlDBType {
|
2021-04-30 16:48:45 +02:00
|
|
|
query = query.Suffix("ON DUPLICATE KEY UPDATE value = ?", value)
|
|
|
|
} else {
|
|
|
|
query = query.Suffix("ON CONFLICT (id) DO UPDATE SET value = EXCLUDED.value")
|
|
|
|
}
|
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
_, err := query.Exec()
|
2020-10-19 14:55:20 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-19 14:55:20 +02:00
|
|
|
return nil
|
|
|
|
}
|