Fixed importer mapping for renamed default_locale, active_timezone, ghost_* settings

refs #10318
refs 2614565d5a

- Adds importer mapping for fields as in referenced migration
- The intention is to allow exports from v2/v3 to still be compatilbe with current version
- Adds a mapper for deprecated fields and imports them with new settings "keys"
This commit is contained in:
Nazar Gargol 2020-06-23 12:45:05 +12:00
parent 2de1c07dd4
commit 8ea245fc7c
2 changed files with 58 additions and 2 deletions

View File

@ -4,8 +4,15 @@ const _ = require('lodash');
const BaseImporter = require('./base');
const models = require('../../../../models');
const defaultSettings = require('../../../schema').defaultSettings;
const labsDefaults = JSON.parse(defaultSettings.labs.labs.defaultValue);
const deprecatedSettings = ['active_apps', 'installed_apps'];
const ignoredSettings = ['active_apps', 'installed_apps'];
const deprecatedSupportedSettingsMap = {
default_locale: 'lang',
active_timezone: 'timezone',
ghost_head: 'codeinjection_head',
ghost_foot: 'codeinjection_foot'
};
const isFalse = (value) => {
// Catches false, null, undefined, empty string
@ -68,7 +75,16 @@ class SettingsImporter extends BaseImporter {
// Don't import any old, deprecated settings
this.dataToImport = _.filter(this.dataToImport, (data) => {
return !_.includes(deprecatedSettings, data.key);
return !_.includes(ignoredSettings, data.key);
});
// NOTE: import settings removed in v3 and move them to ignored once Ghost v4 changes are done
this.dataToImport = this.dataToImport.map((data) => {
if (deprecatedSupportedSettingsMap[data.key]) {
data.key = deprecatedSupportedSettingsMap[data.key];
}
return data;
});
// Remove core and theme data types

View File

@ -930,6 +930,46 @@ describe('Integration: Importer', function () {
});
});
it('imports settings fields deprecated in v2 and removed in v3: slack hook, permalinks', function () {
const exportData = exportedLatestBody().db[0];
exportData.data.settings[0] = testUtils.DataGenerator.forKnex.createSetting({
key: 'default_locale',
value: 'ua'
});
exportData.data.settings[1] = testUtils.DataGenerator.forKnex.createSetting({
key: 'active_timezone',
value: 'Pacific/Auckland'
});
exportData.data.settings[2] = testUtils.DataGenerator.forKnex.createSetting({
key: 'ghost_foot',
value: 'AVADA KEDAVRA'
});
return dataImporter.doImport(exportData, importOptions)
.then(function (imported) {
imported.problems.length.should.eql(0);
return models.Settings.findOne(_.merge({key: 'lang'}, testUtils.context.internal));
})
.then(function (result) {
result.attributes.value.should.eql('ua');
})
.then(function () {
return models.Settings.findOne(_.merge({key: 'timezone'}, testUtils.context.internal));
})
.then(function (result) {
result.attributes.value.should.eql('Pacific/Auckland');
})
.then(function () {
return models.Settings.findOne(_.merge({key: 'codeinjection_foot'}, testUtils.context.internal));
})
.then(function (result) {
result.attributes.value.should.eql('AVADA KEDAVRA');
});
});
it('does import settings with string booleans', function () {
const exportData = exportedLatestBody().db[0];