From 9c23e196440830d0b94ca18bfb1002a0db27b54c Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 4 Mar 2026 16:52:56 +0100 Subject: [PATCH] fix: preserve cover image when duplicating task Track old-to-new attachment ID mapping during duplication and re-set CoverImageAttachmentID on the new task if the original had a cover image configured. --- pkg/models/task_duplicate.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/models/task_duplicate.go b/pkg/models/task_duplicate.go index a2b1d8a8d..ea65038e4 100644 --- a/pkg/models/task_duplicate.go +++ b/pkg/models/task_duplicate.go @@ -113,7 +113,9 @@ func (td *TaskDuplicate) Create(s *xorm.Session, doer web.Auth) (err error) { if err != nil { return err } + oldToNewAttachmentIDs := make(map[int64]int64) for _, attachment := range attachments { + oldAttachmentID := attachment.ID attachment.ID = 0 attachment.TaskID = newTask.ID attachment.File = &files.File{ID: attachment.FileID} @@ -133,6 +135,19 @@ func (td *TaskDuplicate) Create(s *xorm.Session, doer web.Auth) (err error) { if err != nil { return err } + oldToNewAttachmentIDs[oldAttachmentID] = attachment.ID + } + + // Re-set the cover image if the original task had one + if originalTask.CoverImageAttachmentID != 0 { + if newAttachmentID, ok := oldToNewAttachmentIDs[originalTask.CoverImageAttachmentID]; ok { + newTask.CoverImageAttachmentID = newAttachmentID + if _, err := s.Where("id = ?", newTask.ID). + Cols("cover_image_attachment_id"). + Update(newTask); err != nil { + return err + } + } } // Create "copied from/to" relation