mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
8b6ec4d922
closes #12003 There are a few parts of Ghost that rely on the settings events being emitted anytime a setting is changed, so that the data is kept in sync. When a setting is renamed in a migration essentially what happens is that the settings value is changed from a default value to its actual value, but this does no emit an event. Anything that is initialised before migrations have run that relies on the events to keep it up to date will have stale data - e.g. the themes i18n service. This change ensures that when we `reinit` after migrations have been run, we emit events for every setting to tell the rest of Ghost that it has changed.
23 lines
676 B
JavaScript
23 lines
676 B
JavaScript
/**
|
|
* Settings Lib
|
|
* A collection of utilities for handling settings including a cache
|
|
*/
|
|
const models = require('../../models');
|
|
const SettingsCache = require('./cache');
|
|
|
|
module.exports = {
|
|
async init() {
|
|
const settingsCollection = await models.Settings.populateDefaults();
|
|
SettingsCache.init(settingsCollection);
|
|
},
|
|
|
|
async reinit() {
|
|
SettingsCache.shutdown();
|
|
const settingsCollection = await models.Settings.populateDefaults();
|
|
SettingsCache.init(settingsCollection);
|
|
for (const model of settingsCollection.models) {
|
|
model.emitChange(model.attributes.key + '.' + 'edited', {});
|
|
}
|
|
}
|
|
};
|