updates to new settings mechanism, updating markdown minver, minor linting for upgrades.js, and upgrade stmt for markdown migration

v1.18.x
Julian Lam 11 years ago
parent 39b22058b7
commit 61afee98c3

@ -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

@ -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,42 +269,97 @@ 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!');
} else {
winston.info('[upgrade] Schema already up to date!');
}
if(updatesMade) {
winston.info('[upgrade] Schema update complete!');
} else {
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();
}
});
process.exit();
} else {
switch(err.message) {
case 'upgrade-not-possible':
winston.error('[upgrade] NodeBB upgrade could not complete, as your database schema is too far out of date.');
winston.error('[upgrade] Please ensure that you did not skip any minor version upgrades.');
winston.error('[upgrade] (e.g. v0.1.x directly to v0.3.x)');
process.exit();
break;
default:
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
process.exit();
break;
case 'upgrade-not-possible':
winston.error('[upgrade] NodeBB upgrade could not complete, as your database schema is too far out of date.');
winston.error('[upgrade] Please ensure that you did not skip any minor version upgrades.');
winston.error('[upgrade] (e.g. v0.1.x directly to v0.3.x)');
process.exit();
break;
default:
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
process.exit();
break;
}
}
});

Loading…
Cancel
Save