Skip to content

Commit a581576

Browse files
authored
Merge pull request #341 from contentstack/feature/migration-wordpress-integration
Feature/migration wordpress integration
2 parents 10932fb + ef768ed commit a581576

File tree

26 files changed

+3816
-3717
lines changed

26 files changed

+3816
-3717
lines changed

api/src/constants/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,34 @@ export const MIGRATION_DATA_CONFIG = {
212212
ASSETS_SCHEMA_FILE: "index.json",
213213
ASSETS_FAILED_FILE: "cs_failed.json",
214214
ASSETS_METADATA_FILE: "metadata.json",
215+
ASSETS_FOLDER_FILE_NAME: "folders.json",
215216

216217
ENTRIES_DIR_NAME: "entries",
217218
ENTRIES_MASTER_FILE: "index.json",
218219

220+
AUTHORS_DIR_NAME : "authors",
221+
AUTHORS_FILE_NAME : "en-us.json",
222+
AUTHORS_MASTER_FILE : "authors.json",
223+
224+
CATEGORIES_DIR_NAME: "categories",
225+
CATEGORIES_FILE_NAME: "en-us.json",
226+
CATEGORIES_MASTER_FILE: "categories.json",
227+
228+
TAG_DIR_NAME: "tags",
229+
TAG_FILE_NAME: "en-us.json",
230+
TAG_MASTER_FILE: "tag.json",
231+
232+
TERMS_DIR_NAME: "terms",
233+
TERMS_FILE_NAME: "en-us.json",
234+
TERMS_MASTER_FILE: "terms.json",
235+
236+
POSTS_DIR_NAME: "posts",
237+
POSTS_FOLDER_NAME: "en-us",
238+
POSTS_FILE_NAME: "en-us.json",
239+
POSTS_MASTER_FILE: "posts.json",
240+
241+
CHUNKS_DIR_NAME: "chunks",
242+
219243
GLOBAL_FIELDS_DIR_NAME: "global_fields",
220244
GLOBAL_FIELDS_FILE_NAME: "globalfields.json",
221245

api/src/models/FieldMapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from "path";
55
/**
66
* Represents the advanced configuration options for a field mapper.
77
*/
8-
interface Advanced {
8+
export interface Advanced {
99
validationRegex: string;
1010
mandatory: boolean;
1111
multiple: boolean;

api/src/services/contentMapper.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const putTestData = async (req: Request) => {
4949
*/
5050
contentTypes.map((type: any, index: any) => {
5151
const fieldIds: string[] = [];
52-
const fields = type?.fieldMapping?.map?.((field: any) => {
53-
const id = field?.id?.replace(/[{}]/g, "")?.toLowerCase() || uuidv4();
52+
const fields = type?.fieldMapping?.filter((field: any) => field)?.map?.((field: any) => {
53+
const id = field?.id ? field?.id?.replace(/[{}]/g, "")?.toLowerCase() : uuidv4();
5454
field.id = id;
5555
fieldIds.push(id);
5656
return { id, projectId, isDeleted: false, ...field };

api/src/services/migration.service.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { HTTP_TEXTS, HTTP_CODES, LOCALE_MAPPER, STEPPER_STEPS, CMS } from "../co
1111
import { BadRequestError, ExceptionFunction } from "../utils/custom-errors.utils.js";
1212
import { fieldAttacher } from "../utils/field-attacher.utils.js";
1313
import { siteCoreService } from "./sitecore.service.js";
14+
import { wordpressService } from "./wordpress.service.js";
1415
import { testFolderCreator } from "../utils/test-folder-creator.utils.js";
1516
import { utilsCli } from './runCli.service.js';
1617
import customLogger from "../utils/custom-logger.utils.js";
@@ -223,10 +224,27 @@ const startTestMigration = async (req: Request): Promise<any> => {
223224
case CMS.SITECORE_V8:
224225
case CMS.SITECORE_V9:
225226
case CMS.SITECORE_V10: {
227+
if (packagePath) {
228+
await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.current_test_stack_id, projectId,keyMapper: project?.mapperKeys });
229+
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
230+
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
231+
}
232+
break;
233+
}
234+
case CMS.WORDPRESS: {
226235
if (packagePath) {
227-
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.current_test_stack_id, projectId, keyMapper: project?.mapperKeys });
228-
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
229-
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
236+
await wordpressService?.getAllAssets(file_path, packagePath, project?.current_test_stack_id, projectId)
237+
await wordpressService?.createAssetFolderFile(file_path, project?.current_test_stack_id, projectId)
238+
await wordpressService?.getAllreference(file_path, packagePath, project?.current_test_stack_id, projectId)
239+
await wordpressService?.extractChunks(file_path, packagePath, project?.current_test_stack_id, projectId)
240+
await wordpressService?.getAllAuthors(file_path, packagePath,project?.current_test_stack_id, projectId,contentTypes, project?.mapperKeys)
241+
//await wordpressService?.extractContentTypes(projectId, project?.current_test_stack_id, contentTypes)
242+
await wordpressService?.getAllTerms(file_path, packagePath,project?.current_test_stack_id, projectId,contentTypes, project?.mapperKeys)
243+
await wordpressService?.getAllTags(file_path, packagePath,project?.current_test_stack_id, projectId,contentTypes, project?.mapperKeys)
244+
await wordpressService?.getAllCategories(file_path, packagePath,project?.current_test_stack_id, projectId,contentTypes, project?.mapperKeys)
245+
await wordpressService?.extractPosts( packagePath,project?.current_test_stack_id, projectId,contentTypes, project?.mapperKeys)
246+
await wordpressService?.extractGlobalFields(project?.current_test_stack_id, projectId)
247+
await wordpressService?.createVersionFile(project?.current_test_stack_id, projectId);
230248
}
231249
break;
232250
}
@@ -288,6 +306,25 @@ const startMigration = async (req: Request): Promise<any> => {
288306
}
289307
break;
290308
}
309+
case CMS.WORDPRESS: {
310+
if (packagePath) {
311+
await wordpressService?.getAllAssets(file_path, packagePath, project?.destination_stack_id, projectId)
312+
await wordpressService?.createAssetFolderFile(file_path, project?.destination_stack_id, projectId)
313+
await wordpressService?.getAllreference(file_path, packagePath, project?.destination_stack_id, projectId)
314+
await wordpressService?.extractChunks(file_path, packagePath, project?.destination_stack_id, projectId)
315+
await wordpressService?.getAllAuthors(file_path, packagePath,project?.destination_stack_id, projectId,contentTypes, project?.mapperKeys)
316+
//await wordpressService?.extractContentTypes(projectId, project?.destination_stack_id)
317+
await wordpressService?.getAllTerms(file_path, packagePath,project?.destination_stack_id, projectId,contentTypes, project?.mapperKeys)
318+
await wordpressService?.getAllTags(file_path, packagePath,project?.destination_stack_id, projectId,contentTypes, project?.mapperKeys)
319+
await wordpressService?.getAllCategories(file_path, packagePath,project?.destination_stack_id, projectId,contentTypes, project?.mapperKeys)
320+
await wordpressService?.extractPosts( packagePath,project?.destination_stack_id, projectId,contentTypes, project?.mapperKeys)
321+
await wordpressService?.extractGlobalFields(project?.destination_stack_id, projectId)
322+
await wordpressService?.createVersionFile(project?.destination_stack_id, projectId);
323+
324+
325+
}
326+
break;
327+
}
291328
case CMS.CONTENTFUL: {
292329
await contentfulService?.createLocale(file_path, project?.destination_stack_id, projectId);
293330
await contentfulService?.createRefrence(file_path, project?.destination_stack_id, projectId);

0 commit comments

Comments
 (0)