upgraded categories to sorted set, score is the order set from acp, check if category topic exists before posting

v1.18.x
Baris Soner Usakli 11 years ago
parent d6d9776cde
commit 6e5a6b8784

@ -736,7 +736,7 @@ define(['taskbar'], function(taskbar) {
}, done); }, done);
} else if (parseInt(postData.tid, 10) > 0) { } else if (parseInt(postData.tid, 10) > 0) {
socket.emit('posts.reply', { socket.emit('posts.reply', {
topic_id: postData.tid, tid: postData.tid,
content: bodyEl.val(), content: bodyEl.val(),
toPid: postData.toPid toPid: postData.toPid
}, done); }, done);

@ -13,10 +13,12 @@ var db = require('./../database'),
for (var key in category) { for (var key in category) {
db.setObjectField('category:' + cid, key, category[key]); db.setObjectField('category:' + cid, key, category[key]);
if (key == 'name') { if (key === 'name') {
// reset slugs if name is updated // reset slugs if name is updated
var slug = cid + '/' + utils.slugify(category[key]); var slug = cid + '/' + utils.slugify(category[key]);
db.setObjectField('category:' + cid, 'slug', slug); db.setObjectField('category:' + cid, 'slug', slug);
} else if (key === 'order') {
db.sortedSetAdd('categories:cid', category[key], cid);
} }
} }

@ -18,11 +18,10 @@ var db = require('./database'),
Categories.create = function(data, callback) { Categories.create = function(data, callback) {
db.incrObjectField('global', 'nextCid', function(err, cid) { db.incrObjectField('global', 'nextCid', function(err, cid) {
if (err) { if (err) {
return callback(err, null); return callback(err);
} }
var slug = cid + '/' + utils.slugify(data.name); var slug = cid + '/' + utils.slugify(data.name);
db.listAppend('categories:cid', cid);
var category = { var category = {
cid: cid, cid: cid,
@ -36,14 +35,20 @@ var db = require('./database'),
topic_count: 0, topic_count: 0,
disabled: 0, disabled: 0,
order: data.order, order: data.order,
link: "", link: '',
numRecentReplies: 2, numRecentReplies: 2,
class: 'col-md-3 col-xs-6', class: 'col-md-3 col-xs-6',
imageClass: 'default' imageClass: 'default'
}; };
db.setObject('category:' + cid, category, function(err, data) { db.setObject('category:' + cid, category, function(err) {
callback(err, category); if(err) {
return callback(err);
}
db.sortedSetAdd('categories:cid', data.order, cid);
callback(null, category);
}); });
}); });
}; };
@ -132,6 +137,10 @@ var db = require('./database'),
return callback(err); return callback(err);
} }
if (parseInt(topicCount, 10) === 0) {
return callback(null, 1);
}
user.getSettings(uid, function(err, settings) { user.getSettings(uid, function(err, settings) {
if(err) { if(err) {
return callback(err); return callback(err);
@ -142,8 +151,8 @@ var db = require('./database'),
}); });
}; };
Categories.getAllCategories = function(current_user, callback) { Categories.getAllCategories = function(uid, callback) {
db.getListRange('categories:cid', 0, -1, function(err, cids) { db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
@ -152,7 +161,7 @@ var db = require('./database'),
return callback(null, {categories : []}); return callback(null, {categories : []});
} }
Categories.getCategories(cids, current_user, callback); Categories.getCategories(cids, uid, callback);
}); });
}; };
@ -311,14 +320,11 @@ var db = require('./database'),
async.map(cids, getCategory, function(err, categories) { async.map(cids, getCategory, function(err, categories) {
if (err) { if (err) {
winston.err(err); return callback(err);
return callback(err, null);
} }
categories = categories.filter(function(category) { categories = categories.filter(function(category) {
return !!category; return !!category;
}).sort(function(a, b) {
return parseInt(a.order, 10) - parseInt(b.order, 10);
}); });
callback(null, { callback(null, {

@ -2,9 +2,14 @@ var Groups = require('./groups'),
User = require('./user'), User = require('./user'),
async = require('async'), async = require('async'),
db = require('./database'),
CategoryTools = {}; CategoryTools = {};
CategoryTools.exists = function(cid, callback) {
db.isSortedSetMember('categories:cid', cid, callback);
};
CategoryTools.privileges = function(cid, uid, callback) { CategoryTools.privileges = function(cid, uid, callback) {
async.parallel({ async.parallel({
"+r": function(next) { "+r": function(next) {

@ -87,7 +87,7 @@ var db = require('./database'),
function(postData, next) { function(postData, next) {
postTools.parse(postData.content, function(err, content) { postTools.parse(postData.content, function(err, content) {
if(err) { if(err) {
return next(err, null); return next(err);
} }
postData.content = content; postData.content = content;
@ -303,24 +303,24 @@ var db = require('./database'),
}); });
}, },
function(postData, next) { function(postData, next) {
if (postData.content) { if (!postData.content) {
postTools.parse(postData.content, function(err, content) { return next(null, postData);
if(err) { }
return next(err);
}
if(stripTags) { postTools.parse(postData.content, function(err, content) {
var s = S(content); if(err) {
postData.content = s.stripTags.apply(s, utils.getTagsExcept(['img', 'i'])).s; return next(err);
} else { }
postData.content = content;
} if(stripTags) {
var s = S(content);
postData.content = s.stripTags.apply(s, utils.getTagsExcept(['img', 'i'])).s;
} else {
postData.content = content;
}
next(null, postData);
});
} else {
next(null, postData); next(null, postData);
} });
} }
], callback); ], callback);
} }

@ -25,7 +25,7 @@ SocketPosts.reply = function(socket, data, callback) {
return callback(new Error('not-logged-in')); return callback(new Error('not-logged-in'));
} }
if(!data || !data.topic_id || !data.content) { if(!data || !data.tid || !data.content) {
return callback(new Error('invalid data')); return callback(new Error('invalid data'));
} }

@ -18,15 +18,7 @@ var winston = require('winston'),
(function(ThreadTools) { (function(ThreadTools) {
ThreadTools.exists = function(tid, callback) { ThreadTools.exists = function(tid, callback) {
db.isSortedSetMember('topics:tid', tid, callback);
db.isSortedSetMember('topics:tid', tid, function(err, ismember) {
if (err) {
callback(false);
}
callback(ismember);
});
} }
ThreadTools.privileges = function(tid, uid, callback) { ThreadTools.privileges = function(tid, uid, callback) {

@ -106,6 +106,12 @@ var async = require('async'),
async.waterfall([ async.waterfall([
function(next) { function(next) {
categoryTools.exists(cid, next);
},
function(categoryExists, next) {
if(!categoryExists) {
return next(new Error('category doesn\'t exist'))
}
categoryTools.privileges(cid, uid, next); categoryTools.privileges(cid, uid, next);
}, },
function(privileges, next) { function(privileges, next) {
@ -144,7 +150,7 @@ var async = require('async'),
}; };
Topics.reply = function(data, callback) { Topics.reply = function(data, callback) {
var tid = data.topic_id, var tid = data.tid,
uid = data.uid, uid = data.uid,
toPid = data.toPid, toPid = data.toPid,
content = data.content, content = data.content,
@ -153,6 +159,12 @@ var async = require('async'),
async.waterfall([ async.waterfall([
function(next) { function(next) {
threadTools.exists(tid, next);
},
function(topicExists, next) {
if (!topicExists) {
return next(new Error('topic doesn\'t exist'));
}
threadTools.privileges(tid, uid, next); threadTools.privileges(tid, uid, next);
}, },
function(privilegesData, next) { function(privilegesData, next) {
@ -265,9 +277,9 @@ var async = require('async'),
}; };
Topics.movePostToTopic = function(pid, tid, callback) { Topics.movePostToTopic = function(pid, tid, callback) {
threadTools.exists(tid, function(exists) { threadTools.exists(tid, function(err, exists) {
if(!exists) { if(err || !exists) {
return callback(new Error('Topic doesn\'t exist')); return callback(err || new Error('Topic doesn\'t exist'));
} }
posts.getPostFields(pid, ['deleted', 'tid', 'timestamp'], function(err, postData) { posts.getPostFields(pid, ['deleted', 'tid', 'timestamp'], function(err, postData) {
@ -426,7 +438,9 @@ var async = require('async'),
if(err) { if(err) {
return callback(err); return callback(err);
} }
if(!parseInt(postCount, 10)) {
return callback(null, 1);
}
user.getSettings(uid, function(err, settings) { user.getSettings(uid, function(err, settings) {
if(err) { if(err) {
return callback(err); return callback(err);
@ -762,9 +776,9 @@ var async = require('async'),
}; };
Topics.getTopicWithPosts = function(tid, current_user, start, end, quiet, callback) { Topics.getTopicWithPosts = function(tid, current_user, start, end, quiet, callback) {
threadTools.exists(tid, function(exists) { threadTools.exists(tid, function(err, exists) {
if (!exists) { if (err || !exists) {
return callback(new Error('Topic tid \'' + tid + '\' not found')); return callback(err || new Error('Topic tid \'' + tid + '\' not found'));
} }
// "quiet" is used for things like RSS feed updating, HTML parsing for non-js users, etc // "quiet" is used for things like RSS feed updating, HTML parsing for non-js users, etc

@ -7,6 +7,7 @@ var db = require('./database'),
User = require('./user'), User = require('./user'),
Topics = require('./topics'), Topics = require('./topics'),
Posts = require('./posts'), Posts = require('./posts'),
Categories = require('./categories'),
Groups = require('./groups'), Groups = require('./groups'),
Meta = require('./meta'), Meta = require('./meta'),
Plugins = require('./plugins'), Plugins = require('./plugins'),
@ -19,7 +20,7 @@ var db = require('./database'),
Upgrade.check = function(callback) { Upgrade.check = function(callback) {
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
var latestSchema = new Date(2014, 1, 20, 20, 25).getTime(); var latestSchema = new Date(2014, 1, 22).getTime();
db.get('schemaDate', function(err, value) { db.get('schemaDate', function(err, value) {
if (parseInt(value, 10) >= latestSchema) { if (parseInt(value, 10) >= latestSchema) {
@ -691,7 +692,7 @@ Upgrade.upgrade = function(callback) {
if (schemaDate < thisSchemaDate) { if (schemaDate < thisSchemaDate) {
updatesMade = true; updatesMade = true;
db.setObjectField('widgets:home.tpl', 'motd', JSON.stringify([ db.setObjectField('widgets:home.tpl', 'motd', JSON.stringify([
{ {
"widget": "html", "widget": "html",
@ -717,9 +718,9 @@ Upgrade.upgrade = function(callback) {
if (schemaDate < thisSchemaDate) { if (schemaDate < thisSchemaDate) {
updatesMade = true; updatesMade = true;
var container = '<div class="panel panel-default"><div class="panel-heading">{title}</div><div class="panel-body">{body}</div></div>'; var container = '<div class="panel panel-default"><div class="panel-heading">{title}</div><div class="panel-body">{body}</div></div>';
db.setObjectField('widgets:category.tpl', 'sidebar', JSON.stringify([ db.setObjectField('widgets:category.tpl', 'sidebar', JSON.stringify([
{ {
"widget": "recentreplies", "widget": "recentreplies",
@ -756,7 +757,7 @@ Upgrade.upgrade = function(callback) {
if (schemaDate < thisSchemaDate) { if (schemaDate < thisSchemaDate) {
updatesMade = true; updatesMade = true;
db.setObjectField('widgets:home.tpl', 'footer', JSON.stringify([ db.setObjectField('widgets:home.tpl', 'footer', JSON.stringify([
{ {
"widget": "forumstats", "widget": "forumstats",
@ -778,7 +779,7 @@ Upgrade.upgrade = function(callback) {
updatesMade = true; updatesMade = true;
var container = '<div class="panel panel-default"><div class="panel-heading">{title}</div><div class="panel-body">{body}</div></div>'; var container = '<div class="panel panel-default"><div class="panel-heading">{title}</div><div class="panel-body">{body}</div></div>';
db.setObjectField('widgets:home.tpl', 'sidebar', JSON.stringify([ db.setObjectField('widgets:home.tpl', 'sidebar', JSON.stringify([
{ {
"widget": "html", "widget": "html",
@ -813,6 +814,59 @@ Upgrade.upgrade = function(callback) {
winston.info('[2014/2/20] Activating NodeBB Essential Widgets - skipped'); winston.info('[2014/2/20] Activating NodeBB Essential Widgets - skipped');
next(); next();
} }
},
function(next) {
thisSchemaDate = new Date(2014, 1, 22).getTime();
if (schemaDate < thisSchemaDate) {
updatesMade = true;
db.exists('categories:cid', function(err, exists) {
if(err) {
return next(err);
}
if(!exists) {
winston.info('[2014/2/22] Added categories to sorted set - skipped');
return next();
}
db.getListRange('categories:cid', 0, -1, function(err, cids) {
if(err) {
return next(err);
}
if(!Array.isArray(cids)) {
winston.info('[2014/2/22] Add categories to sorted set - skipped (cant find any cids)');
return next();
}
db.rename('categories:cid', 'categories:cid:old', function(err) {
if(err) {
return next(err);
}
async.each(cids, function(cid, next) {
Categories.getCategoryField(cid, 'order', function(err, order) {
if(err) {
return next(err);
}
db.sortedSetAdd('categories:cid', order, cid, next);
});
}, function(err) {
if(err) {
return next(err);
}
winston.info('[2014/2/22] Added categories to sorted set');
db.delete('categories:cid:old', next);
});
});
});
});
} else {
winston.info('[2014/2/22] Added categories to sorted set - skipped');
next();
}
} }
// Add new schema updates here // Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!! // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!

Loading…
Cancel
Save