浏览代码

Copy custom fields to new board

John R. Supplee 4 年之前
父节点
当前提交
27d05ee828
共有 1 个文件被更改,包括 19 次插入0 次删除
  1. 19 0
      models/boards.js

+ 19 - 0
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?