diff --git a/core/server/data/importer/importers/data/settings.js b/core/server/data/importer/importers/data/settings.js index 3c7696d11b..a41d23cd68 100644 --- a/core/server/data/importer/importers/data/settings.js +++ b/core/server/data/importer/importers/data/settings.js @@ -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 diff --git a/test/regression/importer/importer_spec.js b/test/regression/importer/importer_spec.js index a92d569a1c..e2b7e65e84 100644 --- a/test/regression/importer/importer_spec.js +++ b/test/regression/importer/importer_spec.js @@ -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];