2018-01-20 06:50:29 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"html"
|
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
|
|
|
"strconv"
|
2018-01-20 06:50:29 +00:00
|
|
|
"time"
|
|
|
|
|
2019-12-08 03:40:56 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2018-01-20 06:50:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var profileReplyStmts ProfileReplyStmts
|
|
|
|
|
|
|
|
type ProfileReply struct {
|
2018-12-27 05:42:41 +00:00
|
|
|
ID int
|
|
|
|
ParentID int
|
|
|
|
Content string
|
|
|
|
CreatedBy int
|
|
|
|
Group int
|
|
|
|
CreatedAt time.Time
|
|
|
|
LastEdit int
|
|
|
|
LastEditBy int
|
|
|
|
ContentLines int
|
2019-12-08 03:40:56 +00:00
|
|
|
IP string
|
2018-01-20 06:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProfileReplyStmts struct {
|
|
|
|
edit *sql.Stmt
|
|
|
|
delete *sql.Stmt
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
DbInits.Add(func(acc *qgen.Accumulator) error {
|
2019-12-08 03:40:56 +00:00
|
|
|
ur := "users_replies"
|
2018-01-20 06:50:29 +00:00
|
|
|
profileReplyStmts = ProfileReplyStmts{
|
2020-01-14 05:07:00 +00:00
|
|
|
edit: acc.Update(ur).Set("content=?,parsed_content=?").Where("rid=?").Prepare(),
|
|
|
|
delete: acc.Delete(ur).Where("rid=?").Prepare(),
|
2018-01-20 06:50:29 +00:00
|
|
|
}
|
|
|
|
return acc.FirstError()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-28 06:27:12 +00:00
|
|
|
// Mostly for tests, so we don't wind up with out-of-date profile reply initialisation logic there
|
|
|
|
func BlankProfileReply(id int) *ProfileReply {
|
|
|
|
return &ProfileReply{ID: id}
|
|
|
|
}
|
|
|
|
|
2018-01-20 06:50:29 +00:00
|
|
|
// TODO: Write tests for this
|
2019-08-31 22:34:43 +00:00
|
|
|
func (r *ProfileReply) Delete() error {
|
|
|
|
_, err := profileReplyStmts.delete.Exec(r.ID)
|
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
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// TODO: Better coupling between the two paramsextra queries
|
|
|
|
aids, err := Activity.AidsByParamsExtra("reply", r.ParentID, "user", strconv.Itoa(r.ID))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, aid := range aids {
|
|
|
|
DismissAlert(r.ParentID, aid)
|
|
|
|
}
|
|
|
|
err = Activity.DeleteByParamsExtra("reply", r.ParentID, "user", strconv.Itoa(r.ID))
|
2018-01-20 06:50:29 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-31 22:34:43 +00:00
|
|
|
func (r *ProfileReply) SetBody(content string) error {
|
2018-01-20 06:50:29 +00:00
|
|
|
content = PreparseMessage(html.UnescapeString(content))
|
2019-12-08 03:40:56 +00:00
|
|
|
_, err := profileReplyStmts.edit.Exec(content, ParseMessage(content, 0, "", nil), r.ID)
|
2018-01-20 06:50:29 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: We can get this from the topic store instead of a query which will always miss the cache...
|
2019-08-31 22:34:43 +00:00
|
|
|
func (r *ProfileReply) Creator() (*User, error) {
|
|
|
|
return Users.Get(r.CreatedBy)
|
2018-01-20 06:50:29 +00:00
|
|
|
}
|