Fixed migration issue with slot.slotType = slotFiller
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user