Skip to content

Commit

Permalink
Merge pull request #621 from PAWECOGmbH/development
Browse files Browse the repository at this point in the history
Dev to Staging
  • Loading branch information
ptruessel authored Feb 8, 2025
2 parents dc0041d + 0959a3d commit 69ad31d
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 118 deletions.
62 changes: 62 additions & 0 deletions config/db/core/V7__schedulecontrol.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
ALTER TABLE `schedulecontrol`
ADD COLUMN `blnIsRunning` tinyint NULL DEFAULT 0 AFTER `dtmEnd`;

ALTER TABLE `scheduler_01`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_02`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_03`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_04`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_05`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_06`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_07`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_08`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_09`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_10`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_11`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_12`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_13`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_14`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_15`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_16`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_17`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_18`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_19`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;

ALTER TABLE `scheduler_20`
ADD COLUMN `intDuringSeconds` tinyint NULL DEFAULT 0 AFTER `dtmLastRun`;
90 changes: 57 additions & 33 deletions www/backend/core/com/modules.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ component displayname="modules" output="false" {

loop query="local.qGetScheduleTask" {

// We need to delete the value
// If we need to delete the entries
if (local.whatsToDo eq "stop") {

loop from="1" to="20" index="local.i" {
Expand All @@ -508,13 +508,13 @@ component displayname="modules" output="false" {

}

// We need to insert the value
// If we need to insert the entries
if (local.whatsToDo eq "run") {

// Initialize variables to track the table with the fewest records
local.minRecords = 99999999;
local.targetTable;
local.sqlCount;
local.targetTable = "";
local.sqlCount = "";

// Generate the SQL for counting entries in each table and combine them using UNION
loop from="1" to="20" index="local.i" {
Expand All @@ -527,17 +527,17 @@ component displayname="modules" output="false" {

local.sqlCount &= "SELECT '" & local.tableName & "' AS tableName, COUNT(*) AS thisCount FROM " & local.tableName;

// Execute the combined query
local.qCount = queryExecute(sql=local.sqlCount, options={datasource: application.datasource});
}

// Iterate over the results to find the table with the fewest entries
loop from="1" to="#local.qCount.recordCount#" index="local.j" {
if (local.j eq 1 or local.qCount.thisCount[local.j] < local.minRecords) {
local.minRecords = local.qCount.thisCount[local.j];
local.targetTable = local.qCount.tableName[local.j];
}
}
// Execute the combined query
local.qCount = queryExecute(sql=local.sqlCount, options={datasource: application.datasource});

// Iterate over the results to find the table with the fewest entries
loop from="1" to="#local.qCount.recordCount#" index="local.j" {
if (local.qCount.thisCount[local.j] < local.minRecords) {
local.minRecords = local.qCount.thisCount[local.j];
local.targetTable = local.qCount.tableName[local.j];
}
}

// Now we have found the table with the fewest entries, so we insert the data record there
Expand All @@ -546,29 +546,54 @@ component displayname="modules" output="false" {
// Calculate next run
local.nextRun = application.objSysadmin.calcNextRun(local.qGetScheduleTask.dtmStartTime, local.qGetScheduleTask.intIterationMinutes);

queryExecute (
options = {datasource = application.datasource, result="checkInsert"},
params = {
schedID: {type: "numeric", value: local.qGetScheduleTask.intScheduletaskID},
customerID: {type: "numeric", value: arguments.customerID},
nextRun: {type: "datetime", value: local.nextRun}
},
sql = "
INSERT INTO #local.targetTable# (intScheduletaskID, intCustomerID, dtmLastRun, dtmNextRun)
SELECT :schedID, :customerID, NULL, :nextRun
FROM DUAL
WHERE NOT EXISTS (
// Check if the combination already exists in any table
local.exists = false;
loop from="1" to="20" index="local.i" {
local.tableName = "scheduler_#numberFormat(local.i, '00')#";
local.qCheckExist = queryExecute(
options = {datasource = application.datasource},
params = {
schedID: {type: "numeric", value: local.qGetScheduleTask.intScheduletaskID},
customerID: {type: "numeric", value: arguments.customerID}
},
sql = "
SELECT 1
FROM #local.targetTable#
FROM #local.tableName#
WHERE intScheduletaskID = :schedID AND intCustomerID = :customerID
)
LIMIT 1
"
)
"
);
if (local.qCheckExist.recordCount) {
local.exists = true;
break;
}
}

if (!local.exists) {

queryExecute (
options = {datasource = application.datasource, result="local.checkInsert"},
params = {
schedID: {type: "numeric", value: local.qGetScheduleTask.intScheduletaskID},
customerID: {type: "numeric", value: arguments.customerID},
nextRun: {type: "datetime", value: local.nextRun}
},
sql = "
INSERT INTO #local.targetTable# (intScheduletaskID, intCustomerID, dtmLastRun, dtmNextRun)
SELECT :schedID, :customerID, NULL, :nextRun
FROM DUAL
WHERE NOT EXISTS (
SELECT 1
FROM #local.targetTable#
WHERE intScheduletaskID = :schedID AND intCustomerID = :customerID
)
LIMIT 1
"
)

// Maybe we have to update
if (!checkInsert.recordCount) {

} else {

// Maybe we have to update
queryExecute (
options = {datasource = application.datasource},
params = {
Expand All @@ -592,7 +617,6 @@ component displayname="modules" output="false" {
}



// If the customerID is 0, we need to update
} else {

Expand Down
18 changes: 18 additions & 0 deletions www/backend/core/com/sysadmin.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,24 @@ component displayname="sysadmin" output="false" {
}


public void function stopScheduleControl(required numeric task) {

queryExecute(
options = {datasource = application.datasource},
params = {
utcDate: {type: "datetime", value: now()}
},
sql = "
UPDATE schedulecontrol
SET dtmEnd =:utcDate,
blnIsRunning = 0
WHERE strTaskName = 'task_#arguments.task#'
"
)

}




}
60 changes: 20 additions & 40 deletions www/backend/core/com/time.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -98,63 +98,43 @@ component displayname="time" output="false" {
}


// Covert a given date to local timezone
public date function utc2local(date utcDate, string timezone) {

local.utcDate = arguments.utcDate ?: now();
local.timezone = arguments.timezone ?: variables.timezone;
local.utcDate = isDate(arguments.utcDate) ? arguments.utcDate : now();
local.utcDate = parseDateTime(local.utcDate);

// Init the Java object
local.objJAVATimezone = createObject( "java", "java.util.TimeZone" );
local.timezone = arguments.timezone ?: variables.timezone;

// Get infos of the corresponding timezone
// Init Java TimeZone object
local.objJAVATimezone = createObject("java", "java.util.TimeZone");
local.zoneInfos = local.objJAVATimezone.getTimeZone(local.timezone);

// Get utc offset of timezone
local.offsetHours = local.zoneInfos.getOffset(0)/3600000;
// Calculate offset including daylight saving time
local.offsetHours = local.zoneInfos.getOffset(local.utcDate.getTime()) / 3600000;

// Are we having dst time?
local.inDST = local.zoneInfos.inDayLightTime(local.utcDate);

// Add 1 hour to offsetHours if dst
if (local.inDST) {
local.offsetHours = local.offsetHours+1;
}

// Add hours to time
local.localDate = dateAdd("h", local.offsetHours, local.utcDate);

return local.localDate;
// Convert to local time
return dateAdd("h", local.offsetHours, local.utcDate);

}


// Convert a given date with the timezone to utc
// Covert a given date to UTC timezone
public date function local2utc(required date givenDate, string timezone) {

local.givenDate = arguments.givenDate ?: now();
local.timeZone = arguments.timezone ?: variables.timezone;
local.givenDate = isDate(arguments.givenDate) ? arguments.givenDate : now();
local.givenDate = parseDateTime(local.givenDate);

// Init the Java object
local.objJAVATimezone = createObject( "java", "java.util.TimeZone" );
local.timeZone = arguments.timezone ?: variables.timezone;

// Get infos of the corresponding timezone
// Init Java TimeZone object
local.objJAVATimezone = createObject("java", "java.util.TimeZone");
local.zoneInfos = local.objJAVATimezone.getTimeZone(local.timeZone);

// Get utc offset of timezone
local.offsetHours = local.zoneInfos.getOffset(0)/3600000;

// Are we having dst time?
local.inDST = local.zoneInfos.inDayLightTime(local.givenDate);

// Add 1 hour to offsetHours if dst
if (local.inDST) {
local.offsetHours = local.offsetHours+1;
}

// Substract hours to time
local.utcDate = dateAdd("h", -local.offsetHours, local.givenDate);
// Calculate offset including daylight saving time
local.offsetHours = local.zoneInfos.getOffset(local.givenDate.getTime()) / 3600000;

return local.utcDate;
// Convert to UTC (only subtract offset!)
return dateAdd("h", -local.offsetHours, local.givenDate);

}

Expand Down
Loading

0 comments on commit 69ad31d

Please sign in to comment.