Skip to content

Commit 7e998ba

Browse files
committed
fix: fixed contentmapper issue and added switchcase for migration service as per cms
1 parent 4accf80 commit 7e998ba

File tree

6 files changed

+153
-38
lines changed

6 files changed

+153
-38
lines changed

api/src/constants/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
export const CS_REGIONS = ["NA", "EU", "AZURE_NA", "AZURE_EU", "GCP_NA"];
2+
export const CMS = {
3+
CONTENTFUL:"contentful",
4+
SITECORE_V8:"sitecore v8",
5+
SITECORE_V9:"sitecore v9",
6+
SITECORE_V10:"sitecore v10",
7+
WORDPRESS:"wordpress",
8+
AEM:"aem",
9+
}
210
export const MODULES = [
311
"Project",
412
"Migration",

api/src/services/migration.service.ts

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import https from "../utils/https.utils.js";
77
import { LoginServiceType } from "../models/types.js"
88
import getAuthtoken from "../utils/auth.utils.js";
99
import logger from "../utils/logger.js";
10-
import { HTTP_TEXTS, HTTP_CODES, LOCALE_MAPPER, STEPPER_STEPS } from "../constants/index.js";
10+
import { HTTP_TEXTS, HTTP_CODES, LOCALE_MAPPER, STEPPER_STEPS, CMS } from "../constants/index.js";
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";
@@ -213,26 +213,44 @@ const startTestMigration = async (req: Request): Promise<any> => {
213213
await ProjectModelLowdb.read();
214214
const project = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
215215
const packagePath = project?.extract_path;
216-
if (packagePath && project?.current_test_stack_id) {
216+
if (project?.current_test_stack_id) {
217+
const { legacy_cms: { cms, affix } } = project;
217218
const loggerPath = path.join(process.cwd(), 'logs', projectId, `${project?.current_test_stack_id}.log`);
218219
const message = getLogMessage('startTestMigration', 'Starting Test Migration...', {});
219220
await customLogger(projectId, project?.current_test_stack_id, 'info', message);
220221
await setLogFilePath(loggerPath);
221-
// const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.current_test_stack_id });
222-
// await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.current_test_stack_id, projectId });
223-
// await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
224-
// await siteCoreService?.createVersionFile(project?.current_test_stack_id);
225-
await wordpressService?.getAllAssets(project?.legacy_cms?.affix, packagePath, project?.current_test_stack_id)
226-
await wordpressService?.createAssetFolderFile(project?.legacy_cms?.affix)
227-
await wordpressService?.getAllreference(project?.legacy_cms?.affix, packagePath, project?.current_test_stack_id)
228-
await wordpressService?.extractChunks(project?.legacy_cms?.affix, packagePath, project?.current_test_stack_id)
229-
await wordpressService?.getAllAuthors(project?.legacy_cms?.affix, packagePath)
230-
await wordpressService?.extractContentTypes(project?.legacy_cms?.affix, project?.current_test_stack_id)
231-
await wordpressService?.getAllTerms(project?.legacy_cms?.affix, packagePath)
232-
await wordpressService?.getAllTags(project?.legacy_cms?.affix, packagePath)
233-
await wordpressService?.getAllCategories(project?.legacy_cms?.affix, packagePath)
234-
await wordpressService?.extractPosts(project?.legacy_cms?.affix, packagePath)
235-
await wordpressService?.extractGlobalFields(project?.current_test_stack_id)
222+
const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.current_test_stack_id });
223+
224+
switch (cms) {
225+
case CMS.SITECORE_V8:
226+
case CMS.SITECORE_V9:
227+
case CMS.SITECORE_V10: {
228+
if (packagePath) {
229+
await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.current_test_stack_id, projectId });
230+
await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
231+
await siteCoreService?.createVersionFile(project?.current_test_stack_id);
232+
}
233+
break;
234+
}
235+
case CMS.WORDPRESS: {
236+
if (packagePath) {
237+
await wordpressService?.getAllAssets(affix, packagePath, project?.current_test_stack_id)
238+
await wordpressService?.createAssetFolderFile(affix)
239+
await wordpressService?.getAllreference(affix, packagePath, project?.current_test_stack_id)
240+
await wordpressService?.extractChunks(affix, packagePath, project?.current_test_stack_id)
241+
await wordpressService?.getAllAuthors(affix, packagePath)
242+
await wordpressService?.extractContentTypes(affix, project?.current_test_stack_id)
243+
await wordpressService?.getAllTerms(affix, packagePath)
244+
await wordpressService?.getAllTags(affix, packagePath)
245+
await wordpressService?.getAllCategories(affix, packagePath)
246+
await wordpressService?.extractPosts(affix, packagePath)
247+
await wordpressService?.extractGlobalFields(project?.current_test_stack_id)
248+
}
249+
break;
250+
}
251+
default:
252+
break;
253+
}
236254
// await testFolderCreator?.({ destinationStackId: project?.current_test_stack_id });
237255
await utilsCli?.runCli(region, user_id, project?.current_test_stack_id, projectId, true, loggerPath);
238256
}
@@ -258,26 +276,44 @@ const startMigration = async (req: Request): Promise<any> => {
258276
}
259277

