Skip to content

Commit

Permalink
new import/export command -
Browse files Browse the repository at this point in the history
keys without access to webhooks do not block import
  • Loading branch information
KarolNet committed Dec 10, 2024
1 parent 27c476e commit 0100247
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
33 changes: 21 additions & 12 deletions commands/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fetch = require('node-fetch')
const FlotiqApi = require("./../src/flotiq-api");
const config = require("./../src/configuration/config");
const {mediaImporter} = require("./../src/media");
const WEBHOOKS_MESSAGE_403 = 'It looks like the api key does not have access to webhooks, it continues without deactivating webhooks';

exports.command = 'import'
exports.description = 'Import flotiq entities from JSON structure'
Expand Down Expand Up @@ -120,12 +121,16 @@ async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions,

let existingWebhooks = [];
if (disableWebhooks) {
let existingWebhooks = await flotiqApi.fetchContentObjects('_webhooks');
logger.info(`Pass 1a - disable webhooks`);
await flotiqApi.patchContentObjectBatch('_webhooks', existingWebhooks.map(webhook => ({
id: webhook.id,
enabled: false
})));
try {
let existingWebhooks = await flotiqApi.fetchContentObjects('_webhooks');
logger.info(`Pass 1a - disable webhooks`);
await flotiqApi.patchContentObjectBatch('_webhooks', existingWebhooks.map(webhook => ({
id: webhook.id,
enabled: false
})));
} catch (e) {
logger.warn(WEBHOOKS_MESSAGE_403);
}
}

const CTDFiles = await glob(`${directory}/**/ContentTypeDefinition.json`)
Expand Down Expand Up @@ -417,12 +422,16 @@ async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions,
if (disableWebhooks && existingWebhooks.length > 0) {
// We should restore our webhooks even if we're importing webhooks,
// so any webhooks not imported are restored correctly.
logger.info('Pass 5a - Restoring webhooks')
await flotiqApi
.persistContentObjectBatch(
'_webhooks',
existingWebhooks
);
logger.info('Pass 5a - Restoring webhooks');
try {
await flotiqApi
.persistContentObjectBatch(
'_webhooks',
existingWebhooks
);
} catch (e) {
logger.warn(WEBHOOKS_MESSAGE_403);
}
}

if (CTDs.map(c => c.name).includes('_webhooks')) {
Expand Down
1 change: 0 additions & 1 deletion src/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const FlotiqApi = require("./flotiq-api");
const { Blob } = require('buffer');

async function mediaImporter (directory, flotiqApiUrl, flotiqApiKey, batchSize = 100, checkIfMediaUsed = true) {
logger.info(`Start import media files!!!!!!!!!!!!`)
const flotiqApi = new FlotiqApi(flotiqApiUrl, flotiqApiKey, {
batchSize: batchSize,
});
Expand Down

0 comments on commit 0100247

Please sign in to comment.