Skip to content

Node.js based forum software built for the modern web

closes #5802

Barış Soner Uşaklı71e3fea55b5c
diff --git a/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js b/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js
index 6cbf6b7254..37e2fce239 100644
--- a/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js
+++ b/src/upgrades/1.1.0/dismiss_flags_from_deleted_topics.js
@@ -34,8 +34,72 @@ module.exports = {
}).filter(Boolean);
winston.verbose('[2016/04/29] ' + toDismiss.length + ' dismissable flags found');
- async.each(toDismiss, posts.dismissFlag, next);
+ async.each(toDismiss, dismissFlag, next);
},
], callback);
},
};
+
+// copied from core since this function was removed
+// https://github.com/NodeBB/NodeBB/blob/v1.x.x/src/posts/flags.js
+function dismissFlag(pid, callback) {
+ async.waterfall([
+ function (next) {
+ db.getObjectFields('post:' + pid, ['pid', 'uid', 'flags'], next);
+ },
+ function (postData, next) {
+ if (!postData.pid) {
+ return callback();
+ }
+ async.parallel([
+ function (next) {
+ if (parseInt(postData.uid, 10)) {
+ if (parseInt(postData.flags, 10) > 0) {
+ async.parallel([
+ async.apply(db.sortedSetIncrBy, 'users:flags', -postData.flags, postData.uid),
+ async.apply(db.incrObjectFieldBy, 'user:' + postData.uid, 'flags', -postData.flags),
+ ], next);
+ } else {
+ next();
+ }
+ } else {
+ next();
+ }
+ },
+ function (next) {
+ db.sortedSetsRemove([
+ 'posts:flagged',
+ 'posts:flags:count',
+ 'uid:' + postData.uid + ':flag:pids',
+ ], pid, next);
+ },
+ function (next) {
+ async.series([
+ function (next) {
+ db.getSortedSetRange('pid:' + pid + ':flag:uids', 0, -1, function (err, uids) {
+ if (err) {
+ return next(err);
+ }
+
+ async.each(uids, function (uid, next) {
+ var nid = 'post_flag:' + pid + ':uid:' + uid;
+ async.parallel([
+ async.apply(db.delete, 'notifications:' + nid),
+ async.apply(db.sortedSetRemove, 'notifications', 'post_flag:' + pid + ':uid:' + uid),
+ ], next);
+ }, next);
+ });
+ },
+ async.apply(db.delete, 'pid:' + pid + ':flag:uids'),
+ ], next);
+ },
+ async.apply(db.deleteObjectField, 'post:' + pid, 'flags'),
+ async.apply(db.delete, 'pid:' + pid + ':flag:uid:reason'),
+ async.apply(db.deleteObjectFields, 'post:' + pid, ['flag:state', 'flag:assignee', 'flag:notes', 'flag:history']),
+ ], next);
+ },
+ function (results, next) {
+ db.sortedSetsRemoveRangeByScore(['users:flags'], '-inf', 0, next);
+ },
+ ], callback);
+}