From 4f4779c3e59402b10d28597ca67874f0b2b3d53d Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Wed, 21 Jun 2023 14:31:15 +0200 Subject: [PATCH] Fixed migration issue with slot.slotType = slotFiller --- .../api/library/methods/getDefaultSlotFiller.js | 7 ++++++- .../migrations/archive/migrateArchive1To2.js | 4 ++++ app/imports/migrations/server/dbv2/dbv2.js | 17 ++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/imports/api/library/methods/getDefaultSlotFiller.js b/app/imports/api/library/methods/getDefaultSlotFiller.js index f704bbf7..aeb5917b 100644 --- a/app/imports/api/library/methods/getDefaultSlotFiller.js +++ b/app/imports/api/library/methods/getDefaultSlotFiller.js @@ -2,8 +2,13 @@ export default function getDefaultSlotFiller(slot) { if (typeof slot !== 'object') throw 'getDefaultSlotFiller requires a slot'; if (slot.type !== 'propertySlot') throw 'provided slot must be a propertySlot'; + let slotType = slot.slotType; + if (!slotType || slot.slotType === 'slotFiller') { + slotType = 'folder'; + } + const filler = { - type: slot.slotType || 'folder', + type: slotType, libraryTags: slot.slotTags || [], name: 'Custom ' + slot.name || 'slot filler', parent: { collection: 'creatureProperties', id: slot._id }, diff --git a/app/imports/migrations/archive/migrateArchive1To2.js b/app/imports/migrations/archive/migrateArchive1To2.js index 20e934aa..6038c2a9 100644 --- a/app/imports/migrations/archive/migrateArchive1To2.js +++ b/app/imports/migrations/archive/migrateArchive1To2.js @@ -11,6 +11,10 @@ export default function migrate1To2(archive) { if (prop.type === 'slotFiller') { prop.type = 'folder'; } + // Migrate slot filler slot type to folders + if (prop.slotType === 'slotFiller') { + prop.slotType = 'folder'; + } // Get the schema const schema = CreatureProperties.simpleSchema(prop); // Replace dollar signs in calculations with tildes diff --git a/app/imports/migrations/server/dbv2/dbv2.js b/app/imports/migrations/server/dbv2/dbv2.js index 6796aab8..9df7b2ce 100644 --- a/app/imports/migrations/server/dbv2/dbv2.js +++ b/app/imports/migrations/server/dbv2/dbv2.js @@ -33,11 +33,11 @@ Migrations.add({ function migrateCollection(collection, migrateDoc) { const bulk = collection.rawCollection().initializeUnorderedBulkOp(); - collection.find({}).forEach(doc => migrateDoc(bulk, doc)); + collection.find({}).forEach(doc => migrateDoc(bulk, doc, collection)); bulk.execute(); } -export function migratePropUp(bulk, prop) { +export function migratePropUp(bulk, prop, collection) { let update; if (prop.type === 'slotFiller') { update = update || { $set: {} }; @@ -49,14 +49,25 @@ export function migratePropUp(bulk, prop) { update.$unset = { picture: 1 }; } } + + // Don't look for slot fillers + if (prop.slotType === 'slotFiller') { + update = update || { $set: {} }; + update.$set.slotType = 'folder' + } + // If there are tags, copy them to libraryTags and set findable flags - if (Array.isArray(prop.tags) && prop.tags.length) { + if (Array.isArray(prop.tags) && prop.tags.length && collection === LibraryNodes) { update = update || { $set: {} }; update.$set.libraryTags = prop.tags; update.$set.fillSlots = true; update.$set.searchable = true; } + + // Replace dollar sign with tilde in calculated fields update = dollarSignToTilde(prop, update); + + // Add the update to the bulk op if (update) { bulk.find({ _id: prop._id }).updateOne(update); }