Skip to content

Commit

Permalink
🐛 Honour labs defaults on import (#8667)
Browse files Browse the repository at this point in the history
closes #8601

- This makes sure that when you do an import, you still get the LATEST
  default settings for labs. Even if you had a different value before.
- LTS -> 1.0 is an upgrade, and Public API should be on by default, even if you
  had deliberately turned it off before.
- Cheeky test added
  • Loading branch information
ErisDS authored and kirrg001 committed Jul 9, 2017
1 parent c49e840 commit 6a45ca2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/server/data/importer/importers/data/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const debug = require('ghost-ignition').debug('importer:settings'),
Promise = require('bluebird'),
_ = require('lodash'),
BaseImporter = require('./base'),
models = require('../../../../models');
models = require('../../../../models'),
defaultSettings = require('../../../schema/default-settings.json'),
labsDefaults = JSON.parse(defaultSettings.blog.labs.defaultValue);

class SettingsImporter extends BaseImporter {
constructor(options) {
Expand All @@ -31,6 +33,7 @@ class SettingsImporter extends BaseImporter {
/**
* - 'core' and 'theme' are blacklisted
* - clean up legacy plugin setting references
* - handle labs setting
*/
beforeImport() {
debug('beforeImport');
Expand All @@ -54,6 +57,12 @@ class SettingsImporter extends BaseImporter {

_.each(this.dataToImport, function (obj) {
obj.key = self.legacySettingsKeyValues[obj.key] || obj.key;

if (obj.key === 'labs' && obj.value) {
// Overwrite the labs setting with our current defaults
// Ensures things that are enabled in new versions, are turned on
obj.value = JSON.stringify(_.assign({}, JSON.parse(obj.value), labsDefaults));
}
});

return super.beforeImport();
Expand Down
3 changes: 3 additions & 0 deletions core/test/integration/data/importer/importers/data_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@ describe('Import (new test structure)', function () {
settings[9].key.should.eql('default_locale');
settings[9].value.should.eql('en');

settings[18].key.should.eql('labs');
settings[18].value.should.eql('{"publicAPI":true}');

// Check post language is null
should(firstPost.locale).equal(null);
// Check user language is null
Expand Down

0 comments on commit 6a45ca2

Please sign in to comment.