PLT-7 adding loc db calls for system table

Этот коммит содержится в:
=Corey Hulen
2016-01-20 08:07:52 -06:00
родитель f5eb3c1bcb
Коммит ca33812cb5
5 изменённых файлов: 22 добавлений и 20 удалений

Просмотреть файл

@@ -92,14 +92,14 @@ func main() {
} }
func setDiagnosticId() { func setDiagnosticId() {
if result := <-api.Srv.Store.System().Get(); result.Err == nil { if result := <-api.Srv.Store.System().Get(utils.T); result.Err == nil {
props := result.Data.(model.StringMap) props := result.Data.(model.StringMap)
id := props[model.SYSTEM_DIAGNOSTIC_ID] id := props[model.SYSTEM_DIAGNOSTIC_ID]
if len(id) == 0 { if len(id) == 0 {
id = model.NewId() id = model.NewId()
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id} systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
<-api.Srv.Store.System().Save(systemId) <-api.Srv.Store.System().Save(utils.T, systemId)
} }
utils.CfgDiagnosticId = id utils.CfgDiagnosticId = id
@@ -110,7 +110,7 @@ func runSecurityAndDiagnosticsJobAndForget() {
go func() { go func() {
for { for {
if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert { if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
if result := <-api.Srv.Store.System().Get(); result.Err == nil { if result := <-api.Srv.Store.System().Get(utils.T); result.Err == nil {
props := result.Data.(model.StringMap) props := result.Data.(model.StringMap)
lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0) lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
currentTime := model.GetMillis() currentTime := model.GetMillis()
@@ -135,9 +135,9 @@ func runSecurityAndDiagnosticsJobAndForget() {
systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)} systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)}
if lastSecurityTime == 0 { if lastSecurityTime == 0 {
<-api.Srv.Store.System().Save(systemSecurityLastTime) <-api.Srv.Store.System().Save(utils.T, systemSecurityLastTime)
} else { } else {
<-api.Srv.Store.System().Update(systemSecurityLastTime) <-api.Srv.Store.System().Update(utils.T, systemSecurityLastTime)
} }
if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil { if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
@@ -185,7 +185,7 @@ func runSecurityAndDiagnosticsJobAndForget() {
} }
bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id} bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id}
<-api.Srv.Store.System().Save(bulletinSeen) <-api.Srv.Store.System().Save(utils.T, bulletinSeen)
} }
} }
} }

Просмотреть файл

@@ -151,12 +151,12 @@ func NewSqlStore() Store {
sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T) sqlStore.preference.(*SqlPreferenceStore).DeleteUnusedFeatures(utils.T)
if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 { if model.IsPreviousVersion(schemaVersion) || isSchemaVersion07 || isSchemaVersion10 {
sqlStore.system.Update(&model.System{Name: "Version", Value: model.CurrentVersion}) sqlStore.system.Update(utils.T, &model.System{Name: "Version", Value: model.CurrentVersion})
l4g.Warn("The database schema has been upgraded to version " + model.CurrentVersion) l4g.Warn("The database schema has been upgraded to version " + model.CurrentVersion)
} }
if schemaVersion == "" { if schemaVersion == "" {
sqlStore.system.Save(&model.System{Name: "Version", Value: model.CurrentVersion}) sqlStore.system.Save(utils.T, &model.System{Name: "Version", Value: model.CurrentVersion})
l4g.Info("The database schema has been set to version " + model.CurrentVersion) l4g.Info("The database schema has been set to version " + model.CurrentVersion)
} }
@@ -210,12 +210,12 @@ func (ss SqlStore) GetCurrentSchemaVersion() string {
} }
func (ss SqlStore) MarkSystemRanUnitTests() { func (ss SqlStore) MarkSystemRanUnitTests() {
if result := <-ss.System().Get(); result.Err == nil { if result := <-ss.System().Get(utils.T); result.Err == nil {
props := result.Data.(model.StringMap) props := result.Data.(model.StringMap)
unitTests := props[model.SYSTEM_RAN_UNIT_TESTS] unitTests := props[model.SYSTEM_RAN_UNIT_TESTS]
if len(unitTests) == 0 { if len(unitTests) == 0 {
systemTests := &model.System{Name: model.SYSTEM_RAN_UNIT_TESTS, Value: "1"} systemTests := &model.System{Name: model.SYSTEM_RAN_UNIT_TESTS, Value: "1"}
<-ss.System().Save(systemTests) <-ss.System().Save(utils.T, systemTests)
} }
} }
} }

Просмотреть файл

@@ -5,6 +5,7 @@ package store
import ( import (
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
goi18n "github.com/nicksnyder/go-i18n/i18n"
) )
type SqlSystemStore struct { type SqlSystemStore struct {
@@ -29,7 +30,7 @@ func (s SqlSystemStore) UpgradeSchemaIfNeeded() {
func (s SqlSystemStore) CreateIndexesIfNotExists() { func (s SqlSystemStore) CreateIndexesIfNotExists() {
} }
func (s SqlSystemStore) Save(system *model.System) StoreChannel { func (s SqlSystemStore) Save(T goi18n.TranslateFunc, system *model.System) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
@@ -47,7 +48,7 @@ func (s SqlSystemStore) Save(system *model.System) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlSystemStore) Update(system *model.System) StoreChannel { func (s SqlSystemStore) Update(T goi18n.TranslateFunc, system *model.System) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)
@@ -65,7 +66,7 @@ func (s SqlSystemStore) Update(system *model.System) StoreChannel {
return storeChannel return storeChannel
} }
func (s SqlSystemStore) Get() StoreChannel { func (s SqlSystemStore) Get(T goi18n.TranslateFunc) StoreChannel {
storeChannel := make(StoreChannel) storeChannel := make(StoreChannel)

Просмотреть файл

@@ -5,6 +5,7 @@ package store
import ( import (
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"testing" "testing"
) )
@@ -12,9 +13,9 @@ func TestSqlSystemStore(t *testing.T) {
Setup() Setup()
system := &model.System{Name: model.NewId(), Value: "value"} system := &model.System{Name: model.NewId(), Value: "value"}
Must(store.System().Save(system)) Must(store.System().Save(utils.T, system))
result := <-store.System().Get() result := <-store.System().Get(utils.T)
systems := result.Data.(model.StringMap) systems := result.Data.(model.StringMap)
if systems[system.Name] != system.Value { if systems[system.Name] != system.Value {
@@ -22,9 +23,9 @@ func TestSqlSystemStore(t *testing.T) {
} }
system.Value = "value2" system.Value = "value2"
Must(store.System().Update(system)) Must(store.System().Update(utils.T, system))
result2 := <-store.System().Get() result2 := <-store.System().Get(utils.T)
systems2 := result2.Data.(model.StringMap) systems2 := result2.Data.(model.StringMap)
if systems2[system.Name] != system.Value { if systems2[system.Name] != system.Value {

Просмотреть файл

@@ -162,9 +162,9 @@ type OAuthStore interface {
} }
type SystemStore interface { type SystemStore interface {
Save(system *model.System) StoreChannel Save(T goi18n.TranslateFunc, system *model.System) StoreChannel
Update(system *model.System) StoreChannel Update(T goi18n.TranslateFunc, system *model.System) StoreChannel
Get() StoreChannel Get(T goi18n.TranslateFunc) StoreChannel
} }
type WebhookStore interface { type WebhookStore interface {