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
4 changes: 2 additions & 2 deletions api/src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ const resetToInitialMapping = async (req: Request) => {
const fieldMappingData = contentTypeData.fieldMapping.map((itemId: any) => {
const fieldData = FieldMapperModel.chain
.get("field_mapper")
.find({ id: itemId, projectId: projectId })
.find({ id: itemId, projectId: projectId , contentTypeId: contentTypeId})
.value();
return fieldData;
});
Expand All @@ -771,7 +771,7 @@ const resetToInitialMapping = async (req: Request) => {
//await FieldMapperModel.read();
(fieldMappingData || []).forEach((field: any) => {
const fieldIndex = FieldMapperModel.data.field_mapper.findIndex(
(f: any) => f?.id === field?.id
(f: any) => f?.id === field?.id && f?.projectId === projectId && f?.contentTypeId === contentTypeId
);
if (fieldIndex > -1) {
FieldMapperModel.update((data: any) => {
Expand Down
32 changes: 24 additions & 8 deletions api/src/services/sitecore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,32 @@ async function writeFiles(
console.error('Error writing files:', error);
}
}
const uidCorrector = ({ uid } :{uid : string}) => {
if (!uid || typeof uid !== 'string') {
return '';
}

let newUid = uid;

// Note: UIDs starting with numbers and restricted keywords are handled externally in Sitecore
// The prefix is applied in contentTypeMaker function when needed

const uidCorrector = ({ uid }: any) => {
if (startsWithNumber(uid)) {
return `${append}_${_.replace(
uid,
new RegExp('[ -]', 'g'),
'_'
)?.toLowerCase()}`;
// Clean up the UID
newUid = newUid
.replace(/[ -]/g, '_') // Replace spaces and hyphens with underscores
.replace(/[^a-zA-Z0-9_]+/g, '_') // Replace non-alphanumeric characters (except underscore)
.replace(/\$/g, '') // Remove dollar signs
.toLowerCase() // Convert to lowercase
.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`) // Handle camelCase
.replace(/_+/g, '_') // Replace multiple underscores with single
.replace(/^_|_$/g, ''); // Remove leading/trailing underscores

// Ensure UID doesn't start with underscore (Contentstack requirement)
if (newUid.startsWith('_')) {
newUid = newUid.substring(1);
}
return _.replace(uid, new RegExp('[ -]', 'g'), '_')?.toLowerCase();

return newUid;
};

const createAssets = async ({
Expand Down
31 changes: 26 additions & 5 deletions api/src/utils/content-type-creator.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,33 @@ function startsWithNumber(str: string) {
return /^\d/.test(str);
}

const uidCorrector = ({ uid }: any) => {
if (startsWithNumber(uid)) {
return `a_${_.replace(uid, new RegExp("[ -]", "g"), '_')?.toLowerCase()}`
const uidCorrector = ({ uid } : {uid : string}) => {
if (!uid || typeof uid !== 'string') {
return '';
}
return _.replace(uid, new RegExp("[ -]", "g"), '_')?.toLowerCase()
}

let newUid = uid;

// Note: UIDs starting with numbers and restricted keywords are handled externally in Sitecore
// The prefix is applied in contentTypeMaker function when needed

// Clean up the UID
newUid = newUid
.replace(/[ -]/g, '_') // Replace spaces and hyphens with underscores
.replace(/[^a-zA-Z0-9_]+/g, '_') // Replace non-alphanumeric characters (except underscore)
.replace(/\$/g, '') // Remove dollar signs
.toLowerCase() // Convert to lowercase
.replace(/([A-Z])/g, (match) => `_${match.toLowerCase()}`) // Handle camelCase
.replace(/_+/g, '_') // Replace multiple underscores with single
.replace(/^_|_$/g, ''); // Remove leading/trailing underscores

// Ensure UID doesn't start with underscore (Contentstack requirement)
if (newUid.startsWith('_')) {
newUid = newUid.substring(1);
}

return newUid;
};


function buildFieldSchema(item: any, marketPlacePath: string, parentUid = ''): any {
Expand Down
3 changes: 2 additions & 1 deletion upload-api/migration-sitecore/libs/contenttypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ const groupFlat = (data, item) => {
contentstackField: item?.meta?.name,
contentstackFieldUid: data?.uid, // Use the corrected UID from groupSchema
contentstackFieldType: 'group',
backupFieldType: 'group'
backupFieldType: 'group',
backupFieldUid: data?.uid
};
flat?.push(group);
data?.schema?.forEach((element) => {
Expand Down