summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-08-26 12:49:07 -0400
committerChristopher Speller <crspeller@gmail.com>2015-09-04 11:11:38 -0400
commitf0fd9a9e8b85544089246bde71b6d61ba90eeb0e (patch)
tree256896117078ef1396a52fcecf3116863b3bb716 /store
parent1b923528448eace438a1f498116a19361a8b0fb2 (diff)
downloadchat-f0fd9a9e8b85544089246bde71b6d61ba90eeb0e.tar.gz
chat-f0fd9a9e8b85544089246bde71b6d61ba90eeb0e.tar.bz2
chat-f0fd9a9e8b85544089246bde71b6d61ba90eeb0e.zip
Adding ability to export data from mattermost
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go22
-rw-r--r--store/sql_post_store.go24
-rw-r--r--store/sql_team_store.go20
-rw-r--r--store/sql_user_store.go27
-rw-r--r--store/store.go4
5 files changed, 97 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index d2e3943df..b58166fd6 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -678,3 +678,25 @@ func (s SqlChannelStore) UpdateNotifyLevel(channelId, userId, notifyLevel string
return storeChannel
}
+
+func (s SqlChannelStore) GetForExport(teamId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var data []*model.Channel
+ _, err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND Type = 'O'", map[string]interface{}{"TeamId": teamId})
+
+ if err != nil {
+ result.Err = model.NewAppError("SqlChannelStore.GetAllChannels", "We couldn't get all the channels", "teamId="+teamId+", err="+err.Error())
+ } else {
+ result.Data = data
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 297d60397..20de23eb7 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -506,3 +506,27 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht
return storeChannel
}
+
+func (s SqlPostStore) GetForExport(channelId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var posts []*model.Post
+ _, err := s.GetReplica().Select(
+ &posts,
+ "SELECT * FROM Posts WHERE ChannelId = :ChannelId AND DeleteAt = 0",
+ map[string]interface{}{"ChannelId": channelId})
+ if err != nil {
+ result.Err = model.NewAppError("SqlPostStore.GetForExport", "We couldn't get the posts for the channel", "channelId="+channelId+err.Error())
+ } else {
+ result.Data = posts
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_team_store.go b/store/sql_team_store.go
index 2784f8630..fcbcaab9f 100644
--- a/store/sql_team_store.go
+++ b/store/sql_team_store.go
@@ -193,3 +193,23 @@ func (s SqlTeamStore) GetTeamsForEmail(email string) StoreChannel {
return storeChannel
}
+
+func (s SqlTeamStore) GetForExport() StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var data []*model.Team
+ if _, err := s.GetReplica().Select(&data, "SELECT * FROM Teams"); err != nil {
+ result.Err = model.NewAppError("SqlTeamStore.GetForExport", "We could not get all teams", err.Error())
+ }
+
+ result.Data = data
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 64a18545a..be1d29df0 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -452,3 +452,30 @@ func (us SqlUserStore) VerifyEmail(userId string) StoreChannel {
return storeChannel
}
+
+func (us SqlUserStore) GetForExport(teamId string) StoreChannel {
+
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var users []*model.User
+
+ if _, err := us.GetReplica().Select(&users, "SELECT * FROM Users WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil {
+ result.Err = model.NewAppError("SqlUserStore.GetProfiles", "We encounted an error while finding user profiles", err.Error())
+ } else {
+ for _, u := range users {
+ u.Password = ""
+ u.AuthData = ""
+ }
+
+ result.Data = users
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/store.go b/store/store.go
index 271caa366..959e93fa4 100644
--- a/store/store.go
+++ b/store/store.go
@@ -44,6 +44,7 @@ type TeamStore interface {
Get(id string) StoreChannel
GetByName(name string) StoreChannel
GetTeamsForEmail(domain string) StoreChannel
+ GetForExport() StoreChannel
}
type ChannelStore interface {
@@ -55,6 +56,7 @@ type ChannelStore interface {
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
+ GetForExport(teamId string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel
GetMembers(channelId string) StoreChannel
@@ -78,6 +80,7 @@ type PostStore interface {
GetPostsSince(channelId string, time int64) StoreChannel
GetEtag(channelId string) StoreChannel
Search(teamId string, userId string, terms string, isHashtagSearch bool) StoreChannel
+ GetForExport(channelId string) StoreChannel
}
type UserStore interface {
@@ -96,6 +99,7 @@ type UserStore interface {
VerifyEmail(userId string) StoreChannel
GetEtagForProfiles(teamId string) StoreChannel
UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel
+ GetForExport(teamId string) StoreChannel
}
type SessionStore interface {