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
28 changes: 14 additions & 14 deletions api/src/services/contentful.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ const transformCloudinaryObject = (input: any) => {
for (const metaData of input ?? []) {
if (metaData?.public_id) {
result?.push({
public_id: metaData.public_id,
resource_type: metaData.resource_type,
type: metaData.type,
format: metaData.format,
version: metaData.version,
url: metaData.original_url,
secure_url: metaData.original_secure_url,
width: metaData.width,
height: metaData.height,
bytes: metaData.bytes,
duration: metaData.duration,
tags: metaData.tags,
metadata: metaData.metadata,
created_at: metaData.created_at,
public_id: metaData?.public_id,
resource_type: metaData?.resource_type,
type: metaData?.type,
format: metaData?.format,
version: metaData?.version,
url: metaData?.original_url,
secure_url: metaData?.original_secure_url,
width: metaData?.width,
height: metaData?.height,
bytes: metaData?.bytes,
duration: metaData?.duration,
tags: metaData?.tags,
metadata: metaData?.metadata,
created_at: metaData?.created_at,
access_mode: "public",
access_control: [],
created_by: {
Expand Down
50 changes: 25 additions & 25 deletions api/src/services/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ const startTestMigration = async (req: Request): Promise<any> => {
await wordpressService?.extractChunks(file_path, packagePath, project?.current_test_stack_id, projectId)
await wordpressService?.getAllAuthors(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
//await wordpressService?.extractContentTypes(projectId, project?.current_test_stack_id, contentTypes)
await wordpressService?.getAllTerms(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.getAllTags(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.getAllCategories(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.extractPosts(packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.getAllTerms(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.getAllTags(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.getAllCategories(file_path, packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.extractPosts(packagePath, project?.current_test_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.extractGlobalFields(project?.current_test_stack_id, projectId)
await wordpressService?.createVersionFile(project?.current_test_stack_id, projectId);
}
Expand Down Expand Up @@ -318,12 +318,12 @@ const startMigration = async (req: Request): Promise<any> => {
await wordpressService?.createAssetFolderFile(file_path, project?.destination_stack_id, projectId)
await wordpressService?.getAllreference(file_path, packagePath, project?.destination_stack_id, projectId)
await wordpressService?.extractChunks(file_path, packagePath, project?.destination_stack_id, projectId)
await wordpressService?.getAllAuthors(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.getAllAuthors(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
//await wordpressService?.extractContentTypes(projectId, project?.destination_stack_id)
await wordpressService?.getAllTerms(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.getAllTags(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.getAllCategories(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys,project?.stackDetails?.master_locale)
await wordpressService?.getAllTags(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.getAllCategories(file_path, packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.extractPosts(packagePath, project?.destination_stack_id, projectId, contentTypes, project?.mapperKeys, project?.stackDetails?.master_locale)
await wordpressService?.extractGlobalFields(project?.destination_stack_id, projectId)
await wordpressService?.createVersionFile(project?.destination_stack_id, projectId);

Expand Down Expand Up @@ -426,23 +426,23 @@ export const createSourceLocales = async (req: Request) => {

try {
// Check if the project.json file exists
if (!fs.existsSync(projectFilePath)) {
if (!fs?.existsSync?.(projectFilePath)) {
console.error(`project.json not found at ${projectFilePath}`);
throw new Error(`project.json not found.`);
}

// Find the project with the specified projectId
const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value?.();
if (project) {
const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value();
if (index > -1) {
ProjectModelLowdb.update((data: any) => {

ProjectModelLowdb?.update((data: any) => {
data.projects[index].source_locales = locales;
});
} // Write back the updated projects
} else {
logger.error(`Project with ID: ${projectId} not found`,{
logger.error(`Project with ID: ${projectId} not found`, {
status: HTTP_CODES?.NOT_FOUND,
message: HTTP_TEXTS?.INVALID_ID
})
Expand All @@ -467,30 +467,30 @@ export const createSourceLocales = async (req: Request) => {
* @return - void
* @throws Exception if the project ID is invalid or the when the path to project.json is incorrect
*/
export const updateLocaleMapper = async (req:Request) =>{
const mapperObject = req.body;
const projectFilePath = path.join(process.cwd(), 'database', 'project.json'); // Adjusted path to project.json
const projectId = req.params.projectId;
export const updateLocaleMapper = async (req: Request) => {
const mapperObject = req?.body;
const projectFilePath = path?.join?.(process?.cwd(), 'database', 'project.json'); // Adjusted path to project.json
const projectId = req?.params?.projectId;

try {
// Check if the project.json file exists
if (!fs.existsSync(projectFilePath)) {
if (!fs?.existsSync?.(projectFilePath)) {
console.error(`project.json not found at ${projectFilePath}`);
throw new Error(`project.json not found.`);
}

// Find the project with the specified projectId
const project: any = ProjectModelLowdb.chain.get("projects").find({ id: projectId }).value();
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value();
if (project) {
const index = ProjectModelLowdb.chain.get("projects").findIndex({ id: projectId }).value();
const index = ProjectModelLowdb?.chain?.get("projects")?.findIndex?.({ id: projectId })?.value();
if (index > -1) {
ProjectModelLowdb.update((data: any) => {
ProjectModelLowdb?.update((data: any) => {
data.projects[index].master_locale = mapperObject?.master_locale;
data.projects[index].locales = mapperObject?.locales;
});
} // Write back the updated projects
} else {
logger.error(`Project with ID: ${projectId} not found`,{
logger.error(`Project with ID: ${projectId} not found`, {
status: HTTP_CODES?.NOT_FOUND,
message: HTTP_TEXTS?.INVALID_ID
})
Expand Down
16 changes: 8 additions & 8 deletions upload-api/migration-contentful/libs/extractLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const fs = require("fs");
*/
const extractLocale = async (jsonFilePath) => {
try {
const rawData = fs.readFileSync(jsonFilePath, "utf8");
const jsonData = JSON.parse(rawData);
const rawData = fs?.readFileSync?.(jsonFilePath, "utf8");
const jsonData = JSON?.parse?.(rawData);

// Extract unique language codes from locales array
const uniqueLanguages = new Set();
if (Array.isArray(jsonData.locales)) {
jsonData.locales.forEach(locale => {
if (locale.code) {
uniqueLanguages.add(locale.code.toLowerCase()); // Normalize to lowercase
if (Array?.isArray?.(jsonData?.locales)) {
jsonData?.locales?.forEach?.(locale => {
if (locale?.code) {
uniqueLanguages.add(locale?.code?.toLowerCase?.()); // Normalize to lowercase
}
});
}

return [...uniqueLanguages]; // Convert Set to array for output
} catch (error) {
console.error(`Error reading JSON file:`, error.message);
Expand Down
18 changes: 9 additions & 9 deletions upload-api/migration-sitecore/libs/extractLocales.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ const path = require("path");
const uniqueLanguages = new Set(); // Define uniqueLanguages globally or pass it as a parameter

const extractLocales = (dir) => {
const items = fs.readdirSync(dir, { withFileTypes: true });
const items = fs?.readdirSync?.(dir, { withFileTypes: true });

for (const item of items) {
const fullPath = path.join(dir, item.name);
const fullPath = path?.join?.(dir, item?.name);

if (item.isDirectory()) {
extractLocales(fullPath); // Proper recursion
} else if (item.isFile() && item.name === "data.json.json") {
extractLocales?.(fullPath); // Proper recursion
} else if (item?.isFile() && item?.name === "data.json.json") {
try {
const rawData = fs.readFileSync(fullPath, "utf8");
const jsonData = JSON.parse(rawData);
const rawData = fs?.readFileSync?.(fullPath, "utf8");
const jsonData = JSON?.parse?.(rawData);
const language = jsonData?.item?.$?.language;

if (language) {
uniqueLanguages.add(language);
uniqueLanguages?.add?.(language);
}
} catch (error) {
console.error(`Error reading ${fullPath}:`, error.message);
console.error(`Error reading ${fullPath}:`, error?.message);
}
}
}
Expand Down