Skip to content

Commit

Permalink
Fix issue with backup/restore of space labels
Browse files Browse the repository at this point in the history
Closed #206
  • Loading branch information
sauls8t committed Feb 21, 2019
1 parent ac84eaf commit 9aaea94
Show file tree
Hide file tree
Showing 6 changed files with 818 additions and 720 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions domain/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 := ""
Expand Down
65 changes: 65 additions & 0 deletions domain/backup/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions edition/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 9aaea94

Please sign in to comment.