05c2ac3ce4
Add the ActivityStream interface to abstract Get, Add and Count. Rename the GlobalCount methods to Count for simplicity. Simplify the variable names in the Count methods. Rename the GlobalCount method to Count and rename the original Count method to CountUser in LoginLogStore. Add a float64 case for bunit, sort of. Theme.RunTmpl now returns ErrBadDefaultTemplate instead of panicking when an interpreted template doesn't exist. Widget.Allowed now checks the zoneid. Fire the alert off in the background in AddActivityAndNotifyTarget instead of blocking the request. Use ErrBadDefaultTemplate instead of calling DefaultTemplates.Lookup directly for custom pages. Split the page struct for the debug page into multiple structs to make things more organised. Add the Count method to ProfileReplyStore. Add the Count method to ReplyStore. Add the DirSize utility function. Add a few ActivityStream tests. Secret gallery stuff.
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package common
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
)
|
|
|
|
var Prstore ProfileReplyStore
|
|
|
|
type ProfileReplyStore interface {
|
|
Get(id int) (*ProfileReply, error)
|
|
Create(profileID int, content string, createdBy int, ipaddress string) (id int, err error)
|
|
Count() (count int)
|
|
}
|
|
|
|
// TODO: Refactor this to stop using the global stmt store
|
|
// TODO: Add more methods to this like Create()
|
|
type SQLProfileReplyStore struct {
|
|
get *sql.Stmt
|
|
create *sql.Stmt
|
|
count *sql.Stmt
|
|
}
|
|
|
|
func NewSQLProfileReplyStore(acc *qgen.Accumulator) (*SQLProfileReplyStore, error) {
|
|
return &SQLProfileReplyStore{
|
|
get: acc.Select("users_replies").Columns("uid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress").Where("rid = ?").Prepare(),
|
|
create: acc.Insert("users_replies").Columns("uid, content, parsed_content, createdAt, createdBy, ipaddress").Fields("?,?,?,UTC_TIMESTAMP(),?,?").Prepare(),
|
|
count: acc.Count("users_replies").Prepare(),
|
|
}, acc.FirstError()
|
|
}
|
|
|
|
func (s *SQLProfileReplyStore) Get(id int) (*ProfileReply, error) {
|
|
r := ProfileReply{ID: id}
|
|
err := s.get.QueryRow(id).Scan(&r.ParentID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy, &r.IPAddress)
|
|
return &r, err
|
|
}
|
|
|
|
func (s *SQLProfileReplyStore) Create(profileID int, content string, createdBy int, ipaddress string) (id int, err error) {
|
|
res, err := s.create.Exec(profileID, content, ParseMessage(content, 0, ""), createdBy, ipaddress)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
lastID, err := res.LastInsertId()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
// Should we reload the user?
|
|
return int(lastID), err
|
|
}
|
|
|
|
// TODO: Write a test for this
|
|
// Count returns the total number of topic replies on these forums
|
|
func (s *SQLProfileReplyStore) Count() (count int) {
|
|
err := s.count.QueryRow().Scan(&count)
|
|
if err != nil {
|
|
LogError(err)
|
|
}
|
|
return count
|
|
}
|