1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-31 02:59:44 +02:00

force space delete

This commit is contained in:
Harvey Kandola 2017-09-18 13:35:51 +01:00
parent 300b617583
commit cd543a1506
10 changed files with 119 additions and 16 deletions

View file

@ -315,8 +315,8 @@ func (s Scope) MoveDocumentSpace(ctx domain.RequestContext, id, move string) (er
return
}
// Delete delete the document pages in the database, updates the search subsystem, deletes the associated revisions and attachments,
// audits the deletion, then finally deletes the document itself.
// Delete removes the specified document.
// Remove document pages, revisions, attachments, updates the search subsystem.
func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64, err error) {
b := mysql.BaseQuery{}
rows, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE from page WHERE documentid=\"%s\" AND orgid=\"%s\"", documentID, ctx.OrgID))
@ -337,3 +337,26 @@ func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64,
return b.DeleteConstrained(ctx.Transaction, "document", ctx.OrgID, documentID)
}
// Delete removes all documents for given space.
// Remove document pages, revisions, attachments, updates the search subsystem.
func (s Scope) DeleteBySpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
b := mysql.BaseQuery{}
rows, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE from page WHERE labelid=\"%s\" AND orgid=\"%s\"", spaceID, ctx.OrgID))
if err != nil {
return
}
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE from revision WHERE labelid=\"%s\" AND orgid=\"%s\"", spaceID, ctx.OrgID))
if err != nil {
return
}
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE from attachment WHERE labelid=\"%s\" AND orgid=\"%s\"", spaceID, ctx.OrgID))
if err != nil {
return
}
return b.DeleteConstrained(ctx.Transaction, "document", ctx.OrgID, spaceID)
}

View file

@ -474,7 +474,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
response.WriteEmpty(w)
}
// Delete deletes empty space.
// Delete removes space.
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
method := "space.Delete"
ctx := domain.GetRequestContext(r)
@ -503,6 +503,14 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
return
}
_, err = h.Store.Document.DeleteBySpace(ctx, id)
if err != nil {
ctx.Transaction.Rollback()
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
_, err = h.Store.Space.Delete(ctx, id)
if err != nil {
ctx.Transaction.Rollback()

View file

@ -244,8 +244,7 @@ func (s Scope) GetPermissions(ctx domain.RequestContext, spaceID string) (r []sp
func (s Scope) DeletePermissions(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
b := mysql.BaseQuery{}
sql := fmt.Sprintf("DELETE FROM permission WHERE orgid='%s' AND location='space' AND refid='%s'",
ctx.OrgID, spaceID)
sql := fmt.Sprintf("DELETE FROM permission WHERE orgid='%s' AND location='space' AND refid='%s'", ctx.OrgID, spaceID)
return b.DeleteWhere(ctx.Transaction, sql)
}

View file

@ -141,6 +141,7 @@ type DocumentStorer interface {
ChangeDocumentSpace(ctx RequestContext, document, space string) (err error)
MoveDocumentSpace(ctx RequestContext, id, move string) (err error)
Delete(ctx RequestContext, documentID string) (rows int64, err error)
DeleteBySpace(ctx RequestContext, spaceID string) (rows int64, err error)
}
// SettingStorer defines required methods for persisting global and user level settings