260278
const packagePath = project?.extract_path;
261-
if (packagePath && project?.destination_stack_id) {
279+
if (project?.destination_stack_id) {
280+
const { legacy_cms: { cms, affix } } = project;
262281
const loggerPath = path.join(process.cwd(), 'logs', projectId, `${project?.destination_stack_id}.log`);
263282
const message = getLogMessage('startTestMigration', 'Starting Migration...', {});
264283
await customLogger(projectId, project?.destination_stack_id, 'info', message);
265284
await setLogFilePath(loggerPath);
266-
// const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.destination_stack_id });
267-
// await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.destination_stack_id, projectId });
268-
// await siteCoreService?.createLocale(req, project?.destination_stack_id, projectId);
269-
// await siteCoreService?.createVersionFile(project?.destination_stack_id);
270-
await wordpressService?.getAllAssets(project?.legacy_cms?.affix, packagePath, project?.current_test_stack_id)
271-
await wordpressService?.createAssetFolderFile(project?.legacy_cms?.affix)
272-
await wordpressService?.getAllreference(project?.legacy_cms?.affix, packagePath, project?.current_test_stack_id)
273-
await wordpressService?.extractChunks(project?.legacy_cms?.affix, packagePath, project?.current_test_stack_id)
274-
await wordpressService?.getAllAuthors(project?.legacy_cms?.affix, packagePath)
275-
await wordpressService?.extractContentTypes(project?.legacy_cms?.affix, project?.current_test_stack_id)
276-
await wordpressService?.getAllTerms(project?.legacy_cms?.affix, packagePath)
277-
await wordpressService?.getAllTags(project?.legacy_cms?.affix, packagePath)
278-
await wordpressService?.getAllCategories(project?.legacy_cms?.affix, packagePath)
279-
await wordpressService?.extractPosts(project?.legacy_cms?.affix, packagePath)
280-
await wordpressService?.extractGlobalFields(project?.current_test_stack_id)
285+
const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.destination_stack_id });
286+
287+
switch (cms) {
288+
case CMS.SITECORE_V8:
289+
case CMS.SITECORE_V9:
290+
case CMS.SITECORE_V10: {
291+
if (packagePath) {
292+
await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.destination_stack_id, projectId });
293+
await siteCoreService?.createLocale(req, project?.destination_stack_id, projectId);
294+
await siteCoreService?.createVersionFile(project?.destination_stack_id);
295+
}
296+
break;
297+
}
298+
case CMS.WORDPRESS: {
299+
if (packagePath) {
300+
await wordpressService?.getAllAssets(affix, packagePath, project?.current_test_stack_id)
301+
await wordpressService?.createAssetFolderFile(affix)
302+
await wordpressService?.getAllreference(affix, packagePath, project?.current_test_stack_id)
303+
await wordpressService?.extractChunks(affix, packagePath, project?.current_test_stack_id)
304+
await wordpressService?.getAllAuthors(affix, packagePath)
305+
await wordpressService?.extractContentTypes(affix, project?.current_test_stack_id)
306+
await wordpressService?.getAllTerms(affix, packagePath)
307+
await wordpressService?.getAllTags(affix, packagePath)
308+
await wordpressService?.getAllCategories(affix, packagePath)
309+
await wordpressService?.extractPosts(affix, packagePath)
310+
await wordpressService?.extractGlobalFields(project?.current_test_stack_id)
311+
}
312+
break;
313+
}
314+
default:
315+
break;
316+
}
281317
await utilsCli?.runCli(region, user_id, project?.destination_stack_id, projectId, false, loggerPath);
282318
}
283319
}

