Skip to content

Commit 6caf0cf

Browse files
committed
refactor:refactored the wordpress migration code
1 parent 4a08728 commit 6caf0cf

File tree

10 files changed

+525
-433
lines changed

10 files changed

+525
-433
lines changed

api/src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ 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",

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: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,34 +225,27 @@ const startTestMigration = async (req: Request): Promise<any> => {
225225
case CMS.SITECORE_V9:
226226
case CMS.SITECORE_V10: {
227227
if (packagePath) {
228-
const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.current_test_stack_id });
229-
230-
await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.current_test_stack_id, projectId });
228+
await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.current_test_stack_id, projectId,keyMapper: project?.mapperKeys });
231229
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
232230
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
233231
}
234232
break;
235233
}
236234
case CMS.WORDPRESS: {
237235
if (packagePath) {
238-
await wordpressService?.getAllAssets(affix, packagePath, project?.current_test_stack_id, projectId)
239-
await wordpressService?.createAssetFolderFile(affix, project?.current_test_stack_id, projectId)
240-
await wordpressService?.getAllreference(affix, packagePath, project?.current_test_stack_id, projectId)
241-
await wordpressService?.extractChunks(affix, packagePath, project?.current_test_stack_id, projectId)
242-
await wordpressService?.getAllAuthors(affix, packagePath,project?.current_test_stack_id, projectId)
243-
await wordpressService?.extractContentTypes(projectId, project?.current_test_stack_id)
244-
await wordpressService?.getAllTerms(affix, packagePath,project?.current_test_stack_id, projectId)
245-
await wordpressService?.getAllTags(affix, packagePath,project?.current_test_stack_id, projectId)
246-
await wordpressService?.getAllCategories(affix, packagePath,project?.current_test_stack_id, projectId)
247-
await wordpressService?.extractPosts( packagePath,project?.current_test_stack_id, projectId)
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)
248246
await wordpressService?.extractGlobalFields(project?.current_test_stack_id, projectId)
249247
await wordpressService?.createVersionFile(project?.current_test_stack_id, projectId);
250248
}
251-
if (packagePath) {
252-
await siteCoreService?.createEntry({ packagePath, contentTypes, master_locale: project?.stackDetails?.master_locale, destinationStackId: project?.current_test_stack_id, projectId, keyMapper: project?.mapperKeys });
253-
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
254-
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
255-
}
256249
break;
257250
}
258251
case CMS.CONTENTFUL: {
@@ -319,12 +312,12 @@ const startMigration = async (req: Request): Promise<any> => {
319312
await wordpressService?.createAssetFolderFile(file_path, project?.destination_stack_id, projectId)
320313
await wordpressService?.getAllreference(file_path, packagePath, project?.destination_stack_id, projectId)
321314
await wordpressService?.extractChunks(file_path, packagePath, project?.destination_stack_id, projectId)
322-
await wordpressService?.getAllAuthors(file_path, packagePath,project?.destination_stack_id, projectId)
323-
await wordpressService?.extractContentTypes(projectId, project?.destination_stack_id)
324-
await wordpressService?.getAllTerms(file_path, packagePath,project?.destination_stack_id, projectId)
325-
await wordpressService?.getAllTags(file_path, packagePath,project?.destination_stack_id, projectId)
326-
await wordpressService?.getAllCategories(file_path, packagePath,project?.destination_stack_id, projectId)
327-
await wordpressService?.extractPosts( 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)
328321
await wordpressService?.extractGlobalFields(project?.destination_stack_id, projectId)
329322
await wordpressService?.createVersionFile(project?.destination_stack_id, projectId);
330323

0 commit comments

Comments
 (0)