Add trello migration (#734)
Fix tests for background images Generate docs Fix lint Do the swag Add more logging Remove the default bucket if it was empty Add launch.json Make importing backgrounds work Add comment Fix getting task attachments Fix getting trello token Add trello migration routes and status Add support for converting checklists Add test for attachments Add the actual conversion Add Trello conversion test Add migration function stubs Add basic trello migration structure Add trello migration config Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/734 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
@ -20,6 +20,7 @@ import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
|
||||
"code.vikunja.io/api/pkg/files"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
@ -49,6 +50,8 @@ func InsertFromStructure(str []*models.NamespaceWithLists, user *user.User) (err
|
||||
// to be able to still loop over them aftere the list was created.
|
||||
tasks := l.Tasks
|
||||
originalBuckets := l.Buckets
|
||||
originalBackgroundInformation := l.BackgroundInformation
|
||||
needsDefaultBucket := false
|
||||
|
||||
l.NamespaceID = n.ID
|
||||
err = l.Create(user)
|
||||
@ -58,6 +61,23 @@ func InsertFromStructure(str []*models.NamespaceWithLists, user *user.User) (err
|
||||
|
||||
log.Debugf("[creating structure] Created list %d", l.ID)
|
||||
|
||||
backgroundFile, is := originalBackgroundInformation.(*bytes.Buffer)
|
||||
if is {
|
||||
log.Debugf("[creating structure] Creating a background file for list %d", l.ID)
|
||||
|
||||
file, err := files.Create(backgroundFile, "", uint64(backgroundFile.Len()), user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = models.SetListBackground(l.ID, file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("[creating structure] Created a background file as new file %d for list %d", file.ID, l.ID)
|
||||
}
|
||||
|
||||
// Create all buckets
|
||||
buckets := make(map[int64]*models.Bucket) // old bucket id is the key
|
||||
if len(l.Buckets) > 0 {
|
||||
@ -86,6 +106,9 @@ func InsertFromStructure(str []*models.NamespaceWithLists, user *user.User) (err
|
||||
log.Debugf("[creating structure] No bucket created for original bucket id %d", t.BucketID)
|
||||
t.BucketID = 0
|
||||
}
|
||||
if !exists || t.BucketID == 0 {
|
||||
needsDefaultBucket = true
|
||||
}
|
||||
|
||||
t.ListID = l.ID
|
||||
err = t.Create(user)
|
||||
@ -178,6 +201,20 @@ func InsertFromStructure(str []*models.NamespaceWithLists, user *user.User) (err
|
||||
}
|
||||
}
|
||||
|
||||
// All tasks brought their own bucket with them, therefore the newly created default bucket is just extra space
|
||||
if !needsDefaultBucket {
|
||||
b := &models.Bucket{ListID: l.ID}
|
||||
bucketsIn, _, _, err := b.ReadAll(user, "", 1, 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buckets := bucketsIn.([]*models.Bucket)
|
||||
err = buckets[0].Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
l.Tasks = tasks
|
||||
l.Buckets = originalBuckets
|
||||
}
|
||||
|
Reference in New Issue
Block a user