From 225af93b9e3be3eb4e00cd542ca4d5a0ba574e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 17 Feb 2018 14:34:56 -0500 Subject: [PATCH] closes #6329 --- src/navigation/admin.js | 16 +++----- src/navigation/index.js | 3 -- src/topics/bookmarks.js | 2 +- src/upgrades/1.7.6/flatten_navigation_data.js | 38 +++++++++++++++++++ 4 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 src/upgrades/1.7.6/flatten_navigation_data.js diff --git a/src/navigation/admin.js b/src/navigation/admin.js index cf854a80a4..8bab6d4219 100644 --- a/src/navigation/admin.js +++ b/src/navigation/admin.js @@ -15,17 +15,13 @@ pubsub.on('admin:navigation:save', function () { admin.save = function (data, callback) { var order = Object.keys(data); - var items = data.map(function (item, idx) { - var data = {}; - + var items = data.map(function (item) { for (var i in item) { - if (item.hasOwnProperty(i)) { - item[i] = typeof item[i] === 'string' ? translator.escape(item[i]) : item[i]; + if (item.hasOwnProperty(i) && typeof item[i] === 'string' && (i === 'title' || i === 'text')) { + item[i] = translator.escape(item[i]); } } - - data[idx] = item; - return JSON.stringify(data); + return JSON.stringify(item); }); admin.cache = null; @@ -53,8 +49,8 @@ admin.get = function (callback) { db.getSortedSetRange('navigation:enabled', 0, -1, next); }, function (data, next) { - data = data.map(function (item, idx) { - return JSON.parse(item)[idx]; + data = data.map(function (item) { + return JSON.parse(item); }); next(null, data); diff --git a/src/navigation/index.js b/src/navigation/index.js index 0712ce79f5..65628fda1c 100644 --- a/src/navigation/index.js +++ b/src/navigation/index.js @@ -38,6 +38,3 @@ navigation.get = function (callback) { }, ], callback); }; - - -module.exports = navigation; diff --git a/src/topics/bookmarks.js b/src/topics/bookmarks.js index d1782b6713..6952474ff6 100644 --- a/src/topics/bookmarks.js +++ b/src/topics/bookmarks.js @@ -30,7 +30,7 @@ module.exports = function (Topics) { }; Topics.getTopicBookmarks = function (tid, callback) { - db.getSortedSetRangeWithScores(['tid:' + tid + ':bookmarks'], 0, -1, callback); + db.getSortedSetRangeWithScores('tid:' + tid + ':bookmarks', 0, -1, callback); }; Topics.updateTopicBookmarks = function (tid, pids, callback) { diff --git a/src/upgrades/1.7.6/flatten_navigation_data.js b/src/upgrades/1.7.6/flatten_navigation_data.js new file mode 100644 index 0000000000..9fd0901274 --- /dev/null +++ b/src/upgrades/1.7.6/flatten_navigation_data.js @@ -0,0 +1,38 @@ +'use strict'; + +var async = require('async'); +var db = require('../../database'); + +module.exports = { + name: 'Flatten navigation data', + timestamp: Date.UTC(2018, 1, 17), + method: function (callback) { + async.waterfall([ + function (next) { + db.getSortedSetRangeWithScores('navigation:enabled', 0, -1, next); + }, + function (data, next) { + var order = []; + var items = []; + data.forEach(function (item) { + var navItem = JSON.parse(item.value); + var keys = Object.keys(navItem); + if (keys.length && parseInt(keys[0], 10) >= 0) { + navItem = navItem[keys[0]]; + } + order.push(item.score); + items.push(JSON.stringify(navItem)); + }); + + async.series([ + function (next) { + db.delete('navigation:enabled', next); + }, + function (next) { + db.sortedSetAdd('navigation:enabled', order, items, next); + }, + ], next); + }, + ], callback); + }, +};