[MM-31247] Add support for compressed export files with attachments (#16614)
* Include filepaths for post attachments * Cleanup * Enable exporting file attachments * Fix file import * Enable zip export * Support creating missing directories when unzipping * Add test * Add translations * Export direct channel posts attachments * Fix returned values order Remove pointer to slice in return * [MM-31597] Implement export process job (#16626) * Implement export process job * Add translations * Remove unused value * [MM-31249] Add /exports API endpoint (#16633) * Implement API endpoints to list, download and delete export files * Add endpoint for single resource * Update i18n/en.json Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * Update i18n/en.json Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * Fix var name Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9a33c3706a
Коммит
572f861675
@@ -7,13 +7,15 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
var ExportCmd = &cobra.Command{
|
||||
@@ -74,6 +76,8 @@ func init() {
|
||||
GlobalRelayZipExportCmd.Flags().Int64("exportFrom", -1, "The timestamp of the earliest post to export, expressed in seconds since the unix epoch.")
|
||||
|
||||
BulkExportCmd.Flags().Bool("all-teams", true, "Export all teams from the server.")
|
||||
BulkExportCmd.Flags().Bool("attachments", false, "Also export file attachments.")
|
||||
BulkExportCmd.Flags().Bool("archive", false, "Outputs a single archive file.")
|
||||
|
||||
ExportCmd.AddCommand(ScheduleExportCmd)
|
||||
ExportCmd.AddCommand(CsvExportCmd)
|
||||
@@ -202,25 +206,31 @@ func bulkExportCmdF(command *cobra.Command, args []string) error {
|
||||
return errors.New("Nothing to export. Please specify the --all-teams flag to export all teams.")
|
||||
}
|
||||
|
||||
attachments, err := command.Flags().GetBool("attachments")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "attachments flag error")
|
||||
}
|
||||
|
||||
archive, err := command.Flags().GetBool("archive")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "archive flag error")
|
||||
}
|
||||
|
||||
fileWriter, err := os.Create(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fileWriter.Close()
|
||||
|
||||
// Path to directory of custom emoji
|
||||
pathToEmojiDir := "data/emoji/"
|
||||
|
||||
customDataDir := a.Config().FileSettings.Directory
|
||||
if customDataDir != nil && *customDataDir != "" {
|
||||
pathToEmojiDir = *customDataDir + "emoji/"
|
||||
outPath, err := filepath.Abs(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Name of the directory to export custom emoji
|
||||
dirNameToExportEmoji := "exported_emoji"
|
||||
|
||||
// args[0] points to the filename/filepath passed with export bulk command
|
||||
if err := a.BulkExport(fileWriter, args[0], pathToEmojiDir, dirNameToExportEmoji); err != nil {
|
||||
var opts app.BulkExportOpts
|
||||
opts.IncludeAttachments = attachments
|
||||
opts.CreateArchive = archive
|
||||
if err := a.BulkExport(fileWriter, filepath.Dir(outPath), opts); err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ func init() {
|
||||
BulkImportCmd.Flags().Bool("apply", false, "Save the import data to the database. Use with caution - this cannot be reverted.")
|
||||
BulkImportCmd.Flags().Bool("validate", false, "Validate the import data without making any changes to the system.")
|
||||
BulkImportCmd.Flags().Int("workers", 2, "How many workers to run whilst doing the import.")
|
||||
BulkImportCmd.Flags().String("import-path", "", "A path to the data directory to import files from.")
|
||||
|
||||
ImportCmd.AddCommand(
|
||||
BulkImportCmd,
|
||||
@@ -118,6 +119,11 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
return errors.New("Workers flag error")
|
||||
}
|
||||
|
||||
importPath, err := command.Flags().GetString("import-path")
|
||||
if err != nil {
|
||||
return errors.New("import-path flag error")
|
||||
}
|
||||
|
||||
if len(args) != 1 {
|
||||
return errors.New("Incorrect number of arguments.")
|
||||
}
|
||||
@@ -143,7 +149,7 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("")
|
||||
|
||||
if err, lineNumber := a.BulkImport(fileReader, !apply, workers); err != nil {
|
||||
if err, lineNumber := a.BulkImportWithPath(fileReader, !apply, workers, importPath); err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
if lineNumber != 0 {
|
||||
CommandPrintErrorln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
||||
|
||||
Ссылка в новой задаче
Block a user