ReloadSettings initializes and reloads the stored application settings. If no settings were stored it will persist the current app ones.
()
| 27 | // |
| 28 | // If no settings were stored it will persist the current app ones. |
| 29 | func (app *BaseApp) ReloadSettings() error { |
| 30 | param := &Param{} |
| 31 | err := app.ModelQuery(param).Model(paramsKeySettings, param) |
| 32 | if err != nil && !errors.Is(err, sql.ErrNoRows) { |
| 33 | return err |
| 34 | } |
| 35 | |
| 36 | // no settings were previously stored -> save |
| 37 | // (ReloadSettings() will be invoked again by a system hook after successful save) |
| 38 | if param.Id == "" { |
| 39 | // force insert in case the param entry was deleted manually after application start |
| 40 | app.Settings().MarkAsNew() |
| 41 | return app.Save(app.Settings()) |
| 42 | } |
| 43 | |
| 44 | event := new(SettingsReloadEvent) |
| 45 | event.App = app |
| 46 | |
| 47 | return app.OnSettingsReload().Trigger(event, func(e *SettingsReloadEvent) error { |
| 48 | return e.App.Settings().loadParam(e.App, param) |
| 49 | }) |
| 50 | } |
| 51 | |
| 52 | // loadParam loads the settings from the stored param into the app ones. |
| 53 | // |