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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ad652f1840
Коммит
5e00295b5a
@@ -493,7 +493,7 @@ type AppIface interface {
|
||||
CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
|
||||
CreateSession(session *model.Session) (*model.Session, *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)
|
||||
CreateTermsOfService(text, userID string) (*model.TermsOfService, *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)
|
||||
DoPostActionWithCookie(c *request.Context, postID, actionId, userID, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError)
|
||||
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)
|
||||
DownloadFromURL(downloadURL string) ([]byte, error)
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
return info, err
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func processAttachments(line *LineImportData, basePath string, filesMap map[stri
|
||||
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{}
|
||||
directPostLines := []LineImportWorkerData{}
|
||||
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
|
||||
// filesystem in the locations specified by the JSONL file according
|
||||
// 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)
|
||||
buf := make([]byte, 0, 64*1024)
|
||||
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 {
|
||||
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 {
|
||||
@@ -281,7 +281,7 @@ func processImportDataFileVersionLine(line LineImportData) (int, *model.AppError
|
||||
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 {
|
||||
case line.Type == "scheme":
|
||||
if line.Scheme == nil {
|
||||
|
||||
@@ -158,7 +158,7 @@ func (a *App) importRole(data *RoleImportData, dryRun bool, isSchemeRole bool) *
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (a *App) importTeam(c *request.Context, data *TeamImportData, dryRun bool)
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -1090,7 +1090,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model.
|
||||
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
|
||||
usernames := []string{}
|
||||
for _, replyData := range data {
|
||||
@@ -1192,7 +1192,7 @@ func (a *App) importReplies(c *request.Context, data []ReplyImportData, post *mo
|
||||
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 (
|
||||
name string
|
||||
file io.Reader
|
||||
@@ -1343,7 +1343,7 @@ func getPostStrID(post *model.Post) string {
|
||||
|
||||
// importMultiplePostLines will return an error and the line that
|
||||
// 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 {
|
||||
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
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
@@ -1645,7 +1645,7 @@ func (a *App) importDirectChannel(c request.CTX, data *DirectChannelImportData,
|
||||
|
||||
// importMultipleDirectPostLines will return an error and the line
|
||||
// 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 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -2491,7 +2491,7 @@ func (a *OpenTracingAppLayer) CreateSidebarCategory(c request.CTX, userID string
|
||||
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
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateTeam")
|
||||
|
||||
@@ -3830,7 +3830,7 @@ func (a *OpenTracingAppLayer) 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
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DoUploadFile")
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ func (a *App) SoftDeleteAllTeamsExcept(teamID string) *model.AppError {
|
||||
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)
|
||||
if err != nil {
|
||||
var invErr *store.ErrInvalidInput
|
||||
|
||||
@@ -4875,10 +4875,6 @@
|
||||
"id": "app.import.bulk_import.json_decode.error",
|
||||
"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",
|
||||
"translation": "Incorrect or missing version in the data import file. Make sure version is the first object in your import file and try again."
|
||||
|
||||
Ссылка в новой задаче
Block a user