Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const HTTP_TEXTS = {
"Project Deleted Successfully",
PROJECT_REVERT:
"Project Reverted Successfully",
LOGS_NOT_FOUND:
"Sorry, no logs found for requested stack migration."
};

export const HTTP_RESPONSE_HEADERS = {
Expand Down
8 changes: 7 additions & 1 deletion api/src/controllers/migration.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ const deleteTestStack = async (req: Request, res: Response): Promise<void> => {
res.status(200).json(resp);
};

const getLogs = async (req: Request, res: Response): Promise<void> => {
const resp = await migrationService.getLogs(req);
res.status(200).json(resp);
};

export const migrationController = {
createTestStack,
deleteTestStack,
startTestMigration,
startMigration
startMigration,
getLogs,
};
6 changes: 6 additions & 0 deletions api/src/routes/migration.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@ router.post(
asyncRouter(migrationController.startMigration)
);

router.get(
"/get_migration_logs/:orgId/:projectId/:stackId",
asyncRouter(migrationController.getLogs)

)


export default router;
58 changes: 56 additions & 2 deletions api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { LoginServiceType } from "../models/types.js"
import getAuthtoken from "../utils/auth.utils.js";
import logger from "../utils/logger.js";
import { HTTP_TEXTS, HTTP_CODES, LOCALE_MAPPER, STEPPER_STEPS } from "../constants/index.js";
import { ExceptionFunction } from "../utils/custom-errors.utils.js";
import { BadRequestError, ExceptionFunction } from "../utils/custom-errors.utils.js";
import { fieldAttacher } from "../utils/field-attacher.utils.js";
import { siteCoreService } from "./sitecore.service.js";
import { testFolderCreator } from "../utils/test-folder-creator.utils.js";
import { utilsCli } from './runCli.service.js';
import customLogger from "../utils/custom-logger.utils.js";
import { setLogFilePath } from "../server.js";
import fs from 'fs';



Expand Down Expand Up @@ -258,9 +259,62 @@ const startMigration = async (req: Request): Promise<any> => {
}
}

const getLogs = async (req: Request): Promise<any> => {
const orgId = req?.params?.orgId;
const projectId = req?.params?.projectId;
const stackId = req?.params?.stackId;
const srcFunc = "getLogs";
const { region, user_id } = req?.body?.token_payload ?? {};
try {
const loggerPath = path.join(process.cwd(), 'logs', projectId, `${stackId}.log`);
if(fs.existsSync(loggerPath)){
const logs = fs.readFileSync(loggerPath,'utf-8');
const logEntries = logs
.split('\n')
.map(line => {
try {
return JSON.parse(line);
} catch (error) {
return null;
}
})
.filter(entry => entry !== null);
return logEntries

}
else{
logger.error(
getLogMessage(
srcFunc,
HTTP_TEXTS.LOGS_NOT_FOUND,

)
);
throw new BadRequestError(HTTP_TEXTS.LOGS_NOT_FOUND);

}

} catch (error:any) {
logger.error(
getLogMessage(
srcFunc,
HTTP_TEXTS.LOGS_NOT_FOUND,
error
)
);
throw new ExceptionFunction(
error?.message || HTTP_TEXTS.INTERNAL_ERROR,
error?.statusCode || error?.status || HTTP_CODES.SERVER_ERROR
);

}

}

export const migrationService = {
createTestStack,
deleteTestStack,
startTestMigration,
startMigration
startMigration,
getLogs,
};
3 changes: 2 additions & 1 deletion api/src/services/runCli.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const addCustomMessageInCliLogs = async (loggerPath: string, level: string = 'in

export const runCli = async (rg: string, user_id: string, stack_uid: any, projectId: string, isTest = false, transformePath: string) => {
try {
const message: string = isTest ? 'Test Migration Process Completed' : 'Migration Process Completed'
const regionPresent = CS_REGIONS?.find((item: string) => item === rg) ?? 'NA';
await AuthenticationModel.read();
const userData = AuthenticationModel.chain
Expand Down Expand Up @@ -56,7 +57,7 @@ export const runCli = async (rg: string, user_id: string, stack_uid: any, projec
})
ProjectModelLowdb.write();
}
await addCustomMessageInCliLogs(loggerPath, 'info', 'Test Migration Process Completed');
await addCustomMessageInCliLogs(loggerPath, 'info', message);
}
});

Expand Down
4 changes: 2 additions & 2 deletions api/src/utils/field-attacher.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const fieldAttacher = async ({ projectId, orgId, destinationStackId }: an
for await (const contentId of projectData?.content_mapper ?? []) {
const contentType: any = ContentTypesMapperModelLowdb.chain
.get("ContentTypesMappers")
.find({ id: contentId })
.find({ id: contentId, projectId: projectId })
.value();
if (contentType?.fieldMapping?.length) {
contentType.fieldMapping = contentType?.fieldMapping?.map((fieldUid: any) => {
const field = FieldMapperModel.chain
.get("field_mapper")
.find({ id: fieldUid })
.find({ id: fieldUid, projectId: projectId })
.value()
return field;
})
Expand Down
4 changes: 3 additions & 1 deletion cli/packages/contentstack/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ coverage
tsconfig.tsbuildinfo
/merge_scripts
/merge-summary.json
!bin
!bin
/sitecoreMigrationData
/migration-data
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const HorizontalStepper = forwardRef(
const stepIndex = parseInt(stepId || '', 10) - 1;

if (!Number.isNaN(stepIndex) && stepIndex >= 0 && stepIndex < steps?.length) {
setShowStep(stepIndex);
!newMigrationData?.isprojectMapped && setShowStep(stepIndex);
setStepsCompleted(prev => {
const updatedStepsCompleted = [...prev];
for (let i = 0; i < stepIndex; i++) {
Expand Down Expand Up @@ -171,7 +171,7 @@ const HorizontalStepper = forwardRef(
};

const setTabStep = (idx: number) => {
if (stepsCompleted?.includes(idx) || stepsCompleted?.length === idx) {
if ((stepsCompleted?.includes(idx) || stepsCompleted?.length === idx) && !newMigrationData?.isprojectMapped) {
setShowStep(idx);
const url = `/projects/${projectId}/migration/steps/${idx + 1}`;
navigate(url, { replace: true });
Expand All @@ -190,6 +190,8 @@ const HorizontalStepper = forwardRef(
!stepsCompleted.includes(idx) && idx !== showStep && !stepsCompleted?.includes(idx - 1)
? 'disableEvents'
: '';
const disableStep = newMigrationData?.isprojectMapped && stepsCompleted.includes(idx) && idx !== showStep ? 'disableEvents'
: '';

const completeDisable = stepsCompleted?.includes(idx) && idx < stepIndex - 1 && newMigrationData?.test_migration?.isMigrationStarted ? 'disableEvents' : '';

Expand All @@ -199,7 +201,7 @@ const HorizontalStepper = forwardRef(
<React.Fragment key={id}>
<div className="stepWrapperContainer">
<div
className={`stepWrapper ${completedClass} ${activeClass} ${disableClass} ${completeDisable} ${disableMapper}`}
className={`stepWrapper ${completedClass} ${activeClass} ${disableClass} ${completeDisable} ${disableMapper} ${disableStep}`}
onClick={() => handleTabStep(idx)}
>
<div className="circle-title-wrapper">
Expand Down