1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-20 13:49:42 +02:00

Change document activity records after space move

This commit is contained in:
McMatts 2018-04-05 20:00:42 +01:00
parent 19a916a4b4
commit 5fb41e9fb1
3 changed files with 23 additions and 0 deletions

View file

@ -221,6 +221,13 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
if oldDoc.LabelID != d.LabelID { if oldDoc.LabelID != d.LabelID {
h.Store.Category.RemoveDocumentCategories(ctx, d.RefID) h.Store.Category.RemoveDocumentCategories(ctx, d.RefID)
err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.LabelID, d.LabelID)
if err != nil {
ctx.Transaction.Rollback()
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
} }
err = h.Store.Document.Update(ctx, d) err = h.Store.Document.Update(ctx, d)

View file

@ -238,6 +238,9 @@ func (s Scope) MoveDocumentSpace(ctx domain.RequestContext, id, move string) (er
_, err = ctx.Transaction.Exec("UPDATE document SET labelid=? WHERE orgid=? AND labelid=?", _, err = ctx.Transaction.Exec("UPDATE document SET labelid=? WHERE orgid=? AND labelid=?",
move, ctx.OrgID, id) move, ctx.OrgID, id)
if err == sql.ErrNoRows {
err = nil
}
if err != nil { if err != nil {
err = errors.Wrap(err, fmt.Sprintf("execute document space move %s", id)) err = errors.Wrap(err, fmt.Sprintf("execute document space move %s", id))
} }
@ -245,6 +248,18 @@ func (s Scope) MoveDocumentSpace(ctx domain.RequestContext, id, move string) (er
return return
} }
// MoveActivity changes the space for all document activity records.
func (s Scope) MoveActivity(ctx domain.RequestContext, documentID, oldSpaceID, newSpaceID string) (err error) {
_, err = ctx.Transaction.Exec("UPDATE useractivity SET labelid=? WHERE orgid=? AND labelid=? AND documentid=?",
newSpaceID, ctx.OrgID, oldSpaceID, documentID)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("execute document activity move %s", documentID))
}
return
}
// Delete removes the specified document. // Delete removes the specified document.
// Remove document pages, revisions, attachments, updates the search subsystem. // Remove document pages, revisions, attachments, updates the search subsystem.
func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64, err error) { func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64, err error) {

View file

@ -180,6 +180,7 @@ type DocumentStorer interface {
Delete(ctx RequestContext, documentID string) (rows int64, err error) Delete(ctx RequestContext, documentID string) (rows int64, err error)
DeleteBySpace(ctx RequestContext, spaceID string) (rows int64, err error) DeleteBySpace(ctx RequestContext, spaceID string) (rows int64, err error)
GetVersions(ctx RequestContext, groupID string) (v []doc.Version, err error) GetVersions(ctx RequestContext, groupID string) (v []doc.Version, err error)
MoveActivity(ctx RequestContext, documentID, oldSpaceID, newSpaceID string) (err error)
} }
// SettingStorer defines required methods for persisting global and user level settings // SettingStorer defines required methods for persisting global and user level settings