fix(migration): import card covers when migrating from Trello
This commit is contained in:
@ -267,6 +267,8 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
for _, a := range t.Attachments {
|
||||
// Check if we have a file to create
|
||||
if len(a.File.FileContent) > 0 {
|
||||
oldID := a.ID
|
||||
a.ID = 0
|
||||
a.TaskID = t.ID
|
||||
fr := io.NopCloser(bytes.NewReader(a.File.FileContent))
|
||||
err = a.NewAttachment(s, fr, a.File.Name, a.File.Size, user)
|
||||
@ -274,6 +276,14 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
return
|
||||
}
|
||||
log.Debugf("[creating structure] Created new attachment %d", a.ID)
|
||||
|
||||
if t.CoverImageAttachmentID == oldID {
|
||||
t.CoverImageAttachmentID = a.ID
|
||||
err = t.Update(s, user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -319,18 +319,49 @@ func convertTrelloDataToVikunja(trelloData []*trello.Board, token string) (fullV
|
||||
return nil, err
|
||||
}
|
||||
|
||||
task.Attachments = append(task.Attachments, &models.TaskAttachment{
|
||||
vikunjaAttachment := &models.TaskAttachment{
|
||||
File: &files.File{
|
||||
Name: attachment.Name,
|
||||
Mime: attachment.MimeType,
|
||||
Size: uint64(buf.Len()),
|
||||
FileContent: buf.Bytes(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if card.IDAttachmentCover != "" && card.IDAttachmentCover == attachment.ID {
|
||||
vikunjaAttachment.ID = 42
|
||||
task.CoverImageAttachmentID = 42
|
||||
}
|
||||
|
||||
task.Attachments = append(task.Attachments, vikunjaAttachment)
|
||||
|
||||
log.Debugf("[Trello Migration] Downloaded card attachment %s", attachment.ID)
|
||||
}
|
||||
|
||||
// When the cover image was set manually, we need to add it as an attachment
|
||||
if card.ManualCoverAttachment && len(card.Cover.Scaled) > 0 {
|
||||
|
||||
cover := card.Cover.Scaled[len(card.Cover.Scaled)-1]
|
||||
|
||||
buf, err := migration.DownloadFile(cover.URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
coverAttachment := &models.TaskAttachment{
|
||||
ID: 43,
|
||||
File: &files.File{
|
||||
Name: cover.ID + ".jpg",
|
||||
Mime: "image/jpg", // Seems to always return jpg
|
||||
Size: uint64(buf.Len()),
|
||||
FileContent: buf.Bytes(),
|
||||
},
|
||||
}
|
||||
|
||||
task.Attachments = append(task.Attachments, coverAttachment)
|
||||
task.CoverImageAttachmentID = coverAttachment.ID
|
||||
}
|
||||
|
||||
project.Tasks = append(project.Tasks, &models.TaskWithComments{Task: *task})
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,7 @@ func TestConvertTrelloToVikunja(t *testing.T) {
|
||||
},
|
||||
Attachments: []*trello.Attachment{
|
||||
{
|
||||
ID: "5cc71b16f0c7a57bed3c94e9",
|
||||
Name: "Testimage.jpg",
|
||||
IsUpload: true,
|
||||
MimeType: "image/jpg",
|
||||
|
Reference in New Issue
Block a user