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"
|
|
|
|
|
|
|
|
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) {
|
|
|
|
// Engine specific code
|
|
|
|
err = _initDatabase()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-14 07:09:44 +00:00
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
log.Print("Loading the usergroups.")
|
2017-09-15 22:20:01 +00:00
|
|
|
gstore = NewMemoryGroupStore()
|
|
|
|
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 {
|
|
|
|
users = NewMemoryUserStore(config.UserCacheCapacity)
|
|
|
|
topics = NewMemoryTopicStore(config.TopicCacheCapacity)
|
|
|
|
} else {
|
|
|
|
users = NewSQLUserStore()
|
|
|
|
topics = NewSQLTopicStore()
|
|
|
|
}
|
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
log.Print("Loading the forums.")
|
2017-09-10 16:57:22 +00:00
|
|
|
fstore = NewMemoryForumStore()
|
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-09-03 04:50:31 +00:00
|
|
|
err = buildForumPermissions()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-02 02:52:21 +00:00
|
|
|
fpstore = NewForumPermsStore()
|
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
|
|
|
}
|