Migrate PermanentDelete method from ChannelStore to return error inte… (#14706)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
88e8f56f03
Коммит
6f28f3526d
@@ -2296,8 +2296,8 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Channel().PermanentDelete(channel.Id); err != nil {
|
||||
return err
|
||||
if nErr := a.Srv().Store.Channel().PermanentDelete(channel.Id); nErr != nil {
|
||||
return model.NewAppError("PermanentDeleteChannel", "app.channel.permanent_delete.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
20
i18n/en.json
20
i18n/en.json
@@ -3002,6 +3002,10 @@
|
||||
"id": "app.channel.move_channel.members_do_not_match.error",
|
||||
"translation": "Unable to move a channel unless all its members are already members of the destination team."
|
||||
},
|
||||
{
|
||||
"id": "app.channel.permanent_delete.app_error",
|
||||
"translation": "Unable to delete the channel."
|
||||
},
|
||||
{
|
||||
"id": "app.channel.post_update_channel_purpose_message.post.error",
|
||||
"translation": "Failed to post channel purpose message"
|
||||
@@ -6246,22 +6250,6 @@
|
||||
"id": "store.sql_channel.migrate_channel_members.update.app_error",
|
||||
"translation": "Failed to update the channel member."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.permanent_delete.app_error",
|
||||
"translation": "Unable to delete the channel."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.permanent_delete.commit_transaction.app_error",
|
||||
"translation": "Unable to commit transaction."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.permanent_delete.delete_public_channel.app_error",
|
||||
"translation": "Unable to delete materialized public channel."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.permanent_delete.open_transaction.app_error",
|
||||
"translation": "Unable to open transaction."
|
||||
},
|
||||
{
|
||||
"id": "store.sql_channel.permanent_delete_by_team.app_error",
|
||||
"translation": "Unable to delete the channels."
|
||||
|
||||
@@ -1503,7 +1503,7 @@ func (s *OpenTracingLayerChannelStore) MigratePublicChannels() error {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) *model.AppError {
|
||||
func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) error {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDelete")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
|
||||
@@ -194,7 +194,7 @@ func (c *SearchChannelStore) PermanentDeleteMembersByChannel(channelId string) *
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *SearchChannelStore) PermanentDelete(channelId string) *model.AppError {
|
||||
func (c *SearchChannelStore) PermanentDelete(channelId string) error {
|
||||
channel, channelErr := c.ChannelStore.Get(channelId, true)
|
||||
if channelErr != nil {
|
||||
mlog.Error("Encountered error deleting channel", mlog.String("channel_id", channelId), mlog.Err(channelErr))
|
||||
|
||||
@@ -317,9 +317,9 @@ func (th *SearchTestHelper) deleteChannel(channel *model.Channel) error {
|
||||
return errors.New(appError.Error())
|
||||
}
|
||||
|
||||
appError = th.Store.Channel().PermanentDelete(channel.Id)
|
||||
if appError != nil {
|
||||
return errors.New(appError.Error())
|
||||
err := th.Store.Channel().PermanentDelete(channel.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -865,15 +865,15 @@ func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction,
|
||||
}
|
||||
|
||||
// PermanentDelete removes the given channel from the database.
|
||||
func (s SqlChannelStore) PermanentDelete(channelId string) *model.AppError {
|
||||
func (s SqlChannelStore) PermanentDelete(channelId string) error {
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrap(err, "PermanentDelete: begin_transaction")
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
if err := s.permanentDeleteT(transaction, channelId); err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "permanentDeleteT")
|
||||
}
|
||||
|
||||
// Additionally propagate the deletion to the PublicChannels table.
|
||||
@@ -885,19 +885,19 @@ func (s SqlChannelStore) PermanentDelete(channelId string) *model.AppError {
|
||||
`, map[string]interface{}{
|
||||
"ChannelId": channelId,
|
||||
}); err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.delete_public_channel.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "failed to delete public channels with id=%s", channelId)
|
||||
}
|
||||
|
||||
if err := transaction.Commit(); err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrap(err, "PermanentDelete: commit_transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channelId string) *model.AppError {
|
||||
func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channelId string) error {
|
||||
if _, err := transaction.Exec("DELETE FROM Channels WHERE Id = :ChannelId", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
||||
return model.NewAppError("SqlChannelStore.PermanentDelete", "store.sql_channel.permanent_delete.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "failed to delete channel with id=%s", channelId)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -141,7 +141,7 @@ type ChannelStore interface {
|
||||
Delete(channelId string, time int64) error
|
||||
Restore(channelId string, time int64) error
|
||||
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error
|
||||
PermanentDelete(channelId string) *model.AppError
|
||||
PermanentDelete(channelId string) error
|
||||
PermanentDeleteByTeam(teamId string) *model.AppError
|
||||
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)
|
||||
GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError)
|
||||
|
||||
@@ -31,8 +31,8 @@ func cleanupStoreState(t *testing.T, ss store.Store) {
|
||||
allChannels, err := ss.Channel().GetAllChannels(0, 100000, store.ChannelSearchOpts{IncludeDeleted: true})
|
||||
require.Nilf(t, err, "error cleaning all test channels: %v", err)
|
||||
for _, channel := range *allChannels {
|
||||
err = ss.Channel().PermanentDelete(channel.Id)
|
||||
require.Nil(t, err, "failed cleaning up test channel %s", channel.Id)
|
||||
nErr := ss.Channel().PermanentDelete(channel.Id)
|
||||
require.Nil(t, nErr, "failed cleaning up test channel %s", channel.Id)
|
||||
}
|
||||
|
||||
//remove existing teams
|
||||
|
||||
@@ -1272,16 +1272,14 @@ func (_m *ChannelStore) MigratePublicChannels() error {
|
||||
}
|
||||
|
||||
// PermanentDelete provides a mock function with given fields: channelId
|
||||
func (_m *ChannelStore) PermanentDelete(channelId string) *model.AppError {
|
||||
func (_m *ChannelStore) PermanentDelete(channelId string) error {
|
||||
ret := _m.Called(channelId)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(channelId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
|
||||
@@ -1409,7 +1409,7 @@ func (s *TimerLayerChannelStore) MigratePublicChannels() error {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (s *TimerLayerChannelStore) PermanentDelete(channelId string) *model.AppError {
|
||||
func (s *TimerLayerChannelStore) PermanentDelete(channelId string) error {
|
||||
start := timemodule.Now()
|
||||
|
||||
resultVar0 := s.ChannelStore.PermanentDelete(channelId)
|
||||
|
||||
Ссылка в новой задаче
Block a user