@@ -7,7 +7,7 @@ import https from "../utils/https.utils.js";
77import { LoginServiceType } from "../models/types.js"
88import getAuthtoken from "../utils/auth.utils.js" ;
99import logger from "../utils/logger.js" ;
10- import { HTTP_TEXTS , HTTP_CODES , LOCALE_MAPPER , STEPPER_STEPS } from "../constants/index.js" ;
10+ import { HTTP_TEXTS , HTTP_CODES , LOCALE_MAPPER , STEPPER_STEPS , CMS } from "../constants/index.js" ;
1111import { BadRequestError , ExceptionFunction } from "../utils/custom-errors.utils.js" ;
1212import { fieldAttacher } from "../utils/field-attacher.utils.js" ;
1313import { siteCoreService } from "./sitecore.service.js" ;
@@ -213,26 +213,44 @@ const startTestMigration = async (req: Request): Promise<any> => {
213213 await ProjectModelLowdb . read ( ) ;
214214 const project = ProjectModelLowdb . chain . get ( "projects" ) . find ( { id : projectId } ) . value ( ) ;
215215 const packagePath = project ?. extract_path ;
216- if ( packagePath && project ?. current_test_stack_id ) {
216+ if ( project ?. current_test_stack_id ) {
217+ const { legacy_cms : { cms, affix } } = project ;
217218 const loggerPath = path . join ( process . cwd ( ) , 'logs' , projectId , `${ project ?. current_test_stack_id } .log` ) ;
218219 const message = getLogMessage ( 'startTestMigration' , 'Starting Test Migration...' , { } ) ;
219220 await customLogger ( projectId , project ?. current_test_stack_id , 'info' , message ) ;
220221 await setLogFilePath ( loggerPath ) ;
221- // const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.current_test_stack_id });
222- // await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.current_test_stack_id, projectId });
223- // await siteCoreService?.createLocale(req, project?.current_test_stack_id, projectId);
224- // await siteCoreService?.createVersionFile(project?.current_test_stack_id);
225- await wordpressService ?. getAllAssets ( project ?. legacy_cms ?. affix , packagePath , project ?. current_test_stack_id )
226- await wordpressService ?. createAssetFolderFile ( project ?. legacy_cms ?. affix )
227- await wordpressService ?. getAllreference ( project ?. legacy_cms ?. affix , packagePath , project ?. current_test_stack_id )
228- await wordpressService ?. extractChunks ( project ?. legacy_cms ?. affix , packagePath , project ?. current_test_stack_id )
229- await wordpressService ?. getAllAuthors ( project ?. legacy_cms ?. affix , packagePath )
230- await wordpressService ?. extractContentTypes ( project ?. legacy_cms ?. affix , project ?. current_test_stack_id )
231- await wordpressService ?. getAllTerms ( project ?. legacy_cms ?. affix , packagePath )
232- await wordpressService ?. getAllTags ( project ?. legacy_cms ?. affix , packagePath )
233- await wordpressService ?. getAllCategories ( project ?. legacy_cms ?. affix , packagePath )
234- await wordpressService ?. extractPosts ( project ?. legacy_cms ?. affix , packagePath )
235- await wordpressService ?. extractGlobalFields ( project ?. current_test_stack_id )
222+ const contentTypes = await fieldAttacher ( { orgId, projectId, destinationStackId : project ?. current_test_stack_id } ) ;
223+
224+ switch ( cms ) {
225+ case CMS . SITECORE_V8 :
226+ case CMS . SITECORE_V9 :
227+ case CMS . SITECORE_V10 : {
228+ if ( packagePath ) {
229+ await siteCoreService ?. createEntry ( { packagePath, contentTypes, destinationStackId : project ?. current_test_stack_id , projectId } ) ;
230+ await siteCoreService ?. createLocale ( req , project ?. current_test_stack_id , projectId ) ;
231+ await siteCoreService ?. createVersionFile ( project ?. current_test_stack_id ) ;
232+ }
233+ break ;
234+ }
235+ case CMS . WORDPRESS : {
236+ if ( packagePath ) {
237+ await wordpressService ?. getAllAssets ( affix , packagePath , project ?. current_test_stack_id )
238+ await wordpressService ?. createAssetFolderFile ( affix )
239+ await wordpressService ?. getAllreference ( affix , packagePath , project ?. current_test_stack_id )
240+ await wordpressService ?. extractChunks ( affix , packagePath , project ?. current_test_stack_id )
241+ await wordpressService ?. getAllAuthors ( affix , packagePath )
242+ await wordpressService ?. extractContentTypes ( affix , project ?. current_test_stack_id )
243+ await wordpressService ?. getAllTerms ( affix , packagePath )
244+ await wordpressService ?. getAllTags ( affix , packagePath )
245+ await wordpressService ?. getAllCategories ( affix , packagePath )
246+ await wordpressService ?. extractPosts ( affix , packagePath )
247+ await wordpressService ?. extractGlobalFields ( project ?. current_test_stack_id )
248+ }
249+ break ;
250+ }
251+ default :
252+ break ;
253+ }
236254 // await testFolderCreator?.({ destinationStackId: project?.current_test_stack_id });
237255 await utilsCli ?. runCli ( region , user_id , project ?. current_test_stack_id , projectId , true , loggerPath ) ;
238256 }
@@ -258,26 +276,44 @@ const startMigration = async (req: Request): Promise<any> => {
258276 }
259277
260278 const packagePath = project ?. extract_path ;
261- if ( packagePath && project ?. destination_stack_id ) {
279+ if ( project ?. destination_stack_id ) {
280+ const { legacy_cms : { cms, affix } } = project ;
262281 const loggerPath = path . join ( process . cwd ( ) , 'logs' , projectId , `${ project ?. destination_stack_id } .log` ) ;
263282 const message = getLogMessage ( 'startTestMigration' , 'Starting Migration...' , { } ) ;
264283 await customLogger ( projectId , project ?. destination_stack_id , 'info' , message ) ;
265284 await setLogFilePath ( loggerPath ) ;
266- // const contentTypes = await fieldAttacher({ orgId, projectId, destinationStackId: project?.destination_stack_id });
267- // await siteCoreService?.createEntry({ packagePath, contentTypes, destinationStackId: project?.destination_stack_id, projectId });
268- // await siteCoreService?.createLocale(req, project?.destination_stack_id, projectId);
269- // await siteCoreService?.createVersionFile(project?.destination_stack_id);
270- await wordpressService ?. getAllAssets ( project ?. legacy_cms ?. affix , packagePath , project ?. current_test_stack_id )
271- await wordpressService ?. createAssetFolderFile ( project ?. legacy_cms ?. affix )
272- await wordpressService ?. getAllreference ( project ?. legacy_cms ?. affix , packagePath , project ?. current_test_stack_id )
273- await wordpressService ?. extractChunks ( project ?. legacy_cms ?. affix , packagePath , project ?. current_test_stack_id )
274- await wordpressService ?. getAllAuthors ( project ?. legacy_cms ?. affix , packagePath )
275- await wordpressService ?. extractContentTypes ( project ?. legacy_cms ?. affix , project ?. current_test_stack_id )
276- await wordpressService ?. getAllTerms ( project ?. legacy_cms ?. affix , packagePath )
277- await wordpressService ?. getAllTags ( project ?. legacy_cms ?. affix , packagePath )
278- await wordpressService ?. getAllCategories ( project ?. legacy_cms ?. affix , packagePath )
279- await wordpressService ?. extractPosts ( project ?. legacy_cms ?. affix , packagePath )
280- await wordpressService ?. extractGlobalFields ( project ?. current_test_stack_id )
285+ const contentTypes = await fieldAttacher ( { orgId, projectId, destinationStackId : project ?. destination_stack_id } ) ;
286+
287+ switch ( cms ) {
288+ case CMS . SITECORE_V8 :
289+ case CMS . SITECORE_V9 :
290+ case CMS . SITECORE_V10 : {
291+ if ( packagePath ) {
292+ await siteCoreService ?. createEntry ( { packagePath, contentTypes, destinationStackId : project ?. destination_stack_id , projectId } ) ;
293+ await siteCoreService ?. createLocale ( req , project ?. destination_stack_id , projectId ) ;
294+ await siteCoreService ?. createVersionFile ( project ?. destination_stack_id ) ;
295+ }
296+ break ;
297+ }
298+ case CMS . WORDPRESS : {
299+ if ( packagePath ) {
300+ await wordpressService ?. getAllAssets ( affix , packagePath , project ?. current_test_stack_id )
301+ await wordpressService ?. createAssetFolderFile ( affix )
302+ await wordpressService ?. getAllreference ( affix , packagePath , project ?. current_test_stack_id )
303+ await wordpressService ?. extractChunks ( affix , packagePath , project ?. current_test_stack_id )
304+ await wordpressService ?. getAllAuthors ( affix , packagePath )
305+ await wordpressService ?. extractContentTypes ( affix , project ?. current_test_stack_id )
306+ await wordpressService ?. getAllTerms ( affix , packagePath )
307+ await wordpressService ?. getAllTags ( affix , packagePath )
308+ await wordpressService ?. getAllCategories ( affix , packagePath )
309+ await wordpressService ?. extractPosts ( affix , packagePath )
310+ await wordpressService ?. extractGlobalFields ( project ?. current_test_stack_id )
311+ }
312+ break ;
313+ }
314+ default :
315+ break ;
316+ }
281317 await utilsCli ?. runCli ( region , user_id , project ?. destination_stack_id , projectId , false , loggerPath ) ;
282318 }
283319}
0 commit comments