upload-api/migration-wordpress/libs/contenttypemapper.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ const ContentTypeSchema = ({
5353
if (type === 'text') {
5454
type = multiline ? 'Multi-Line Text' : 'Single-Line Text';
5555
}
56+
if(sitecoreKey === 'title'){
57+
return {
58+
uid: sitecoreKey,
59+
otherCmsField: name.toLowerCase(),
60+
otherCmsType: 'text',
61+
contentstackField: name.toLowerCase(),
62+
contentstackFieldUid: uid,
63+
contentstackFieldType: 'text',
64+
backupFieldType: 'text',
65+
};
66+
}
67+
if(sitecoreKey === 'url'){
68+
name = name.toLowerCase();
69+
return {
70+
uid: sitecoreKey,
71+
otherCmsField: name.toLowerCase(),
72+
otherCmsType: 'text',
73+
contentstackField: name.toLowerCase(),
74+
contentstackFieldUid: uid,
75+
contentstackFieldType: 'url',
76+
backupFieldType: 'url'
77+
};
78+
}
5679
switch (type) {
5780
case 'Single-Line Text': {
5881
return {

upload-api/src/models/types.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export interface Config {
2+
plan: {
3+
dropdown: {
4+
optionLimit: number;
5+
};
6+
};
7+
cmsType: string;
8+
isLocalPath: boolean;
9+
awsData: {
10+
awsRegion: string;
11+
awsAccessKeyId: string;
12+
awsSecretAccessKey: string;
13+
awsSessionToken: string;
14+
bucketName: string;
15+
buketKey: string;
16+
};
17+
localPath: string;
18+
}

upload-api/src/routes/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import {
1212
import { client } from '../services/aws/client';
1313
import { fileOperationLimiter } from '../helper';
1414
import handleFileProcessing from '../services/fileProcessing';
15-
import createSitecoreMapper from '../controllers/sitecore';
1615
import config from '../config/index';
17-
import createWordpressMapper from '../controllers/wordpress';
16+
import createMapper from '../services/createMapper';
1817

1918
const router: Router = express.Router();
2019
// Use memory storage to avoid saving the file locally
@@ -138,7 +137,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
138137
res.status(data?.status || 200).json(data);
139138
if (data?.status === 200) {
140139
const filePath = path.join(__dirname, '..', '..', 'extracted_files', name);
141-
createSitecoreMapper(filePath, projectId, app_token, affix, config);
140+
createMapper(filePath, projectId, app_token, affix, config);
142141
}
143142
});
144143
} else if (fileExt === 'xml') {
@@ -164,7 +163,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
164163
res.status(data?.status || 200).json(data);
165164
if (data?.status === 200) {
166165
const filePath = path.join(__dirname, '..', '..', 'extracted_files', "data.json");
167-
createWordpressMapper(filePath, projectId, app_token, affix, config);
166+
createMapper(filePath, projectId, app_token, affix, config);
168167
}
169168
});
170169
}
@@ -218,7 +217,7 @@ router.get('/validator', express.json(), fileOperationLimiter, async function (r
218217
res.send('file valited sucessfully.');
219218
const filePath = path.join(__dirname, '..', '..', 'extracted_files', fileName);
220219
console.log("🚀 ~ bodyStream.on ~ filePath:", filePath)
221-
createSitecoreMapper(filePath, projectId, app_token, affix, config);
220+
createMapper(filePath, projectId, app_token, affix, config);
222221
});
223222
}
224223

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import createSitecoreMapper from '../controllers/sitecore';
2+
import createWordpressMapper from '../controllers/wordpress';
3+
import { Config } from '../models/types';
4+
// import createContentfulMapper from './contentful';
5+
6+
const createMapper = async (filePath: string = "", projectId: string | string[], app_token: string | string[], affix: string | string[], config: Config) => {
7+
const CMSIdentifier = config?.cmsType?.toLowerCase();
8+
switch (CMSIdentifier) {
9+
case 'sitecore': {
10+
console.error('🚀 ~ sitecore create mapper ~ initial mapper');
11+
return await createSitecoreMapper(filePath, projectId, app_token, affix, config);
12+
}
13+
14+
// case 'contentful': {
15+
// return await createContentfulMapper(projectId, app_token, affix, config);
16+
// }
17+
18+
case 'wordpress': {
19+
return createWordpressMapper(filePath, projectId, app_token, affix, config);
20+
}
21+
22+
// case 'aem': {
23+
// return createAemMapper({ data });
24+
// }
25+
26+
default:
27+
return false;
28+
}
29+
};
30+
31+
export default createMapper;

0 commit comments

Comments
 (0)