|
|
@ -145,26 +145,33 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da |
|
|
|
parsed.Log.EventName = eventName |
|
|
|
parsed.Log.ChannelName = channelName |
|
|
|
|
|
|
|
log, err := s.logs.Insert(ctx, parsed.Log) |
|
|
|
newLog, err := s.logs.Insert(ctx, parsed.Log) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
for _, post := range parsed.Posts { |
|
|
|
post.LogID = log.ShortID |
|
|
|
post.LogID = newLog.ShortID |
|
|
|
} |
|
|
|
|
|
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
|
if err != nil { |
|
|
|
_ = s.logs.Delete(ctx, *log) |
|
|
|
_ = s.logs.Delete(ctx, *newLog) |
|
|
|
|
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(log), log) |
|
|
|
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(log, posts), log, posts) |
|
|
|
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(newLog), newLog) |
|
|
|
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(newLog, posts), newLog, posts) |
|
|
|
|
|
|
|
results = append(results, log) |
|
|
|
refreshedLog, err := s.refreshLogCharacters(ctx, *newLog, nil, false) |
|
|
|
if err != nil { |
|
|
|
log.Printf("Failed to update characters in newLog %s: %s", newLog.ID, err) |
|
|
|
} else { |
|
|
|
newLog = refreshedLog |
|
|
|
} |
|
|
|
|
|
|
|
results = append(results, newLog) |
|
|
|
} |
|
|
|
case models.LogImporterForumLog: |
|
|
|
{ |
|
|
@ -174,7 +181,7 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da |
|
|
|
} |
|
|
|
|
|
|
|
for _, parsed := range parseResults { |
|
|
|
log, err := s.logs.Insert(ctx, parsed.Log) |
|
|
|
newLog, err := s.logs.Insert(ctx, parsed.Log) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@ -182,18 +189,27 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da |
|
|
|
parsed.Log.ChannelName = channelName |
|
|
|
|
|
|
|
for _, post := range parsed.Posts { |
|
|
|
post.LogID = log.ShortID |
|
|
|
post.LogID = newLog.ShortID |
|
|
|
} |
|
|
|
|
|
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
|
if err != nil { |
|
|
|
_ = s.logs.Delete(ctx, *log) |
|
|
|
_ = s.logs.Delete(ctx, *newLog) |
|
|
|
|
|
|
|
return nil, err |
|
|
|
return results, err |
|
|
|
} |
|
|
|
|
|
|
|
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(log), log) |
|
|
|
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(log, posts), log, posts) |
|
|
|
refreshedLog, err := s.refreshLogCharacters(ctx, *newLog, nil, false) |
|
|
|
if err != nil { |
|
|
|
log.Printf("Failed to update characters in newLog %s: %s", newLog.ID, err) |
|
|
|
} else { |
|
|
|
newLog = refreshedLog |
|
|
|
} |
|
|
|
|
|
|
|
s.changeService.Submit(ctx, models.ChangeModelLog, "add", true, changekeys.Listed(newLog), newLog) |
|
|
|
s.changeService.Submit(ctx, models.ChangeModelPost, "add", true, changekeys.Listed(newLog, posts), newLog, posts) |
|
|
|
|
|
|
|
results = append(results, newLog) |
|
|
|
} |
|
|
|
} |
|
|
|
default: |
|
|
|