2017-11-11 23:34:27 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2018-12-14 04:08:53 +00:00
|
|
|
"time"
|
2017-11-11 23:34:27 +00:00
|
|
|
|
2019-11-10 02:37:53 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2017-11-11 23:34:27 +00:00
|
|
|
)
|
|
|
|
|
2017-11-23 05:37:08 +00:00
|
|
|
var ModLogs LogStore
|
|
|
|
var AdminLogs LogStore
|
|
|
|
|
2018-05-16 10:46:14 +00:00
|
|
|
type LogItem struct {
|
|
|
|
Action string
|
|
|
|
ElementID int
|
|
|
|
ElementType string
|
2019-11-10 02:37:53 +00:00
|
|
|
IP string
|
2018-05-16 10:46:14 +00:00
|
|
|
ActorID int
|
|
|
|
DoneAt string
|
2019-11-10 02:37:53 +00:00
|
|
|
Extra string
|
2018-05-16 10:46:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 05:37:08 +00:00
|
|
|
type LogStore interface {
|
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 07:22:08 +00:00
|
|
|
Create(action string, elementID int, elementType, ip string, actorID int) (err error)
|
|
|
|
CreateExtra(action string, elementID int, elementType, ip string, actorID int, extra string) (err error)
|
2019-06-01 12:31:48 +00:00
|
|
|
Count() int
|
2019-11-10 02:37:53 +00:00
|
|
|
GetOffset(offset, perPage int) (logs []LogItem, err error)
|
2017-11-11 23:34:27 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 05:37:08 +00:00
|
|
|
type SQLModLogStore struct {
|
2018-05-16 10:46:14 +00:00
|
|
|
create *sql.Stmt
|
|
|
|
count *sql.Stmt
|
|
|
|
getOffset *sql.Stmt
|
2017-11-23 05:37:08 +00:00
|
|
|
}
|
2017-11-11 23:34:27 +00:00
|
|
|
|
2018-05-16 10:46:14 +00:00
|
|
|
func NewModLogStore(acc *qgen.Accumulator) (*SQLModLogStore, error) {
|
2019-10-28 07:46:14 +00:00
|
|
|
ml := "moderation_logs"
|
2017-11-23 05:37:08 +00:00
|
|
|
return &SQLModLogStore{
|
2019-11-10 02:37:53 +00:00
|
|
|
create: acc.Insert(ml).Columns("action, elementID, elementType, ipaddress, actorID, doneAt, extra").Fields("?,?,?,?,?,UTC_TIMESTAMP(),?").Prepare(),
|
2019-10-28 07:46:14 +00:00
|
|
|
count: acc.Count(ml).Prepare(),
|
2019-11-10 02:37:53 +00:00
|
|
|
getOffset: acc.Select(ml).Columns("action, elementID, elementType, ipaddress, actorID, doneAt, extra").Orderby("doneAt DESC").Limit("?,?").Prepare(),
|
2017-11-23 05:37:08 +00:00
|
|
|
}, acc.FirstError()
|
2017-11-11 23:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Make a store for this?
|
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 07:22:08 +00:00
|
|
|
func (s *SQLModLogStore) Create(action string, elementID int, elementType, ip string, actorID int) (err error) {
|
2019-11-10 02:37:53 +00:00
|
|
|
return s.CreateExtra(action, elementID, elementType, ip, actorID, "")
|
|
|
|
}
|
|
|
|
|
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 07:22:08 +00:00
|
|
|
func (s *SQLModLogStore) CreateExtra(action string, elementID int, elementType, ip string, actorID int, extra string) (err error) {
|
2019-11-10 02:37:53 +00:00
|
|
|
_, err = s.create.Exec(action, elementID, elementType, ip, actorID, extra)
|
2017-11-11 23:34:27 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func (s *SQLModLogStore) Count() (count int) {
|
|
|
|
err := s.count.QueryRow().Scan(&count)
|
2017-11-23 05:37:08 +00:00
|
|
|
if err != nil {
|
|
|
|
LogError(err)
|
|
|
|
}
|
2019-06-01 12:31:48 +00:00
|
|
|
return count
|
2017-11-23 05:37:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 10:46:14 +00:00
|
|
|
func buildLogList(rows *sql.Rows) (logs []LogItem, err error) {
|
|
|
|
for rows.Next() {
|
2019-08-31 22:34:43 +00:00
|
|
|
var l LogItem
|
2018-12-14 04:08:53 +00:00
|
|
|
var doneAt time.Time
|
2019-11-10 02:37:53 +00:00
|
|
|
err := rows.Scan(&l.Action, &l.ElementID, &l.ElementType, &l.IP, &l.ActorID, &doneAt, &l.Extra)
|
2018-05-16 10:46:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return logs, err
|
|
|
|
}
|
2019-08-31 22:34:43 +00:00
|
|
|
l.DoneAt = doneAt.Format("2006-01-02 15:04:05")
|
|
|
|
logs = append(logs, l)
|
2018-05-16 10:46:14 +00:00
|
|
|
}
|
|
|
|
return logs, rows.Err()
|
|
|
|
}
|
|
|
|
|
2019-11-10 02:37:53 +00:00
|
|
|
func (s *SQLModLogStore) GetOffset(offset, perPage int) (logs []LogItem, err error) {
|
2019-08-31 22:34:43 +00:00
|
|
|
rows, err := s.getOffset.Query(offset, perPage)
|
2018-05-16 10:46:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return logs, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
return buildLogList(rows)
|
|
|
|
}
|
|
|
|
|
2017-11-23 05:37:08 +00:00
|
|
|
type SQLAdminLogStore struct {
|
2018-05-16 10:46:14 +00:00
|
|
|
create *sql.Stmt
|
|
|
|
count *sql.Stmt
|
|
|
|
getOffset *sql.Stmt
|
2017-11-23 05:37:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 10:46:14 +00:00
|
|
|
func NewAdminLogStore(acc *qgen.Accumulator) (*SQLAdminLogStore, error) {
|
2019-10-28 07:46:14 +00:00
|
|
|
al := "administration_logs"
|
2017-11-23 05:37:08 +00:00
|
|
|
return &SQLAdminLogStore{
|
2019-11-10 02:37:53 +00:00
|
|
|
create: acc.Insert(al).Columns("action, elementID, elementType, ipaddress, actorID, doneAt, extra").Fields("?,?,?,?,?,UTC_TIMESTAMP(),?").Prepare(),
|
2019-10-28 07:46:14 +00:00
|
|
|
count: acc.Count(al).Prepare(),
|
2019-11-10 02:37:53 +00:00
|
|
|
getOffset: acc.Select(al).Columns("action, elementID, elementType, ipaddress, actorID, doneAt, extra").Orderby("doneAt DESC").Limit("?,?").Prepare(),
|
2017-11-23 05:37:08 +00:00
|
|
|
}, acc.FirstError()
|
|
|
|
}
|
|
|
|
|
2017-11-11 23:34:27 +00:00
|
|
|
// TODO: Make a store for this?
|
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 07:22:08 +00:00
|
|
|
func (s *SQLAdminLogStore) Create(action string, elementID int, elementType, ip string, actorID int) (err error) {
|
2019-11-10 02:37:53 +00:00
|
|
|
return s.CreateExtra(action, elementID, elementType, ip, actorID, "")
|
|
|
|
}
|
|
|
|
|
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 07:22:08 +00:00
|
|
|
func (s *SQLAdminLogStore) CreateExtra(action string, elementID int, elementType, ip string, actorID int, extra string) (err error) {
|
2019-11-10 02:37:53 +00:00
|
|
|
_, err = s.create.Exec(action, elementID, elementType, ip, actorID, extra)
|
2017-11-11 23:34:27 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-11-23 05:37:08 +00:00
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func (s *SQLAdminLogStore) Count() (count int) {
|
|
|
|
err := s.count.QueryRow().Scan(&count)
|
2017-11-23 05:37:08 +00:00
|
|
|
if err != nil {
|
|
|
|
LogError(err)
|
|
|
|
}
|
2019-06-01 12:31:48 +00:00
|
|
|
return count
|
2017-11-23 05:37:08 +00:00
|
|
|
}
|
2018-05-16 10:46:14 +00:00
|
|
|
|
2019-11-10 02:37:53 +00:00
|
|
|
func (s *SQLAdminLogStore) GetOffset(offset, perPage int) (logs []LogItem, err error) {
|
2019-06-01 12:31:48 +00:00
|
|
|
rows, err := s.getOffset.Query(offset, perPage)
|
2018-05-16 10:46:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return logs, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
return buildLogList(rows)
|
|
|
|
}
|