fix(migration): import task comments with original timestamps

Partially resolves https://community.vikunja.io/t/trello-import-comments-and-assignments/2174/14
This commit is contained in:
kolaente 2024-04-13 14:44:55 +02:00
parent bf3c8ac9da
commit 6e2b540394
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 20 additions and 4 deletions

View File

@ -65,6 +65,14 @@ func (tc *TaskComment) TableName() string {
// @Failure 500 {object} models.Message "Internal error"
// @Router /tasks/{taskID}/comments [put]
func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
tc.Created = time.Time{}
tc.Updated = time.Time{}
return tc.CreateWithTimestamps(s, a)
}
func (tc *TaskComment) CreateWithTimestamps(s *xorm.Session, a web.Auth) (err error) {
// Check if the task exists
task, err := GetTaskSimple(s, &Task{ID: tc.TaskID})
if err != nil {
@ -77,9 +85,16 @@ func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
}
tc.AuthorID = tc.Author.ID
_, err = s.Insert(tc)
if err != nil {
return
if !tc.Created.IsZero() && !tc.Updated.IsZero() {
_, err = s.NoAutoTime().Insert(tc)
if err != nil {
return
}
} else {
_, err = s.Insert(tc)
if err != nil {
return
}
}
return events.Dispatch(&TaskCommentCreatedEvent{

View File

@ -359,10 +359,11 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
log.Debugf("[creating structure] Associated task %d with label %d", t.ID, lb.ID)
}
// Comments
for _, comment := range t.Comments {
comment.TaskID = t.ID
comment.ID = 0
err = comment.Create(s, user)
err = comment.CreateWithTimestamps(s, user)
if err != nil {
return
}