Skip to content
Merged

Dev #340

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,5 @@ upload-api/build
package-lock.json
ui/.env
upload-api/sitecoreMigrationData
upload-api/cmsMigrationData
upload-api/extracted_files
1 change: 1 addition & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,5 @@ package-lock.json

database/
/sitecoreMigrationData
/cmsMigrationData
/migration-data
45 changes: 45 additions & 0 deletions api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,48 @@ export const LOCALE_MAPPER: any = {
},
'fr': 'fr-fr'
}

export const MIGRATION_DATA_CONFIG = {
DATA :"cmsMigrationData",

BACKUP_DATA: "migration-data",
BACKUP_LOG_DIR: "logs",
BACKUP_FOLDER_NAME: "import",
BACKUP_FILE_NAME: "success.log",

LOCALE_DIR_NAME : "locale",
LOCALE_FILE_NAME : "locales.json",
LOCALE_MASTER_LOCALE : "master-locale.json",
LOCALE_CF_LANGUAGE : "language.json",

WEBHOOKS_DIR_NAME : "webhooks",
WEBHOOKS_FILE_NAME : "webhooks.json",

ENVIRONMENTS_DIR_NAME : "environments",
ENVIRONMENTS_FILE_NAME : "environments.json",

CONTENT_TYPES_DIR_NAME : "content_types",
CONTENT_TYPES_FILE_NAME : "contenttype.json",
CONTENT_TYPES_MASTER_FILE : "contenttypes.json",
CONTENT_TYPES_SCHEMA_FILE : "schema.json",

REFERENCES_DIR_NAME : "reference",
REFERENCES_FILE_NAME : "reference.json",

RTE_REFERENCES_DIR_NAME : "rteReference",
RTE_REFERENCES_FILE_NAME : "rteReference.json",

ASSETS_DIR_NAME : "assets",
ASSETS_FILE_NAME : "assets.json",
ASSETS_SCHEMA_FILE : "index.json",
ASSETS_FAILED_FILE : "cs_failed.json",
ASSETS_METADATA_FILE :"metadata.json",

ENTRIES_DIR_NAME : "entries",
ENTRIES_MASTER_FILE : "index.json",

GLOBAL_FIELDS_DIR_NAME : "global_fields",
GLOBAL_FIELDS_FILE_NAME : "globalfields.json",

EXPORT_INFO_FILE: "export-info.json"
}
20 changes: 10 additions & 10 deletions api/src/models/FieldMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import path from "path";
*/
interface Advanced {
validationRegex: string;
Mandatory: boolean;
Multiple: boolean;
Unique: boolean;
NonLocalizable: boolean;
EmbedObject: boolean;
EmbedObjects: any;
MinChars: string;
MaxChars: number;
Default_value: string;
mandatory: boolean;
multiple: boolean;
unique: boolean;
nonLocalizable: boolean;
embedObject: boolean;
embedObjects: any;
minChars: string;
maxChars: number;
default_value: string;
options: any[];
}

