@@ -19,7 +19,7 @@ var db = require('./database'),
19
19
schemaDate , thisSchemaDate ,
20
20
21
21
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
22
- latestSchema = Date . UTC ( 2014 , 1 , 22 ) ;
22
+ latestSchema = Date . UTC ( 2014 , 2 , 18 ) ;
23
23
24
24
Upgrade . check = function ( callback ) {
25
25
db . get ( 'schemaDate' , function ( err , value ) {
@@ -269,42 +269,97 @@ Upgrade.upgrade = function(callback) {
269
269
winston . info ( '[2014/2/22] Added categories to sorted set - skipped' ) ;
270
270
next ( ) ;
271
271
}
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
+ }
272
338
}
273
339
// Add new schema updates here
274
340
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!
275
341
] , function ( err ) {
276
342
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
+ }
284
348
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 ( ) ;
295
350
} else {
296
351
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 ;
308
363
}
309
364
}
310
365
} ) ;
0 commit comments