Skip to content

Node.js based forum software built for the modern web

closes #6274

Barış Soner Uşaklı8ceb102ed3f0
diff --git a/src/topics/tools.js b/src/topics/tools.js
index 7ff9d23348..bacfe20b4d 100644
--- a/src/topics/tools.js
+++ b/src/topics/tools.js
@@ -253,16 +253,13 @@ module.exports = function (Topics) {
async.waterfall([
function (next) {
- Topics.exists(tid, next);
- },
- function (exists, next) {
- if (!exists) {
- return next(new Error('[[error:no-topic]]'));
- }
- Topics.getTopicFields(tid, ['cid', 'lastposttime', 'pinned', 'deleted', 'postcount', 'upvotes', 'downvotes'], next);
+ Topics.getTopicData(tid, next);
},
function (topicData, next) {
topic = topicData;
+ if (!topic) {
+ return next(new Error('[[error:no-topic]]'));
+ }
if (parseInt(cid, 10) === parseInt(topic.cid, 10)) {
return next(new Error('[[error:cant-move-topic-to-same-category]]'));
}
@@ -273,11 +270,15 @@ module.exports = function (Topics) {
'cid:' + topicData.cid + ':tids:votes',
'cid:' + topicData.cid + ':tids:lastposttime',
'cid:' + topicData.cid + ':recent_tids',
+ 'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids',
], tid, next);
},
function (next) {
db.sortedSetAdd('cid:' + cid + ':tids:lastposttime', topic.lastposttime, tid, next);
},
+ function (next) {
+ db.sortedSetAdd('cid:' + cid + ':uid:' + topic.uid + ':tids', topic.timestamp, tid, next);
+ },
function (next) {
if (parseInt(topic.pinned, 10)) {
db.sortedSetAdd('cid:' + cid + ':tids:pinned', Date.now(), tid, next);
diff --git a/src/upgrades/1.7.4/fix_user_topics_per_category.js b/src/upgrades/1.7.4/fix_user_topics_per_category.js
new file mode 100644
index 0000000000..bd963c6ea1
--- /dev/null
+++ b/src/upgrades/1.7.4/fix_user_topics_per_category.js
@@ -0,0 +1,52 @@
+'use strict';
+
+var async = require('async');
+var batch = require('../../batch');
+var db = require('../../database');
+
+module.exports = {
+ name: 'Fix topics in categories per user if they were moved',
+ timestamp: Date.UTC(2018, 0, 22),
+ method: function (callback) {
+ var progress = this.progress;
+
+ batch.processSortedSet('topics:tid', function (tids, next) {
+ async.eachLimit(tids, 500, function (tid, _next) {
+ progress.incr();
+ var topicData;
+ async.waterfall([
+ function (next) {
+ db.getObjectFields('topic:' + tid, ['cid', 'tid', 'uid', 'oldCid', 'timestamp'], next);
+ },
+ function (_topicData, next) {
+ topicData = _topicData;
+ if (!topicData.cid || !topicData.oldCid) {
+ return _next();
+ }
+
+ db.isSortedSetMember('cid:' + topicData.oldCid + ':uid:' + topicData.uid, topicData.tid, next);
+ },
+ function (isMember, next) {
+ if (isMember) {
+ async.series([
+ function (next) {
+ db.sortedSetRemove('cid:' + topicData.oldCid + ':uid:' + topicData.uid + ':tids', tid, next);
+ },
+ function (next) {
+ db.sortedSetAdd('cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids', topicData.timestamp, tid, next);
+ },
+ ], function (err) {
+ next(err);
+ });
+ } else {
+ next();
+ }
+ },
+ ], _next);
+ }, next);
+ }, {
+ progress: progress,
+ batch: 500,
+ }, callback);
+ },
+};