mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
updates to new settings mechanism, updating markdown minver, minor linting for upgrades.js, and upgrade stmt for markdown migration
This commit is contained in:
@@ -39,8 +39,8 @@
|
||||
"xregexp": "~2.0.0",
|
||||
"socket.io-wildcard": "~0.1.1",
|
||||
"bcryptjs": "~0.7.10",
|
||||
"nodebb-plugin-mentions": "~0.4",
|
||||
"nodebb-plugin-markdown": "~0.4",
|
||||
"nodebb-plugin-mentions": "~0.4.0",
|
||||
"nodebb-plugin-markdown": "~0.4.1",
|
||||
"nodebb-widget-essentials": "~0.0.11",
|
||||
"nodebb-theme-vanilla": "~0.0.17",
|
||||
"nodebb-theme-cerulean": "~0.0.13",
|
||||
|
||||
@@ -34,6 +34,14 @@ define(function() {
|
||||
if (formEl.length) {
|
||||
var values = formEl.serializeObject();
|
||||
|
||||
// "Fix" checkbox values, so that unchecked options are not omitted
|
||||
formEl.find('input[type="checkbox"]').each(function(idx, inputEl) {
|
||||
inputEl = $(inputEl);
|
||||
if (!inputEl.is(':checked')) {
|
||||
values[inputEl.attr('id')] = 'off';
|
||||
}
|
||||
});
|
||||
|
||||
socket.emit('admin.settings.set', {
|
||||
hash: hash,
|
||||
values: values
|
||||
|
||||
24
src/meta.js
24
src/meta.js
@@ -372,11 +372,35 @@ var fs = require('fs'),
|
||||
db.getObject(hash, callback);
|
||||
};
|
||||
|
||||
Meta.settings.getOne = function(hash, field, callback) {
|
||||
hash = 'settings:' + hash;
|
||||
db.getObjectField(hash, field, callback);
|
||||
};
|
||||
|
||||
Meta.settings.set = function(hash, values, callback) {
|
||||
hash = 'settings:' + hash;
|
||||
db.setObject(hash, values, callback);
|
||||
};
|
||||
|
||||
Meta.settings.setOne = function(hash, field, value, callback) {
|
||||
hash = 'settings:' + hash;
|
||||
db.setObjectField(hash, field, value, callback);
|
||||
};
|
||||
|
||||
Meta.settings.setOnEmpty = function (hash, field, value, callback) {
|
||||
Meta.settings.getOne(hash, field, function (err, curValue) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!curValue) {
|
||||
Meta.settings.setOne(hash, field, value, callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* Assorted */
|
||||
Meta.css = {
|
||||
cache: undefined
|
||||
|
||||
@@ -19,7 +19,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2014, 1, 22);
|
||||
latestSchema = Date.UTC(2014, 2, 18);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -269,12 +269,76 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2014/2/22] Added categories to sorted set - skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2014, 2, 18);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
db.exists('settings:markdown', function(err, exists) {
|
||||
if (err || exists) {
|
||||
winston.info('[2014/3/18] Migrating Markdown settings to new configuration - skipped');
|
||||
return next();
|
||||
}
|
||||
|
||||
var fields = [
|
||||
'nodebb-plugin-markdown:options:gfm',
|
||||
'nodebb-plugin-markdown:options:highlight',
|
||||
'nodebb-plugin-markdown:options:tables',
|
||||
'nodebb-plugin-markdown:options:breaks',
|
||||
'nodebb-plugin-markdown:options:pedantic',
|
||||
'nodebb-plugin-markdown:options:sanitize',
|
||||
'nodebb-plugin-markdown:options:smartLists',
|
||||
'nodebb-plugin-markdown:options:smartypants',
|
||||
'nodebb-plugin-markdown:options:langPrefix'
|
||||
],
|
||||
settings = {},
|
||||
newFieldName;
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
db.getObjectFields('config', fields, function(err, values) {
|
||||
if (err) {
|
||||
return next();
|
||||
}
|
||||
|
||||
for(var field in values) {
|
||||
if (values.hasOwnProperty(field)) {
|
||||
newFieldName = field.slice(31);
|
||||
settings[newFieldName] = values[field] === '1' ? 'on' : values[field];
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
console.log('saving new settings');
|
||||
db.setObject('settings:markdown', settings, next);
|
||||
},
|
||||
function(next) {
|
||||
async.each(fields, function(field, next) {
|
||||
console.log('deleting', field);
|
||||
db.deleteObjectField('config', field, next);
|
||||
}, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
winston.error('[2014/3/18] Problem migrating Markdown settings.');
|
||||
next();
|
||||
} else {
|
||||
winston.info('[2014/3/18] Migrated Markdown settings to new configuration');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/3/18] Migrating Markdown settings to new configuration - skipped');
|
||||
next();
|
||||
}
|
||||
}
|
||||
// Add new schema updates here
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!
|
||||
], function(err) {
|
||||
if (!err) {
|
||||
db.set('schemaDate', thisSchemaDate, function(err) {
|
||||
if (!err) {
|
||||
if(updatesMade) {
|
||||
winston.info('[upgrade] Schema update complete!');
|
||||
@@ -282,16 +346,7 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[upgrade] Schema already up to date!');
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(err);
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
} else {
|
||||
winston.error('[upgrade] Could not update NodeBB schema data!');
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
switch(err.message) {
|
||||
case 'upgrade-not-possible':
|
||||
|
||||
Reference in New Issue
Block a user