From 15420d4d89f0078aae4d9699a08eccae4b8a456b Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 23 Apr 2018 22:08:31 +0100 Subject: [PATCH] The patcher (schema updating part of the updater) finally works, yay. Partially rewrote the forum permissions system to make it more stable. Moved config.go into it's own package in /config/ Removed Go Git as a dependency. Tweaked the GopherJS pulling. Fixed inserts where all the columns have default values. Reverted a silly tweak I made thinking that mOrder == order. Removed the /common/ hack from the patcher. Fixed a bug where the forum creator would ignore the visiblity value you provided. The tests now work again. Swapped a misplaced fmt.Println with a fmt.Printf. Fixed a bug in the installer where all the table logs would be on one line in the console. Added more logging to the installer. --- .gitignore | 2 +- .travis.yml | 2 +- README.md | 4 +- common/forum.go | 2 +- common/forum_perms_store.go | 195 ++++++++++++-------------- common/group.go | 1 - common/group_store.go | 11 +- {patcher/common => config}/filler.txt | 0 dev-update-linux | 9 +- dev-update-travis | 4 - dev-update.bat | 12 +- general_test.go | 2 + install-linux | 5 +- install.bat | 9 +- install/install.go | 11 +- install/install/install.go | 3 + install/install/mysql.go | 16 ++- main.go | 4 +- misc_test.go | 6 +- new-update.bat | 9 +- panel_routes.go | 9 +- patcher/main.go | 21 +-- patcher/patches.go | 6 +- query_gen/lib/mssql.go | 4 +- query_gen/lib/mysql.go | 9 +- query_gen/main.go | 29 +--- schema/mssql/inserts.sql | 2 +- schema/mysql/inserts.sql | 2 +- update-deps-linux | 5 +- update-deps.bat | 9 +- 30 files changed, 155 insertions(+), 248 deletions(-) rename {patcher/common => config}/filler.txt (100%) diff --git a/.gitignore b/.gitignore index 4279c942..af37f1cd 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,6 @@ out/* *.log .DS_Store .vscode/launch.json -config.go +config/config.go Gosora Install diff --git a/.travis.yml b/.travis.yml index c22196f8..efa818a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ before_install: - cd $HOME - git clone https://github.com/Azareal/Gosora - cd Gosora - - mv config_default.noparse config.go + - mv config_default.noparse ./config/config.go - chmod 755 ./update-deps-linux - chmod 755 ./dev-update-travis - chmod 755 ./run-linux-tests diff --git a/README.md b/README.md index 904d8b0f..3c9d9eec 100644 --- a/README.md +++ b/README.md @@ -120,9 +120,7 @@ go get -u github.com/denisenkom/go-mssqldb go get -u github.com/fsnotify/fsnotify -go get -u gopkg.in/src-d/go-git.v4/... - -go get -u github.com/gopherjs/gopherjs +go get -u github.com/gopherjs/gopherjs/... go generate diff --git a/common/forum.go b/common/forum.go index 9ad794b7..94f3c22e 100644 --- a/common/forum.go +++ b/common/forum.go @@ -117,7 +117,7 @@ func (forum *Forum) SetPerms(fperms *ForumPerms, preset string, gid int) (err er if err != nil { return errors.New("Unable to reload forum") } - err = FPStore.ReloadGroup(forum.ID, gid) + err = FPStore.Reload(forum.ID) if err != nil { return errors.New("Unable to reload the forum permissions") } diff --git a/common/forum_perms_store.go b/common/forum_perms_store.go index f6f48713..75814c0a 100644 --- a/common/forum_perms_store.go +++ b/common/forum_perms_store.go @@ -14,72 +14,52 @@ type ForumPermsStore interface { Init() error Get(fid int, gid int) (fperms *ForumPerms, err error) GetCopy(fid int, gid int) (fperms ForumPerms, err error) + ReloadAll() error Reload(id int) error - ReloadGroup(fid int, gid int) error } type ForumPermsCache interface { } type MemoryForumPermsStore struct { - get *sql.Stmt getByForum *sql.Stmt getByForumGroup *sql.Stmt - updateMutex sync.Mutex + evenForums map[int]map[int]*ForumPerms + oddForums map[int]map[int]*ForumPerms // [fid][gid]*ForumPerms + evenLock sync.RWMutex + oddLock sync.RWMutex } func NewMemoryForumPermsStore() (*MemoryForumPermsStore, error) { acc := qgen.Builder.Accumulator() return &MemoryForumPermsStore{ - get: acc.Select("forums_permissions").Columns("gid, fid, permissions").Orderby("gid ASC, fid ASC").Prepare(), getByForum: acc.Select("forums_permissions").Columns("gid, permissions").Where("fid = ?").Orderby("gid ASC").Prepare(), getByForumGroup: acc.Select("forums_permissions").Columns("permissions").Where("fid = ? AND gid = ?").Prepare(), + + evenForums: make(map[int]map[int]*ForumPerms), + oddForums: make(map[int]map[int]*ForumPerms), }, acc.FirstError() } func (fps *MemoryForumPermsStore) Init() error { - fps.updateMutex.Lock() - defer fps.updateMutex.Unlock() + DebugLog("Initialising the forum perms store") + return fps.ReloadAll() +} + +func (fps *MemoryForumPermsStore) ReloadAll() error { + DebugLog("Reloading the forum perms") fids, err := Forums.GetAllIDs() if err != nil { return err } - DebugDetail("fids: ", fids) - - rows, err := fps.get.Query() - if err != nil { - return err - } - defer rows.Close() - DebugLog("Adding the forum permissions") - DebugDetail("forumPerms[gid][fid]") - - forumPerms = make(map[int]map[int]*ForumPerms) - for rows.Next() { - var gid, fid int - var perms []byte - err = rows.Scan(&gid, &fid, &perms) + for _, fid := range fids { + err := fps.Reload(fid) if err != nil { return err } - - pperms, err := fps.parseForumPerm(perms) - if err != nil { - return err - } - _, ok := forumPerms[gid] - if !ok { - forumPerms[gid] = make(map[int]*ForumPerms) - } - - DebugDetail("gid: ", gid) - DebugDetail("fid: ", fid) - DebugDetailf("perms: %+v\n", pperms) - forumPerms[gid][fid] = pperms } - - return fps.cascadePermSetToGroups(forumPerms, fids) + return nil } func (fps *MemoryForumPermsStore) parseForumPerm(perms []byte) (pperms *ForumPerms, err error) { @@ -93,20 +73,14 @@ func (fps *MemoryForumPermsStore) parseForumPerm(perms []byte) (pperms *ForumPer // TODO: Need a more thread-safe way of doing this. Possibly with sync.Map? func (fps *MemoryForumPermsStore) Reload(fid int) error { - fps.updateMutex.Lock() - defer fps.updateMutex.Unlock() DebugLogf("Reloading the forum permissions for forum #%d", fid) - fids, err := Forums.GetAllIDs() - if err != nil { - return err - } - rows, err := fps.getByForum.Query(fid) if err != nil { return err } defer rows.Close() + var forumPerms = make(map[int]*ForumPerms) for rows.Next() { var gid int var perms []byte @@ -119,99 +93,104 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error { if err != nil { return err } - _, ok := forumPerms[gid] - if !ok { - forumPerms[gid] = make(map[int]*ForumPerms) - } - - forumPerms[gid][fid] = pperms + forumPerms[gid] = pperms + } + DebugLogf("forumPerms: %+v\n", forumPerms) + if fid%2 == 0 { + fps.evenLock.Lock() + fps.evenForums[fid] = forumPerms + fps.evenLock.Unlock() + } else { + fps.oddLock.Lock() + fps.oddForums[fid] = forumPerms + fps.oddLock.Unlock() } - return fps.cascadePermSetToGroups(forumPerms, fids) -} - -func (fps *MemoryForumPermsStore) ReloadGroup(fid int, gid int) (err error) { - fps.updateMutex.Lock() - defer fps.updateMutex.Unlock() - var perms []byte - err = fps.getByForumGroup.QueryRow(fid, gid).Scan(&perms) - if err != nil { - return err - } - fperms, err := fps.parseForumPerm(perms) - if err != nil { - return err - } - group, err := Groups.Get(gid) - if err != nil { - return err - } - // TODO: Refactor this - group.Forums[fid] = fperms - return nil -} - -func (fps *MemoryForumPermsStore) cascadePermSetToGroups(forumPerms map[int]map[int]*ForumPerms, fids []int) error { groups, err := Groups.GetAll() if err != nil { return err } + fids, err := Forums.GetAllIDs() + if err != nil { + return err + } for _, group := range groups { DebugLogf("Updating the forum permissions for Group #%d", group.ID) - group.Forums = []*ForumPerms{BlankForumPerms()} group.CanSee = []int{} - fps.cascadePermSetToGroup(forumPerms, group, fids) + for _, fid := range fids { + DebugDetailf("Forum #%+v\n", fid) + var forumPerms = make(map[int]*ForumPerms) + var ok bool + if fid%2 == 0 { + fps.evenLock.RLock() + forumPerms, ok = fps.evenForums[fid] + fps.evenLock.RUnlock() + } else { + fps.oddLock.RLock() + forumPerms, ok = fps.oddForums[fid] + fps.oddLock.RUnlock() + } - DebugDetailf("group.CanSee (length %d): %+v \n", len(group.CanSee), group.CanSee) - DebugDetailf("group.Forums (length %d): %+v\n", len(group.Forums), group.Forums) - } - return nil -} + var forumPerm *ForumPerms + if !ok { + forumPerm = BlankForumPerms() + } else { + forumPerm, ok = forumPerms[group.ID] + if !ok { + forumPerm = BlankForumPerms() + } + } -func (fps *MemoryForumPermsStore) cascadePermSetToGroup(forumPerms map[int]map[int]*ForumPerms, group *Group, fids []int) { - for _, fid := range fids { - DebugDetailf("Forum #%+v\n", fid) - forumPerm, ok := forumPerms[group.ID][fid] - if ok { - //log.Printf("Overriding permissions for forum #%d",fid) - group.Forums = append(group.Forums, forumPerm) - } else { - //log.Printf("Inheriting from group defaults for forum #%d",fid) - forumPerm = BlankForumPerms() - group.Forums = append(group.Forums, forumPerm) - } - if forumPerm.Overrides { - if forumPerm.ViewTopic { + if forumPerm.Overrides { + if forumPerm.ViewTopic { + group.CanSee = append(group.CanSee, fid) + } + } else if group.Perms.ViewTopic { group.CanSee = append(group.CanSee, fid) } - } else if group.Perms.ViewTopic { - group.CanSee = append(group.CanSee, fid) - } - DebugDetail("group.ID: ", group.ID) - DebugDetailf("forumPerm: %+v\n", forumPerm) - DebugDetail("group.CanSee: ", group.CanSee) + DebugDetail("group.ID: ", group.ID) + DebugDetailf("forumPerm: %+v\n", forumPerm) + DebugDetail("group.CanSee: ", group.CanSee) + } + DebugDetailf("group.CanSee (length %d): %+v \n", len(group.CanSee), group.CanSee) } + return nil } // TODO: Add a hook here and have plugin_guilds use it // TODO: Check if the forum exists? // TODO: Fix the races func (fps *MemoryForumPermsStore) Get(fid int, gid int) (fperms *ForumPerms, err error) { - group, err := Groups.Get(gid) - if err != nil { + var fmap map[int]*ForumPerms + var ok bool + if fid%2 == 0 { + fps.evenLock.RLock() + fmap, ok = fps.evenForums[fid] + fps.evenLock.RUnlock() + } else { + fps.oddLock.RLock() + fmap, ok = fps.oddForums[fid] + fps.oddLock.RUnlock() + } + if !ok { return fperms, ErrNoRows } - return group.Forums[fid], nil + + fperms, ok = fmap[gid] + if !ok { + return fperms, ErrNoRows + } + return fperms, nil } // TODO: Check if the forum exists? // TODO: Fix the races func (fps *MemoryForumPermsStore) GetCopy(fid int, gid int) (fperms ForumPerms, err error) { - group, err := Groups.Get(gid) + fPermsPtr, err := fps.Get(fid, gid) if err != nil { - return fperms, ErrNoRows + return fperms, err } - return *group.Forums[fid], nil + return *fPermsPtr, nil } diff --git a/common/group.go b/common/group.go index 7adacba0..0ce623dc 100644 --- a/common/group.go +++ b/common/group.go @@ -26,7 +26,6 @@ type Group struct { PermissionsText []byte PluginPerms map[string]bool // Custom permissions defined by plugins. What if two plugins declare the same permission, but they handle them in incompatible ways? Very unlikely, we probably don't need to worry about this, the plugin authors should be aware of each other to some extent PluginPermsText []byte - Forums []*ForumPerms CanSee []int // The IDs of the forums this group can see UserCount int // ! Might be temporary as I might want to lean on the database instead for this } diff --git a/common/group_store.go b/common/group_store.go index 1ae74aaa..58226cb9 100644 --- a/common/group_store.go +++ b/common/group_store.go @@ -226,7 +226,6 @@ func (mgs *MemoryGroupStore) Create(name string, tag string, isAdmin bool, isMod gid = int(gid64) var perms = BlankPerms - var blankForums []*ForumPerms var blankIntList []int var pluginPerms = make(map[string]bool) var pluginPermsBytes = []byte("{}") @@ -277,15 +276,13 @@ func (mgs *MemoryGroupStore) Create(name string, tag string, isAdmin bool, isMod } mgs.Lock() - mgs.groups[gid] = &Group{gid, name, isMod, isAdmin, isBanned, tag, perms, []byte(permstr), pluginPerms, pluginPermsBytes, blankForums, blankIntList, 0} + mgs.groups[gid] = &Group{gid, name, isMod, isAdmin, isBanned, tag, perms, []byte(permstr), pluginPerms, pluginPermsBytes, blankIntList, 0} mgs.groupCount++ mgs.Unlock() - for _, forum := range fdata { - err = FPStore.Reload(forum.ID) - if err != nil { - return gid, err - } + err = FPStore.ReloadAll() + if err != nil { + return gid, err } return gid, nil diff --git a/patcher/common/filler.txt b/config/filler.txt similarity index 100% rename from patcher/common/filler.txt rename to config/filler.txt diff --git a/dev-update-linux b/dev-update-linux index 60d18289..c2131cf6 100644 --- a/dev-update-linux +++ b/dev-update-linux @@ -28,11 +28,8 @@ go get -u github.com/bamiaux/rez echo "Updating fsnotify" go get -u github.com/fsnotify/fsnotify -echo "Updating Go Git" -go get -u gopkg.in/src-d/go-git.v4/... - echo "Updating GopherJS" -go get -u github.com/gopherjs/gopherjs +go get -u github.com/gopherjs/gopherjs/... echo "Updating Gosora" rm ./schema/lastSchema.json @@ -40,10 +37,6 @@ cp ./schema/schema.json ./schema/lastSchema.json git pull origin master echo "Patching Gosora" -rm ./patcher/config.go -cp ./config.go ./patcher/config.go -rm ./patcher/common/site.go -cp ./common/site.go ./patcher/common/site.go cd ./patcher go generate go build -o Patcher diff --git a/dev-update-travis b/dev-update-travis index 9fd16dae..a271c651 100644 --- a/dev-update-travis +++ b/dev-update-travis @@ -1,9 +1,5 @@ echo "Building the patcher" cp ./schema/schema.json ./schema/lastSchema.json -rm ./patcher/config.go -cp ./config.go ./patcher/config.go -rm ./patcher/common/site.go -cp ./common/site.go ./patcher/common/site.go cd ./patcher go generate go build -o Patcher diff --git a/dev-update.bat b/dev-update.bat index 662758e4..b2aae510 100644 --- a/dev-update.bat +++ b/dev-update.bat @@ -85,15 +85,8 @@ if %errorlevel% neq 0 ( exit /b %errorlevel% ) -echo Updating Go Git -go get -u gopkg.in/src-d/go-git.v4/... -if %errorlevel% neq 0 ( - pause - exit /b %errorlevel% -) - echo Updating GopherJS -go get -u github.com/gopherjs/gopherjs +go get -u github.com/gopherjs/gopherjs/... if %errorlevel% neq 0 ( pause exit /b %errorlevel% @@ -109,9 +102,6 @@ if %errorlevel% neq 0 ( ) echo Patching Gosora -rem Temporary hack until we switch to JSON or TOML for config files -copy ./config.go ./patcher/config.go -copy ./common/site.go ./patcher/common/site.go go generate go build ./patcher patcher.exe \ No newline at end of file diff --git a/general_test.go b/general_test.go index 25915249..def7c284 100644 --- a/general_test.go +++ b/general_test.go @@ -13,6 +13,7 @@ import ( "time" "./common" + "./config" "./install/install" "./query_gen/lib" "./routes" @@ -87,6 +88,7 @@ func gloinit() (err error) { } func init() { + config.Config() err := gloinit() if err != nil { log.Print("Something bad happened") diff --git a/install-linux b/install-linux index cdd1e1ac..39b2918d 100644 --- a/install-linux +++ b/install-linux @@ -28,11 +28,8 @@ go get -u github.com/bamiaux/rez echo "Installing fsnotify" go get -u github.com/fsnotify/fsnotify -echo "Installing Go Git" -go get -u gopkg.in/src-d/go-git.v4/... - echo "Installing GopherJS" -go get -u github.com/gopherjs/gopherjs +go get -u github.com/gopherjs/gopherjs/... echo "Building the installer" cd ./install diff --git a/install.bat b/install.bat index fd27286f..41f7a08b 100644 --- a/install.bat +++ b/install.bat @@ -85,15 +85,8 @@ if %errorlevel% neq 0 ( exit /b %errorlevel% ) -echo Installing Go Git -go get -u gopkg.in/src-d/go-git.v4/... -if %errorlevel% neq 0 ( - pause - exit /b %errorlevel% -) - echo Installing GopherJS -go get -u github.com/gopherjs/gopherjs +go get -u github.com/gopherjs/gopherjs/... if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/install/install.go b/install/install.go index 47a7459a..09893081 100644 --- a/install/install.go +++ b/install/install.go @@ -13,6 +13,7 @@ import ( "os" "runtime/debug" "strconv" + "strings" "./install" ) @@ -95,11 +96,11 @@ func main() { return } - configContents := []byte(`package main + configContents := []byte(`package config -import "./common" +import "../common" -func init() { +func Config() { // Site Info common.Site.ShortName = "` + siteShortName + `" // This should be less than three letters to fit in the navbar common.Site.Name = "` + siteName + `" @@ -167,7 +168,7 @@ func init() { `) fmt.Println("Opening the configuration file") - configFile, err := os.Create("./config.go") + configFile, err := os.Create("./config/config.go") if err != nil { abortError(err) return @@ -209,7 +210,7 @@ func handleDatabaseDetails() (adap install.InstallAdapter, ok bool) { if !scanner.Scan() { return nil, false } - dbAdapter := scanner.Text() + dbAdapter := strings.TrimSpace(scanner.Text()) if dbAdapter == "" { dbAdapter = defaultAdapter } diff --git a/install/install/install.go b/install/install/install.go index ea732ecf..1acaefae 100644 --- a/install/install/install.go +++ b/install/install/install.go @@ -1,6 +1,8 @@ package install import ( + "fmt" + "../../query_gen/lib" ) @@ -28,6 +30,7 @@ func Lookup(name string) (InstallAdapter, bool) { } func createAdmin() error { + fmt.Println("Creating the admin user") hashedPassword, salt, err := BcryptGeneratePassword("password") if err != nil { return err diff --git a/install/install/mysql.go b/install/install/mysql.go index 0afad84d..24b41ed2 100644 --- a/install/install/mysql.go +++ b/install/install/mysql.go @@ -105,7 +105,7 @@ func (ins *MysqlInstaller) InitDatabase() (err error) { } func (ins *MysqlInstaller) TableDefs() (err error) { - //fmt.Println("Creating the tables") + fmt.Println("Creating the tables") files, _ := ioutil.ReadDir("./schema/mysql/") for _, f := range files { if !strings.HasPrefix(f.Name(), "query_") { @@ -127,7 +127,7 @@ func (ins *MysqlInstaller) TableDefs() (err error) { return err } - fmt.Printf("Creating table '%s'", table) + fmt.Printf("Creating table '%s'\n", table) data, err := ioutil.ReadFile("./schema/mysql/" + f.Name()) if err != nil { return err @@ -148,7 +148,7 @@ func (ins *MysqlInstaller) TableDefs() (err error) { /*INSERT INTO settings(`name`,`content`,`type`) VALUES ('meta_desc','','html-attribute');*/ func (ins *MysqlInstaller) InitialData() error { - //fmt.Println("Seeding the tables") + fmt.Println("Seeding the tables") data, err := ioutil.ReadFile("./schema/mysql/inserts.sql") if err != nil { return err @@ -156,13 +156,15 @@ func (ins *MysqlInstaller) InitialData() error { data = bytes.TrimSpace(data) statements := bytes.Split(data, []byte(";")) - for key, statement := range statements { - if len(statement) == 0 { + for key, sBytes := range statements { + statement := string(sBytes) + if statement == "" { continue } + statement += ";" - fmt.Println("Executing query #" + strconv.Itoa(key) + " " + string(statement)) - _, err = ins.db.Exec(string(statement)) + fmt.Println("Executing query #" + strconv.Itoa(key) + " " + statement) + _, err = ins.db.Exec(statement) if err != nil { return err } diff --git a/main.go b/main.go index b0aed2bd..c477e60d 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "./common" "./common/counters" + "./config" "github.com/fsnotify/fsnotify" ) @@ -78,7 +79,7 @@ func afterDBInit() (err error) { return err } menuHold := common.Menus.Get(1) - fmt.Println("menuHold: %+v", menuHold) + fmt.Printf("menuHold: %+v\n", menuHold) var b bytes.Buffer menuHold.Build(&b, &common.GuestUser) fmt.Println("menuHold output: ", string(b.Bytes())) @@ -192,6 +193,7 @@ func main() { } log.Printf("tagIndices: %+v\n", tagIndices) log.Fatal("")*/ + config.Config() // TODO: Have a file for each run with the time/date the server started as the file name? // TODO: Log panics with recover() diff --git a/misc_test.go b/misc_test.go index 986cc141..8b42907b 100644 --- a/misc_test.go +++ b/misc_test.go @@ -537,7 +537,7 @@ func topicStoreTest(t *testing.T) { recordMustExist(t, err, "Couldn't find TID #1") if topic.ID != 1 { - t.Error("topic.ID does not match the requested TID. Got '%d' instead.", topic.ID) + t.Errorf("topic.ID does not match the requested TID. Got '%d' instead.", topic.ID) } // TODO: Add BulkGetMap() to the TopicStore @@ -578,7 +578,7 @@ func TestForumStore(t *testing.T) { recordMustExist(t, err, "Couldn't find FID #1") if forum.ID != 1 { - t.Error("forum.ID doesn't not match the requested FID. Got '%d' instead.'", forum.ID) + t.Errorf("forum.ID doesn't not match the requested FID. Got '%d' instead.'", forum.ID) } // TODO: Check the preset and forum permissions expect(t, forum.Name == "Reports", fmt.Sprintf("FID #0 is named '%s' and not 'Reports'", forum.Name)) @@ -618,7 +618,7 @@ func TestForumStore(t *testing.T) { expect(t, forum.ID == 2, fmt.Sprintf("The FID should be 3 not %d", forum.ID)) expect(t, forum.Name == "Test Forum", fmt.Sprintf("The name of the forum should be 'Test Forum' not '%s'", forum.Name)) expect(t, forum.Active, fmt.Sprintf("The test forum should be active")) - expect(t, forum.Desc == "", fmt.Sprintf("The forum description should be blank not '%s'", expectDesc, forum.Desc)) + expect(t, forum.Desc == "", fmt.Sprintf("The forum description should be blank not '%s'", forum.Desc)) // TODO: More forum creation tests // TODO: Test forum deletion diff --git a/new-update.bat b/new-update.bat index eac79b3a..8d74b45e 100644 --- a/new-update.bat +++ b/new-update.bat @@ -85,15 +85,8 @@ if %errorlevel% neq 0 ( exit /b %errorlevel% ) -echo Updating Go Git -go get -u gopkg.in/src-d/go-git.v4/... -if %errorlevel% neq 0 ( - pause - exit /b %errorlevel% -) - echo Updating GopherJS -go get -u github.com/gopherjs/gopherjs +go get -u github.com/gopherjs/gopherjs/... if %errorlevel% neq 0 ( pause exit /b %errorlevel% diff --git a/panel_routes.go b/panel_routes.go index 6d9263da..54a3b2f8 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -222,7 +222,7 @@ func routePanelForumsCreateSubmit(w http.ResponseWriter, r *http.Request, user c fname := r.PostFormValue("forum-name") fdesc := r.PostFormValue("forum-desc") fpreset := common.StripInvalidPreset(r.PostFormValue("forum-preset")) - factive := r.PostFormValue("forum-name") + factive := r.PostFormValue("forum-active") active := (factive == "on" || factive == "1") _, err := common.Forums.Create(fname, fdesc, active, fpreset) @@ -331,8 +331,11 @@ func routePanelForumsEdit(w http.ResponseWriter, r *http.Request, user common.Us if gid == 0 { continue } - // TODO: Don't access the cache on the group directly - gplist = append(gplist, common.GroupForumPermPreset{group, common.ForumPermsToGroupForumPreset(group.Forums[fid])}) + forumPerms, err := common.FPStore.Get(fid, group.ID) + if err != nil { + return common.InternalError(err, w, r) + } + gplist = append(gplist, common.GroupForumPermPreset{group, common.ForumPermsToGroupForumPreset(forumPerms)}) } if r.FormValue("updated") == "1" { diff --git a/patcher/main.go b/patcher/main.go index 41716024..f085a77b 100644 --- a/patcher/main.go +++ b/patcher/main.go @@ -10,8 +10,9 @@ import ( "os" "runtime/debug" + "../common" + "../config" "../query_gen/lib" - "./common" _ "github.com/go-sql-driver/mysql" ) @@ -29,7 +30,8 @@ func main() { } }() - if common.DbConfig != "mysql" && common.DbConfig != "" { + config.Config() + if common.DbConfig.Adapter != "mysql" && common.DbConfig.Adapter != "" { log.Fatal("Only MySQL is supported for upgrades right now, please wait for a newer build of the patcher") } @@ -42,15 +44,6 @@ func main() { if err != nil { log.Fatal(err) } - - err = os.Remove("./patcher/config.go") - if err != nil { - log.Fatal(err) - } - err = os.Remove("./patcher/common/site.go") - if err != nil { - log.Fatal(err) - } } func pressAnyKey(scanner *bufio.Scanner) { @@ -73,8 +66,8 @@ func prepMySQL() error { } type SchemaFile struct { - DBVersion int // Current version of the database schema - DynamicFileVersion int + DBVersion string // Current version of the database schema + DynamicFileVersion string MinGoVersion string // TODO: Minimum version of Go needed to install this version MinVersion string // TODO: Minimum version of Gosora to jump to this version, might be tricky as we don't store this in the schema file, maybe store it in the database } @@ -85,7 +78,7 @@ func patcher(scanner *bufio.Scanner) error { return err } - var schemaFile LanguagePack + var schemaFile SchemaFile err = json.Unmarshal(data, &schemaFile) if err != nil { return err diff --git a/patcher/patches.go b/patcher/patches.go index ca36e2b5..f1cef946 100644 --- a/patcher/patches.go +++ b/patcher/patches.go @@ -48,12 +48,12 @@ func patch0(scanner *bufio.Scanner) error { return err } - var mOrder int + var order int var mOrder = "mid, htmlID, cssClass, position, path, aria, tooltip, guestOnly, memberOnly, staffOnly, adminOnly" var addMenuItem = func(data map[string]interface{}) error { cols, values := qgen.InterfaceMapToInsertStrings(data, mOrder) - err := execStmt(qgen.Builder.SimpleInsert("menu_items", cols+", order", values+","+strconv.Itoa(mOrder))) - mOrder++ + err := execStmt(qgen.Builder.SimpleInsert("menu_items", cols+", order", values+","+strconv.Itoa(order))) + order++ return err } diff --git a/query_gen/lib/mssql.go b/query_gen/lib/mssql.go index 1d5e960f..4233273d 100644 --- a/query_gen/lib/mssql.go +++ b/query_gen/lib/mssql.go @@ -136,12 +136,12 @@ func (adapter *MssqlAdapter) SimpleInsert(name string, table string, columns str return "", errors.New("You need a name for this table") } - var querystr = "INSERT INTO [" + table + "]" + var querystr = "INSERT INTO [" + table + "] (" if columns == "" { + querystr += ") VALUES ()" adapter.pushStatement(name, "insert", querystr) return querystr, nil } - querystr += " (" // Escape the column names, just in case we've used a reserved keyword for _, column := range processColumns(columns) { diff --git a/query_gen/lib/mysql.go b/query_gen/lib/mysql.go index f6ca1dcb..79525eb3 100644 --- a/query_gen/lib/mysql.go +++ b/query_gen/lib/mysql.go @@ -144,9 +144,9 @@ func (adapter *MysqlAdapter) SimpleInsert(name string, table string, columns str return "", errors.New("You need a name for this table") } - var querystr = "INSERT INTO `" + table + "`" + var querystr = "INSERT INTO `" + table + "`(" if columns != "" { - querystr += "(" + adapter.buildColumns(columns) + ") VALUES (" + querystr += adapter.buildColumns(columns) + ") VALUES (" for _, field := range processFields(fields) { nameLen := len(field.Name) if field.Name[0] == '"' && field.Name[nameLen-1] == '"' && nameLen >= 3 { @@ -157,8 +157,11 @@ func (adapter *MysqlAdapter) SimpleInsert(name string, table string, columns str } querystr += field.Name + "," } - querystr = querystr[0:len(querystr)-1] + ")" + querystr = querystr[0 : len(querystr)-1] + } else { + querystr += ") VALUES (" } + querystr += ")" adapter.pushStatement(name, "insert", querystr) return querystr, nil diff --git a/query_gen/main.go b/query_gen/main.go index 77bdf352..fbf08a24 100644 --- a/query_gen/main.go +++ b/query_gen/main.go @@ -225,36 +225,9 @@ func seedTables(adapter qgen.Adapter) error { qgen.Install.SimpleInsert("menus", "", "") + // Go maps have a random iteration order, so we have to do this, otherwise the schema files will become unstable and harder to audit var order = 0 var mOrder = "mid, htmlID, cssClass, position, path, aria, tooltip, guestOnly, memberOnly, staffOnly, adminOnly" - /*var addMenuItem = func(data map[string]interface{}) { - var cols, values string - for col, value := range data { - cols += col + "," - switch value := value.(type) { - case string: - values += "'" + strings.Replace(value, "'", "\\'", -1) + "'," - case int: - values += strconv.Itoa(value) + "," - case LitStr: - values += string(value) + "," - case bool: - if value { - values += "1," - } else { - values += "0," - } - } - } - if cols != "" { - cols = cols[:len(cols)-1] - values = values[:len(values)-1] - } - qgen.Install.SimpleInsert("menu_items", cols+", order", values+","+strconv.Itoa(order)) - order++ - }*/ - - // Go maps have a random iteration order, so we have to do this, otherwise the schema files will become unstable and harder to audit var addMenuItem = func(data map[string]interface{}) { cols, values := qgen.InterfaceMapToInsertStrings(data, mOrder) qgen.Install.SimpleInsert("menu_items", cols+", order", values+","+strconv.Itoa(order)) diff --git a/schema/mssql/inserts.sql b/schema/mssql/inserts.sql index b47026db..067adcaf 100644 --- a/schema/mssql/inserts.sql +++ b/schema/mssql/inserts.sql @@ -28,7 +28,7 @@ INSERT INTO [forums_permissions] ([gid],[fid],[permissions]) VALUES (5,2,'{"View INSERT INTO [forums_permissions] ([gid],[fid],[permissions]) VALUES (6,2,'{"ViewTopic":true}'); INSERT INTO [topics] ([title],[content],[parsed_content],[createdAt],[lastReplyAt],[lastReplyBy],[createdBy],[parentID],[ipaddress]) VALUES ('Test Topic','A topic automatically generated by the software.','A topic automatically generated by the software.',GETUTCDATE(),GETUTCDATE(),1,1,2,'::1'); INSERT INTO [replies] ([tid],[content],[parsed_content],[createdAt],[createdBy],[lastUpdated],[lastEdit],[lastEditBy],[ipaddress]) VALUES (1,'A reply!','A reply!',GETUTCDATE(),1,GETUTCDATE(),0,0,'::1'); -INSERT INTO [menus]; +INSERT INTO [menus] () VALUES (); INSERT INTO [menu_items] ([mid],[htmlID],[position],[path],[aria],[tooltip],[order]) VALUES (1,'menu_forums','left','/forums/','{lang.menu_forums_aria}','{lang.menu_forums_tooltip}',0); INSERT INTO [menu_items] ([mid],[htmlID],[cssClass],[position],[path],[aria],[tooltip],[order]) VALUES (1,'menu_topics','menu_topics','left','/topics/','{lang.menu_topics_aria}','{lang.menu_topics_tooltip}',1); INSERT INTO [menu_items] ([mid],[htmlID],[cssClass],[position],[tmplName],[order]) VALUES (1,'general_alerts','menu_alerts','right','menu_alerts',2); diff --git a/schema/mysql/inserts.sql b/schema/mysql/inserts.sql index d4632c22..4fe3d06f 100644 --- a/schema/mysql/inserts.sql +++ b/schema/mysql/inserts.sql @@ -28,7 +28,7 @@ INSERT INTO `forums_permissions`(`gid`,`fid`,`permissions`) VALUES (5,2,'{"ViewT INSERT INTO `forums_permissions`(`gid`,`fid`,`permissions`) VALUES (6,2,'{"ViewTopic":true}'); INSERT INTO `topics`(`title`,`content`,`parsed_content`,`createdAt`,`lastReplyAt`,`lastReplyBy`,`createdBy`,`parentID`,`ipaddress`) VALUES ('Test Topic','A topic automatically generated by the software.','A topic automatically generated by the software.',UTC_TIMESTAMP(),UTC_TIMESTAMP(),1,1,2,'::1'); INSERT INTO `replies`(`tid`,`content`,`parsed_content`,`createdAt`,`createdBy`,`lastUpdated`,`lastEdit`,`lastEditBy`,`ipaddress`) VALUES (1,'A reply!','A reply!',UTC_TIMESTAMP(),1,UTC_TIMESTAMP(),0,0,'::1'); -INSERT INTO `menus`; +INSERT INTO `menus`() VALUES (); INSERT INTO `menu_items`(`mid`,`htmlID`,`position`,`path`,`aria`,`tooltip`,`order`) VALUES (1,'menu_forums','left','/forums/','{lang.menu_forums_aria}','{lang.menu_forums_tooltip}',0); INSERT INTO `menu_items`(`mid`,`htmlID`,`cssClass`,`position`,`path`,`aria`,`tooltip`,`order`) VALUES (1,'menu_topics','menu_topics','left','/topics/','{lang.menu_topics_aria}','{lang.menu_topics_tooltip}',1); INSERT INTO `menu_items`(`mid`,`htmlID`,`cssClass`,`position`,`tmplName`,`order`) VALUES (1,'general_alerts','menu_alerts','right','menu_alerts',2); diff --git a/update-deps-linux b/update-deps-linux index 7b4b1df2..bc61cbf7 100644 --- a/update-deps-linux +++ b/update-deps-linux @@ -28,8 +28,5 @@ go get -u github.com/bamiaux/rez echo "Updating fsnotify" go get -u github.com/fsnotify/fsnotify -echo "Updating Go Git" -go get -u gopkg.in/src-d/go-git.v4/... - echo "Updating GopherJS" -go get -u github.com/gopherjs/gopherjs \ No newline at end of file +go get -u github.com/gopherjs/gopherjs/... \ No newline at end of file diff --git a/update-deps.bat b/update-deps.bat index a69a0120..3dd47548 100644 --- a/update-deps.bat +++ b/update-deps.bat @@ -82,15 +82,8 @@ if %errorlevel% neq 0 ( exit /b %errorlevel% ) -echo Updating Go Git -go get -u gopkg.in/src-d/go-git.v4/... -if %errorlevel% neq 0 ( - pause - exit /b %errorlevel% -) - echo Updating GopherJS -go get -u github.com/gopherjs/gopherjs +go get -u github.com/gopherjs/gopherjs/... if %errorlevel% neq 0 ( pause exit /b %errorlevel%