mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
fix: username, email history disappering if content was deleted
This commit is contained in:
@@ -348,6 +348,7 @@ Flags.create = async function (type, id, uid, reason, timestamp) {
|
|||||||
flagId: flagId,
|
flagId: flagId,
|
||||||
type: type,
|
type: type,
|
||||||
targetId: id,
|
targetId: id,
|
||||||
|
targetUid: targetUid,
|
||||||
datetime: timestamp,
|
datetime: timestamp,
|
||||||
}),
|
}),
|
||||||
Flags.addReport(flagId, type, id, uid, reason, timestamp),
|
Flags.addReport(flagId, type, id, uid, reason, timestamp),
|
||||||
@@ -573,8 +574,7 @@ Flags.resolveFlag = async function (type, id, uid) {
|
|||||||
Flags.getHistory = async function (flagId) {
|
Flags.getHistory = async function (flagId) {
|
||||||
const uids = [];
|
const uids = [];
|
||||||
let history = await db.getSortedSetRevRangeWithScores('flag:' + flagId + ':history', 0, -1);
|
let history = await db.getSortedSetRevRangeWithScores('flag:' + flagId + ':history', 0, -1);
|
||||||
const flagData = await db.getObjectFields('flag:' + flagId, ['type', 'targetId']);
|
const targetUid = await db.getObjectField('flag:' + flagId, 'targetUid');
|
||||||
const targetUid = await Flags.getTargetUid(flagData.type, flagData.targetId);
|
|
||||||
|
|
||||||
history = history.map(function (entry) {
|
history = history.map(function (entry) {
|
||||||
entry.value = JSON.parse(entry.value);
|
entry.value = JSON.parse(entry.value);
|
||||||
|
|||||||
37
src/upgrades/1.15.0/add_target_uid_to_flags.js
Normal file
37
src/upgrades/1.15.0/add_target_uid_to_flags.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const db = require('../../database');
|
||||||
|
const batch = require('../../batch');
|
||||||
|
const posts = require('../../posts');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'Add target uid to flag objects',
|
||||||
|
timestamp: Date.UTC(2020, 7, 22),
|
||||||
|
method: async function () {
|
||||||
|
const progress = this.progress;
|
||||||
|
|
||||||
|
await batch.processSortedSet('flags:datetime', async function (flagIds) {
|
||||||
|
progress.incr(flagIds.length);
|
||||||
|
const flagData = await db.getObjects(flagIds.map(id => 'flag:' + id));
|
||||||
|
for (const flagObj of flagData) {
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
if (flagObj) {
|
||||||
|
const targetId = flagObj.targetId;
|
||||||
|
if (targetId) {
|
||||||
|
if (flagObj.type === 'post') {
|
||||||
|
const targetUid = await posts.getPostField(targetId, 'uid');
|
||||||
|
if (targetUid) {
|
||||||
|
await db.setObjectField('flag:' + flagObj.flagId, 'targetUid', targetUid);
|
||||||
|
}
|
||||||
|
} else if (flagObj.type === 'user') {
|
||||||
|
await db.setObjectField('flag:' + flagObj.flagId, 'targetUid', targetId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
progress: progress,
|
||||||
|
batch: 500,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user