Fix inserting task structure with related tasks #142
|
@ -65,13 +65,18 @@ func InsertFromStructure(str []*models.NamespaceWithLists, user *user.User) (err
|
|||
|
||||
log.Debugf("[creating structure] Created task %d", t.ID)
|
||||
if len(t.RelatedTasks) > 0 {
|
||||
log.Debugf("[creating structure] Creating %d related tasks", len(t.RelatedTasks))
|
||||
log.Debugf("[creating structure] Creating %d related task kinds", len(t.RelatedTasks))
|
||||
}
|
||||
|
||||
// Create all relation for each task
|
||||
for kind, tasks := range t.RelatedTasks {
|
||||
// First create the related tasks if they does not exist
|
||||
|
||||
if len(tasks) > 0 {
|
||||
log.Debugf("[creating structure] Creating %d related tasks for kind %v", len(tasks), kind)
|
||||
}
|
||||
|
||||
for _, rt := range tasks {
|
||||
// First create the related tasks if they does not exist
|
||||
if rt.ID == 0 {
|
||||
rt.ListID = t.ListID
|
||||
err = rt.Create(user)
|
||||
|
@ -83,8 +88,8 @@ func InsertFromStructure(str []*models.NamespaceWithLists, user *user.User) (err
|
|||
|
||||
// Then create the relation
|
||||
taskRel := &models.TaskRelation{
|
||||
TaskID: rt.ID,
|
||||
OtherTaskID: t.ID,
|
||||
TaskID: t.ID,
|
||||
OtherTaskID: rt.ID,
|
||||
RelationKind: kind,
|
||||
}
|
||||
err = taskRel.Create(user)
|
||||
|
@ -92,7 +97,7 @@ func InsertFromStructure(str []*models.NamespaceWithLists, user *user.User) (err
|
|||
return
|
||||
}
|
||||
|
||||
log.Debugf("[creating structure] Created task relation between task %d and %d with new ID %d", t.ID, rt.ID, taskRel.ID)
|
||||
log.Debugf("[creating structure] Created task relation between task %d and %d", t.ID, rt.ID)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue