2015-10-08 12:27:09 -04:00
|
|
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
2015-07-07 09:16:13 -04:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
2016-01-11 09:12:51 -06:00
|
|
|
l4g "github.com/alecthomas/log4go"
|
2015-07-07 09:16:13 -04:00
|
|
|
"github.com/mattermost/platform/model"
|
2016-01-22 01:37:11 -03:00
|
|
|
"github.com/mattermost/platform/utils"
|
2015-07-07 09:16:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Import functions are sutible for entering posts and users into the database without
|
|
|
|
|
// some of the usual checks. (IsValid is still run)
|
|
|
|
|
//
|
|
|
|
|
|
2016-01-20 13:36:16 -06:00
|
|
|
func ImportPost(post *model.Post) {
|
2015-07-07 09:16:13 -04:00
|
|
|
post.Hashtags, _ = model.ParseHashtags(post.Message)
|
|
|
|
|
|
2016-01-20 13:36:16 -06:00
|
|
|
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
|
2016-01-22 01:37:11 -03:00
|
|
|
l4g.Debug(utils.T("api.import.import_post.saving.debug"), post.UserId, post.Message)
|
2015-07-07 09:16:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-21 22:37:01 -07:00
|
|
|
func ImportUser(teamId string, user *model.User) *model.User {
|
2015-07-07 09:16:13 -04:00
|
|
|
user.MakeNonNil()
|
|
|
|
|
|
2016-01-20 13:36:16 -06:00
|
|
|
if result := <-Srv.Store.User().Save(user); result.Err != nil {
|
2016-01-22 01:37:11 -03:00
|
|
|
l4g.Error(utils.T("api.import.import_user.saving.error"), result.Err)
|
2015-07-07 09:16:13 -04:00
|
|
|
return nil
|
|
|
|
|
} else {
|
|
|
|
|
ruser := result.Data.(*model.User)
|
|
|
|
|
|
2016-04-21 22:37:01 -07:00
|
|
|
if err := JoinDefaultChannels(teamId, ruser, ""); err != nil {
|
|
|
|
|
l4g.Error(utils.T("api.import.import_user.joining_default.error"), ruser.Id, teamId, err)
|
2015-07-07 09:16:13 -04:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 13:36:16 -06:00
|
|
|
if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
|
2016-01-22 01:37:11 -03:00
|
|
|
l4g.Error(utils.T("api.import.import_user.set_email.error"), cresult.Err)
|
2015-07-07 09:16:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ruser
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-20 13:36:16 -06:00
|
|
|
func ImportChannel(channel *model.Channel) *model.Channel {
|
|
|
|
|
if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
|
2015-07-07 09:16:13 -04:00
|
|
|
return nil
|
|
|
|
|
} else {
|
|
|
|
|
sc := result.Data.(*model.Channel)
|
|
|
|
|
|
|
|
|
|
return sc
|
|
|
|
|
}
|
|
|
|
|
}
|