v1.18.x
Barış Soner Uşaklı 7 years ago
parent b4dea7930a
commit 225af93b9e

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

@ -38,6 +38,3 @@ navigation.get = function (callback) {
},
], callback);
};
module.exports = navigation;

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

@ -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);
},
};
Loading…
Cancel
Save