This commit is contained in:
parent
09c4f13f2c
commit
2d962d18d2
16 changed files with 520 additions and 89 deletions
53
server/sqlstore/file.go
Normal file
53
server/sqlstore/file.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
)
|
||||
|
||||
const (
|
||||
fileInfoTable = "FileInfo"
|
||||
)
|
||||
|
||||
func (s *SQLStore) DetatchAttachmentFromChannel(fileID string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
update := map[string]interface{}{
|
||||
"ChannelId": "",
|
||||
"PostId": "",
|
||||
"DeleteAt": model.GetMillis(),
|
||||
}
|
||||
|
||||
query := s.masterBuilder.
|
||||
Update(fileInfoTable).
|
||||
SetMap(update).
|
||||
Where(sq.Eq{"Id": fileID})
|
||||
|
||||
tx, err := s.master.Begin()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error starting transaction: %w", err)
|
||||
}
|
||||
|
||||
q, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating query: %w", err)
|
||||
}
|
||||
|
||||
_, err = tx.ExecContext(ctx, q, args...)
|
||||
if err != nil {
|
||||
s.logger.Error("error detaching attachment from channel", "fileId", fileID, "err", err)
|
||||
return tx.Rollback()
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("error committing transaction: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in a new issue