summaryrefslogtreecommitdiffstats
path: root/cmd/commands/import.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-05-17 12:40:40 -0700
committerGitHub <noreply@github.com>2018-05-17 12:40:40 -0700
commit11cbb597471127c1b29e78e6cad0a1a4d93ea24c (patch)
tree0eceb950872c7234348f0b41d4492073908840d0 /cmd/commands/import.go
parent1f6c271b3bedd6656ae7155714423b1b39a669c1 (diff)
downloadchat-11cbb597471127c1b29e78e6cad0a1a4d93ea24c.tar.gz
chat-11cbb597471127c1b29e78e6cad0a1a4d93ea24c.tar.bz2
chat-11cbb597471127c1b29e78e6cad0a1a4d93ea24c.zip
Renaming platform binary to mattermost. (#8801)
Diffstat (limited to 'cmd/commands/import.go')
-rw-r--r--cmd/commands/import.go145
1 files changed, 0 insertions, 145 deletions
diff --git a/cmd/commands/import.go b/cmd/commands/import.go
deleted file mode 100644
index 51fbb8d70..000000000
--- a/cmd/commands/import.go
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-package commands
-
-import (
- "errors"
- "os"
-
- "fmt"
-
- "github.com/mattermost/mattermost-server/cmd"
- "github.com/spf13/cobra"
-)
-
-var ImportCmd = &cobra.Command{
- Use: "import",
- Short: "Import data.",
-}
-
-var SlackImportCmd = &cobra.Command{
- Use: "slack [team] [file]",
- Short: "Import a team from Slack.",
- Long: "Import a team from a Slack export zip file.",
- Example: " import slack myteam slack_export.zip",
- RunE: slackImportCmdF,
-}
-
-var BulkImportCmd = &cobra.Command{
- Use: "bulk [file]",
- Short: "Import bulk data.",
- Long: "Import data from a Mattermost Bulk Import File.",
- Example: " import bulk bulk_data.json",
- RunE: bulkImportCmdF,
-}
-
-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.")
-
- ImportCmd.AddCommand(
- BulkImportCmd,
- SlackImportCmd,
- )
- cmd.RootCmd.AddCommand(ImportCmd)
-}
-
-func slackImportCmdF(command *cobra.Command, args []string) error {
- a, err := cmd.InitDBCommandContextCobra(command)
- if err != nil {
- return err
- }
- defer a.Shutdown()
-
- if len(args) != 2 {
- return errors.New("Incorrect number of arguments.")
- }
-
- team := getTeamFromTeamArg(a, args[0])
- if team == nil {
- return errors.New("Unable to find team '" + args[0] + "'")
- }
-
- fileReader, err := os.Open(args[1])
- if err != nil {
- return err
- }
- defer fileReader.Close()
-
- fileInfo, err := fileReader.Stat()
- if err != nil {
- return err
- }
-
- cmd.CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
-
- a.SlackImport(fileReader, fileInfo.Size(), team.Id)
-
- cmd.CommandPrettyPrintln("Finished Slack Import.")
-
- return nil
-}
-
-func bulkImportCmdF(command *cobra.Command, args []string) error {
- a, err := cmd.InitDBCommandContextCobra(command)
- if err != nil {
- return err
- }
- defer a.Shutdown()
-
- apply, err := command.Flags().GetBool("apply")
- if err != nil {
- return errors.New("Apply flag error")
- }
-
- validate, err := command.Flags().GetBool("validate")
- if err != nil {
- return errors.New("Validate flag error")
- }
-
- workers, err := command.Flags().GetInt("workers")
- if err != nil {
- return errors.New("Workers flag error")
- }
-
- if len(args) != 1 {
- return errors.New("Incorrect number of arguments.")
- }
-
- fileReader, err := os.Open(args[0])
- if err != nil {
- return err
- }
- defer fileReader.Close()
-
- if apply && validate {
- cmd.CommandPrettyPrintln("Use only one of --apply or --validate.")
- return nil
- } else if apply && !validate {
- cmd.CommandPrettyPrintln("Running Bulk Import. This may take a long time.")
- } else {
- cmd.CommandPrettyPrintln("Running Bulk Import Data Validation.")
- cmd.CommandPrettyPrintln("** This checks the validity of the entities in the data file, but does not persist any changes **")
- cmd.CommandPrettyPrintln("Use the --apply flag to perform the actual data import.")
- }
-
- cmd.CommandPrettyPrintln("")
-
- if err, lineNumber := a.BulkImport(fileReader, !apply, workers); err != nil {
- cmd.CommandPrettyPrintln(err.Error())
- if lineNumber != 0 {
- cmd.CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
- }
- return err
- } else {
- if apply {
- cmd.CommandPrettyPrintln("Finished Bulk Import.")
- } else {
- cmd.CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
- }
- }
-
- return nil
-}