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
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

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