From 3e1f9effa392b3a79883518ca6c966ff5b7ce00a Mon Sep 17 00:00:00 2001 From: CiotkaCierpienia Date: Wed, 19 Feb 2025 09:23:34 +0100 Subject: [PATCH] prepare importer for relation validation on CTD creation --- commands/importer.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/commands/importer.js b/commands/importer.js index 8d76873..c1a4414 100644 --- a/commands/importer.js +++ b/commands/importer.js @@ -94,6 +94,16 @@ async function restoreDefinitions(remoteContentTypeDefinitions, brokenConstraint } } +function fixRelationsInCTDs(remoteContentTypeDefinitions, CTDs) { + return remoteContentTypeDefinitions.map(rCTD => { + const newCTD = CTDs.find(ctd => ctd.name === rCTD.name); + if (newCTD) { + return newCTD; + } + return rCTD; + }); +} + async function importer(directory, flotiqApi, skipDefinitions, skipContent, updateDefinitions, disableWebhooks, fixDefinitions, ctd, skipCtd) { if (fixDefinitions) { @@ -207,6 +217,7 @@ async function importer(directory, flotiqApi, skipDefinitions, skipContent, upda if (skipContent) { if(brokenConstraints.length) { remoteContentTypeDefinitions = await flotiqApi.fetchContentTypeDefs(); + remoteContentTypeDefinitions = fixRelationsInCTDs(remoteContentTypeDefinitions, CTDs) await restoreDefinitions(remoteContentTypeDefinitions, brokenConstraints, flotiqApi, '2'); } logger.info('All done') @@ -217,6 +228,7 @@ async function importer(directory, flotiqApi, skipDefinitions, skipContent, upda if(!remoteContentTypeDefinitions) { remoteContentTypeDefinitions = await flotiqApi.fetchContentTypeDefs(); + remoteContentTypeDefinitions = fixRelationsInCTDs(remoteContentTypeDefinitions, CTDs) } /**