From ba56810790a34f5bd4fb10b170e0f5c324bb52e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 8 Jan 2018 12:03:02 -0500 Subject: [PATCH] upgrade script fixes --- src/topics/tools.js | 4 ++++ src/upgrades/1.7.3/topic_votes.js | 8 ++++++-- src/upgrades/1.8.0/fix_moved_topics_byvotes.js | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/topics/tools.js b/src/topics/tools.js index e0d33b53b2..7ff9d23348 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -250,6 +250,7 @@ module.exports = function (Topics) { var topic; var oldCid; var cid = data.cid; + async.waterfall([ function (next) { Topics.exists(tid, next); @@ -262,6 +263,9 @@ module.exports = function (Topics) { }, function (topicData, next) { topic = topicData; + if (parseInt(cid, 10) === parseInt(topic.cid, 10)) { + return next(new Error('[[error:cant-move-topic-to-same-category]]')); + } db.sortedSetsRemove([ 'cid:' + topicData.cid + ':tids', 'cid:' + topicData.cid + ':tids:pinned', diff --git a/src/upgrades/1.7.3/topic_votes.js b/src/upgrades/1.7.3/topic_votes.js index 76a4d0900c..7e360286a9 100644 --- a/src/upgrades/1.7.3/topic_votes.js +++ b/src/upgrades/1.7.3/topic_votes.js @@ -16,7 +16,7 @@ module.exports = { var topicData; async.waterfall([ function (next) { - db.getObjectFields('topic:' + tid, ['mainPid', 'cid'], next); + db.getObjectFields('topic:' + tid, ['mainPid', 'cid', 'pinned'], next); }, function (_topicData, next) { topicData = _topicData; @@ -44,7 +44,11 @@ module.exports = { db.sortedSetAdd('topics:votes', votes, tid, next); }, function (next) { - db.sortedSetAdd('cid:' + topicData.cid + ':tids:votes', votes, tid, next); + if (parseInt(topicData.pinned, 10) !== 1) { + db.sortedSetAdd('cid:' + topicData.cid + ':tids:votes', votes, tid, next); + } else { + next(); + } }, ], function (err) { next(err); diff --git a/src/upgrades/1.8.0/fix_moved_topics_byvotes.js b/src/upgrades/1.8.0/fix_moved_topics_byvotes.js index f59d6f154c..c5f6121b95 100644 --- a/src/upgrades/1.8.0/fix_moved_topics_byvotes.js +++ b/src/upgrades/1.8.0/fix_moved_topics_byvotes.js @@ -28,12 +28,12 @@ module.exports = { var downvotes = parseInt(topicData.downvotes, 10) || 0; var votes = upvotes - downvotes; - async.parallel([ + async.series([ function (next) { db.sortedSetRemove('cid:' + topicData.oldCid + ':tids:votes', tid, next); }, function (next) { - if (!parseInt(topicData.pinned, 10)) { + if (parseInt(topicData.pinned, 10) !== 1) { db.sortedSetAdd('cid:' + topicData.cid + ':tids:votes', votes, tid, next); } else { next();