Migrate Delete/Restore/SetDeleteAt methods from ChannelStore to return error interface (#14700)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
18ddae2c1b
Коммит
ac32b2da41
@@ -770,28 +770,28 @@ func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*mode
|
||||
}
|
||||
|
||||
// Delete records the given deleted timestamp to the channel in question.
|
||||
func (s SqlChannelStore) Delete(channelId string, time int64) *model.AppError {
|
||||
func (s SqlChannelStore) Delete(channelId string, time int64) error {
|
||||
return s.SetDeleteAt(channelId, time, time)
|
||||
}
|
||||
|
||||
// Restore reverts a previous deleted timestamp from the channel in question.
|
||||
func (s SqlChannelStore) Restore(channelId string, time int64) *model.AppError {
|
||||
func (s SqlChannelStore) Restore(channelId string, time int64) error {
|
||||
return s.SetDeleteAt(channelId, 0, time)
|
||||
}
|
||||
|
||||
// SetDeleteAt records the given deleted and updated timestamp to the channel in question.
|
||||
func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt, updateAt int64) *model.AppError {
|
||||
func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt, updateAt int64) error {
|
||||
defer s.InvalidateChannel(channelId)
|
||||
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlChannelStore.SetDeleteAt", "store.sql_channel.set_delete_at.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrap(err, "SetDeleteAt: begin_transaction")
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
appErr := s.setDeleteAtT(transaction, channelId, deleteAt, updateAt)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
err = s.setDeleteAtT(transaction, channelId, deleteAt, updateAt)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "setDeleteAtT")
|
||||
}
|
||||
|
||||
// Additionally propagate the write to the PublicChannels table.
|
||||
@@ -806,20 +806,20 @@ func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt, updateAt int64)
|
||||
"DeleteAt": deleteAt,
|
||||
"ChannelId": channelId,
|
||||
}); err != nil {
|
||||
return model.NewAppError("SqlChannelStore.SetDeleteAt", "store.sql_channel.set_delete_at.update_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.SetDeleteAt", "store.sql_channel.set_delete_at.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "SetDeleteAt: commit_transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) setDeleteAtT(transaction *gorp.Transaction, channelId string, deleteAt, updateAt int64) *model.AppError {
|
||||
func (s SqlChannelStore) setDeleteAtT(transaction *gorp.Transaction, channelId string, deleteAt, updateAt int64) error {
|
||||
_, err := transaction.Exec("Update Channels SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :ChannelId", map[string]interface{}{"DeleteAt": deleteAt, "UpdateAt": updateAt, "ChannelId": channelId})
|
||||
if err != nil {
|
||||
return model.NewAppError("SqlChannelStore.Delete", "store.sql_channel.delete.channel.app_error", nil, "id="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
return errors.Wrapf(err, "failed to delete channel with id=%s", channelId)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Ссылка в новой задаче
Block a user