2017-06-14 07:09:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
2017-09-15 22:20:01 +00:00
|
|
|
|
2017-06-15 11:40:35 +00:00
|
|
|
import "database/sql"
|
|
|
|
|
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-09-03 04:50:31 +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-09-03 04:50:31 +00:00
|
|
|
log.Print("Loading the usergroups.")
|
2017-11-02 13:35:19 +00:00
|
|
|
gstore, err = NewMemoryGroupStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-15 22:20:01 +00:00
|
|
|
err = gstore.LoadGroups()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
if config.CacheTopicUser == CACHE_STATIC {
|
2017-11-02 13:35:19 +00:00
|
|
|
users, err = NewMemoryUserStore(config.UserCacheCapacity)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
topics, err = NewMemoryTopicStore(config.TopicCacheCapacity)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-28 22:16:34 +00:00
|
|
|
} else {
|
2017-11-02 13:35:19 +00:00
|
|
|
users, err = NewSQLUserStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
topics, err = NewSQLTopicStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-28 22:16:34 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
log.Print("Loading the forums.")
|
2017-11-02 13:35:19 +00:00
|
|
|
fstore, err = NewMemoryForumStore()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-28 12:05:26 +00:00
|
|
|
err = 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-05 01:04:57 +00:00
|
|
|
fpstore = NewForumPermsStore()
|
|
|
|
err = 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-06-14 09:55:47 +00:00
|
|
|
err = LoadSettings()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("Loading the plugins.")
|
2017-09-28 22:16:34 +00:00
|
|
|
err = initExtend()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("Loading the themes.")
|
2017-09-03 04:50:31 +00:00
|
|
|
return LoadThemes()
|
2017-06-14 07:09:44 +00:00
|
|
|
}
|