Make sure all associated entities of a task are deleted when the task is deleted
This commit is contained in:
parent
d28390d792
commit
e4a0066e20
1 changed files with 43 additions and 0 deletions
|
@ -1353,6 +1353,49 @@ func (t *Task) Delete(s *xorm.Session, a web.Auth) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete Favorites
|
||||||
|
err = removeFromFavorite(s, t.ID, a, FavoriteKindTask)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete label associations
|
||||||
|
_, err = s.Where("task_id = ?", t.ID).Delete(&LabelTask{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete task attachments
|
||||||
|
attachments, err := getTaskAttachmentsByTaskIDs(s, []int64{t.ID})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, attachment := range attachments {
|
||||||
|
// Using the attachment delete method here because that takes care of removing all files properly
|
||||||
|
err = attachment.Delete(s, a)
|
||||||
|
if err != nil && !IsErrTaskAttachmentDoesNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all comments
|
||||||
|
_, err = s.Where("task_id = ?", t.ID).Delete(&TaskComment{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all relations
|
||||||
|
_, err = s.Where("task_id = ? OR other_task_id = ?", t.ID, t.ID).Delete(&TaskRelation{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all reminders
|
||||||
|
_, err = s.Where("task_id = ?", t.ID).Delete(&TaskReminder{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
doer, _ := user.GetFromAuth(a)
|
doer, _ := user.GetFromAuth(a)
|
||||||
err = events.Dispatch(&TaskDeletedEvent{
|
err = events.Dispatch(&TaskDeletedEvent{
|
||||||
Task: t,
|
Task: t,
|
||||||
|
|
Loading…
Reference in a new issue