gosora/common/menu_store.go
Azareal 6935637867 Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.

Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.

Add DropColumn, RenameColumn and ChangeColumn to the database adapters.

Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.

You need to run the updater / patcher for this commit.
2020-01-31 17:22:08 +10:00

76 lines
1.8 KiB
Go

package common
import (
"database/sql"
"strconv"
"sync/atomic"
qgen "github.com/Azareal/Gosora/query_gen"
)
var Menus *DefaultMenuStore
type DefaultMenuStore struct {
menus map[int]*atomic.Value
itemStore *DefaultMenuItemStore
}
func NewDefaultMenuStore() *DefaultMenuStore {
return &DefaultMenuStore{
make(map[int]*atomic.Value),
NewDefaultMenuItemStore(),
}
}
// TODO: Add actual support for multiple menus
func (s *DefaultMenuStore) GetAllMap() (out map[int]*MenuListHolder) {
out = make(map[int]*MenuListHolder)
for mid, atom := range s.menus {
out[mid] = atom.Load().(*MenuListHolder)
}
return out
}
func (s *DefaultMenuStore) Get(mid int) (*MenuListHolder, error) {
aStore, ok := s.menus[mid]
if ok {
return aStore.Load().(*MenuListHolder), nil
}
return nil, ErrNoRows
}
func (s *DefaultMenuStore) Items(mid int) (mlist MenuItemList, err error) {
err = qgen.NewAcc().Select("menu_items").Columns("miid,name,htmlID,cssClass,position,path,aria,tooltip,order,tmplName,guestOnly,memberOnly,staffOnly,adminOnly").Where("mid=" + strconv.Itoa(mid)).Orderby("order ASC").Each(func(rows *sql.Rows) error {
i := MenuItem{MenuID: mid}
err := rows.Scan(&i.ID, &i.Name, &i.HTMLID, &i.CSSClass, &i.Position, &i.Path, &i.Aria, &i.Tooltip, &i.Order, &i.TmplName, &i.GuestOnly, &i.MemberOnly, &i.SuperModOnly, &i.AdminOnly)
if err != nil {
return err
}
s.itemStore.Add(i)
mlist = append(mlist, i)
return nil
})
return mlist, err
}
func (s *DefaultMenuStore) Load(mid int) error {
mlist, err := s.Items(mid)
if err != nil {
return err
}
hold := &MenuListHolder{mid, mlist, make(map[int]menuTmpl)}
err = hold.Preparse()
if err != nil {
return err
}
aStore := &atomic.Value{}
aStore.Store(hold)
s.menus[mid] = aStore
return nil
}
func (s *DefaultMenuStore) ItemStore() *DefaultMenuItemStore {
return s.itemStore
}