From 260d7a0f850a6f772b14b011022f1f65213a08a1 Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Fri, 1 Jun 2018 12:45:46 -0400 Subject: MM-10412: Adds deleteBy prop to posts. (#8896) --- store/sqlstore/post_store.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'store/sqlstore') diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index e4872fe11..229005b73 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -398,11 +398,24 @@ func (s *SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.Stor }) } -func (s *SqlPostStore) Delete(postId string, time int64) store.StoreChannel { +func (s *SqlPostStore) Delete(postId string, time int64, deleteByID string) store.StoreChannel { return store.Do(func(result *store.StoreResult) { - _, err := s.GetMaster().Exec("Update Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId}) + + appErr := func(errMsg string) *model.AppError { + return model.NewAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+errMsg, http.StatusInternalServerError) + } + + var post model.Post + err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": postId}) + if err != nil { + result.Err = appErr(err.Error()) + } + + post.Props[model.POST_PROPS_DELETE_BY] = deleteByID + + _, err = s.GetMaster().Exec("UPDATE Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt, Props = :Props WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId, "Props": model.StringInterfaceToJson(post.Props)}) if err != nil { - result.Err = model.NewAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+err.Error(), http.StatusInternalServerError) + result.Err = appErr(err.Error()) } }) } -- cgit v1.2.3-1-g7c22