1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 07:39:43 +02:00

clone reusable content blocks

This commit is contained in:
Harvey Kandola 2017-08-21 18:47:59 +01:00
parent bf390ed0b9
commit 5a2c44717e

View file

@ -128,8 +128,6 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
// Get back new space
sp, _ = h.Store.Space.Get(ctx, sp.RefID)
fmt.Println(model)
// clone existing space?
if model.CloneID != "" && (model.CopyDocument || model.CopyPermission || model.CopyTemplate) {
ctx.Transaction, err = h.Runtime.Db.Beginx()
@ -251,6 +249,24 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
}
}
if model.CopyTemplate {
blocks, err := h.Store.Block.GetBySpace(ctx, model.CloneID)
for _, b := range blocks {
b.RefID = uniqueid.Generate()
b.LabelID = sp.RefID
b.UserID = ctx.UserID
err = h.Store.Block.Add(ctx, b)
if err != nil {
ctx.Transaction.Rollback()
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
}
}
ctx.Transaction.Commit()
}