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.")
|
|
|
|
common.Gstore, err = common.NewMemoryGroupStore()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
err2 := common.Gstore.LoadGroups()
|
|
|
|
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-11 04:06:16 +00:00
|
|
|
if common.Config.CacheTopicUser == common.CACHE_STATIC {
|
|
|
|
common.Users, err = common.NewMemoryUserStore(common.Config.UserCacheCapacity)
|
|
|
|
common.Topics, err2 = common.NewMemoryTopicStore(common.Config.TopicCacheCapacity)
|
2017-09-28 22:16:34 +00:00
|
|
|
} else {
|
2017-11-11 04:06:16 +00:00
|
|
|
common.Users, err = common.NewSQLUserStore()
|
|
|
|
common.Topics, err2 = common.NewSQLTopicStore()
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err2 != nil {
|
|
|
|
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-11 04:06:16 +00:00
|
|
|
common.Fstore, err = common.NewMemoryForumStore()
|
2017-11-02 13:35:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
err = common.Fstore.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-11 04:06:16 +00:00
|
|
|
common.Fpstore, err = common.NewMemoryForumPermsStore()
|
2017-11-06 04:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-11 04:06:16 +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
|
|
|
}
|