From 27d05ee8289933d1f23fc6880a3041111231085d Mon Sep 17 00:00:00 2001 From: "John R. Supplee" Date: Wed, 20 Jan 2021 18:04:55 +0200 Subject: [PATCH] Copy custom fields to new board --- models/boards.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/models/boards.js b/models/boards.js index cfeda7309..006b58ed5 100644 --- a/models/boards.js +++ b/models/boards.js @@ -518,6 +518,25 @@ Boards.helpers({ swimlane.type = 'swimlane'; swimlane.copy(_id); }); + + // copy custom field definitions + const cfMap = {}; + CustomFields.find({ boardIds: oldId }).forEach(cf => { + const id = cf._id; + delete cf._id; + cf.boardIds = [_id]; + cfMap[id] = CustomFields.insert(cf); + }); + Cards.find({ boardId: _id }).forEach(card => { + Cards.update(card._id, { + $set: { + customFields: card.customFields.map(cf => { + cf._id = cfMap[cf._id]; + return cf; + }), + }, + }); + }); }, /** * Is supplied user authorized to view this board?