summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/channel_store.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-09-17 15:51:26 +0100
committerGitHub <noreply@github.com>2018-09-17 15:51:26 +0100
commitab99f0656fabed8a62a8c6340be7d538cc7bf8d9 (patch)
treebb68ee1d0c743be23bba470f5d81ef11dc134182 /store/sqlstore/channel_store.go
parent5786b0d6d57b90bbb0c262235dd9d19b497b5fae (diff)
downloadchat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.tar.gz
chat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.tar.bz2
chat-ab99f0656fabed8a62a8c6340be7d538cc7bf8d9.zip
MM-11781: Basic Data Export Command Line. (#9296)
* MM-11781: Basic Data Export Command Line. * ChannelStore new unit tests. * TeamStore new unit tests. * Unit test for new UserStore function. * Unit tests for post store new methods. * Review fixes. * Fix duplicate command name.
Diffstat (limited to 'store/sqlstore/channel_store.go')
-rw-r--r--store/sqlstore/channel_store.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go
index 4103980c5..c0c1d2c8a 100644
--- a/store/sqlstore/channel_store.go
+++ b/store/sqlstore/channel_store.go
@@ -2016,3 +2016,57 @@ func (s SqlChannelStore) IsExperimentalPublicChannelsMaterializationEnabled() bo
// See SqlChannelStoreExperimental
return false
}
+
+func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string) store.StoreChannel {
+ return store.Do(func(result *store.StoreResult) {
+ var data []*model.ChannelForExport
+ if _, err := s.GetReplica().Select(&data, `
+ SELECT
+ Channels.*,
+ Teams.Name as TeamName,
+ Schemes.Name as SchemeName
+ FROM Channels
+ INNER JOIN
+ Teams ON Channels.TeamId = Teams.Id
+ LEFT JOIN
+ Schemes ON Channels.SchemeId = Schemes.Id
+ WHERE
+ Channels.Id > :AfterId
+ AND Channels.Type IN ('O', 'P')
+ ORDER BY
+ Id
+ LIMIT :Limit`,
+ map[string]interface{}{"AfterId": afterId, "Limit": limit}); err != nil {
+ result.Err = model.NewAppError("SqlTeamStore.GetAllChannelsForExportAfter", "store.sql_channel.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ result.Data = data
+ })
+}
+
+func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string) store.StoreChannel {
+ return store.Do(func(result *store.StoreResult) {
+ var members []*model.ChannelMemberForExport
+ _, err := s.GetReplica().Select(&members, `
+ SELECT
+ ChannelMembers.*,
+ Channels.Name as ChannelName
+ FROM
+ ChannelMembers
+ INNER JOIN
+ Channels ON ChannelMembers.ChannelId = Channels.Id
+ WHERE
+ ChannelMembers.UserId = :UserId
+ AND Channels.TeamId = :TeamId
+ AND Channels.DeleteAt = 0`,
+ map[string]interface{}{"TeamId": teamId, "UserId": userId})
+
+ if err != nil {
+ result.Err = model.NewAppError("SqlChannelStore.GetChannelMembersForExport", "store.sql_channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ result.Data = members
+ })
+}