mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
dont modify counts on soft post delete
This commit is contained in:
@@ -141,51 +141,23 @@ var winston = require('winston'),
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
posts.setPostField(pid, 'deleted', isDelete ? 1 : 0, function(err) {
|
events[isDelete ? 'logPostDelete' : 'logPostRestore'](uid, pid);
|
||||||
if (err) {
|
if (isDelete) {
|
||||||
return callback(err);
|
posts.delete(pid, callback);
|
||||||
}
|
} else {
|
||||||
|
posts.restore(pid, function(err, postData) {
|
||||||
events[isDelete ? 'logPostDelete' : 'logPostRestore'](uid, pid);
|
|
||||||
|
|
||||||
db.incrObjectFieldBy('global', 'postCount', isDelete ? -1 : 1);
|
|
||||||
|
|
||||||
posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp'], function(err, postData) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
PostTools.parse(postData.content, function(err, parsed) {
|
||||||
if (isDelete) {
|
if (err) {
|
||||||
plugins.fireHook('action:post.delete', pid);
|
return callback(err);
|
||||||
} else {
|
|
||||||
plugins.fireHook('action:post.restore', postData);
|
|
||||||
}
|
|
||||||
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
topics[isDelete ? 'decreasePostCount' : 'increasePostCount'](postData.tid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
user.incrementUserPostCountBy(postData.uid, isDelete ? -1 : 1, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
updateTopicTimestamp(postData.tid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
addOrRemoveFromCategory(pid, postData.tid, postData.timestamp, isDelete, next);
|
|
||||||
}
|
}
|
||||||
], function(err) {
|
postData.content = parsed;
|
||||||
if (!isDelete) {
|
callback(null, postData);
|
||||||
PostTools.parse(postData.content, function(err, parsed) {
|
|
||||||
postData.content = parsed;
|
|
||||||
callback(err, postData);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback(err, postData);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,41 +171,6 @@ var winston = require('winston'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateTopicTimestamp(tid, callback) {
|
|
||||||
topics.getLatestUndeletedPid(tid, function(err, pid) {
|
|
||||||
if(err || !pid) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timestamp) {
|
|
||||||
return topics.updateTimestamp(tid, timestamp, callback);
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function addOrRemoveFromCategory(pid, tid, timestamp, isDelete, callback) {
|
|
||||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
db.incrObjectFieldBy('category:' + cid, 'post_count', isDelete ? -1 : 1);
|
|
||||||
|
|
||||||
if (isDelete) {
|
|
||||||
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid, callback);
|
|
||||||
} else {
|
|
||||||
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid, callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
PostTools.parse = function(raw, callback) {
|
PostTools.parse = function(raw, callback) {
|
||||||
parse('filter:post.parse', raw, callback);
|
parse('filter:post.parse', raw, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,10 +3,105 @@
|
|||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
|
user = require('../user'),
|
||||||
plugins = require('../plugins');
|
plugins = require('../plugins');
|
||||||
|
|
||||||
module.exports = function(Posts) {
|
module.exports = function(Posts) {
|
||||||
|
|
||||||
|
|
||||||
|
Posts.delete = function(pid, callback) {
|
||||||
|
Posts.setPostField(pid, 'deleted', 1, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'timestamp'], function(err, postData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.fireHook('action:post.delete', pid);
|
||||||
|
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
updateTopicTimestamp(postData.tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
removeFromCategoryRecentPosts(pid, postData.tid, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
callback(err, postData);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.restore = function(pid, callback) {
|
||||||
|
Posts.setPostField(pid, 'deleted', 0, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp'], function(err, postData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.fireHook('action:post.restore', postData);
|
||||||
|
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
updateTopicTimestamp(postData.tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
addToCategoryRecentPosts(pid, postData.tid, postData.timestamp, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
callback(err, postData);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateTopicTimestamp(tid, callback) {
|
||||||
|
topics.getLatestUndeletedPid(tid, function(err, pid) {
|
||||||
|
if(err || !pid) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timestamp) {
|
||||||
|
return topics.updateTimestamp(tid, timestamp, callback);
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFromCategoryRecentPosts(pid, tid, callback) {
|
||||||
|
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.sortedSetRemove('categories:recent_posts:cid:' + cid, pid, callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addToCategoryRecentPosts(pid, tid, timestamp, callback) {
|
||||||
|
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid, callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Posts.purge = function(pid, callback) {
|
Posts.purge = function(pid, callback) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
function(next) {
|
||||||
@@ -23,7 +118,7 @@ module.exports = function(Posts) {
|
|||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
db.sortedSetRemove('posts:pid', pid, next);
|
db.sortedSetRemove('posts:pid', pid, next);
|
||||||
}
|
},
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -35,7 +130,7 @@ module.exports = function(Posts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function deletePostFromTopicAndUser(pid, callback) {
|
function deletePostFromTopicAndUser(pid, callback) {
|
||||||
Posts.getPostFields(pid, ['tid', 'uid', 'deleted'], function(err, postData) {
|
Posts.getPostFields(pid, ['tid', 'uid'], function(err, postData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@@ -54,21 +149,20 @@ module.exports = function(Posts) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(postData.deleted, 10) === 0 && parseInt(topicData.deleted, 10) !== 1) {
|
async.parallel([
|
||||||
async.parallel([
|
function (next) {
|
||||||
function (next) {
|
db.decrObjectField('global', 'postCount', next);
|
||||||
db.decrObjectField('global', 'postCount', next);
|
},
|
||||||
},
|
function (next) {
|
||||||
function (next) {
|
db.decrObjectField('category:' + topicData.cid, 'post_count', next);
|
||||||
db.decrObjectField('category:' + topicData.cid, 'post_count', next);
|
},
|
||||||
},
|
function (next) {
|
||||||
function (next) {
|
topics.decreasePostCount(postData.tid, next);
|
||||||
db.decrObjectField('topic:' + postData.tid, 'postcount', next);
|
},
|
||||||
}
|
function(next) {
|
||||||
], callback);
|
user.incrementUserPostCountBy(postData.uid, -1, next);
|
||||||
} else {
|
},
|
||||||
callback();
|
], callback);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ module.exports = function(Topics) {
|
|||||||
Topics.deleteTopicTags(tid, next);
|
Topics.deleteTopicTags(tid, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
updateCounters(tid, -1, next);
|
reduceCounters(tid, next);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -72,7 +72,7 @@ module.exports = function(Topics) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function deleteTopicFromCategoryAndUser(tid, callback) {
|
function deleteTopicFromCategoryAndUser(tid, callback) {
|
||||||
Topics.getTopicFields(tid, ['cid', 'uid', 'deleted'], function(err, topicData) {
|
Topics.getTopicFields(tid, ['cid', 'uid'], function(err, topicData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,8 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCounters(tid, incr, callback) {
|
function reduceCounters(tid, callback) {
|
||||||
|
var incr = -1;
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function(next) {
|
function(next) {
|
||||||
db.incrObjectFieldBy('global', 'topicCount', incr, next);
|
db.incrObjectFieldBy('global', 'topicCount', incr, next);
|
||||||
|
|||||||
Reference in New Issue
Block a user