v1.18.x
parent
17c52a515d
commit
4f2f84e47c
@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var topics = require('../../topics');
|
||||
var privileges = require('../../privileges');
|
||||
|
||||
module.exports = function (SocketTopics) {
|
||||
SocketTopics.merge = function (socket, tids, callback) {
|
||||
if (!Array.isArray(tids)) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.map(tids, function (tid, next) {
|
||||
privileges.topics.isAdminOrMod(tid, socket.uid, next);
|
||||
}, next);
|
||||
},
|
||||
function (allowed, next) {
|
||||
if (allowed.includes(false)) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
topics.merge(tids, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
module.exports = function (Topics) {
|
||||
Topics.merge = function (tids, callback) {
|
||||
var mergeIntoTid = findOldestTopic(tids);
|
||||
|
||||
var otherTids = tids.filter(function (tid) {
|
||||
return tid && parseInt(tid, 10) !== parseInt(mergeIntoTid, 10);
|
||||
});
|
||||
|
||||
async.eachSeries(otherTids, function (tid, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Topics.getPids(tid, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
async.eachSeries(pids, function (pid, next) {
|
||||
Topics.movePostToTopic(pid, mergeIntoTid, next);
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
Topics.setTopicField(tid, 'mainPid', 0, next);
|
||||
},
|
||||
], next);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
function findOldestTopic(tids) {
|
||||
return Math.min.apply(null, tids);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue