2017-06-14 07:09:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "fmt"
|
|
|
|
import "encoding/json"
|
2017-06-15 11:40:35 +00:00
|
|
|
import "database/sql"
|
|
|
|
|
|
|
|
var db *sql.DB
|
|
|
|
var db_version string
|
|
|
|
var db_collation string = "utf8mb4_general_ci"
|
2017-06-14 07:09:44 +00:00
|
|
|
|
|
|
|
func init_database() (err error) {
|
|
|
|
// Engine specific code
|
|
|
|
err = _init_database()
|
|
|
|
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.Is_Mod, &group.Is_Admin, &group.Is_Banned, &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")
|
|
|
|
fill_group_id_gap(i, group.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(group.PermissionsText, &group.Perms)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if debug {
|
|
|
|
log.Print(group.Name + ": ")
|
|
|
|
fmt.Printf("%+v\n", group.Perms)
|
|
|
|
}
|
|
|
|
|
|
|
|
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.")
|
2017-06-14 09:55:47 +00:00
|
|
|
err = 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.")
|
|
|
|
err = build_forum_permissions()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-15 11:40:35 +00:00
|
|
|
fstore = NewStaticForumStore()
|
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-06-14 09:55:47 +00:00
|
|
|
err = LoadPlugins()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Print("Loading the themes.")
|
2017-06-14 09:55:47 +00:00
|
|
|
err = LoadThemes()
|
2017-06-14 07:09:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|