mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrates Channel.GetDeletedByName to sync by default (#11203)
This commit is contained in:
committed by
Jesús Espino
parent
e9e65fe8bb
commit
9ad2dd9514
@@ -510,7 +510,7 @@ func (a *App) SlackAddChannels(teamId string, slackchannels []SlackChannel, post
|
||||
if mChannel, err = a.Srv.Store.Channel().GetByName(teamId, sChannel.Name, true); err == nil {
|
||||
// The channel already exists as an active channel. Merge with the existing one.
|
||||
importerLog.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
|
||||
} else if result := <-a.Srv.Store.Channel().GetDeletedByName(teamId, sChannel.Name); result.Err == nil {
|
||||
} else if _, err := a.Srv.Store.Channel().GetDeletedByName(teamId, sChannel.Name); err == nil {
|
||||
// The channel already exists but has been deleted. Generate a random string for the handle instead.
|
||||
newChannel.Name = model.NewId()
|
||||
newChannel = SlackSanitiseChannelProperties(newChannel)
|
||||
|
||||
@@ -1231,21 +1231,17 @@ func (s SqlChannelStore) getByName(teamId string, name string, includeDeleted bo
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetDeletedByName(teamId string, name string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
channel := model.Channel{}
|
||||
func (s SqlChannelStore) GetDeletedByName(teamId string, name string) (*model.Channel, *model.AppError) {
|
||||
channel := model.Channel{}
|
||||
|
||||
if err := s.GetReplica().SelectOne(&channel, "SELECT * FROM Channels WHERE (TeamId = :TeamId OR TeamId = '') AND Name = :Name AND DeleteAt != 0", map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.missing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
result.Err = model.NewAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.existing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
if err := s.GetReplica().SelectOne(&channel, "SELECT * FROM Channels WHERE (TeamId = :TeamId OR TeamId = '') AND Name = :Name AND DeleteAt != 0", map[string]interface{}{"TeamId": teamId, "Name": name}); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.missing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusNotFound)
|
||||
}
|
||||
return nil, model.NewAppError("SqlChannelStore.GetDeletedByName", "store.sql_channel.get_deleted_by_name.existing.app_error", nil, "teamId="+teamId+", "+"name="+name+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
result.Data = &channel
|
||||
})
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
|
||||
@@ -145,7 +145,7 @@ type ChannelStore interface {
|
||||
GetByName(team_id string, name 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)
|
||||
GetDeletedByName(team_id string, name string) StoreChannel
|
||||
GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError)
|
||||
GetDeleted(team_id string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||
GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||
GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError)
|
||||
|
||||
@@ -751,15 +751,15 @@ func testChannelStoreGetDeletedByName(t *testing.T, ss store.Store) {
|
||||
o1.DeleteAt = now
|
||||
o1.UpdateAt = now
|
||||
|
||||
if r1 := <-ss.Channel().GetDeletedByName(o1.TeamId, o1.Name); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Channel().GetDeletedByName(o1.TeamId, o1.Name); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
|
||||
if r1.ToJson() != o1.ToJson() {
|
||||
t.Fatal("invalid returned channel")
|
||||
}
|
||||
}
|
||||
|
||||
if err := (<-ss.Channel().GetDeletedByName(o1.TeamId, "")).Err; err == nil {
|
||||
if _, err := ss.Channel().GetDeletedByName(o1.TeamId, ""); err == nil {
|
||||
t.Fatal("Missing id should have failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,19 +620,28 @@ func (_m *ChannelStore) GetDeleted(team_id string, offset int, limit int) (*mode
|
||||
}
|
||||
|
||||
// GetDeletedByName provides a mock function with given fields: team_id, name
|
||||
func (_m *ChannelStore) GetDeletedByName(team_id string, name string) store.StoreChannel {
|
||||
func (_m *ChannelStore) GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError) {
|
||||
ret := _m.Called(team_id, name)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 *model.Channel
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.Channel); ok {
|
||||
r0 = rf(team_id, name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||
r1 = rf(team_id, name)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetForPost provides a mock function with given fields: postId
|
||||
|
||||
Reference in New Issue
Block a user