MM-38702: Do not fail during importing without attachment (#20800)

We just log a warning instead of failing completely.

https://mattermost.atlassian.net/browse/MM-38702

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2022-08-17 13:36:36 +05:30
коммит произвёл GitHub
родитель ad652f1840
Коммит 5e00295b5a
7 изменённых файлов: 17 добавлений и 21 удалений

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

@@ -493,7 +493,7 @@ type AppIface interface {
CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError) CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
CreateSession(session *model.Session) (*model.Session, *model.AppError) CreateSession(session *model.Session) (*model.Session, *model.AppError)
CreateSidebarCategory(c request.CTX, userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) CreateSidebarCategory(c request.CTX, userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError)
CreateTeam(c *request.Context, team *model.Team) (*model.Team, *model.AppError) CreateTeam(c request.CTX, team *model.Team) (*model.Team, *model.AppError)
CreateTeamWithUser(c *request.Context, team *model.Team, userID string) (*model.Team, *model.AppError) CreateTeamWithUser(c *request.Context, team *model.Team, userID string) (*model.Team, *model.AppError)
CreateTermsOfService(text, userID string) (*model.TermsOfService, *model.AppError) CreateTermsOfService(text, userID string) (*model.TermsOfService, *model.AppError)
CreateUploadSession(c request.CTX, us *model.UploadSession) (*model.UploadSession, *model.AppError) CreateUploadSession(c request.CTX, us *model.UploadSession) (*model.UploadSession, *model.AppError)
@@ -546,7 +546,7 @@ type AppIface interface {
DoPostAction(c *request.Context, postID, actionId, userID, selectedOption string) (string, *model.AppError) DoPostAction(c *request.Context, postID, actionId, userID, selectedOption string) (string, *model.AppError)
DoPostActionWithCookie(c *request.Context, postID, actionId, userID, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError) DoPostActionWithCookie(c *request.Context, postID, actionId, userID, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError)
DoSystemConsoleRolesCreationMigration() DoSystemConsoleRolesCreationMigration()
DoUploadFile(c *request.Context, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError) DoUploadFile(c request.CTX, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError)
DoUploadFileExpectModification(c request.CTX, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError) DoUploadFileExpectModification(c request.CTX, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError)
DownloadFromURL(downloadURL string) ([]byte, error) DownloadFromURL(downloadURL string) ([]byte, error)
EnableUserAccessToken(token *model.UserAccessToken) *model.AppError EnableUserAccessToken(token *model.UserAccessToken) *model.AppError

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

@@ -476,7 +476,7 @@ func (a *App) UploadFile(c request.CTX, data []byte, channelID string, filename
return info, nil return info, nil
} }
func (a *App) DoUploadFile(c *request.Context, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError) { func (a *App) DoUploadFile(c request.CTX, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError) {
info, _, err := a.DoUploadFileExpectModification(c, now, rawTeamId, rawChannelId, rawUserId, rawFilename, data) info, _, err := a.DoUploadFileExpectModification(c, now, rawTeamId, rawChannelId, rawUserId, rawFilename, data)
return info, err return info, err
} }

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

@@ -108,7 +108,7 @@ func processAttachments(line *LineImportData, basePath string, filesMap map[stri
return nil return nil
} }
func (a *App) bulkImportWorker(c *request.Context, dryRun bool, wg *sync.WaitGroup, lines <-chan LineImportWorkerData, errors chan<- LineImportWorkerError) { func (a *App) bulkImportWorker(c request.CTX, dryRun bool, wg *sync.WaitGroup, lines <-chan LineImportWorkerData, errors chan<- LineImportWorkerError) {
postLines := []LineImportWorkerData{} postLines := []LineImportWorkerData{}
directPostLines := []LineImportWorkerData{} directPostLines := []LineImportWorkerData{}
for line := range lines { for line := range lines {
@@ -167,7 +167,7 @@ func (a *App) BulkImportWithPath(c *request.Context, jsonlReader io.Reader, atta
// not nil. If it is nil, it will look for attachments on the // not nil. If it is nil, it will look for attachments on the
// filesystem in the locations specified by the JSONL file according // filesystem in the locations specified by the JSONL file according
// to the older behavior // to the older behavior
func (a *App) bulkImport(c *request.Context, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun bool, workers int, importPath string) (*model.AppError, int) { func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun bool, workers int, importPath string) (*model.AppError, int) {
scanner := bufio.NewScanner(jsonlReader) scanner := bufio.NewScanner(jsonlReader)
buf := make([]byte, 0, 64*1024) buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, maxScanTokenSize) scanner.Buffer(buf, maxScanTokenSize)
@@ -200,7 +200,7 @@ func (a *App) bulkImport(c *request.Context, jsonlReader io.Reader, attachmentsR
} }
if err := processAttachments(&line, importPath, attachedFiles); err != nil { if err := processAttachments(&line, importPath, attachedFiles); err != nil {
return model.NewAppError("BulkImport", "app.import.bulk_import.process_attachments.error", nil, err.Error(), http.StatusBadRequest), lineNumber c.Logger().Warn("Error while processing import attachments. Objects might be broken.", mlog.Err(err))
} }
if lineNumber == 1 { if lineNumber == 1 {
@@ -281,7 +281,7 @@ func processImportDataFileVersionLine(line LineImportData) (int, *model.AppError
return *line.Version, nil return *line.Version, nil
} }
func (a *App) importLine(c *request.Context, line LineImportData, dryRun bool) *model.AppError { func (a *App) importLine(c request.CTX, line LineImportData, dryRun bool) *model.AppError {
switch { switch {
case line.Type == "scheme": case line.Type == "scheme":
if line.Scheme == nil { if line.Scheme == nil {

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

@@ -158,7 +158,7 @@ func (a *App) importRole(data *RoleImportData, dryRun bool, isSchemeRole bool) *
return err return err
} }
func (a *App) importTeam(c *request.Context, data *TeamImportData, dryRun bool) *model.AppError { func (a *App) importTeam(c request.CTX, data *TeamImportData, dryRun bool) *model.AppError {
if err := validateTeamImportData(data); err != nil { if err := validateTeamImportData(data); err != nil {
return err return err
} }
@@ -226,7 +226,7 @@ func (a *App) importTeam(c *request.Context, data *TeamImportData, dryRun bool)
return nil return nil
} }
func (a *App) importChannel(c *request.Context, data *ChannelImportData, dryRun bool) *model.AppError { func (a *App) importChannel(c request.CTX, data *ChannelImportData, dryRun bool) *model.AppError {
if err := validateChannelImportData(data); err != nil { if err := validateChannelImportData(data); err != nil {
return err return err
} }
@@ -1090,7 +1090,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model.
return nil return nil
} }
func (a *App) importReplies(c *request.Context, data []ReplyImportData, post *model.Post, teamID string) *model.AppError { func (a *App) importReplies(c request.CTX, data []ReplyImportData, post *model.Post, teamID string) *model.AppError {
var err *model.AppError var err *model.AppError
usernames := []string{} usernames := []string{}
for _, replyData := range data { for _, replyData := range data {
@@ -1192,7 +1192,7 @@ func (a *App) importReplies(c *request.Context, data []ReplyImportData, post *mo
return nil return nil
} }
func (a *App) importAttachment(c *request.Context, data *AttachmentImportData, post *model.Post, teamID string) (*model.FileInfo, *model.AppError) { func (a *App) importAttachment(c request.CTX, data *AttachmentImportData, post *model.Post, teamID string) (*model.FileInfo, *model.AppError) {
var ( var (
name string name string
file io.Reader file io.Reader
@@ -1343,7 +1343,7 @@ func getPostStrID(post *model.Post) string {
// importMultiplePostLines will return an error and the line that // importMultiplePostLines will return an error and the line that
// caused it whenever possible // caused it whenever possible
func (a *App) importMultiplePostLines(c *request.Context, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) { func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
if len(lines) == 0 { if len(lines) == 0 {
return 0, nil return 0, nil
} }
@@ -1532,7 +1532,7 @@ func (a *App) importMultiplePostLines(c *request.Context, lines []LineImportWork
} }
// uploadAttachments imports new attachments and returns current attachments of the post as a map // uploadAttachments imports new attachments and returns current attachments of the post as a map
func (a *App) uploadAttachments(c *request.Context, attachments *[]AttachmentImportData, post *model.Post, teamID string) map[string]bool { func (a *App) uploadAttachments(c request.CTX, attachments *[]AttachmentImportData, post *model.Post, teamID string) map[string]bool {
if attachments == nil { if attachments == nil {
return nil return nil
} }
@@ -1645,7 +1645,7 @@ func (a *App) importDirectChannel(c request.CTX, data *DirectChannelImportData,
// importMultipleDirectPostLines will return an error and the line // importMultipleDirectPostLines will return an error and the line
// that caused it whenever possible // that caused it whenever possible
func (a *App) importMultipleDirectPostLines(c *request.Context, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) { func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
if len(lines) == 0 { if len(lines) == 0 {
return 0, nil return 0, nil
} }

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

@@ -2491,7 +2491,7 @@ func (a *OpenTracingAppLayer) CreateSidebarCategory(c request.CTX, userID string
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (a *OpenTracingAppLayer) CreateTeam(c *request.Context, team *model.Team) (*model.Team, *model.AppError) { func (a *OpenTracingAppLayer) CreateTeam(c request.CTX, team *model.Team) (*model.Team, *model.AppError) {
origCtx := a.ctx origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateTeam") span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateTeam")
@@ -3830,7 +3830,7 @@ func (a *OpenTracingAppLayer) DoSystemConsoleRolesCreationMigration() {
a.app.DoSystemConsoleRolesCreationMigration() a.app.DoSystemConsoleRolesCreationMigration()
} }
func (a *OpenTracingAppLayer) DoUploadFile(c *request.Context, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError) { func (a *OpenTracingAppLayer) DoUploadFile(c request.CTX, now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError) {
origCtx := a.ctx origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DoUploadFile") span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DoUploadFile")

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

@@ -147,7 +147,7 @@ func (a *App) SoftDeleteAllTeamsExcept(teamID string) *model.AppError {
return nil return nil
} }
func (a *App) CreateTeam(c *request.Context, team *model.Team) (*model.Team, *model.AppError) { func (a *App) CreateTeam(c request.CTX, team *model.Team) (*model.Team, *model.AppError) {
rteam, err := a.ch.srv.teamService.CreateTeam(team) rteam, err := a.ch.srv.teamService.CreateTeam(team)
if err != nil { if err != nil {
var invErr *store.ErrInvalidInput var invErr *store.ErrInvalidInput

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

@@ -4875,10 +4875,6 @@
"id": "app.import.bulk_import.json_decode.error", "id": "app.import.bulk_import.json_decode.error",
"translation": "JSON decode of line failed." "translation": "JSON decode of line failed."
}, },
{
"id": "app.import.bulk_import.process_attachments.error",
"translation": "Error while processing bulk import attachments."
},
{ {
"id": "app.import.bulk_import.unsupported_version.error", "id": "app.import.bulk_import.unsupported_version.error",
"translation": "Incorrect or missing version in the data import file. Make sure version is the first object in your import file and try again." "translation": "Incorrect or missing version in the data import file. Make sure version is the first object in your import file and try again."