2017-11-10 03:33:11 +00:00
|
|
|
package common
|
2017-11-06 07:44:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2017-11-11 04:06:16 +00:00
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2017-11-06 07:44:08 +00:00
|
|
|
)
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
var Prstore ProfileReplyStore
|
2017-11-06 07:44:08 +00:00
|
|
|
|
|
|
|
type ProfileReplyStore interface {
|
2018-01-20 06:50:29 +00:00
|
|
|
Get(id int) (*ProfileReply, error)
|
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
|
|
|
Exists(id int) bool
|
2020-01-02 21:52:41 +00:00
|
|
|
Create(profileID int, content string, createdBy int, ip string) (id int, err error)
|
2019-06-01 12:31:48 +00:00
|
|
|
Count() (count int)
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Refactor this to stop using the global stmt store
|
|
|
|
// TODO: Add more methods to this like Create()
|
|
|
|
type SQLProfileReplyStore struct {
|
2017-11-06 16:24:45 +00:00
|
|
|
get *sql.Stmt
|
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
|
|
|
exists *sql.Stmt
|
2017-11-06 16:24:45 +00:00
|
|
|
create *sql.Stmt
|
2019-06-01 12:31:48 +00:00
|
|
|
count *sql.Stmt
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 08:56:56 +00:00
|
|
|
func NewSQLProfileReplyStore(acc *qgen.Accumulator) (*SQLProfileReplyStore, error) {
|
2019-11-12 06:56:51 +00:00
|
|
|
ur := "users_replies"
|
2017-11-06 07:44:08 +00:00
|
|
|
return &SQLProfileReplyStore{
|
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
|
|
|
get: acc.Select(ur).Columns("uid, content, createdBy, createdAt, lastEdit, lastEditBy, ip").Where("rid=?").Prepare(),
|
|
|
|
exists: acc.Exists(ur, "rid").Prepare(),
|
|
|
|
create: acc.Insert(ur).Columns("uid, content, parsed_content, createdAt, createdBy, ip").Fields("?,?,?,UTC_TIMESTAMP(),?,?").Prepare(),
|
2019-11-12 06:56:51 +00:00
|
|
|
count: acc.Count(ur).Prepare(),
|
2017-11-06 16:24:45 +00:00
|
|
|
}, acc.FirstError()
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func (s *SQLProfileReplyStore) Get(id int) (*ProfileReply, error) {
|
|
|
|
r := ProfileReply{ID: id}
|
2019-08-31 22:34:43 +00:00
|
|
|
err := s.get.QueryRow(id).Scan(&r.ParentID, &r.Content, &r.CreatedBy, &r.CreatedAt, &r.LastEdit, &r.LastEditBy, &r.IP)
|
2019-06-01 12:31:48 +00:00
|
|
|
return &r, err
|
2017-11-06 07:44:08 +00:00
|
|
|
}
|
2017-11-06 16:24:45 +00:00
|
|
|
|
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 *SQLProfileReplyStore) Exists(id int) bool {
|
|
|
|
err := s.exists.QueryRow(id).Scan(&id)
|
|
|
|
if err != nil && err != ErrNoRows {
|
|
|
|
LogError(err)
|
|
|
|
}
|
|
|
|
return err != ErrNoRows
|
|
|
|
}
|
|
|
|
|
2020-01-02 21:52:41 +00:00
|
|
|
func (s *SQLProfileReplyStore) Create(profileID int, content string, createdBy int, ip string) (id int, err error) {
|
|
|
|
if Config.DisablePostIP {
|
|
|
|
ip = "0"
|
|
|
|
}
|
|
|
|
res, err := s.create.Exec(profileID, content, ParseMessage(content, 0, "", nil), createdBy, ip)
|
2017-11-06 16:24:45 +00:00
|
|
|
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
|
|
|
|
}
|
2019-06-01 12:31:48 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|