Work around tasks with attachments not being duplicated

This commit is contained in:
kolaente 2020-08-16 23:44:16 +02:00
parent 301bebf8d3
commit a58b932743
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 8 additions and 1 deletions

View File

@ -111,6 +111,8 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
return err
}
// This map contains the old task id as key and the new duplicated task id as value.
// It is used to map old task items to new ones.
taskMap := make(map[int64]int64)
// Create + update all tasks (includes reminders)
oldTaskIDs := make([]int64, len(tasks))
@ -143,7 +145,12 @@ func (ld *ListDuplicate) Create(a web.Auth) (err error) {
for _, attachment := range attachments {
oldAttachmentID := attachment.ID
attachment.ID = 0
attachment.TaskID = oldTaskIDs[attachment.TaskID]
var exists bool
attachment.TaskID, exists = taskMap[attachment.TaskID]
if !exists {
log.Debugf("Error duplicating attachment %d from old task %d to new task: Old task <-> new task does not seem to exist.", oldAttachmentID, attachment.TaskID)
continue
}
attachment.File = &files.File{ID: attachment.FileID}
if err := attachment.File.LoadFileMetaByID(); err != nil {
if files.IsErrFileDoesNotExist(err) {