1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 22:29:41 +02:00

Fix issue with backup/restore of space labels

Closed #206
This commit is contained in:
sauls8t 2019-02-21 10:56:15 +00:00
parent ac84eaf85d
commit 9aaea9492a
6 changed files with 825 additions and 727 deletions

View file

@ -54,9 +54,9 @@ Integrations for embedding SaaS data within documents, zero add-on/marketplace f
## Latest Release
[Community Edition: v2.0.4](https://github.com/documize/community/releases)
[Community Edition: v2.0.5](https://github.com/documize/community/releases)
[Enterprise Edition: v2.0.4](https://documize.com/downloads)
[Enterprise Edition: v2.0.5](https://documize.com/downloads)
## OS support

View file

@ -45,6 +45,7 @@ import (
"github.com/documize/community/model/category"
"github.com/documize/community/model/doc"
"github.com/documize/community/model/group"
"github.com/documize/community/model/label"
"github.com/documize/community/model/link"
"github.com/documize/community/model/page"
"github.com/documize/community/model/permission"
@ -170,6 +171,12 @@ func (b backerHandler) produce(id string) (files []backupItem, err error) {
return
}
// Space Label
err = b.dmzSpaceLabel(&files)
if err != nil {
return
}
// Space, Permission.
err = b.dmzSpace(&files)
if err != nil {
@ -452,6 +459,32 @@ func (b backerHandler) dmzPin(files *[]backupItem) (err error) {
return
}
// Space Label
func (b backerHandler) dmzSpaceLabel(files *[]backupItem) (err error) {
w := ""
if !b.Spec.SystemBackup() {
w = fmt.Sprintf(" WHERE c_orgid='%s' ", b.Spec.OrgID)
}
l := []label.Label{}
err = b.Runtime.Db.Select(&l, `
SELECT id, c_refid AS refid,
c_orgid AS orgid, c_name AS name, c_color AS color,
c_created AS created, c_revised AS revised
FROM dmz_space_label`+w)
if err != nil {
return errors.Wrap(err, "select.space_label")
}
content, err := toJSON(l)
if err != nil {
return errors.Wrap(err, "json.space_label")
}
*files = append(*files, backupItem{Filename: "dmz_space_label.json", Content: content})
return
}
// Space, Permission.
func (b backerHandler) dmzSpace(files *[]backupItem) (err error) {
w := ""

View file

@ -38,6 +38,7 @@ import (
"github.com/documize/community/model/category"
"github.com/documize/community/model/doc"
"github.com/documize/community/model/group"
"github.com/documize/community/model/label"
"github.com/documize/community/model/link"
"github.com/documize/community/model/page"
"github.com/documize/community/model/permission"
@ -154,6 +155,12 @@ func (r *restoreHandler) PerformRestore(b []byte, l int64) (err error) {
return
}
// Space Label.
err = r.dmzSpaceLabel()
if err != nil {
return
}
// Space.
err = r.dmzSpace()
if err != nil {
@ -582,6 +589,64 @@ func (r *restoreHandler) dmzAction() (err error) {
return nil
}
// Space Label.
func (r *restoreHandler) dmzSpaceLabel() (err error) {
filename := "dmz_space_label.json"
label := []label.Label{}
err = r.fileJSON(filename, &label)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("failed to load %s", filename))
return
}
r.Runtime.Log.Info(fmt.Sprintf("Extracted %s", filename))
r.Context.Transaction, err = r.Runtime.Db.Beginx()
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("unable to start TX for %s", filename))
return
}
// Nuke all existing data.
nuke := "TRUNCATE TABLE dmz_space_label"
if !r.Spec.GlobalBackup {
nuke = fmt.Sprintf("DELETE FROM dmz_space_label WHERE c_orgid='%s'", r.Spec.Org.RefID)
}
_, err = r.Context.Transaction.Exec(nuke)
if err != nil {
r.Context.Transaction.Rollback()
err = errors.Wrap(err, fmt.Sprintf("unable to truncate table %s", filename))
return
}
for i := range label {
_, err = r.Context.Transaction.Exec(r.Runtime.Db.Rebind(`
INSERT INTO dmz_space_label
(c_refid, c_orgid, c_name, c_color, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?)`),
label[i].RefID, r.remapOrg(label[i].OrgID), label[i].Name, label[i].Color,
label[i].Created, label[i].Revised)
if err != nil {
r.Context.Transaction.Rollback()
err = errors.Wrap(err, fmt.Sprintf("unable to insert %s %s", filename, label[i].RefID))
return
}
}
err = r.Context.Transaction.Commit()
if err != nil {
r.Context.Transaction.Rollback()
err = errors.Wrap(err, fmt.Sprintf("unable to commit %s", filename))
return
}
r.Runtime.Log.Info(fmt.Sprintf("Processed %s %d records", filename, len(label)))
return nil
}
// Space.
func (r *restoreHandler) dmzSpace() (err error) {
filename := "dmz_space.json"

View file

@ -41,8 +41,8 @@ func main() {
rt.Product = domain.Product{}
rt.Product.Major = "2"
rt.Product.Minor = "0"
rt.Product.Patch = "4"
rt.Product.Revision = "190211190723"
rt.Product.Patch = "5"
rt.Product.Revision = "190221103505"
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
rt.Product.Edition = domain.CommunityEdition
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "documize",
"version": "2.0.4",
"version": "2.0.5",
"description": "The Document IDE",
"repository": "",
"license": "AGPL",