Make sure a bucket exists or use the default bucket when importing tasks

This commit is contained in:
kolaente 2021-07-08 10:34:03 +02:00
parent 50b49ffab6
commit 5b825f1cc8
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 13 additions and 8 deletions

View File

@ -114,18 +114,22 @@ func insertFromStructure(s *xorm.Session, str []*models.NamespaceWithLists, user
log.Debugf("[creating structure] Creating %d tasks", len(tasks))
// Create all tasks
for _, t := range tasks {
bucket, exists := buckets[t.BucketID]
setBucketOrDefault := func(task *models.Task) {
bucket, exists := buckets[task.BucketID]
if exists {
t.BucketID = bucket.ID
} else if t.BucketID > 0 {
log.Debugf("[creating structure] No bucket created for original bucket id %d", t.BucketID)
t.BucketID = 0
task.BucketID = bucket.ID
} else if task.BucketID > 0 {
log.Debugf("[creating structure] No bucket created for original bucket id %d", task.BucketID)
task.BucketID = 0
}
if !exists || t.BucketID == 0 {
if !exists || task.BucketID == 0 {
needsDefaultBucket = true
}
}
// Create all tasks
for _, t := range tasks {
setBucketOrDefault(t)
t.ListID = l.ID
err = t.Create(s, user)
@ -148,6 +152,7 @@ func insertFromStructure(s *xorm.Session, str []*models.NamespaceWithLists, user
for _, rt := range tasks {
// First create the related tasks if they do not exist
if rt.ID == 0 {
setBucketOrDefault(rt)
rt.ListID = t.ListID
err = rt.Create(s, user)
if err != nil {