91f70d2a4a
Added basic support for server sync. Re-added a few missing defers. Renamed TO-DO to TODO across the entire codebase. Renamed StaticForumStore to MemoryForumStore. The ForumStore is now built on a sync.Map with a view slice for generating /forums rather than a slice. Renamed many more functions and variables to satisfy the linter. increase_post_user_stats() and decrease_post_user_stats() are now methods on the User struct. We also fix a bug where they take the moderator's score rather than the target user's into account when recalculating their level after a post / topic is deleted. Transitioned the topic list to CSS Grid for Tempra Simple, with a float fallback. Cosmo and Cosmo Conflux are now hidden from the theme list. Fixed more data races. Added more debug data to the template compiler logs.
102 lines
2.1 KiB
Go
102 lines
2.1 KiB
Go
package main
|
|
|
|
import "log"
|
|
import "encoding/json"
|
|
import "database/sql"
|
|
|
|
var db *sql.DB
|
|
var dbVersion string
|
|
var dbAdapter string
|
|
|
|
// ErrNoRows is an alias of sql.ErrNoRows, just in case we end up with non-database/sql datastores
|
|
var ErrNoRows = sql.ErrNoRows
|
|
|
|
func initDatabase() (err error) {
|
|
// Engine specific code
|
|
err = _initDatabase()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Loading the usergroups.")
|
|
groups = append(groups, Group{ID: 0, Name: "System"})
|
|
|
|
rows, err := get_groups_stmt.Query()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
|
|
i := 1
|
|
for ; rows.Next(); i++ {
|
|
group := Group{ID: 0}
|
|
err := rows.Scan(&group.ID, &group.Name, &group.PermissionsText, &group.PluginPermsText, &group.IsMod, &group.IsAdmin, &group.IsBanned, &group.Tag)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Ugh, you really shouldn't physically delete these items, it makes a big mess of things
|
|
if group.ID != i {
|
|
log.Print("Stop physically deleting groups. You are messing up the IDs. Use the Group Manager or delete_group() instead x.x")
|
|
fillGroupIDGap(i, group.ID)
|
|
}
|
|
|
|
err = json.Unmarshal(group.PermissionsText, &group.Perms)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if dev.DebugMode {
|
|
log.Print(group.Name + ": ")
|
|
log.Printf("%+v\n", group.Perms)
|
|
}
|
|
|
|
err = json.Unmarshal(group.PluginPermsText, &group.PluginPerms)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if dev.DebugMode {
|
|
log.Print(group.Name + ": ")
|
|
log.Printf("%+v\n", group.PluginPerms)
|
|
}
|
|
|
|
//group.Perms.ExtData = make(map[string]bool)
|
|
groups = append(groups, group)
|
|
}
|
|
err = rows.Err()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
groupCapCount = i
|
|
|
|
log.Print("Binding the Not Loggedin Group")
|
|
GuestPerms = groups[6].Perms
|
|
|
|
log.Print("Loading the forums.")
|
|
fstore = NewMemoryForumStore()
|
|
err = fstore.LoadForums()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Loading the forum permissions.")
|
|
err = buildForumPermissions()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Loading the settings.")
|
|
err = LoadSettings()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Loading the plugins.")
|
|
err = LoadPlugins()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Print("Loading the themes.")
|
|
return LoadThemes()
|
|
}
|