diff options
author | George Goldberg <george@gberg.me> | 2017-02-28 23:55:21 +0000 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-02-28 20:55:21 -0300 |
commit | f7682ad11a3f27925b46ffc37fa66c6d4b6feef5 (patch) | |
tree | 0bba7bcb428599e847a9abfd9b003d1e7aa29982 /store/sql_post_store.go | |
parent | 48d124ec9aee139c00538b17c1cf978015641c8e (diff) | |
download | chat-f7682ad11a3f27925b46ffc37fa66c6d4b6feef5.tar.gz chat-f7682ad11a3f27925b46ffc37fa66c6d4b6feef5.tar.bz2 chat-f7682ad11a3f27925b46ffc37fa66c6d4b6feef5.zip |
PLT-5367: Basic post bulk importing. (#5562)
Diffstat (limited to 'store/sql_post_store.go')
-rw-r--r-- | store/sql_post_store.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 060a3b1cf..e224f60bd 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -12,6 +12,7 @@ import ( "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" + "net/http" ) type SqlPostStore struct { @@ -157,6 +158,33 @@ func (s SqlPostStore) Update(newPost *model.Post, oldPost *model.Post) StoreChan return storeChannel } +func (s SqlPostStore) Overwrite(post *model.Post) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + post.UpdateAt = model.GetMillis() + + if result.Err = post.IsValid(); result.Err != nil { + storeChannel <- result + close(storeChannel) + return + } + + if _, err := s.GetMaster().Update(post); err != nil { + result.Err = model.NewLocAppError("SqlPostStore.Overwrite", "store.sql_post.overwrite.app_error", nil, "id="+post.Id+", "+err.Error()) + } else { + result.Data = post + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlPostStore) GetFlaggedPosts(userId string, offset int, limit int) StoreChannel { storeChannel := make(StoreChannel, 1) go func() { @@ -1132,3 +1160,27 @@ func (s SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustH return storeChannel } + +func (s SqlPostStore) GetPostsCreatedAt(channelId string, time int64) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + query := `SELECT * FROM Posts WHERE CreateAt = :CreateAt` + + var posts []*model.Post + _, err := s.GetReplica().Select(&posts, query, map[string]interface{}{"CreateAt": time}) + + if err != nil { + result.Err = model.NewAppError("SqlPostStore.GetPostsCreatedAt", "store.sql_post.get_posts_created_att.app_error", nil, "channelId="+channelId+err.Error(), http.StatusInternalServerError) + } else { + result.Data = posts + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} |