From 3c21fd3ff183d0eaa5baf8bdf13e81b63530834e Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sun, 30 May 2021 11:16:13 +0200 Subject: [PATCH] Added migration for old ChatMessage --- system/scripts/migration.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/system/scripts/migration.js b/system/scripts/migration.js index bf8c099..f05a563 100644 --- a/system/scripts/migration.js +++ b/system/scripts/migration.js @@ -88,6 +88,20 @@ export class MigrationL5r5e { await MigrationL5r5e._migrateCompendium(pack); } + // Migrate ChatMessages + for (let message of game.collections.get("ChatMessage")) { + try { + const updateData = MigrationL5r5e._migrateChatMessage(message.data); + if (!foundry.utils.isObjectEmpty(updateData)) { + console.log(`L5R5E | Migrating ChatMessage entity ${message.id}`); + await message.update(updateData); + } + } catch (err) { + err.message = `L5R5E | Failed L5R5e system migration for Scene ${message.id}: ${err.message}`; + console.error(err); + } + } + // Set the migration as complete await game.settings.set("l5r5e", "systemMigrationVersion", game.system.data.version); ui.notifications.info(`L5R5e System Migration to version ${game.system.data.version} completed!`, { @@ -256,4 +270,22 @@ export class MigrationL5r5e { // Nothing for now return {}; } + + /** + * Migrate a single Item entity to incorporate latest data model changes + * @param {ChatMessageData} message + */ + static _migrateChatMessage(message) { + const updateData = {}; + + // ***** Start of 1.3.0 ***** + if (MigrationL5r5e.needUpdate("1.3.0")) { + // Old chat messages have a "0" in content, in foundry 0.8+ the roll content is generated only if content is null + if (message.content === "0") { + updateData["content"] = ""; + } + } + + return updateData; + } }