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",
|
"xregexp": "~2.0.0",
|
||||||
"socket.io-wildcard": "~0.1.1",
|
"socket.io-wildcard": "~0.1.1",
|
||||||
"bcryptjs": "~0.7.10",
|
"bcryptjs": "~0.7.10",
|
||||||
"nodebb-plugin-mentions": "~0.4",
|
"nodebb-plugin-mentions": "~0.4.0",
|
||||||
"nodebb-plugin-markdown": "~0.4",
|
"nodebb-plugin-markdown": "~0.4.1",
|
||||||
"nodebb-widget-essentials": "~0.0.11",
|
"nodebb-widget-essentials": "~0.0.11",
|
||||||
"nodebb-theme-vanilla": "~0.0.17",
|
"nodebb-theme-vanilla": "~0.0.17",
|
||||||
"nodebb-theme-cerulean": "~0.0.13",
|
"nodebb-theme-cerulean": "~0.0.13",
|
||||||
|
|||||||
@@ -34,6 +34,14 @@ define(function() {
|
|||||||
if (formEl.length) {
|
if (formEl.length) {
|
||||||
var values = formEl.serializeObject();
|
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', {
|
socket.emit('admin.settings.set', {
|
||||||
hash: hash,
|
hash: hash,
|
||||||
values: values
|
values: values
|
||||||
|
|||||||
24
src/meta.js
24
src/meta.js
@@ -372,11 +372,35 @@ var fs = require('fs'),
|
|||||||
db.getObject(hash, callback);
|
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) {
|
Meta.settings.set = function(hash, values, callback) {
|
||||||
hash = 'settings:' + hash;
|
hash = 'settings:' + hash;
|
||||||
db.setObject(hash, values, callback);
|
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 */
|
/* Assorted */
|
||||||
Meta.css = {
|
Meta.css = {
|
||||||
cache: undefined
|
cache: undefined
|
||||||
|
|||||||
111
src/upgrade.js
111
src/upgrade.js
@@ -19,7 +19,7 @@ var db = require('./database'),
|
|||||||
schemaDate, thisSchemaDate,
|
schemaDate, thisSchemaDate,
|
||||||
|
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||||
latestSchema = Date.UTC(2014, 1, 22);
|
latestSchema = Date.UTC(2014, 2, 18);
|
||||||
|
|
||||||
Upgrade.check = function(callback) {
|
Upgrade.check = function(callback) {
|
||||||
db.get('schemaDate', function(err, value) {
|
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');
|
winston.info('[2014/2/22] Added categories to sorted set - skipped');
|
||||||
next();
|
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
|
// Add new schema updates here
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
db.set('schemaDate', thisSchemaDate, function(err) {
|
if(updatesMade) {
|
||||||
if (!err) {
|
winston.info('[upgrade] Schema update complete!');
|
||||||
if(updatesMade) {
|
} else {
|
||||||
winston.info('[upgrade] Schema update complete!');
|
winston.info('[upgrade] Schema already up to date!');
|
||||||
} else {
|
}
|
||||||
winston.info('[upgrade] Schema already up to date!');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
process.exit();
|
||||||
callback(err);
|
|
||||||
} else {
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
winston.error('[upgrade] Could not update NodeBB schema data!');
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
switch(err.message) {
|
switch(err.message) {
|
||||||
case 'upgrade-not-possible':
|
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] 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] Please ensure that you did not skip any minor version upgrades.');
|
||||||
winston.error('[upgrade] (e.g. v0.1.x directly to v0.3.x)');
|
winston.error('[upgrade] (e.g. v0.1.x directly to v0.3.x)');
|
||||||
process.exit();
|
process.exit();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
|
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
|
||||||
process.exit();
|
process.exit();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user