app type transition (#7167)
Этот коммит содержится в:
@@ -12,11 +12,11 @@ import (
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func LoadLicense() {
|
||||
func (a *App) LoadLicense() {
|
||||
utils.RemoveLicense()
|
||||
|
||||
licenseId := ""
|
||||
if result := <-Srv.Store.System().Get(); result.Err == nil {
|
||||
if result := <-a.Srv.Store.System().Get(); result.Err == nil {
|
||||
props := result.Data.(model.StringMap)
|
||||
licenseId = props[model.SYSTEM_ACTIVE_LICENSE_ID]
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func LoadLicense() {
|
||||
license, licenseBytes := utils.GetAndValidateLicenseFileFromDisk()
|
||||
|
||||
if license != nil {
|
||||
if _, err := SaveLicense(licenseBytes); err != nil {
|
||||
if _, err := a.SaveLicense(licenseBytes); err != nil {
|
||||
l4g.Info("Failed to save license key loaded from disk err=%v", err.Error())
|
||||
} else {
|
||||
licenseId = license.Id
|
||||
@@ -34,7 +34,7 @@ func LoadLicense() {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.License().Get(licenseId); result.Err == nil {
|
||||
if result := <-a.Srv.Store.License().Get(licenseId); result.Err == nil {
|
||||
record := result.Data.(*model.LicenseRecord)
|
||||
utils.LoadLicense([]byte(record.Bytes))
|
||||
l4g.Info("License key valid unlocking enterprise features.")
|
||||
@@ -43,13 +43,13 @@ func LoadLicense() {
|
||||
}
|
||||
}
|
||||
|
||||
func SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) {
|
||||
func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) {
|
||||
var license *model.License
|
||||
|
||||
if success, licenseStr := utils.ValidateLicense(licenseBytes); success {
|
||||
license = model.LicenseFromJson(strings.NewReader(licenseStr))
|
||||
|
||||
if result := <-Srv.Store.User().AnalyticsUniqueUserCount(""); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().AnalyticsUniqueUserCount(""); result.Err != nil {
|
||||
return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, result.Err.Error(), http.StatusBadRequest)
|
||||
} else {
|
||||
uniqueUserCount := result.Data.(int64)
|
||||
@@ -66,20 +66,20 @@ func SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) {
|
||||
record := &model.LicenseRecord{}
|
||||
record.Id = license.Id
|
||||
record.Bytes = string(licenseBytes)
|
||||
rchan := Srv.Store.License().Save(record)
|
||||
rchan := a.Srv.Store.License().Save(record)
|
||||
|
||||
if result := <-rchan; result.Err != nil {
|
||||
RemoveLicense()
|
||||
a.RemoveLicense()
|
||||
return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "err="+result.Err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
sysVar := &model.System{}
|
||||
sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID
|
||||
sysVar.Value = license.Id
|
||||
schan := Srv.Store.System().SaveOrUpdate(sysVar)
|
||||
schan := a.Srv.Store.System().SaveOrUpdate(sysVar)
|
||||
|
||||
if result := <-schan; result.Err != nil {
|
||||
RemoveLicense()
|
||||
a.RemoveLicense()
|
||||
return nil, model.NewAppError("addLicense", "api.license.add_license.save_active.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
@@ -87,26 +87,26 @@ func SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) {
|
||||
}
|
||||
|
||||
ReloadConfig()
|
||||
InvalidateAllCaches()
|
||||
a.InvalidateAllCaches()
|
||||
|
||||
return license, nil
|
||||
}
|
||||
|
||||
func RemoveLicense() *model.AppError {
|
||||
func (a *App) RemoveLicense() *model.AppError {
|
||||
utils.RemoveLicense()
|
||||
|
||||
sysVar := &model.System{}
|
||||
sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID
|
||||
sysVar.Value = ""
|
||||
|
||||
if result := <-Srv.Store.System().SaveOrUpdate(sysVar); result.Err != nil {
|
||||
if result := <-a.Srv.Store.System().SaveOrUpdate(sysVar); result.Err != nil {
|
||||
utils.RemoveLicense()
|
||||
return result.Err
|
||||
}
|
||||
|
||||
ReloadConfig()
|
||||
|
||||
InvalidateAllCaches()
|
||||
a.InvalidateAllCaches()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user