2018-01-22 08:15:45 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2018-12-27 05:42:41 +00:00
|
|
|
"errors"
|
2020-02-19 10:32:26 +00:00
|
|
|
|
|
|
|
//"fmt"
|
2020-01-23 06:17:50 +00:00
|
|
|
"os"
|
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
|
|
|
"strings"
|
2018-01-22 08:15:45 +00:00
|
|
|
|
2020-01-23 06:17:50 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2018-01-22 08:15:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var Attachments AttachmentStore
|
|
|
|
|
2018-12-27 05:42:41 +00:00
|
|
|
type MiniAttachment struct {
|
|
|
|
ID int
|
|
|
|
SectionID int
|
|
|
|
OriginID int
|
|
|
|
UploadedBy int
|
|
|
|
Path string
|
2019-04-13 11:54:22 +00:00
|
|
|
Extra string
|
2018-12-27 05:42:41 +00:00
|
|
|
|
|
|
|
Image bool
|
|
|
|
Ext string
|
|
|
|
}
|
|
|
|
|
2020-02-20 04:32:49 +00:00
|
|
|
type Attachment struct {
|
|
|
|
ID int
|
|
|
|
SectionTable string
|
|
|
|
SectionID int
|
|
|
|
OriginTable string
|
|
|
|
OriginID int
|
|
|
|
UploadedBy int
|
|
|
|
Path string
|
|
|
|
Extra string
|
|
|
|
|
|
|
|
Image bool
|
|
|
|
Ext string
|
|
|
|
}
|
|
|
|
|
2018-01-22 08:15:45 +00:00
|
|
|
type AttachmentStore interface {
|
2020-02-20 04:32:49 +00:00
|
|
|
FGet(id int) (*Attachment, error)
|
2018-12-27 05:42:41 +00:00
|
|
|
Get(id int) (*MiniAttachment, error)
|
2018-12-31 09:03:49 +00:00
|
|
|
MiniGetList(originTable string, originID int) (alist []*MiniAttachment, err error)
|
|
|
|
BulkMiniGetList(originTable string, ids []int) (amap map[int][]*MiniAttachment, err error)
|
2020-01-23 06:17:50 +00:00
|
|
|
Add(sectionID int, sectionTable string, originID int, originTable string, uploadedBy int, path, extra string) (int, 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
|
|
|
MoveTo(sectionID, originID int, originTable string) error
|
2020-01-23 06:17:50 +00:00
|
|
|
MoveToByExtra(sectionID int, originTable, extra string) error
|
2019-06-01 12:31:48 +00:00
|
|
|
Count() int
|
2018-12-27 09:12:30 +00:00
|
|
|
CountIn(originTable string, oid int) int
|
2018-12-27 05:42:41 +00:00
|
|
|
CountInPath(path string) int
|
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
|
|
|
Delete(id int) error
|
2020-02-19 10:32:26 +00:00
|
|
|
|
2020-02-20 04:32:49 +00:00
|
|
|
AddLinked(otable string, oid int) (err error)
|
|
|
|
RemoveLinked(otable string, oid int) (err error)
|
2018-01-22 08:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultAttachmentStore struct {
|
2020-02-20 04:32:49 +00:00
|
|
|
fget *sql.Stmt
|
2018-12-27 09:12:30 +00:00
|
|
|
get *sql.Stmt
|
2018-12-31 09:03:49 +00:00
|
|
|
getByObj *sql.Stmt
|
2018-12-27 09:12:30 +00:00
|
|
|
add *sql.Stmt
|
|
|
|
count *sql.Stmt
|
|
|
|
countIn *sql.Stmt
|
|
|
|
countInPath *sql.Stmt
|
2019-04-13 11:54:22 +00:00
|
|
|
move *sql.Stmt
|
|
|
|
moveByExtra *sql.Stmt
|
2018-12-27 09:12:30 +00:00
|
|
|
delete *sql.Stmt
|
2020-02-19 10:32:26 +00:00
|
|
|
|
|
|
|
replyUpdateAttachs *sql.Stmt
|
|
|
|
topicUpdateAttachs *sql.Stmt
|
2018-01-22 08:15:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-13 11:54:22 +00:00
|
|
|
func NewDefaultAttachmentStore(acc *qgen.Accumulator) (*DefaultAttachmentStore, error) {
|
2019-10-28 07:46:14 +00:00
|
|
|
a := "attachments"
|
2018-01-22 08:15:45 +00:00
|
|
|
return &DefaultAttachmentStore{
|
2020-02-20 04:32:49 +00:00
|
|
|
fget: acc.Select(a).Columns("originTable, originID, sectionTable, sectionID, uploadedBy, path, extra").Where("attachID=?").Prepare(),
|
2020-01-23 06:17:50 +00:00
|
|
|
get: acc.Select(a).Columns("originID, sectionID, uploadedBy, path, extra").Where("attachID=?").Prepare(),
|
2020-02-19 10:32:26 +00:00
|
|
|
getByObj: acc.Select(a).Columns("attachID, sectionID, uploadedBy, path, extra").Where("originTable=? AND originID=?").Prepare(),
|
2019-10-28 07:46:14 +00:00
|
|
|
add: acc.Insert(a).Columns("sectionID, sectionTable, originID, originTable, uploadedBy, path, extra").Fields("?,?,?,?,?,?,?").Prepare(),
|
|
|
|
count: acc.Count(a).Prepare(),
|
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
|
|
|
countIn: acc.Count(a).Where("originTable=? and originID=?").Prepare(),
|
2020-02-19 10:32:26 +00:00
|
|
|
countInPath: acc.Count(a).Where("path=?").Prepare(),
|
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
|
|
|
move: acc.Update(a).Set("sectionID=?").Where("originID=? AND originTable=?").Prepare(),
|
|
|
|
moveByExtra: acc.Update(a).Set("sectionID=?").Where("originTable=? AND extra=?").Prepare(),
|
2020-01-23 06:17:50 +00:00
|
|
|
delete: acc.Delete(a).Where("attachID=?").Prepare(),
|
2020-02-19 10:32:26 +00:00
|
|
|
|
|
|
|
// TODO: Less race-y attachment count updates
|
|
|
|
replyUpdateAttachs: acc.Update("replies").Set("attachCount=?").Where("rid=?").Prepare(),
|
|
|
|
topicUpdateAttachs: acc.Update("topics").Set("attachCount=?").Where("tid=?").Prepare(),
|
2018-01-22 08:15:45 +00:00
|
|
|
}, acc.FirstError()
|
|
|
|
}
|
|
|
|
|
2019-09-29 05:10:05 +00:00
|
|
|
func (s *DefaultAttachmentStore) MiniGetList(originTable string, originID int) (alist []*MiniAttachment, err error) {
|
|
|
|
rows, err := s.getByObj.Query(originTable, originID)
|
2018-12-27 05:42:41 +00:00
|
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
2019-09-29 05:10:05 +00:00
|
|
|
a := &MiniAttachment{OriginID: originID}
|
|
|
|
err := rows.Scan(&a.ID, &a.SectionID, &a.UploadedBy, &a.Path, &a.Extra)
|
2018-12-27 05:42:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
extarr := strings.Split(a.Path, ".")
|
2018-12-27 05:42:41 +00:00
|
|
|
if len(extarr) < 2 {
|
|
|
|
return nil, errors.New("corrupt attachment path")
|
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
a.Ext = extarr[len(extarr)-1]
|
|
|
|
a.Image = ImageFileExts.Contains(a.Ext)
|
|
|
|
alist = append(alist, a)
|
2018-12-27 05:42:41 +00:00
|
|
|
}
|
2020-02-19 10:32:26 +00:00
|
|
|
err = rows.Err()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(alist) == 0 {
|
|
|
|
err = sql.ErrNoRows
|
|
|
|
}
|
|
|
|
return alist, err
|
2018-12-27 05:42:41 +00:00
|
|
|
}
|
|
|
|
|
2019-09-29 05:10:05 +00:00
|
|
|
func (s *DefaultAttachmentStore) BulkMiniGetList(originTable string, ids []int) (amap map[int][]*MiniAttachment, err error) {
|
2018-12-31 09:03:49 +00:00
|
|
|
if len(ids) == 0 {
|
|
|
|
return nil, sql.ErrNoRows
|
|
|
|
}
|
|
|
|
if len(ids) == 1 {
|
2019-09-29 05:10:05 +00:00
|
|
|
res, err := s.MiniGetList(originTable, ids[0])
|
2019-04-10 07:40:47 +00:00
|
|
|
return map[int][]*MiniAttachment{ids[0]: res}, err
|
2018-12-31 09:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
amap = make(map[int][]*MiniAttachment)
|
|
|
|
var buffer []*MiniAttachment
|
|
|
|
var currentID int
|
2019-10-28 07:46:14 +00:00
|
|
|
rows, err := qgen.NewAcc().Select("attachments").Columns("attachID,sectionID,originID,uploadedBy,path").Where("originTable=?").In("originID", ids).Orderby("originID ASC").Query(originTable)
|
2018-12-31 09:03:49 +00:00
|
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
2019-09-29 05:10:05 +00:00
|
|
|
a := &MiniAttachment{}
|
|
|
|
err := rows.Scan(&a.ID, &a.SectionID, &a.OriginID, &a.UploadedBy, &a.Path)
|
2018-12-31 09:03:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
extarr := strings.Split(a.Path, ".")
|
2018-12-31 09:03:49 +00:00
|
|
|
if len(extarr) < 2 {
|
|
|
|
return nil, errors.New("corrupt attachment path")
|
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
a.Ext = extarr[len(extarr)-1]
|
|
|
|
a.Image = ImageFileExts.Contains(a.Ext)
|
2019-04-15 01:54:13 +00:00
|
|
|
if currentID == 0 {
|
2019-09-29 05:10:05 +00:00
|
|
|
currentID = a.OriginID
|
2019-04-15 01:54:13 +00:00
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
if a.OriginID != currentID {
|
2018-12-31 09:03:49 +00:00
|
|
|
if len(buffer) > 0 {
|
|
|
|
amap[currentID] = buffer
|
2019-09-29 05:10:05 +00:00
|
|
|
currentID = a.OriginID
|
2018-12-31 09:03:49 +00:00
|
|
|
buffer = nil
|
|
|
|
}
|
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
buffer = append(buffer, a)
|
2018-12-31 09:03:49 +00:00
|
|
|
}
|
2019-04-15 01:54:13 +00:00
|
|
|
if len(buffer) > 0 {
|
|
|
|
amap[currentID] = buffer
|
|
|
|
}
|
2018-12-31 09:03:49 +00:00
|
|
|
return amap, rows.Err()
|
|
|
|
}
|
|
|
|
|
2020-02-20 04:32:49 +00:00
|
|
|
func (s *DefaultAttachmentStore) FGet(id int) (*Attachment, error) {
|
|
|
|
a := &Attachment{ID: id}
|
|
|
|
err := s.fget.QueryRow(id).Scan(&a.OriginTable, &a.OriginID, &a.SectionTable, &a.SectionID, &a.UploadedBy, &a.Path, &a.Extra)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
extarr := strings.Split(a.Path, ".")
|
|
|
|
if len(extarr) < 2 {
|
|
|
|
return nil, errors.New("corrupt attachment path")
|
|
|
|
}
|
|
|
|
a.Ext = extarr[len(extarr)-1]
|
|
|
|
a.Image = ImageFileExts.Contains(a.Ext)
|
|
|
|
return a, nil
|
|
|
|
}
|
|
|
|
|
2019-09-29 05:10:05 +00:00
|
|
|
func (s *DefaultAttachmentStore) Get(id int) (*MiniAttachment, error) {
|
|
|
|
a := &MiniAttachment{ID: id}
|
|
|
|
err := s.get.QueryRow(id).Scan(&a.OriginID, &a.SectionID, &a.UploadedBy, &a.Path, &a.Extra)
|
2018-12-27 05:42:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
extarr := strings.Split(a.Path, ".")
|
2018-12-27 05:42:41 +00:00
|
|
|
if len(extarr) < 2 {
|
|
|
|
return nil, errors.New("corrupt attachment path")
|
|
|
|
}
|
2019-09-29 05:10:05 +00:00
|
|
|
a.Ext = extarr[len(extarr)-1]
|
|
|
|
a.Image = ImageFileExts.Contains(a.Ext)
|
|
|
|
return a, nil
|
2018-12-27 05:42:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 06:17:50 +00:00
|
|
|
func (s *DefaultAttachmentStore) Add(sectionID int, sectionTable string, originID int, originTable string, uploadedBy int, path, extra string) (int, error) {
|
2019-09-29 05:10:05 +00:00
|
|
|
res, err := s.add.Exec(sectionID, sectionTable, originID, originTable, uploadedBy, path, extra)
|
2018-12-27 05:42:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
lid, err := res.LastInsertId()
|
|
|
|
return int(lid), err
|
|
|
|
}
|
|
|
|
|
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 *DefaultAttachmentStore) MoveTo(sectionID, originID int, originTable string) error {
|
2019-06-01 12:31:48 +00:00
|
|
|
_, err := s.move.Exec(sectionID, originID, originTable)
|
2019-04-13 11:54:22 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-01-23 06:17:50 +00:00
|
|
|
func (s *DefaultAttachmentStore) MoveToByExtra(sectionID int, originTable, extra string) error {
|
2019-06-01 12:31:48 +00:00
|
|
|
_, err := s.moveByExtra.Exec(sectionID, originTable, extra)
|
2019-04-13 11:54:22 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func (s *DefaultAttachmentStore) Count() (count int) {
|
|
|
|
err := s.count.QueryRow().Scan(&count)
|
2018-12-27 05:42:41 +00:00
|
|
|
if err != nil {
|
|
|
|
LogError(err)
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2019-09-29 05:10:05 +00:00
|
|
|
func (s *DefaultAttachmentStore) CountIn(originTable string, oid int) (count int) {
|
|
|
|
err := s.countIn.QueryRow(originTable, oid).Scan(&count)
|
2018-12-27 05:42:41 +00:00
|
|
|
if err != nil {
|
|
|
|
LogError(err)
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2019-09-29 05:10:05 +00:00
|
|
|
func (s *DefaultAttachmentStore) CountInPath(path string) (count int) {
|
|
|
|
err := s.countInPath.QueryRow(path).Scan(&count)
|
2018-12-27 05:42:41 +00:00
|
|
|
if err != nil {
|
|
|
|
LogError(err)
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
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 *DefaultAttachmentStore) Delete(id int) error {
|
|
|
|
_, err := s.delete.Exec(id)
|
2018-01-22 08:15:45 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-01-23 06:17:50 +00:00
|
|
|
|
2020-02-19 10:32:26 +00:00
|
|
|
// TODO: Split this out of this store
|
2020-02-20 04:32:49 +00:00
|
|
|
func (s *DefaultAttachmentStore) AddLinked(otable string, oid int) (err error) {
|
2020-02-19 10:32:26 +00:00
|
|
|
switch otable {
|
|
|
|
case "topics":
|
|
|
|
_, err = s.topicUpdateAttachs.Exec(s.CountIn(otable, oid), oid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = Topics.Reload(oid)
|
|
|
|
case "replies":
|
|
|
|
_, err = s.replyUpdateAttachs.Exec(s.CountIn(otable, oid), oid)
|
2020-02-20 04:32:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = Rstore.GetCache().Remove(oid)
|
|
|
|
}
|
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Split this out of this store
|
|
|
|
func (s *DefaultAttachmentStore) RemoveLinked(otable string, oid int) (err error) {
|
|
|
|
switch otable {
|
|
|
|
case "topics":
|
|
|
|
_, err = s.topicUpdateAttachs.Exec(s.CountIn(otable, oid), oid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if tc := Topics.GetCache(); tc != nil {
|
|
|
|
tc.Remove(oid)
|
|
|
|
}
|
|
|
|
case "replies":
|
|
|
|
_, err = s.replyUpdateAttachs.Exec(s.CountIn(otable, oid), oid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = Rstore.GetCache().Remove(oid)
|
2020-02-19 10:32:26 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-23 06:17:50 +00:00
|
|
|
// TODO: Add a table for the files and lock the file row when performing tasks related to the file
|
|
|
|
func DeleteAttachment(aid int) error {
|
2020-02-20 04:32:49 +00:00
|
|
|
a, err := Attachments.FGet(aid)
|
2020-01-23 06:17:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-20 04:32:49 +00:00
|
|
|
err = deleteAttachment(a)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_ = Attachments.RemoveLinked(a.OriginTable, a.OriginID)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteAttachment(a *Attachment) error {
|
|
|
|
err := Attachments.Delete(a.ID)
|
2020-01-23 06:17:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-20 04:32:49 +00:00
|
|
|
count := Attachments.CountInPath(a.Path)
|
2020-01-23 06:17:50 +00:00
|
|
|
if count == 0 {
|
2020-02-20 04:32:49 +00:00
|
|
|
err := os.Remove("./attachs/" + a.Path)
|
2020-01-23 06:17:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2020-01-23 06:17:50 +00:00
|
|
|
return nil
|
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
|
|
|
}
|