app/import_functions: fix a bug while improting for two teams (#16455)

Automatic Merge
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2020-12-04 20:45:17 +03:00
коммит произвёл GitHub
родитель d137cf0aa5
Коммит cc5a12bad0
2 изменённых файлов: 69 добавлений и 8 удалений

Просмотреть файл

@@ -1208,20 +1208,24 @@ func (a *App) getChannelsByNames(names []string, teamId string) (map[string]*mod
return channels, nil
}
func (a *App) getChannelsForPosts(teams map[string]*model.Team, data []*PostImportData) (map[string]*model.Channel, *model.AppError) {
channels := make(map[string]*model.Channel)
// getChannelsForPosts returns map[teamName]map[channelName]*model.Channel
func (a *App) getChannelsForPosts(teams map[string]*model.Team, data []*PostImportData) (map[string]map[string]*model.Channel, *model.AppError) {
teamChannels := make(map[string]map[string]*model.Channel)
for _, postData := range data {
team := teams[*postData.Team]
if channel, ok := channels[*postData.Channel]; !ok || channel == nil {
teamName := *postData.Team
if _, ok := teamChannels[teamName]; !ok {
teamChannels[teamName] = make(map[string]*model.Channel)
}
if channel, ok := teamChannels[teamName][*postData.Channel]; !ok || channel == nil {
var err error
channel, err = a.Srv().Store.Channel().GetByName(team.Id, *postData.Channel, true)
channel, err = a.Srv().Store.Channel().GetByName(teams[teamName].Id, *postData.Channel, true)
if err != nil {
return nil, model.NewAppError("BulkImport", "app.import.import_post.channel_not_found.error", map[string]interface{}{"ChannelName": *postData.Channel}, err.Error(), http.StatusBadRequest)
}
channels[*postData.Channel] = channel
teamChannels[teamName][*postData.Channel] = channel
}
}
return channels, nil
return teamChannels, nil
}
// getPostStrID returns a string ID composed of several post fields to
@@ -1282,7 +1286,7 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
for _, line := range lines {
team := teams[*line.Post.Team]
channel := channels[*line.Post.Channel]
channel := channels[*line.Post.Team][*line.Post.Channel]
user := users[*line.Post.User]
// Check if this post already exists.