github.com/vnforks/kid@v5.11.1+incompatible/cmd/mattermost/commands/init.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package commands
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/app"
     8  	"github.com/mattermost/mattermost-server/model"
     9  	"github.com/mattermost/mattermost-server/utils"
    10  	"github.com/mattermost/viper"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  func InitDBCommandContextCobra(command *cobra.Command) (*app.App, error) {
    15  	config := viper.GetString("config")
    16  
    17  	a, err := InitDBCommandContext(config)
    18  
    19  	if err != nil {
    20  		// Returning an error just prints the usage message, so actually panic
    21  		panic(err)
    22  	}
    23  
    24  	a.InitPlugins(*a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
    25  	a.DoAdvancedPermissionsMigration()
    26  	a.DoEmojisPermissionsMigration()
    27  	a.DoPermissionsMigrations()
    28  
    29  	return a, nil
    30  }
    31  
    32  func InitDBCommandContext(configDSN string) (*app.App, error) {
    33  	if err := utils.TranslationsPreInit(); err != nil {
    34  		return nil, err
    35  	}
    36  	model.AppErrorInit(utils.T)
    37  
    38  	s, err := app.NewServer(
    39  		app.Config(configDSN, false),
    40  		app.StartElasticsearch,
    41  	)
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	a := s.FakeApp()
    47  
    48  	if model.BuildEnterpriseReady == "true" {
    49  		a.LoadLicense()
    50  	}
    51  
    52  	return a, nil
    53  }