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);
} else if (parseInt(postData.tid, 10) > 0) {
socket.emit('posts.reply', {
topic_id: postData.tid,
tid: postData.tid,
content: bodyEl.val(),
toPid: postData.toPid
}, done);

@ -13,10 +13,12 @@ var db = require('./../database'),
for (var key in category) {
db.setObjectField('category:' + cid, key, category[key]);
if (key == 'name') {
if (key === 'name') {
// reset slugs if name is updated
var slug = cid + '/' + utils.slugify(category[key]);
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) {
db.incrObjectField('global', 'nextCid', function(err, cid) {
if (err) {
return callback(err, null);
return callback(err);
}
var slug = cid + '/' + utils.slugify(data.name);
db.listAppend('categories:cid', cid);
var category = {
cid: cid,
@ -36,14 +35,20 @@ var db = require('./database'),
topic_count: 0,
disabled: 0,
order: data.order,
link: "",
link: '',
numRecentReplies: 2,
class: 'col-md-3 col-xs-6',
imageClass: 'default'
};
db.setObject('category:' + cid, category, function(err, data) {
callback(err, category);
db.setObject('category:' + cid, category, function(err) {
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);
}
if (parseInt(topicCount, 10) === 0) {
return callback(null, 1);
}
user.getSettings(uid, function(err, settings) {
if(err) {
return callback(err);
@ -142,8 +151,8 @@ var db = require('./database'),
});
};
Categories.getAllCategories = function(current_user, callback) {
db.getListRange('categories:cid', 0, -1, function(err, cids) {
Categories.getAllCategories = function(uid, callback) {
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
if(err) {
return callback(err);
}
@ -152,7 +161,7 @@ var db = require('./database'),
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) {
if (err) {
winston.err(err);
return callback(err, null);
return callback(err);
}
categories = categories.filter(function(category) {
return !!category;
}).sort(function(a, b) {
return parseInt(a.order, 10) - parseInt(b.order, 10);
});
callback(null, {

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

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

@ -25,7 +25,7 @@ SocketPosts.reply = function(socket, data, callback) {
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'));
}

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

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

@ -7,6 +7,7 @@ var db = require('./database'),
User = require('./user'),
Topics = require('./topics'),
Posts = require('./posts'),
Categories = require('./categories'),
Groups = require('./groups'),
Meta = require('./meta'),
Plugins = require('./plugins'),
@ -19,7 +20,7 @@ var db = require('./database'),
Upgrade.check = function(callback) {
// 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) {
if (parseInt(value, 10) >= latestSchema) {
@ -691,7 +692,7 @@ Upgrade.upgrade = function(callback) {
if (schemaDate < thisSchemaDate) {
updatesMade = true;
db.setObjectField('widgets:home.tpl', 'motd', JSON.stringify([
{
"widget": "html",
@ -717,9 +718,9 @@ Upgrade.upgrade = function(callback) {
if (schemaDate < thisSchemaDate) {
updatesMade = true;
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([
{
"widget": "recentreplies",
@ -756,7 +757,7 @@ Upgrade.upgrade = function(callback) {
if (schemaDate < thisSchemaDate) {
updatesMade = true;
db.setObjectField('widgets:home.tpl', 'footer', JSON.stringify([
{
"widget": "forumstats",
@ -778,7 +779,7 @@ Upgrade.upgrade = function(callback) {
updatesMade = true;
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([
{
"widget": "html",
@ -813,6 +814,59 @@ Upgrade.upgrade = function(callback) {
winston.info('[2014/2/20] Activating NodeBB Essential Widgets - skipped');
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
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!

Loading…
Cancel
Save