|
@ -145,26 +145,33 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da |
|
|
parsed.Log.EventName = eventName |
|
|
parsed.Log.EventName = eventName |
|
|
parsed.Log.ChannelName = channelName |
|
|
parsed.Log.ChannelName = channelName |
|
|
|
|
|
|
|
|
log, err := s.logs.Insert(ctx, parsed.Log) |
|
|
|
|
|
|
|
|
newLog, err := s.logs.Insert(ctx, parsed.Log) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for _, post := range parsed.Posts { |
|
|
for _, post := range parsed.Posts { |
|
|
post.LogID = log.ShortID |
|
|
|
|
|
|
|
|
post.LogID = newLog.ShortID |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = s.logs.Delete(ctx, *log) |
|
|
|
|
|
|
|
|
_ = s.logs.Delete(ctx, *newLog) |
|
|
|
|
|
|
|
|
return nil, err |
|
|
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: |
|
|
case models.LogImporterForumLog: |
|
|
{ |
|
|
{ |
|
@ -177,26 +184,26 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da |
|
|
parsed.Log.EventName = eventName |
|
|
parsed.Log.EventName = eventName |
|
|
parsed.Log.ChannelName = channelName |
|
|
parsed.Log.ChannelName = channelName |
|
|
|
|
|
|
|
|
log, err := s.logs.Insert(ctx, parsed.Log) |
|
|
|
|
|
|
|
|
newLog, err := s.logs.Insert(ctx, parsed.Log) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for _, post := range parsed.Posts { |
|
|
for _, post := range parsed.Posts { |
|
|
post.LogID = log.ShortID |
|
|
|
|
|
|
|
|
post.LogID = newLog.ShortID |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = s.logs.Delete(ctx, *log) |
|
|
|
|
|
|
|
|
_ = s.logs.Delete(ctx, *newLog) |
|
|
|
|
|
|
|
|
return nil, err |
|
|
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) |
|
|
|
|
|
|
|
|
results = append(results, newLog) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -211,26 +218,33 @@ func (s *LogService) Import(ctx context.Context, importer models.LogImporter, da |
|
|
parsed.Log.EventName = eventName |
|
|
parsed.Log.EventName = eventName |
|
|
parsed.Log.ChannelName = channelName |
|
|
parsed.Log.ChannelName = channelName |
|
|
|
|
|
|
|
|
log, err := s.logs.Insert(ctx, parsed.Log) |
|
|
|
|
|
|
|
|
newLog, err := s.logs.Insert(ctx, parsed.Log) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for _, post := range parsed.Posts { |
|
|
for _, post := range parsed.Posts { |
|
|
post.LogID = log.ShortID |
|
|
|
|
|
|
|
|
post.LogID = newLog.ShortID |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
posts, err := s.posts.InsertMany(ctx, parsed.Posts...) |
|
|
if err != nil { |
|
|
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, log) |
|
|
|
|
|
|
|
|
results = append(results, newLog) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|