v1.18.x
Barış Soner Uşaklı 7 years ago
parent df86c2ff3f
commit 8ceb102ed3

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

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