From 003e5cbd4bebeac620aa06bd7c97c05b47ef2d16 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 25 Nov 2021 01:19:00 -0500 Subject: [PATCH] ImportEtherpad: Fix DB key pad ID transformation --- src/node/utils/ImportEtherpad.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index 63c9afc9b..224424a43 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -34,6 +34,13 @@ exports.setPadRaw = async (padId, r) => { const unsupportedElements = new Set(); + // DB key prefixes for pad records. Each key is expected to have the form `${prefix}:${padId}` or + // `${prefix}:${padId}:${otherstuff}`. + const padKeyPrefixes = [ + ...await hooks.aCallAll('exportEtherpadAdditionalContent'), + 'pad', + ]; + await Promise.all(Object.entries(records).map(async ([key, value]) => { if (!value) { return; @@ -47,9 +54,6 @@ exports.setPadRaw = async (padId, r) => { } value.padIDs = {[padId]: 1}; } else { - // Not author data, probably pad data - // we can split it to look to see if it's pad data - // is this an attribute we support or not? If not, tell the admin if (value.pool) { for (const attrib of Object.keys(value.pool.numToAttrib)) { @@ -57,20 +61,9 @@ exports.setPadRaw = async (padId, r) => { if (!supportedElems.has(attribName)) unsupportedElements.add(attribName); } } - const oldPadId = key.split(':'); - - // we know it's pad data - if (oldPadId[0] === 'pad') { - // so set the new pad id for the author - oldPadId[1] = padId; - key = oldPadId.join(':'); - } - - // is this a key that is supported through a plugin? - // get content that has a different prefix IE comments:padId:foo - // a plugin would return something likle ['comments', 'cakes'] - for (const prefix of await hooks.aCallAll('exportEtherpadAdditionalContent')) { - if (prefix === oldPadId[0]) key = `${prefix}:${padId}`; + if (padKeyPrefixes.includes(prefix)) { + keyParts[1] = padId; + key = keyParts.join(':'); } } await db.set(key, value);