From 76e4d1b802693279a861a873b36b9e9f3eaaba7b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 8 Jul 2024 12:00:37 +0200 Subject: [PATCH] Updates migration toolkit code samples --- .../migration_toolkit_map_migrationasset.ts | 20 ++- .../migration_toolkit_map_migrationitem.ts | 129 ++++++++++-------- .../migration_toolkit_migrationitem.ts | 19 ++- 3 files changed, 91 insertions(+), 77 deletions(-) diff --git a/ts/migrate-from-other-systems/migration_toolkit_map_migrationasset.ts b/ts/migrate-from-other-systems/migration_toolkit_map_migrationasset.ts index c5d7840c..69322b05 100644 --- a/ts/migrate-from-other-systems/migration_toolkit_map_migrationasset.ts +++ b/ts/migrate-from-other-systems/migration_toolkit_map_migrationasset.ts @@ -1,10 +1,6 @@ -import { - MigrationAsset, -} from "@kontent-ai-consulting/migration-toolkit"; +import { MigrationAsset } from "@kontent-ai-consulting/migration-toolkit"; import { readFileSync } from "fs"; // Only if loading local data -const migrationAssets: MigrationAsset[] = []; - const asset: MigrationAsset = { // You can load the data from anywhere, not just from the filesystem binaryData: readFileSync("./path/to/file.jpg"), @@ -15,16 +11,18 @@ const asset: MigrationAsset = { // Name the asset title: "My asset", // Asign the asset to a collection - collection: "default", + collection: { + codename: "default", + }, // Specify localized asset descriptions descriptions: [ { language: { - codename: "default" + codename: "default", }, - description: "Alt text" - } - ] + description: "Alt text", + }, + ], }; -migrationAssets.push(asset); \ No newline at end of file +const migrationAssets: MigrationAsset[] = [asset]; diff --git a/ts/migrate-from-other-systems/migration_toolkit_map_migrationitem.ts b/ts/migrate-from-other-systems/migration_toolkit_map_migrationitem.ts index fa178cb8..b0bdb3a9 100644 --- a/ts/migrate-from-other-systems/migration_toolkit_map_migrationitem.ts +++ b/ts/migrate-from-other-systems/migration_toolkit_map_migrationitem.ts @@ -6,7 +6,7 @@ import { } from "@kontent-ai-consulting/migration-toolkit"; // Define the structure of your Kontent.ai content type -interface MovieModel extends MigrationElements { +interface MovieType extends MigrationElements { title: MigrationElementModels.TextElement; plot: MigrationElementModels.RichTextElement; length: MigrationElementModels.NumberElement; @@ -14,71 +14,82 @@ interface MovieModel extends MigrationElements { poster: MigrationElementModels.AssetElement; } -const migrationItems: MigrationItem[] = []; - -const movie: MigrationItem = { +const movie: MigrationItem = { system: { name: "Warrior", // Ensure a unique codename. Check https://kontent.ai/learn/rules-for-codenames codename: "warrior", - collection: { codename: "default", }, + collection: { codename: "default" }, // Map your source language to the language codename in Kontent.ai - language: { codename: "default", }, - type: { codename: "movie", }, - workflow: { codename: "default", }, - // Tip: You can have the item published during the import - workflow_step: { codename: "published", }, + language: { codename: "default" }, + type: { codename: "movie" }, + workflow: { codename: "default" }, }, - elements: { - title: elementsBuilder.textElement({ value: "Warrior" }), - length: elementsBuilder.numberElement({ value: 140 }), - category: elementsBuilder.multipleChoiceElement({ - value: [ // Reference multiple choice options by their codenames - { - codename: "drama" - }, - { - codename: "action" - }, - ] - }), - poster: elementsBuilder.assetElement({ - value: [ // Reference assets by their codenames - { - codename: "warrior_teaser", - }, - ], - }), - plot: elementsBuilder.richTextElement({ - value: { // Check supported HTML elements at https://kontent.ai/learn/rich-text-in-mapi - value: `

Warrior

...

`, - components: [], + // Tip: You can migrate up to 2 versions - 1 published and one in draft state. This is optional and typically + // you only need to migrate a single version of your content + versions: [ + { + workflow_step: { + // Tip: You can have the item published during the import or use any other workflow step + codename: "published", }, - }), - releasecategory: elementsBuilder.taxonomyElement({ - value: [ // Reference taxonomy terms by their codenames - { - codename: "global_release", - }, - ], - }), - released: elementsBuilder.dateTimeElement({ - value: "2011-09-09T00:00:00Z", - }), - seoname: elementsBuilder.urlSlugElement({ - value: { - mode: "autogenerated", - value: "", // Empty string because 'value' is autogenerated based on the dependent text element + elements: { + title: elementsBuilder.textElement({ value: "Warrior" }), + length: elementsBuilder.numberElement({ value: 140 }), + category: elementsBuilder.multipleChoiceElement({ + value: [ + // Reference multiple choice options by their codenames + { + codename: "drama", + }, + { + codename: "action", + }, + ], + }), + poster: elementsBuilder.assetElement({ + value: [ + // Reference assets by their codenames + { + codename: "warrior_teaser", + }, + ], + }), + plot: elementsBuilder.richTextElement({ + value: { + // Check supported HTML elements at https://kontent.ai/learn/rich-text-in-mapi + value: `

Warrior

...

`, + components: [], + }, + }), + releasecategory: elementsBuilder.taxonomyElement({ + value: [ + // Reference taxonomy terms by their codenames + { + codename: "global_release", + }, + ], + }), + released: elementsBuilder.dateTimeElement({ + value: "2011-09-09T00:00:00Z", + }), + seoname: elementsBuilder.urlSlugElement({ + value: { + mode: "autogenerated", + value: "", // Empty string because 'value' is autogenerated based on the dependent text element + }, + }), + stars: elementsBuilder.linkedItemsElement({ + value: [ + // Reference content items by their codenames + { + codename: "tom_hardy", + }, + ], + }), }, - }), - stars: elementsBuilder.linkedItemsElement({ - value: [ // Reference content items by their codenames - { - codename: "tom_hardy", - }, - ], - }), - }, + }, + ], }; -migrationItems.push(movie); \ No newline at end of file +const migrationItems: MigrationItem[] = [movie]; diff --git a/ts/migrate-from-other-systems/migration_toolkit_migrationitem.ts b/ts/migrate-from-other-systems/migration_toolkit_migrationitem.ts index 5a4239fc..79b6e8f1 100644 --- a/ts/migrate-from-other-systems/migration_toolkit_migrationitem.ts +++ b/ts/migrate-from-other-systems/migration_toolkit_migrationitem.ts @@ -13,11 +13,16 @@ const migrationItem: MigrationItem = { type: { codename: "article" }, // Assign the variant to a workflow workflow: { codename: "default" }, - // Put the variant in a specific workflow step - workflow_step: { codename: "draft" }, }, - elements: { // Variant's content - // For each element specified by the item's content type, add properties named using element codenames. - // Example: element_codename: elementsBuilder.textElement({ value: 'plaintext' }), - } -}; \ No newline at end of file + versions: [ + { + // Put the variant in a specific workflow step + workflow_step: { codename: "draft" }, + elements: { + // Variant's content + // For each element specified by the item's content type, add properties named using element codenames. + // Example: element_codename: elementsBuilder.textElement({ value: 'plaintext' }), + }, + }, + ], +};