Skip to content
Open
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
7 changes: 5 additions & 2 deletions api/src/services/wordpress.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ async function createEntry(file_path: string, packagePath: string, destinationSt
const entriesJsonData = JSON.parse(Jsondata);
const entries = entriesJsonData?.rss?.channel?.["item"];
const categories = entriesJsonData?.rss?.channel?.["wp:category"];
const allCategories = Array?.isArray(categories) ? categories : (categories ? [categories] : []);

const authorsData = entriesJsonData?.rss?.channel?.["wp:author"];
const authors = Array?.isArray(authorsData) ? authorsData : [authorsData];
Expand Down Expand Up @@ -677,7 +678,7 @@ async function createEntry(file_path: string, packagePath: string, destinationSt
// console.log(`No ${type} found to extract`);
// }
// }
const content = await saveEntry(contentType?.fieldMapping, entry,file_path, assetData, categories, master_locale, destinationStackId, project, allTerms) || {};
const content = await saveEntry(contentType?.fieldMapping, entry,file_path, assetData, allCategories, master_locale, destinationStackId, project, allTerms) || {};

const filePath = path.join(postFolderPath, `${locale}.json`);
await writeFileAsync(filePath, content, 4);
Expand All @@ -696,7 +697,9 @@ async function createTaxonomy(file_path: string, packagePath: string, destinatio

const Jsondata = await fs.promises.readFile(packagePath, "utf8");
const xmlData = await fs.promises.readFile(file_path, "utf8");
const categoriesJsonData = JSON.parse(Jsondata)?.rss?.channel?.["wp:category"] || JSON.parse(Jsondata)?.channel?.["wp:category"] || [];
const categoriesData = JSON.parse(Jsondata)?.rss?.channel?.["wp:category"] || JSON.parse(Jsondata)?.channel?.["wp:category"];
const categoriesJsonData = Array?.isArray(categoriesData) ? categoriesData : (categoriesData ? [categoriesData] : []);

if(categoriesJsonData?.length > 0){
const allTaxonomies : any = {}
for(const category of categoriesJsonData){
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/AdvancePropertise/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ const AdvancePropertise = (props: SchemaProps) => {
<Select
value={referencedTaxonomies}
isMulti={true}
isDisabled={isTaxonomiesLoading}
//isDisabled={isTaxonomiesLoading}
onChange={(selectedOptions: ContentTypeOption[]) => {

setReferencedTaxonomies(selectedOptions);
Expand Down Expand Up @@ -858,15 +858,15 @@ const AdvancePropertise = (props: SchemaProps) => {
width="350px"
maxMenuHeight={200}
/>
{isTaxonomiesLoading ? (
{/* {isTaxonomiesLoading ? (
<InstructionText>
Loading taxonomies...
</InstructionText>
) : sourceTaxonomies?.length === 0 && destinationTaxonomies?.length === 0 ? (
<InstructionText>
No taxonomies found. Please upload source data or create taxonomies in your destination stack.
</InstructionText>
) : null}
) : null} */}
</Field>
)}

Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/ContentMapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,8 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
(data?.backupFieldType !== 'extension' &&
data?.backupFieldType !== 'app' &&
data?.backupFieldUid !== 'title' &&
data?.backupFieldUid !== 'url')) && (
data?.backupFieldUid !== 'url' &&
data?.backupFieldType !== 'modular_blocks_child')) && (
<div className='advanced-setting-button'>
<Tooltip
content="Advanced properties"
Expand Down
26 changes: 18 additions & 8 deletions upload-api/migration-wordpress/libs/extractItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import config from '../config/index.json';
import extractTaxonomy from './extractTaxonomy';
import { DataConfig, Field, CT } from '../interface/interface';

const MEDIA_BLOCK_NAMES = ['core/image', 'core/video', 'core/audio', 'core/file'];

function resolveBlockName(field: any): string {
if (field?.attributes?.metadata?.name) return field.attributes.metadata.name;
if (field?.name === 'core/missing') return 'body';
if (MEDIA_BLOCK_NAMES.includes(field?.name)) return 'media';
return field?.name;
}

const { contentTypes: contentTypesConfig } = config.modules;

const contentTypeFolderPath = path.resolve(config.data, contentTypesConfig.dirName);
Expand Down Expand Up @@ -288,7 +297,8 @@ const extractItems = async (item: any, config: DataConfig, type: string, affix:

const contentEncoded = targetItem?.find("content\\:encoded")?.text() || '';
const blocksJson = await setupWordPressBlocks(contentEncoded);
//await helper?.writeFileAsync(`${data?.title || 'undefined'}.json`, JSON.stringify({blocks : blocksJson, count :blocksJson?.length}, null, 4), 4);
const folderName = path.basename(localPath, path.extname(localPath));
await helper?.writeFileAsync(`${folderName}/${data?.title || 'undefined'}.json`, JSON.stringify({blocks : blocksJson, count :blocksJson?.length}, null, 4), 4);


// Example usage
Expand All @@ -300,7 +310,7 @@ const extractItems = async (item: any, config: DataConfig, type: string, affix:

for (const field of blocksJson) {
const fieldUid = getFieldUid(`${field?.name}_${field?.clientId}`|| '', affix || '');
const contentstackFieldName = getFieldName(field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name));
const contentstackFieldName = getFieldName(resolveBlockName(field));

const similarBlocks = findSimilarBlocks(result, field?.clientId);

Expand All @@ -310,8 +320,8 @@ const extractItems = async (item: any, config: DataConfig, type: string, affix:
.filter((name, index, array) => name && array?.indexOf(name) === index) // Remove duplicates
.sort(); // Sort for consistency

const filterOutBlock = allBlockNames?.filter((item)=> item !== (field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name)));
const fieldDisplayName = getFieldName( field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name));
const filterOutBlock = allBlockNames?.filter((item)=> item !== resolveBlockName(field));
const fieldDisplayName = getFieldName(resolveBlockName(field));
const firstFilterBlock = filterOutBlock?.[0] ? `Modular Blocks > ${filterOutBlock?.[0]}` : null;

const generatedFieldName = `Modular Blocks > ${fieldDisplayName}`;
Expand All @@ -334,7 +344,7 @@ const extractItems = async (item: any, config: DataConfig, type: string, affix:
// If this block has similar structures
if (similarBlocks?.length > 0) {
// Create a unique key based on the structure/name to track processed groups
const groupKey = field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name);
const groupKey = resolveBlockName(field);
// Skip if we've already processed this group of similar blocks
if (processedSimilarBlocks?.has?.(groupKey) || existingBlock) {
continue;
Expand Down Expand Up @@ -398,10 +408,10 @@ const extractItems = async (item: any, config: DataConfig, type: string, affix:
}
else {
// Handle single blocks (no similar structures found)
const singleBlockName = getFieldName(field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name));
const singleBlockName = getFieldName(resolveBlockName(field));

if(!existingBlock && ! processedSimilarBlocks?.has?.(field?.attributes?.metadata?.name ?? getFieldName(field?.name === 'core/missing' ? 'body' : field?.name) )){
processedSimilarBlocks?.add?.(field?.attributes?.metadata?.name ?? (field?.name === 'core/missing' ? 'body' : field?.name));
if(!existingBlock && ! processedSimilarBlocks?.has?.(resolveBlockName(field))){
processedSimilarBlocks?.add?.(resolveBlockName(field));

// Generate Fieldschema first to check for duplicates
const Fieldschema: Field[] | Field = await schemaMapper(field?.innerBlocks?.length > 0 ? field?.innerBlocks : field, `modular_blocks.${fieldUid}`, groupedContentstackField, affix || '');
Expand Down
36 changes: 26 additions & 10 deletions upload-api/migration-wordpress/libs/schemaMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { Field, WordPressBlock } from '../interface/interface';
import restrictedUid from '../utils/index';
import GenerateSchema from 'generate-schema';

const MEDIA_BLOCK_NAMES = ['core/image', 'core/video', 'core/audio', 'core/file'];

function resolveBlockName(key: any): string {
if (key?.attributes?.metadata?.name) return key.attributes.metadata.name;
if (key?.name === 'core/missing') return 'body';
if (MEDIA_BLOCK_NAMES.includes(key?.name)) return 'media';
return key?.name;
}

const getFieldName = (key: string ) => {
if(key?.includes('/')){
return key?.split('/')?.[1];
Expand Down Expand Up @@ -152,13 +161,16 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
const schemas: Field[] = [];
for (const item of key) {
const result = await schemaMapper(item, parentUid, parentFieldName, affix);
const existingBlock: Field | undefined = schemas.find((schemaItem: Field) =>
result?.otherCmsField === schemaItem?.otherCmsField &&
schemaItem?.contentstackFieldType === result?.contentstackFieldType &&
schemaItem?.contentstackField === result?.contentstackField &&
result?.contentstackFieldUid?.includes(parentUid)
);
item?.contentstackFieldUid?.includes(parentUid) ;

const compareField = Array.isArray(result) ? result[0] : result;
const existingBlock: Field | undefined = compareField ? schemas.find((schemaItem: Field) =>
compareField?.otherCmsField === schemaItem?.otherCmsField &&
schemaItem?.contentstackFieldType === compareField?.contentstackFieldType &&
schemaItem?.contentstackField === compareField?.contentstackField &&
parentUid && compareField?.contentstackFieldUid?.includes(parentUid) &&
parentUid && schemaItem?.contentstackFieldUid?.includes(parentUid)
) : undefined;

if (existingBlock && typeof existingBlock === 'object' && 'advanced' in existingBlock) {
existingBlock.advanced = {
...(existingBlock.advanced as object),
Expand All @@ -175,7 +187,7 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
return schemas;
}

const fieldName = parentFieldName ? `${parentFieldName} > ${getFieldName(key?.attributes?.metadata?.name ?? (key?.name === 'core/missing' ? 'body' : key?.name))}` : getFieldName(key?.attributes?.metadata?.name ?? (key?.name === 'core/missing' ? 'body' : key?.name));
const fieldName = parentFieldName ? `${parentFieldName} > ${getFieldName(resolveBlockName(key))}` : getFieldName(resolveBlockName(key));

switch (key?.name) {
case 'core/paragraph':
Expand All @@ -184,6 +196,7 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
case 'core/table':
case 'core/columns':
case 'core/missing':
case 'core/verse':
case 'core/code': {
const rteUid = parentUid ?
`${parentUid}.${getFieldUid(`${key?.name}_${key?.clientId}`, affix)}`
Expand All @@ -209,9 +222,9 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:

return {
uid: fileUid,
otherCmsField: getFieldName(key?.name),
otherCmsField: 'media',
otherCmsType: getFieldName(key?.attributes?.metadata?.name ?? key?.name),
contentstackField: fieldName,
contentstackField: 'media',
contentstackFieldUid: fileUid,
contentstackFieldType: 'file',
backupFieldType: 'file',
Expand All @@ -222,6 +235,7 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
break;

case 'core/heading':
case 'core/accordion-heading':
case 'core/list-item': {
const textUid = parentUid ? `${parentUid}.${getFieldUid(`${key?.name}_${key?.clientId}`, affix)}` : getFieldUid(`${key?.name}_${key?.clientId}`, affix);
return {
Expand Down Expand Up @@ -260,6 +274,8 @@ async function schemaMapper (key: WordPressBlock | WordPressBlock[], parentUid:
case 'core/social-links':
case 'core/details':
case 'core/group':
case 'core/accordion-item':
case 'core/accordion-panel':
case 'core/navigation': {
const groupSchema: Field[] = [];
const groupUid = parentUid ? `${parentUid}.${getFieldUid(`${key?.name}_${key?.clientId}`, affix)}` : getFieldUid(`${key?.name}_${key?.clientId}`, affix);
Expand Down