2017-06-14 07:09:44 +00:00
|
|
|
package main
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"log"
|
2017-09-15 22:20:01 +00:00
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
"./common"
|
|
|
|
)
|
2017-06-15 11:40:35 +00:00
|
|
|
|
2017-11-05 09:55:34 +00:00
|
|
|
var stmts *Stmts
|
|
|
|
|
2017-06-15 11:40:35 +00:00
|
|
|
var db *sql.DB
|
2017-09-03 04:50:31 +00:00
|
|
|
var dbVersion string
|
|
|
|
var dbAdapter string
|
2017-06-14 07:09:44 +00:00
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
// ErrNoRows is an alias of sql.ErrNoRows, just in case we end up with non-database/sql datastores
|
2017-06-28 12:05:26 +00:00
|
|
|
var ErrNoRows = sql.ErrNoRows
|
|
|
|
|
2017-10-14 07:39:22 +00:00
|
|
|
var _initDatabase func() error
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
func InitDatabase() (err error) {
|
2017-11-05 09:55:34 +00:00
|
|
|
stmts = &Stmts{Mocks: false}
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
// Engine specific code
|
|
|
|
err = _initDatabase()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-05 09:55:34 +00:00
|
|
|
globs = &Globs{stmts}
|
2017-06-14 07:09:44 +00:00
|
|
|
|
2017-11-11 23:34:27 +00:00
|
|
|
log.Print("Running the db handlers.")
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.DbInits.Run()
|
2017-11-02 13:35:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
|
|
|
|
log.Print("Loading the usergroups.")
|
2017-11-23 05:37:08 +00:00
|
|
|
common.Groups, err = common.NewMemoryGroupStore()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-23 05:37:08 +00:00
|
|
|
err2 := common.Groups.LoadGroups()
|
2017-11-11 04:06:16 +00:00
|
|
|
if err2 != nil {
|
|
|
|
return err2
|
|
|
|
}
|
2017-06-14 07:09:44 +00:00
|
|
|
|
2017-09-28 22:16:34 +00:00
|
|
|
// We have to put this here, otherwise LoadForums() won't be able to get the last poster data when building it's forums
|
|
|
|
log.Print("Initialising the user and topic stores")
|
2017-11-23 05:37:08 +00:00
|
|
|
|
|
|
|
var ucache common.UserCache
|
|
|
|
var tcache common.TopicCache
|
2017-11-11 04:06:16 +00:00
|
|
|
if common.Config.CacheTopicUser == common.CACHE_STATIC {
|
2017-11-23 05:37:08 +00:00
|
|
|
ucache = common.NewMemoryUserCache(common.Config.UserCacheCapacity)
|
|
|
|
tcache = common.NewMemoryTopicCache(common.Config.TopicCacheCapacity)
|
2017-11-11 04:06:16 +00:00
|
|
|
}
|
2017-11-23 05:37:08 +00:00
|
|
|
|
|
|
|
common.Users, err = common.NewDefaultUserStore(ucache)
|
2017-11-11 04:06:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-23 05:37:08 +00:00
|
|
|
common.Topics, err = common.NewDefaultTopicStore(tcache)
|
|
|
|
if err != nil {
|
2017-11-11 04:06:16 +00:00
|
|
|
return err2
|
2017-09-28 22:16:34 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
log.Print("Loading the forums.")
|
2017-11-23 05:37:08 +00:00
|
|
|
common.Forums, err = common.NewMemoryForumStore()
|
2017-11-02 13:35:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-23 05:37:08 +00:00
|
|
|
err = common.Forums.LoadForums()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-06-14 09:55:47 +00:00
|
|
|
log.Print("Loading the forum permissions.")
|
2017-11-23 05:37:08 +00:00
|
|
|
common.FPStore, err = common.NewMemoryForumPermsStore()
|
2017-11-06 04:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-23 05:37:08 +00:00
|
|
|
err = common.FPStore.Init()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-28 12:05:26 +00:00
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
log.Print("Loading the settings.")
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.LoadSettings()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("Loading the plugins.")
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.InitExtend()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("Loading the themes.")
|
2017-11-11 04:06:16 +00:00
|
|
|
return common.Themes.LoadActiveStatus()
|
2017-06-14 07:09:44 +00:00
|
|
|
}
|