Skip exporting channels for deleted teams (#19494)
This corrects a bug where exports that contained deleted teams could fail to import. Channels must be skipped that belong to these deleted teams in order to produce a valid import bundle.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d2cabaebab
Коммит
ca8eb1347b
@@ -83,17 +83,18 @@ func (a *App) BulkExport(writer io.Writer, outPath string, opts BulkExportOpts)
|
||||
}
|
||||
|
||||
mlog.Info("Bulk export: exporting teams")
|
||||
if err := a.exportAllTeams(writer); err != nil {
|
||||
teamNames, err := a.exportAllTeams(writer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mlog.Info("Bulk export: exporting channels")
|
||||
if err := a.exportAllChannels(writer); err != nil {
|
||||
if err = a.exportAllChannels(writer, teamNames); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mlog.Info("Bulk export: exporting users")
|
||||
if err := a.exportAllUsers(writer); err != nil {
|
||||
if err = a.exportAllUsers(writer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -165,12 +166,13 @@ func (a *App) exportVersion(writer io.Writer) *model.AppError {
|
||||
return a.exportWriteLine(writer, versionLine)
|
||||
}
|
||||
|
||||
func (a *App) exportAllTeams(writer io.Writer) *model.AppError {
|
||||
func (a *App) exportAllTeams(writer io.Writer) (map[string]bool, *model.AppError) {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
teamNames := make(map[string]bool)
|
||||
for {
|
||||
teams, err := a.Srv().Store.Team().GetAllForExportAfter(1000, afterId)
|
||||
if err != nil {
|
||||
return model.NewAppError("exportAllTeams", "app.team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("exportAllTeams", "app.team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if len(teams) == 0 {
|
||||
@@ -184,18 +186,19 @@ func (a *App) exportAllTeams(writer io.Writer) *model.AppError {
|
||||
if team.DeleteAt != 0 {
|
||||
continue
|
||||
}
|
||||
teamNames[team.Name] = true
|
||||
|
||||
teamLine := ImportLineFromTeam(team)
|
||||
if err := a.exportWriteLine(writer, teamLine); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return teamNames, nil
|
||||
}
|
||||
|
||||
func (a *App) exportAllChannels(writer io.Writer) *model.AppError {
|
||||
func (a *App) exportAllChannels(writer io.Writer, teamNames map[string]bool) *model.AppError {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
for {
|
||||
channels, err := a.Srv().Store.Channel().GetAllChannelsForExportAfter(1000, afterId)
|
||||
@@ -215,6 +218,10 @@ func (a *App) exportAllChannels(writer io.Writer) *model.AppError {
|
||||
if channel.DeleteAt != 0 {
|
||||
continue
|
||||
}
|
||||
// Skip channels on deleted teams.
|
||||
if ok := teamNames[channel.TeamName]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
channelLine := ImportLineFromChannel(channel)
|
||||
if err := a.exportWriteLine(writer, channelLine); err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user