Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
feat!: renames "process" import option to "canImport", updates docs &…
Browse files Browse the repository at this point in the history
… samples
  • Loading branch information
Enngage committed Jul 19, 2021
1 parent 19e9d2b commit 39c36ab
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 24 deletions.
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,36 @@ const run = async () => {
// called when any content is imported
console.log(`Imported: ${item.title} | ${item.type}`);
},
fixLanguages: true,
canImport: {
asset: (item) => {
if(item.title.startsWith('_corporate')) {
// asset will be imported only if the title starts with "_corporate"
return true;
}
// otherwise asset will NOT be imported
return false;
},
contentType: (item) => {
if (item.codename === 'article') {
// content type will be imported only with its codename is 'article'
return true;
}
// all other types will be excluded from import
return false;
},
assetFolder: item => true, // all folders will be imported
contentItem: item => true, // all content items will be imported
contentTypeSnippet: item => true, // all content type snippets will be imported
language: item => true, // all languages will be imported
languageVariant: item => true, // all language variants will be imported
taxonomy: item => true,// all taxonomies will be imported
},
enablePublish: true, // when enables, previously published language variants will be published after restore (does not affect unpublished variants)
projectId: 'targetProjectId',
apiKey: 'targetProjectId',
enableLog: true,
workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000' // workflow id that items are assigned
enableLog: true, // shows progress of immport in console
fixLanguages: true, // backup manager will attempt to create missing languages & map existing languages
workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000' // id that items are assigned
});

// read export data from zip
Expand Down
2 changes: 1 addition & 1 deletion lib/import/import.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface IImportConfig {
onUnsupportedBinaryFile?: (binaryFile: IBinaryFile) => void;
onImport?: (item: IProcessedItem) => void;
fixLanguages: boolean;
process?: {
canImport?: {
taxonomy?: (item: TaxonomyContracts.ITaxonomyContract) => boolean | Promise<boolean>;
contentTypeSnippet?: (
item: ContentTypeSnippetContracts.IContentTypeSnippetContract
Expand Down
32 changes: 16 additions & 16 deletions lib/import/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,54 +216,54 @@ export class ImportService {
}

private removeSkippedItemsFromImport(source: IImportSource): void {
if (this.config.process && this.config.process.asset) {
if (this.config.canImport && this.config.canImport.asset) {
for (const item of source.importData.assets) {
const shouldImport = this.config.process.asset(item);
const shouldImport = this.config.canImport.asset(item);
if (!shouldImport) {
source.importData.assets = source.importData.assets.filter((m) => m.id !== item.id);
}
}
}

if (this.config.process && this.config.process.language) {
if (this.config.canImport && this.config.canImport.language) {
for (const item of source.importData.languages) {
const shouldImport = this.config.process.language(item);
const shouldImport = this.config.canImport.language(item);
if (!shouldImport) {
source.importData.languages = source.importData.languages.filter((m) => m.id !== item.id);
}
}
}

if (this.config.process && this.config.process.assetFolder) {
if (this.config.canImport && this.config.canImport.assetFolder) {
for (const item of source.assetFolders) {
const shouldImport = this.config.process.assetFolder(item);
const shouldImport = this.config.canImport.assetFolder(item);
if (!shouldImport) {
source.assetFolders = source.assetFolders.filter((m) => m.id !== item.id);
}
}
}

if (this.config.process && this.config.process.contentType) {
if (this.config.canImport && this.config.canImport.contentType) {
for (const item of source.importData.contentTypes) {
const shouldImport = this.config.process.contentType(item);
const shouldImport = this.config.canImport.contentType(item);
if (!shouldImport) {
source.importData.contentTypes = source.importData.contentTypes.filter((m) => m.id !== item.id);
}
}
}

if (this.config.process && this.config.process.contentItem) {
if (this.config.canImport && this.config.canImport.contentItem) {
for (const item of source.importData.contentItems) {
const shouldImport = this.config.process.contentItem(item);
const shouldImport = this.config.canImport.contentItem(item);
if (!shouldImport) {
source.importData.contentItems = source.importData.contentItems.filter((m) => m.id !== item.id);
}
}
}

if (this.config.process && this.config.process.contentTypeSnippet) {
if (this.config.canImport && this.config.canImport.contentTypeSnippet) {
for (const item of source.importData.contentTypeSnippets) {
const shouldImport = this.config.process.contentTypeSnippet(item);
const shouldImport = this.config.canImport.contentTypeSnippet(item);
if (!shouldImport) {
source.importData.contentTypeSnippets = source.importData.contentTypeSnippets.filter(
(m) => m.id !== item.id
Expand All @@ -272,9 +272,9 @@ export class ImportService {
}
}

if (this.config.process && this.config.process.languageVariant) {
if (this.config.canImport && this.config.canImport.languageVariant) {
for (const item of source.importData.languageVariants) {
const shouldImport = this.config.process.languageVariant(item);
const shouldImport = this.config.canImport.languageVariant(item);
if (!shouldImport) {
source.importData.languageVariants = source.importData.languageVariants.filter(
(m) => m.item.id !== item.item.id && m.language.id !== item.language.id
Expand All @@ -283,9 +283,9 @@ export class ImportService {
}
}

if (this.config.process && this.config.process.taxonomy) {
if (this.config.canImport && this.config.canImport.taxonomy) {
for (const item of source.importData.taxonomies) {
const shouldImport = this.config.process.taxonomy(item);
const shouldImport = this.config.canImport.taxonomy(item);
if (!shouldImport) {
source.importData.taxonomies = source.importData.taxonomies.filter((m) => m.id !== item.id);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/node/cli/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const restoreAsync = async (config: ICliFileConfig) => {
apiKey: config.apiKey,
enableLog: config.enableLog,
workflowIdForImportedItems: undefined,
process: {
canImport: {
contentItem: (item) => {
return true;
}
Expand Down
32 changes: 29 additions & 3 deletions lib/samples/restore-sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,37 @@ const run = async () => {
// called when any content is imported
console.log(`Imported: ${item.title} | ${item.type}`);
},
enablePublish: true,
// be careful when filtering data to import because you might break data consistency.
// for example, it might not be possible to import language variant without first importing content item and so on.
canImport: {
asset: (item) => {
if(item.title.startsWith('_corporate')) {
// asset will be imported only if the title starts with "_corporate"
return true;
}
// otherwise asset will NOT be imported
return false;
},
contentType: (item) => {
if (item.codename === 'article') {
// content type will be imported only with its codename is 'article'
return true;
}
// all other types will be excluded from import
return false;
},
assetFolder: item => true, // all folders will be imported
contentItem: item => true, // all content items will be imported
contentTypeSnippet: item => true, // all content type snippets will be imported
language: item => true, // all languages will be imported
languageVariant: item => true, // all language variants will be imported
taxonomy: item => true,// all taxonomies will be imported
},
enablePublish: true, // when enables, previously published language variants will be published after restore (does not affect unpublished variants)
projectId: 'targetProjectId',
apiKey: 'targetProjectId',
enableLog: true,
fixLanguages: true,
enableLog: true, // shows progress of immport in console
fixLanguages: true, // backup manager will attempt to create missing languages & map existing languages
workflowIdForImportedItems: '00000000-0000-0000-0000-000000000000' // id that items are assigned
});

Expand Down

0 comments on commit 39c36ab

Please sign in to comment.