Expand All @@ -31,7 +31,7 @@ interface FieldMapper {
otherCmsType: string;
contentstackField: string;
contentstackFieldUid: string;
ContentstackFieldType: string;
contentstackFieldType: string;
isDeleted: boolean;
backupFieldType: string;
refrenceTo: { uid: string; title: string };
Expand Down
16 changes: 8 additions & 8 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,17 @@ const updateContentType = async (req: Request) => {
if (fieldMapping) {
for (const field of fieldMapping) {
if (
!field.ContentstackFieldType ||
field.ContentstackFieldType === "" ||
field.ContentstackFieldType === "No matches found" ||
!field.contentstackFieldType ||
field.contentstackFieldType === "" ||
field.contentstackFieldType === "No matches found" ||
field.contentstackFieldUid === ""
) {
logger.error(
getLogMessage(
srcFun,
`${VALIDATION_ERRORS.STRING_REQUIRED.replace(
"$",
"ContentstackFieldType or contentstackFieldUid"
"contentstackFieldType or contentstackFieldUid"
)}`
)
);
Expand All @@ -424,7 +424,7 @@ const updateContentType = async (req: Request) => {
status: 400,
message: `${VALIDATION_ERRORS.STRING_REQUIRED.replace(
"$",
"ContentstackFieldType or contentstackFieldUid"
"contentstackFieldType or contentstackFieldUid"
)}`,
};
}
Expand Down Expand Up @@ -471,7 +471,7 @@ const updateContentType = async (req: Request) => {
const fieldIndex = FieldMapperModel.data.field_mapper.findIndex(
(f: any) => f?.id === field?.id
);
if (fieldIndex > -1 && field?.ContentstackFieldType !== "") {
if (fieldIndex > -1 && field?.contentstackFieldType !== "") {
FieldMapperModel.update((data: any) => {
data.field_mapper[fieldIndex] = field;
//data.field_mapper[fieldIndex].isDeleted = false;
Expand Down Expand Up @@ -594,7 +594,7 @@ const resetToInitialMapping = async (req: Request) => {
...field,
contentstackField: "",
contentstackFieldUid: "",
ContentstackFieldType: field.backupFieldType,
contentstackFieldType: field.backupFieldType,
};
});
}
Expand Down Expand Up @@ -692,7 +692,7 @@ const resetAllContentTypesMapping = async (projectId: string) => {
...fieldData,
contentstackField: "",
contentstackFieldUid: "",
ContentstackFieldType: fieldData.backupFieldType,
contentstackFieldType: fieldData.backupFieldType,
};
});
}
Expand Down
7 changes: 3 additions & 4 deletions api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ const createTestStack = async (req: Request): Promise<LoginServiceType> => {
const srcFun = "createTestStack";
const orgId = req?.params?.orgId;
const projectId = req?.params?.projectId;
const { token_payload } = req.body;
const { name, token_payload } = req.body;
const description = 'This is a system-generated test stack.'
const name = 'Test';

const testStackName = `${name}-Test`;

try {
const authtoken = await getAuthtoken(
Expand All @@ -46,7 +45,7 @@ const createTestStack = async (req: Request): Promise<LoginServiceType> => {
const projectData: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
const master_locale = projectData?.stackDetails?.master_locale ?? Object?.keys?.(LOCALE_MAPPER?.masterLocale)?.[0];
const testStackCount = projectData?.test_stacks?.length + 1;
const newName = name + "-" + testStackCount;
const newName = testStackName + "-" + testStackCount;

const [err, res] = await safePromise(
https({
Expand Down
9 changes: 5 additions & 4 deletions api/src/services/runCli.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import shell from 'shelljs'
import { v4 } from "uuid";
import { copyDirectory, createDirectoryAndFile } from '../utils/index.js'
import { CS_REGIONS } from "../constants/index.js";
import { CS_REGIONS, MIGRATION_DATA_CONFIG } from "../constants/index.js";
import ProjectModelLowdb from "../models/project-lowdb.js";
import AuthenticationModel from "../models/authentication.js";
import watchLogs from "../utils/watch.utils.js";
Expand Down Expand Up @@ -33,10 +33,11 @@ export const runCli = async (rg: string, user_id: string, stack_uid: any, projec
.find({ region: regionPresent, user_id })
.value();
if (userData?.authtoken && stack_uid) {
const sourcePath = path.join(process.cwd(), 'sitecoreMigrationData', stack_uid);
const backupPath = path.join(process.cwd(), 'migration-data', `${stack_uid}_${v4().slice(0, 4)}`);
const { BACKUP_DATA, BACKUP_LOG_DIR, BACKUP_FOLDER_NAME, BACKUP_FILE_NAME} = MIGRATION_DATA_CONFIG;
const sourcePath = path.join(process.cwd(), MIGRATION_DATA_CONFIG.DATA, stack_uid);
const backupPath = path.join(process.cwd(), BACKUP_DATA, `${stack_uid}_${v4().slice(0, 4)}`);
await copyDirectory(sourcePath, backupPath);
const loggerPath = path.join(backupPath, 'logs', 'import', 'success.log');
const loggerPath = path.join(backupPath, BACKUP_LOG_DIR, BACKUP_FOLDER_NAME, BACKUP_FILE_NAME);
await createDirectoryAndFile(loggerPath, transformePath);
await setLogFilePath(loggerPath);
await watchLogs(loggerPath, transformePath);
Expand Down
38 changes: 25 additions & 13 deletions api/src/services/sitecore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import read from 'fs-readdir-recursive';
import { v4 as uuidv4 } from "uuid";
import _ from 'lodash';
import { LOCALE_MAPPER } from '../constants/index.js';
import { LOCALE_MAPPER, MIGRATION_DATA_CONFIG } from '../constants/index.js';
import { entriesFieldCreator, unflatten } from '../utils/entries-field-creator.utils.js';
import { orgService } from './org.service.js';
import { getLogMessage } from '../utils/index.js';
Expand All @@ -12,6 +12,18 @@ import customLogger from '../utils/custom-logger.utils.js';

const append = "a";

const baseDirName = MIGRATION_DATA_CONFIG.DATA
const {
ENTRIES_DIR_NAME,
LOCALE_DIR_NAME,
LOCALE_MASTER_LOCALE,
LOCALE_FILE_NAME,
EXPORT_INFO_FILE,
ASSETS_DIR_NAME,
ASSETS_FILE_NAME,
ASSETS_SCHEMA_FILE
} = MIGRATION_DATA_CONFIG;

const idCorrector = ({ id }: any) => {
const newId = id?.replace(/[-{}]/g, (match: any) => match === '-' ? '' : '')
if (newId) {
Expand Down Expand Up @@ -82,7 +94,7 @@ const uidCorrector = ({ uid }: any) => {

const cretaeAssets = async ({ packagePath, baseDir, destinationStackId, projectId }: any) => {
const srcFunc = 'cretaeAssets';
const assetsSave = path.join(baseDir, 'assets');
const assetsSave = path.join(baseDir, ASSETS_DIR_NAME);
const allAssetJSON: any = {};
const folderName: any = path.join(packagePath, 'items', 'master', 'sitecore', 'media library');
const entryPath = read?.(folderName);
Expand Down Expand Up @@ -169,15 +181,15 @@ const cretaeAssets = async ({ packagePath, baseDir, destinationStackId, projectI
path.join(
process.cwd(),
assetsSave,
'assets.json'
ASSETS_FILE_NAME
),
JSON.stringify(fileMeta)
);
fs.writeFileSync(
path.join(
process.cwd(),
assetsSave,
'index.json'
ASSETS_SCHEMA_FILE
),
JSON.stringify(allAssetJSON)
);
Expand All @@ -187,8 +199,8 @@ const cretaeAssets = async ({ packagePath, baseDir, destinationStackId, projectI
const createEntry = async ({ packagePath, contentTypes, master_locale = 'en-us', destinationStackId, projectId }: { packagePath: any; contentTypes: any; master_locale?: string, destinationStackId: string, projectId: string }) => {
try {
const srcFunc = 'createEntry';
const baseDir = path.join('sitecoreMigrationData', destinationStackId);
const entrySave = path.join(baseDir, 'entries');
const baseDir = path.join(baseDirName, destinationStackId);
const entrySave = path.join(baseDir, ENTRIES_DIR_NAME);
const allAssetJSON: any = await cretaeAssets({ packagePath, baseDir, destinationStackId, projectId });
const folderName: any = path.join(packagePath, 'items', 'master', 'sitecore', 'content');
const entriesData: any = [];
Expand Down Expand Up @@ -234,7 +246,7 @@ const createEntry = async ({ packagePath, contentTypes, master_locale = 'en-us',
entryObj.uid = uid;
for await (const field of entry?.fields?.field ?? []) {
for await (const fsc of ctType?.fieldMapping ?? []) {
if (fsc?.ContentstackFieldType !== 'group' && !field?.$?.key?.includes('__')) {
if (fsc?.contentstackFieldType !== 'group' && !field?.$?.key?.includes('__')) {
if (fsc?.contentstackFieldUid === 'title') {
entryObj[fsc?.contentstackFieldUid] = entry?.meta?.name;
}
Expand Down Expand Up @@ -287,8 +299,8 @@ const createEntry = async ({ packagePath, contentTypes, master_locale = 'en-us',
const createLocale = async (req: any, destinationStackId: string, projectId: string) => {
const srcFunc = 'createLocale';
try {
const baseDir = path.join('sitecoreMigrationData', destinationStackId);
const localeSave = path.join(baseDir, 'locale');
const baseDir = path.join(baseDirName, destinationStackId);
const localeSave = path.join(baseDir, LOCALE_DIR_NAME);
const allLocalesResp = await orgService.getLocales(req)
const masterLocale = Object?.keys?.(LOCALE_MAPPER?.masterLocale)?.[0];
const msLocale: any = {};
Expand Down Expand Up @@ -323,8 +335,8 @@ const createLocale = async (req: any, destinationStackId: string, projectId: str
await customLogger(projectId, destinationStackId, 'info', message);
}
}
const masterPath = path.join(localeSave, 'master-locale.json');
const allLocalePath = path.join(localeSave, 'locales.json');
const masterPath = path.join(localeSave, LOCALE_MASTER_LOCALE);
const allLocalePath = path.join(localeSave, LOCALE_FILE_NAME);
fs.access(localeSave, async (err) => {
if (err) {
fs.mkdir(localeSave, { recursive: true }, async (err) => {
Expand All @@ -350,8 +362,8 @@ const createLocale = async (req: any, destinationStackId: string, projectId: str
}

const createVersionFile = async (destinationStackId: string) => {
const baseDir = path.join('sitecoreMigrationData', destinationStackId);
fs.writeFile(path?.join?.(baseDir, 'export-info.json'), JSON.stringify({
const baseDir = path.join(baseDirName, destinationStackId);
fs.writeFile(path?.join?.(baseDir, EXPORT_INFO_FILE), JSON.stringify({
"contentVersion": 2,
"logsPath": ""
}), (err) => {
Expand Down
Loading