Make importing backgrounds work
This commit is contained in:
parent
b72a651fe4
commit
cd7a1e04fc
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"code.vikunja.io/api/pkg/files"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"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.
|
// to be able to still loop over them aftere the list was created.
|
||||||
tasks := l.Tasks
|
tasks := l.Tasks
|
||||||
originalBuckets := l.Buckets
|
originalBuckets := l.Buckets
|
||||||
|
originalBackgroundInformation := l.BackgroundInformation
|
||||||
|
|
||||||
l.NamespaceID = n.ID
|
l.NamespaceID = n.ID
|
||||||
err = l.Create(user)
|
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)
|
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
|
// Create all buckets
|
||||||
buckets := make(map[int64]*models.Bucket) // old bucket id is the key
|
buckets := make(map[int64]*models.Bucket) // old bucket id is the key
|
||||||
if len(l.Buckets) > 0 {
|
if len(l.Buckets) > 0 {
|
||||||
|
|
|
@ -132,6 +132,8 @@ func getTrelloData(token string) (trelloData []*trello.Board, err error) {
|
||||||
// `trelloData` should contain all boards with their lists and cards respectively.
|
// `trelloData` should contain all boards with their lists and cards respectively.
|
||||||
func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachie []*models.NamespaceWithLists, err error) {
|
func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachie []*models.NamespaceWithLists, err error) {
|
||||||
|
|
||||||
|
log.Debugf("[Trello Migration] ")
|
||||||
|
|
||||||
fullVikunjaHierachie = []*models.NamespaceWithLists{
|
fullVikunjaHierachie = []*models.NamespaceWithLists{
|
||||||
{
|
{
|
||||||
Namespace: models.Namespace{
|
Namespace: models.Namespace{
|
||||||
|
@ -146,11 +148,21 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
|
||||||
list := &models.List{
|
list := &models.List{
|
||||||
Title: board.Name,
|
Title: board.Name,
|
||||||
Description: board.Desc,
|
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 {
|
for _, l := range board.Lists {
|
||||||
bucket := &models.Bucket{
|
bucket := &models.Bucket{
|
||||||
|
@ -231,7 +243,6 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board) (fullVikunjaHierachi
|
||||||
fullVikunjaHierachie[0].Lists = append(fullVikunjaHierachie[0].Lists, list)
|
fullVikunjaHierachie[0].Lists = append(fullVikunjaHierachie[0].Lists, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOOD: Backgrounds
|
|
||||||
// TODO: Only create a default bucket if no bucket is available
|
// TODO: Only create a default bucket if no bucket is available
|
||||||
// TODO: More logging
|
// TODO: More logging
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue