Migrate PermanentDeleteByTeam method from ChannelStore to return erro… (#14707)

Automatic Merge
Этот коммит содержится в:
Rodrigo Villablanca
2020-06-11 11:26:35 -04:00
коммит произвёл GitHub
родитель 77b468e456
Коммит 172eb1853f
7 изменённых файлов: 16 добавлений и 34 удалений

Просмотреть файл

@@ -6258,22 +6258,6 @@
"id": "store.sql_channel.migrate_channel_members.update.app_error", "id": "store.sql_channel.migrate_channel_members.update.app_error",
"translation": "Failed to update the channel member." "translation": "Failed to update the channel member."
}, },
{
"id": "store.sql_channel.permanent_delete_by_team.app_error",
"translation": "Unable to delete the channels."
},
{
"id": "store.sql_channel.permanent_delete_by_team.commit_transaction.app_error",
"translation": "Unable to commit transaction."
},
{
"id": "store.sql_channel.permanent_delete_by_team.delete_public_channels.app_error",
"translation": "Unable to delete materialized public channels."
},
{
"id": "store.sql_channel.permanent_delete_by_team.open_transaction.app_error",
"translation": "Unable to open transaction."
},
{ {
"id": "store.sql_channel.permanent_delete_members_by_user.app_error", "id": "store.sql_channel.permanent_delete_members_by_user.app_error",
"translation": "Unable to remove the channel member." "translation": "Unable to remove the channel member."

Просмотреть файл

@@ -1521,7 +1521,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDelete(channelId string) error {
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (s *OpenTracingLayerChannelStore) PermanentDeleteByTeam(teamId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteByTeam") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteByTeam")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)

Просмотреть файл

@@ -826,15 +826,15 @@ func (s SqlChannelStore) setDeleteAtT(transaction *gorp.Transaction, channelId s
} }
// PermanentDeleteByTeam removes all channels for the given team from the database. // PermanentDeleteByTeam removes all channels for the given team from the database.
func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) error {
transaction, err := s.GetMaster().Begin() transaction, err := s.GetMaster().Begin()
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "PermanentDeleteByTeam: begin_transaction")
} }
defer finalizeTransaction(transaction) defer finalizeTransaction(transaction)
if err := s.permanentDeleteByTeamtT(transaction, teamId); err != nil { if err := s.permanentDeleteByTeamtT(transaction, teamId); err != nil {
return err return errors.Wrap(err, "permanentDeleteByTeamtT")
} }
// Additionally propagate the deletions to the PublicChannels table. // Additionally propagate the deletions to the PublicChannels table.
@@ -846,19 +846,19 @@ func (s SqlChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError {
`, map[string]interface{}{ `, map[string]interface{}{
"TeamId": teamId, "TeamId": teamId,
}); err != nil { }); err != nil {
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeamt", "store.sql_channel.permanent_delete_by_team.delete_public_channels.app_error", nil, "team_id="+teamId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete public channels by team with teamId=%s", teamId)
} }
if err := transaction.Commit(); err != nil { if err := transaction.Commit(); err != nil {
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "PermanentDeleteByTeam: commit_transaction")
} }
return nil return nil
} }
func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction, teamId string) *model.AppError { func (s SqlChannelStore) permanentDeleteByTeamtT(transaction *gorp.Transaction, teamId string) error {
if _, err := transaction.Exec("DELETE FROM Channels WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil { if _, err := transaction.Exec("DELETE FROM Channels WHERE TeamId = :TeamId", map[string]interface{}{"TeamId": teamId}); err != nil {
return model.NewAppError("SqlChannelStore.PermanentDeleteByTeam", "store.sql_channel.permanent_delete_by_team.app_error", nil, "teamId="+teamId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete channel by team with teamId=%s", teamId)
} }
return nil return nil

Просмотреть файл

@@ -142,7 +142,7 @@ type ChannelStore interface {
Restore(channelId string, time int64) error Restore(channelId string, time int64) error
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error SetDeleteAt(channelId string, deleteAt int64, updateAt int64) error
PermanentDelete(channelId string) error PermanentDelete(channelId string) error
PermanentDeleteByTeam(teamId string) *model.AppError PermanentDeleteByTeam(teamId string) error
GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *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) GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError)
GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError)

Просмотреть файл

@@ -628,8 +628,8 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) {
require.Equal(t, &model.ChannelList{}, list) require.Equal(t, &model.ChannelList{}, list)
} }
err = ss.Channel().PermanentDeleteByTeam(o1.TeamId) nErr = ss.Channel().PermanentDeleteByTeam(o1.TeamId)
require.Nil(t, err, err) require.Nil(t, nErr, nErr)
} }
func testChannelStoreGetByName(t *testing.T, ss store.Store) { func testChannelStoreGetByName(t *testing.T, ss store.Store) {

Просмотреть файл

@@ -1278,16 +1278,14 @@ func (_m *ChannelStore) PermanentDelete(channelId string) error {
} }
// PermanentDeleteByTeam provides a mock function with given fields: teamId // PermanentDeleteByTeam provides a mock function with given fields: teamId
func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) error {
ret := _m.Called(teamId) ret := _m.Called(teamId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(teamId) r0 = rf(teamId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0

Просмотреть файл

@@ -1425,7 +1425,7 @@ func (s *TimerLayerChannelStore) PermanentDelete(channelId string) error {
return resultVar0 return resultVar0
} }
func (s *TimerLayerChannelStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (s *TimerLayerChannelStore) PermanentDeleteByTeam(teamId string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.ChannelStore.PermanentDeleteByTeam(teamId) resultVar0 := s.ChannelStore.PermanentDeleteByTeam(teamId)