Skip to content

Commit 61afee9

Browse files
committed
updates to new settings mechanism, updating markdown minver, minor linting for upgrades.js, and upgrade stmt for markdown migration
1 parent 39b2205 commit 61afee9

File tree

4 files changed

+118
-31
lines changed

4 files changed

+118
-31
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"xregexp": "~2.0.0",
4040
"socket.io-wildcard": "~0.1.1",
4141
"bcryptjs": "~0.7.10",
42-
"nodebb-plugin-mentions": "~0.4",
43-
"nodebb-plugin-markdown": "~0.4",
42+
"nodebb-plugin-mentions": "~0.4.0",
43+
"nodebb-plugin-markdown": "~0.4.1",
4444
"nodebb-widget-essentials": "~0.0.11",
4545
"nodebb-theme-vanilla": "~0.0.17",
4646
"nodebb-theme-cerulean": "~0.0.13",

public/src/modules/settings.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ define(function() {
3434
if (formEl.length) {
3535
var values = formEl.serializeObject();
3636

37+
// "Fix" checkbox values, so that unchecked options are not omitted
38+
formEl.find('input[type="checkbox"]').each(function(idx, inputEl) {
39+
inputEl = $(inputEl);
40+
if (!inputEl.is(':checked')) {
41+
values[inputEl.attr('id')] = 'off';
42+
}
43+
});
44+
3745
socket.emit('admin.settings.set', {
3846
hash: hash,
3947
values: values

src/meta.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,35 @@ var fs = require('fs'),
372372
db.getObject(hash, callback);
373373
};
374374

375+
Meta.settings.getOne = function(hash, field, callback) {
376+
hash = 'settings:' + hash;
377+
db.getObjectField(hash, field, callback);
378+
};
379+
375380
Meta.settings.set = function(hash, values, callback) {
376381
hash = 'settings:' + hash;
377382
db.setObject(hash, values, callback);
378383
};
379384

385+
Meta.settings.setOne = function(hash, field, value, callback) {
386+
hash = 'settings:' + hash;
387+
db.setObjectField(hash, field, value, callback);
388+
};
389+
390+
Meta.settings.setOnEmpty = function (hash, field, value, callback) {
391+
Meta.settings.getOne(hash, field, function (err, curValue) {
392+
if (err) {
393+
return callback(err);
394+
}
395+
396+
if (!curValue) {
397+
Meta.settings.setOne(hash, field, value, callback);
398+
} else {
399+
callback();
400+
}
401+
});
402+
};
403+
380404
/* Assorted */
381405
Meta.css = {
382406
cache: undefined

src/upgrade.js

Lines changed: 84 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var db = require('./database'),
1919
schemaDate, thisSchemaDate,
2020

2121
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
22-
latestSchema = Date.UTC(2014, 1, 22);
22+
latestSchema = Date.UTC(2014, 2, 18);
2323

2424
Upgrade.check = function(callback) {
2525
db.get('schemaDate', function(err, value) {
@@ -269,42 +269,97 @@ Upgrade.upgrade = function(callback) {
269269
winston.info('[2014/2/22] Added categories to sorted set - skipped');
270270
next();
271271
}
272+
},
273+
function(next) {
274+
thisSchemaDate = Date.UTC(2014, 2, 18);
275+
276+
if (schemaDate < thisSchemaDate) {
277+
db.exists('settings:markdown', function(err, exists) {
278+
if (err || exists) {
279+
winston.info('[2014/3/18] Migrating Markdown settings to new configuration - skipped');
280+
return next();
281+
}
282+
283+
var fields = [
284+
'nodebb-plugin-markdown:options:gfm',
285+
'nodebb-plugin-markdown:options:highlight',
286+
'nodebb-plugin-markdown:options:tables',
287+
'nodebb-plugin-markdown:options:breaks',
288+
'nodebb-plugin-markdown:options:pedantic',
289+
'nodebb-plugin-markdown:options:sanitize',
290+
'nodebb-plugin-markdown:options:smartLists',
291+
'nodebb-plugin-markdown:options:smartypants',
292+
'nodebb-plugin-markdown:options:langPrefix'
293+
],
294+
settings = {},
295+
newFieldName;
296+
297+
async.series([
298+
function(next) {
299+
db.getObjectFields('config', fields, function(err, values) {
300+
if (err) {
301+
return next();
302+
}
303+
304+
for(var field in values) {
305+
if (values.hasOwnProperty(field)) {
306+
newFieldName = field.slice(31);
307+
settings[newFieldName] = values[field] === '1' ? 'on' : values[field];
308+
}
309+
}
310+
311+
next();
312+
});
313+
},
314+
function(next) {
315+
console.log('saving new settings');
316+
db.setObject('settings:markdown', settings, next);
317+
},
318+
function(next) {
319+
async.each(fields, function(field, next) {
320+
console.log('deleting', field);
321+
db.deleteObjectField('config', field, next);
322+
}, next);
323+
}
324+
], function(err) {
325+
if (err) {
326+
winston.error('[2014/3/18] Problem migrating Markdown settings.');
327+
next();
328+
} else {
329+
winston.info('[2014/3/18] Migrated Markdown settings to new configuration');
330+
Upgrade.update(thisSchemaDate, next);
331+
}
332+
});
333+
});
334+
} else {
335+
winston.info('[2014/3/18] Migrating Markdown settings to new configuration - skipped');
336+
next();
337+
}
272338
}
273339
// Add new schema updates here
274340
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!
275341
], function(err) {
276342
if (!err) {
277-
db.set('schemaDate', thisSchemaDate, function(err) {
278-
if (!err) {
279-
if(updatesMade) {
280-
winston.info('[upgrade] Schema update complete!');
281-
} else {
282-
winston.info('[upgrade] Schema already up to date!');
283-
}
343+
if(updatesMade) {
344+
winston.info('[upgrade] Schema update complete!');
345+
} else {
346+
winston.info('[upgrade] Schema already up to date!');
347+
}
284348

285-
if (callback) {
286-
callback(err);
287-
} else {
288-
process.exit();
289-
}
290-
} else {
291-
winston.error('[upgrade] Could not update NodeBB schema data!');
292-
process.exit();
293-
}
294-
});
349+
process.exit();
295350
} else {
296351
switch(err.message) {
297-
case 'upgrade-not-possible':
298-
winston.error('[upgrade] NodeBB upgrade could not complete, as your database schema is too far out of date.');
299-
winston.error('[upgrade] Please ensure that you did not skip any minor version upgrades.');
300-
winston.error('[upgrade] (e.g. v0.1.x directly to v0.3.x)');
301-
process.exit();
302-
break;
303-
304-
default:
305-
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
306-
process.exit();
307-
break;
352+
case 'upgrade-not-possible':
353+
winston.error('[upgrade] NodeBB upgrade could not complete, as your database schema is too far out of date.');
354+
winston.error('[upgrade] Please ensure that you did not skip any minor version upgrades.');
355+
winston.error('[upgrade] (e.g. v0.1.x directly to v0.3.x)');
356+
process.exit();
357+
break;
358+
359+
default:
360+
winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message);
361+
process.exit();
362+
break;
308363
}
309364
}
310365
});

0 commit comments

Comments
 (0)