Make importing backgrounds work

This commit is contained in:
kolaente 2020-12-17 01:27:40 +01:00
parent b72a651fe4
commit cd7a1e04fc
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 34 additions and 4 deletions

View File

@ -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,7 @@ 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
l.NamespaceID = n.ID
err = l.Create(user)
@ -58,6 +60,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 {

View File

@ -132,6 +132,8 @@ func getTrelloData(token string) (trelloData []*trello.Board, err error) {
// `trelloData` should contain all boards with their lists and cards respectively.
func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachie []*models.NamespaceWithLists, err error) {
log.Debugf("[Trello Migration] ")
fullVikunjaHierachie = []*models.NamespaceWithLists{
{
Namespace: models.Namespace{
@ -146,11 +148,21 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
list := &models.List{
Title: board.Name,
Description: board.Desc,
// Archived Board (closed)
IsArchived: board.Closed,
IsArchived: board.Closed,
}
// TODO: List Background
// Background
// We're pretty much abusing the backgroundinformation field here - not sure if this is really better than adding a new property to the list
if board.Prefs.BackgroundImage != "" {
buf, err := migration.DownloadFile(board.Prefs.BackgroundImage)
if err != nil {
return nil, err
}
log.Debugf("[Trello Migration] Downloaded background %s for board %s", board.Prefs.BackgroundImage, board.ID)
list.BackgroundInformation = buf
} else {
log.Debugf("[Trello Migration] Board %s does not have a background image, not copying...", board.ID)
}
for _, l := range board.Lists {
bucket := &models.Bucket{
@ -231,7 +243,6 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
fullVikunjaHierachie[0].Lists = append(fullVikunjaHierachie[0].Lists, list)
}
// TOOD: Backgrounds
// TODO: Only create a default bucket if no bucket is available
// TODO: More logging