Migrates Channel.ResetAllChannelSchemes to sync by default (#11275)

Этот коммит содержится в:
Rodrigo Villablanca Vásquez
2019-06-20 16:52:24 -04:00
коммит произвёл Jesús Espino
родитель 41e5ec3c5e
Коммит a760f32526
5 изменённых файлов: 31 добавлений и 36 удалений

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

@@ -23,8 +23,8 @@ func (a *App) ResetPermissionsSystem() *model.AppError {
} }
// Reset all Channels to not have a scheme. // Reset all Channels to not have a scheme.
if result := <-a.Srv.Store.Channel().ResetAllChannelSchemes(); result.Err != nil { if err := a.Srv.Store.Channel().ResetAllChannelSchemes(); err != nil {
return result.Err return err
} }
// Reset all Custom Role assignments to Users. // Reset all Custom Role assignments to Users.

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

@@ -2340,36 +2340,31 @@ func (s SqlChannelStore) MigrateChannelMembers(fromChannelId string, fromUserId
return data, nil return data, nil
} }
func (s SqlChannelStore) ResetAllChannelSchemes() store.StoreChannel { func (s SqlChannelStore) ResetAllChannelSchemes() *model.AppError {
return store.Do(func(result *store.StoreResult) { transaction, err := s.GetMaster().Begin()
transaction, err := s.GetMaster().Begin() if err != nil {
if err != nil { return model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
result.Err = model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) }
return defer finalizeTransaction(transaction)
}
defer finalizeTransaction(transaction)
*result = s.resetAllChannelSchemesT(transaction) resetErr := s.resetAllChannelSchemesT(transaction)
if result.Err != nil { if resetErr != nil {
return return resetErr
}
if err := transaction.Commit(); err != nil {
result.Err = model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
})
}
func (s SqlChannelStore) resetAllChannelSchemesT(transaction *gorp.Transaction) store.StoreResult {
result := store.StoreResult{}
if _, err := transaction.Exec("UPDATE Channels SET SchemeId=''"); err != nil {
result.Err = model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.app_error", nil, err.Error(), http.StatusInternalServerError)
return result
} }
return result if err := transaction.Commit(); err != nil {
return model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
}
func (s SqlChannelStore) resetAllChannelSchemesT(transaction *gorp.Transaction) *model.AppError {
if _, err := transaction.Exec("UPDATE Channels SET SchemeId=''"); err != nil {
return model.NewAppError("SqlChannelStore.ResetAllChannelSchemes", "store.sql_channel.reset_all_channel_schemes.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
} }
func (s SqlChannelStore) ClearAllCustomRoleAssignments() *model.AppError { func (s SqlChannelStore) ClearAllCustomRoleAssignments() *model.AppError {

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

@@ -191,7 +191,7 @@ type ChannelStore interface {
ClearCaches() ClearCaches()
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError) MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError)
ResetAllChannelSchemes() StoreChannel ResetAllChannelSchemes() *model.AppError
ClearAllCustomRoleAssignments() *model.AppError ClearAllCustomRoleAssignments() *model.AppError
MigratePublicChannels() error MigratePublicChannels() error
GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, *model.AppError) GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, *model.AppError)

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

@@ -3037,8 +3037,8 @@ func testResetAllChannelSchemes(t *testing.T, ss store.Store) {
assert.Equal(t, s1.Id, *c1.SchemeId) assert.Equal(t, s1.Id, *c1.SchemeId)
assert.Equal(t, s1.Id, *c2.SchemeId) assert.Equal(t, s1.Id, *c2.SchemeId)
res := <-ss.Channel().ResetAllChannelSchemes() err := ss.Channel().ResetAllChannelSchemes()
assert.Nil(t, res.Err) assert.Nil(t, err)
c1, _ = ss.Channel().Get(c1.Id, true) c1, _ = ss.Channel().Get(c1.Id, true)
c2, _ = ss.Channel().Get(c2.Id, true) c2, _ = ss.Channel().Get(c2.Id, true)

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

@@ -1161,15 +1161,15 @@ func (_m *ChannelStore) RemoveMember(channelId string, userId string) *model.App
} }
// ResetAllChannelSchemes provides a mock function with given fields: // ResetAllChannelSchemes provides a mock function with given fields:
func (_m *ChannelStore) ResetAllChannelSchemes() store.StoreChannel { func (_m *ChannelStore) ResetAllChannelSchemes() *model.AppError {
ret := _m.Called() ret := _m.Called()
var r0 store.StoreChannel var r0 *model.AppError
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok { if rf, ok := ret.Get(0).(func() *model.AppError); ok {
r0 = rf() r0 = rf()
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.AppError)
} }
} }