Cleanup usage of global logger (#26835)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
92a6c6517d
Коммит
30d450c4d8
@@ -84,7 +84,7 @@ func filterNotificationData(data []*model.NotifyAdminData, test func(*model.Noti
|
||||
}
|
||||
|
||||
func (a *App) SendNotifyAdminPosts(c request.CTX, workspaceName string, currentSKU string, trial bool) *model.AppError {
|
||||
if !a.CanNotifyAdmin(trial) {
|
||||
if !a.CanNotifyAdmin(c, trial) {
|
||||
return model.NewAppError("SendNotifyAdminPosts", "app.notify_admin.send_notification_post.app_error", nil, "Cannot notify yet", http.StatusForbidden)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func (a *App) SendNotifyAdminPosts(c request.CTX, workspaceName string, currentS
|
||||
data = filterNotificationData(data, func(nad *model.NotifyAdminData) bool { return nad.RequiredPlan != currentSKU })
|
||||
|
||||
if len(data) == 0 {
|
||||
a.Log().Warn("No notification data available")
|
||||
c.Logger().Warn("No notification data available")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func (a *App) SendNotifyAdminPosts(c request.CTX, workspaceName string, currentS
|
||||
}
|
||||
}
|
||||
|
||||
a.FinishSendAdminNotifyPost(trial, now, pluginBasedData)
|
||||
a.FinishSendAdminNotifyPost(c, trial, now, pluginBasedData)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (a *App) pluginInstallAdminNotifyPost(c request.CTX, userBasedData map[stri
|
||||
|
||||
channel, appErr := a.GetOrCreateDirectChannel(c, systemBot.UserId, admin.Id)
|
||||
if appErr != nil {
|
||||
a.Log().Warn("Error getting direct channel", mlog.Err(appErr))
|
||||
c.Logger().Warn("Error getting direct channel", mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ func (a *App) pluginInstallAdminNotifyPost(c request.CTX, userBasedData map[stri
|
||||
|
||||
_, appErr = a.CreatePost(c, post, channel, false, true)
|
||||
if appErr != nil {
|
||||
a.Log().Warn("Error creating post", mlog.Err(appErr))
|
||||
c.Logger().Warn("Error creating post", mlog.Err(appErr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (a *App) upgradePlanAdminNotifyPost(c request.CTX, workspaceName string, us
|
||||
|
||||
channel, appErr := a.GetOrCreateDirectChannel(c, systemBot.UserId, admin.Id)
|
||||
if appErr != nil {
|
||||
a.Log().Warn("Error getting direct channel", mlog.Err(appErr))
|
||||
c.Logger().Warn("Error getting direct channel", mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ func (a *App) upgradePlanAdminNotifyPost(c request.CTX, workspaceName string, us
|
||||
_, appErr = a.CreatePost(c, post, channel, false, true)
|
||||
|
||||
if appErr != nil {
|
||||
a.Log().Warn("Error creating post", mlog.Err(appErr))
|
||||
c.Logger().Warn("Error creating post", mlog.Err(appErr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func (a *App) UserAlreadyNotifiedOnRequiredFeature(user string, feature model.Ma
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *App) CanNotifyAdmin(trial bool) bool {
|
||||
func (a *App) CanNotifyAdmin(rctx request.CTX, trial bool) bool {
|
||||
systemVarName := lastUpgradeNotificationTimeStamp
|
||||
if trial {
|
||||
systemVarName = lastTrialNotificationTimeStamp
|
||||
@@ -224,13 +224,13 @@ func (a *App) CanNotifyAdmin(trial bool) bool {
|
||||
if errors.As(sysValErr, &nfErr) { // if no timestamps have been recorded before, system is free to notify
|
||||
return true
|
||||
}
|
||||
a.Log().Error("Cannot notify", mlog.Err(sysValErr))
|
||||
rctx.Logger().Error("Cannot notify", mlog.Err(sysValErr))
|
||||
return false
|
||||
}
|
||||
|
||||
lastNotificationTimestamp, err := strconv.ParseFloat(sysVal.Value, 64)
|
||||
if err != nil {
|
||||
a.Log().Error("Cannot notify", mlog.Err(err))
|
||||
rctx.Logger().Error("Cannot notify", mlog.Err(err))
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ func (a *App) CanNotifyAdmin(trial bool) bool {
|
||||
return timeDiff >= int64(daysToMillis)
|
||||
}
|
||||
|
||||
func (a *App) FinishSendAdminNotifyPost(trial bool, now int64, pluginBasedData map[string][]*model.NotifyAdminData) {
|
||||
func (a *App) FinishSendAdminNotifyPost(rctx request.CTX, trial bool, now int64, pluginBasedData map[string][]*model.NotifyAdminData) {
|
||||
systemVarName := lastUpgradeNotificationTimeStamp
|
||||
if trial {
|
||||
systemVarName = lastTrialNotificationTimeStamp
|
||||
@@ -253,7 +253,7 @@ func (a *App) FinishSendAdminNotifyPost(trial bool, now int64, pluginBasedData m
|
||||
val := strconv.FormatInt(model.GetMillis(), 10)
|
||||
sysVar := &model.System{Name: systemVarName, Value: val}
|
||||
if err := a.Srv().Store().System().SaveOrUpdate(sysVar); err != nil {
|
||||
a.Log().Error("Unable to finish send admin notify post job", mlog.Err(err))
|
||||
rctx.Logger().Error("Unable to finish send admin notify post job", mlog.Err(err))
|
||||
}
|
||||
|
||||
// All the requested features notifications are now sent in a post and can safely be removed except
|
||||
@@ -266,13 +266,13 @@ func (a *App) FinishSendAdminNotifyPost(trial bool, now int64, pluginBasedData m
|
||||
requiredPlan := notification.RequiredPlan
|
||||
userId := notification.UserId
|
||||
if err := a.Srv().Store().NotifyAdmin().Update(userId, requiredPlan, requiredFeature, now); err != nil {
|
||||
a.Log().Error("Unable to update SentAt for work template feature", mlog.Err(err))
|
||||
rctx.Logger().Error("Unable to update SentAt for work template feature", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Srv().Store().NotifyAdmin().DeleteBefore(trial, now); err != nil {
|
||||
a.Log().Error("Unable to finish send admin notify post job", mlog.Err(err))
|
||||
rctx.Logger().Error("Unable to finish send admin notify post job", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user