From d172881bbf1bad845ef68b95d9dc919208a3fbd2 Mon Sep 17 00:00:00 2001 From: CF Mitrah Date: Mon, 11 Aug 2025 22:33:54 +0530 Subject: [PATCH] CFCONFIG-64: Fixed an issue with scheduled tasks and event gateways during CFConfig import in Lucee 6. --- models/providers/Lucee6Server.cfc | 33 ++++++++++++++++++++++++++ tests/specs/Lucee6ServerConfigTest.cfc | 26 ++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/models/providers/Lucee6Server.cfc b/models/providers/Lucee6Server.cfc index 3a8c293..4d4b748 100644 --- a/models/providers/Lucee6Server.cfc +++ b/models/providers/Lucee6Server.cfc @@ -346,6 +346,20 @@ component accessors=true extends='cfconfig-services.models.BaseConfig' { } } + if ( configData.keyExists( 'eventGatewaysLucee' ) ) { + var gatewaysStruct = {}; + for ( var gatewayName in configData.eventGatewaysLucee ) { + var gw = configData.eventGatewaysLucee[ gatewayName ]; + var newGateway = {}; + for (var key in gw) { + newGateway[key] = gw[key]; + } + gatewaysStruct[ gatewayName ] = newGateway; + } + configData.gateways = gatewaysStruct; + structDelete( configData, "eventGatewaysLucee" ); + } + // Ensure the parent directories exist directoryCreate( path=getDirectoryFromPath( configFilePath ), createPath=true, ignoreExists=true ); var existingData = {}; @@ -357,6 +371,25 @@ component accessors=true extends='cfconfig-services.models.BaseConfig' { existingData = readJSONC( expandPath( '/cfconfig-services/resources/lucee6/CFConfig-base.json' ) ); } mergeMemento( configData, existingData ) + //scheduledTasks for Lucee 6 export + if ( structKeyExists( existingData, "scheduledTasks" ) && !isArray( existingData.scheduledTasks ) ) { + var tasksArray = []; + for ( var taskName in existingData.scheduledTasks ) { + var task = existingData.scheduledTasks[ taskName ]; + var newTask = duplicate(task); + newTask["name"] = task["task"] ?: taskName; + newTask["startDate"] = isNull(task["startDate"]) ? "" : "{d '" & dateFormat( task["startDate"], "yyyy-mm-dd" ) & "'}"; + newTask["startTime"] = isNull(task["startTime"]) ? "" : "{t '" & timeFormat( task["startTime"], "HH:mm:ss" ) & "'}"; + newTask["port"] = isNull(task["port"]) ? -1 : task["port"]; + newTask["interval"] = task["interval"] ?: "3600"; + newTask["timeout"] = int( task["requestTimeOut"] ?: task["timeout"] ?: 0 ); + ["resolveUrl","publish","hidden","readonly","autoDelete","unique","paused"].each(function(boolField){ + if (!structKeyExists(newTask, boolField)) newTask[boolField] = false; + }); + tasksArray.append(newTask); + } + existingData.scheduledTasks = tasksArray; + } // Make sure this never makes it to the hard drive structDelete( existingData, 'adminPassword' ); diff --git a/tests/specs/Lucee6ServerConfigTest.cfc b/tests/specs/Lucee6ServerConfigTest.cfc index e4e4ccc..d3aa594 100644 --- a/tests/specs/Lucee6ServerConfigTest.cfc +++ b/tests/specs/Lucee6ServerConfigTest.cfc @@ -89,6 +89,32 @@ component extends="tests.BaseTest" appMapping="/tests" { }); + it( "should export scheduledTasks as array and gateways as struct (CFCONFIG-64)", function() { + var Lucee6ServerConfig = getInstance( 'Lucee6Server@cfconfig-services' ); + var testConfig = { + eventGatewaysLucee: { + "eventTest": { + CFCPath: "local/test" + } + }, + scheduledTasks: { + "task": { + interval: "daily", + task: "task" + } + } + }; + Lucee6ServerConfig.setMemento( testConfig ); + Lucee6ServerConfig.write( expandPath( '/tests/resources/tmp' ) ); + + var output = deserializeJSON( fileRead( expandPath( '/tests/resources/tmp/context/.CFConfig.json' ) ) ); + expect( isArray( output.scheduledTasks ) ).toBeTrue(); + expect( arrayLen( output.scheduledTasks ) ).toBe( 1 ); + expect( output.scheduledTasks[1].name ).toBe( "task" ); + expect( isStruct( output.gateways ) ).toBeTrue(); + expect( output.gateways[ "eventTest" ].cfcPath ).toBe( "local/test" ); + }); + }); }