forked from vikunja/vikunja
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:
parent
bf3c8ac9da
commit
6e2b540394
|
@ -65,6 +65,14 @@ func (tc *TaskComment) TableName() string {
|
||||||
// @Failure 500 {object} models.Message "Internal error"
|
// @Failure 500 {object} models.Message "Internal error"
|
||||||
// @Router /tasks/{taskID}/comments [put]
|
// @Router /tasks/{taskID}/comments [put]
|
||||||
func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
|
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
|
// Check if the task exists
|
||||||
task, err := GetTaskSimple(s, &Task{ID: tc.TaskID})
|
task, err := GetTaskSimple(s, &Task{ID: tc.TaskID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,9 +85,16 @@ func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||||
}
|
}
|
||||||
tc.AuthorID = tc.Author.ID
|
tc.AuthorID = tc.Author.ID
|
||||||
|
|
||||||
_, err = s.Insert(tc)
|
if !tc.Created.IsZero() && !tc.Updated.IsZero() {
|
||||||
if err != nil {
|
_, err = s.NoAutoTime().Insert(tc)
|
||||||
return
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_, err = s.Insert(tc)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return events.Dispatch(&TaskCommentCreatedEvent{
|
return events.Dispatch(&TaskCommentCreatedEvent{
|
||||||
|
|
|
@ -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)
|
log.Debugf("[creating structure] Associated task %d with label %d", t.ID, lb.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comments
|
||||||
for _, comment := range t.Comments {
|
for _, comment := range t.Comments {
|
||||||
comment.TaskID = t.ID
|
comment.TaskID = t.ID
|
||||||
comment.ID = 0
|
comment.ID = 0
|
||||||
err = comment.Create(s, user)
|
err = comment.CreateWithTimestamps(s, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user