mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-01 05:06:44 +08:00
Change DKIM and Alias domains on domainRename
This commit is contained in:
parent
8fc272b11e
commit
fe4c09d0e0
1 changed files with 48 additions and 5 deletions
|
@ -7,6 +7,7 @@ const ObjectID = require('mongodb').ObjectID;
|
|||
const tools = require('../tools');
|
||||
const consts = require('../consts');
|
||||
const roles = require('../roles');
|
||||
const log = require('npmlog');
|
||||
|
||||
module.exports = (db, server) => {
|
||||
/**
|
||||
|
@ -2496,6 +2497,14 @@ module.exports = (db, server) => {
|
|||
}
|
||||
});
|
||||
|
||||
let response = {
|
||||
success: true,
|
||||
modifiedAddresses: 0,
|
||||
modifiedUsers: 0,
|
||||
modifiedDkim: 0,
|
||||
modifiedAliases: 0
|
||||
};
|
||||
|
||||
let addressData;
|
||||
try {
|
||||
while ((addressData = await cursor.next())) {
|
||||
|
@ -2539,10 +2548,11 @@ module.exports = (db, server) => {
|
|||
|
||||
if (updateAddresses.length) {
|
||||
try {
|
||||
await db.users.collection('addresses').bulkWrite(updateAddresses, {
|
||||
let r = await db.users.collection('addresses').bulkWrite(updateAddresses, {
|
||||
ordered: false,
|
||||
w: 1
|
||||
});
|
||||
response.modifiedAddresses = r.modifiedCount;
|
||||
} catch (err) {
|
||||
res.json({
|
||||
error: 'MongoDB Error: ' + err.message,
|
||||
|
@ -2552,10 +2562,11 @@ module.exports = (db, server) => {
|
|||
}
|
||||
|
||||
try {
|
||||
await db.users.collection('users').bulkWrite(updateUsers, {
|
||||
let r = await db.users.collection('users').bulkWrite(updateUsers, {
|
||||
ordered: false,
|
||||
w: 1
|
||||
});
|
||||
response.modifiedUsers = r.modifiedCount;
|
||||
} catch (err) {
|
||||
res.json({
|
||||
error: 'MongoDB Error: ' + err.message,
|
||||
|
@ -2565,9 +2576,41 @@ module.exports = (db, server) => {
|
|||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
// UPDATE DKIM
|
||||
try {
|
||||
let r = await db.database.collection('dkim').updateMany(
|
||||
{
|
||||
domain: oldDomain
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
domain: newDomain
|
||||
}
|
||||
}
|
||||
);
|
||||
response.modifiedDkim = r.modifiedCount;
|
||||
} catch (err) {
|
||||
log.error('RenameDomain', 'DKIMERR old=%s new=%s error=%s', oldDomain, newDomain, err.message);
|
||||
}
|
||||
|
||||
// UPDATE ALIASES
|
||||
try {
|
||||
let r = await db.users.collection('domainaliases').updateMany(
|
||||
{
|
||||
domain: oldDomain
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
domain: newDomain
|
||||
}
|
||||
}
|
||||
);
|
||||
response.modifiedAliases = r.modifiedCount;
|
||||
} catch (err) {
|
||||
log.error('RenameDomain', 'ALIASERR old=%s new=%s error=%s', oldDomain, newDomain, err.message);
|
||||
}
|
||||
|
||||
res.json(response);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue