Fixed migration issue with slot.slotType = slotFiller

This commit is contained in:
Stefan Zermatten
2023-06-21 14:31:15 +02:00
parent 7457372e13
commit 4f4779c3e5
3 changed files with 24 additions and 4 deletions

View File

@@ -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 },

View File

@@ -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

View File

@@ -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);
}