fix: importing archived lists or namespaces
This commit is contained in:
parent
190a9f2a4c
commit
8bb3f8d37c
1 changed files with 49 additions and 1 deletions
|
@ -51,13 +51,29 @@ func insertFromStructure(s *xorm.Session, str []*models.NamespaceWithListsAndTas
|
|||
|
||||
labels := make(map[string]*models.Label)
|
||||
|
||||
archivedLists := []int64{}
|
||||
archivedNamespaces := []int64{}
|
||||
|
||||
// Create all namespaces
|
||||
for _, n := range str {
|
||||
n.ID = 0
|
||||
|
||||
// Saving the archived status to archive the namespace again after creating it
|
||||
var wasArchived bool
|
||||
if n.IsArchived {
|
||||
n.IsArchived = false
|
||||
wasArchived = true
|
||||
}
|
||||
|
||||
err = n.Create(s, user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if wasArchived {
|
||||
archivedNamespaces = append(archivedNamespaces, n.ID)
|
||||
}
|
||||
|
||||
log.Debugf("[creating structure] Created namespace %d", n.ID)
|
||||
log.Debugf("[creating structure] Creating %d lists", len(n.Lists))
|
||||
|
||||
|
@ -70,12 +86,24 @@ func insertFromStructure(s *xorm.Session, str []*models.NamespaceWithListsAndTas
|
|||
originalBackgroundInformation := l.BackgroundInformation
|
||||
needsDefaultBucket := false
|
||||
|
||||
// Saving the archived status to archive the list again after creating it
|
||||
var wasArchived bool
|
||||
if l.IsArchived {
|
||||
wasArchived = true
|
||||
l.IsArchived = false
|
||||
}
|
||||
|
||||
l.NamespaceID = n.ID
|
||||
l.ID = 0
|
||||
err = l.Create(s, user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if wasArchived {
|
||||
archivedLists = append(archivedLists, l.ID)
|
||||
}
|
||||
|
||||
log.Debugf("[creating structure] Created list %d", l.ID)
|
||||
|
||||
backgroundFile, is := originalBackgroundInformation.(*bytes.Buffer)
|
||||
|
@ -216,7 +244,7 @@ func insertFromStructure(s *xorm.Session, str []*models.NamespaceWithListsAndTas
|
|||
TaskID: t.ID,
|
||||
}
|
||||
err = lt.Create(s, user)
|
||||
if err != nil {
|
||||
if err != nil && !models.IsErrLabelIsAlreadyOnTask(err) {
|
||||
return err
|
||||
}
|
||||
log.Debugf("[creating structure] Associated task %d with label %d", t.ID, lb.ID)
|
||||
|
@ -251,6 +279,26 @@ func insertFromStructure(s *xorm.Session, str []*models.NamespaceWithListsAndTas
|
|||
}
|
||||
}
|
||||
|
||||
if len(archivedLists) > 0 {
|
||||
_, err = s.
|
||||
Cols("is_archived").
|
||||
In("id", archivedLists).
|
||||
Update(&models.List{IsArchived: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(archivedNamespaces) > 0 {
|
||||
_, err = s.
|
||||
Cols("is_archived").
|
||||
In("id", archivedNamespaces).
|
||||
Update(&models.Namespace{IsArchived: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("[creating structure] Done inserting new task structure")
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue