Merged in bugfix/PMCORE-2369-A (pull request #8173)

PMCORE-2369-A Kpi Report by process and Report by user does not work and the error is displayed on the taskscheduler log

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Roly Gutierrez
2021-09-24 19:10:24 +00:00
committed by Julio Cesar Laura Avendaño
2 changed files with 21 additions and 23 deletions

View File

@@ -54,6 +54,23 @@ class ScheduleRunCommand extends BaseCommand
if (!$win) {
$body = str_replace(" -c"," " . $user . " -c", $p->body);
}
//for init date and finish date parameters
if (strpos($body, "report_by_user") !== false || strpos($body, "report_by_process") !== false) {
//remove if the command is old and contains an incorrect definition of the date
$body = preg_replace("/\s\+init-date\"[0-9\-\s:]+\"/", "", $body);
$body = preg_replace("/\s\+finish-date\"[0-9\-\s:]+\"/", "", $body);
//the start date must be one month back from the current date.
$currentDate = date("Y-m-d H:i:s");
$oneMonthAgo = $currentDate . " -1 month";
$timestamp = strtotime($oneMonthAgo);
$oneMonthAgo = date("Y-m-d H:i:s", $timestamp);
$body = str_replace("report_by_user", "report_by_user +init-date'{$oneMonthAgo}' +finish-date'{$currentDate}'", $body);
$body = str_replace("report_by_process", "report_by_process +init-date'{$oneMonthAgo}' +finish-date'{$currentDate}'", $body);
}
$schedule = $that->schedule->exec($body)->cron($p->expression)->between($starting, $ending)->timezone($timezone)->when(function () use ($p) {
$now = Carbon::now();
$result = false;

View File

@@ -172,9 +172,7 @@ class TaskSchedulerBM
"everyOn" => "1",
"interval" => "week",
"expression" => "*/10 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_REPORT_USERS_DESC",
"initDate" => "+init-date",
"finishDate" => "+finish-date"
"description" => "ID_TASK_SCHEDULER_REPORT_USERS_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_REPORT_PROCESS",
@@ -191,9 +189,7 @@ class TaskSchedulerBM
"everyOn" => "1",
"interval" => "week",
"expression" => "*/10 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_CALCULATE_APP_DESC",
"initDate" => "+init-date",
"finishDate" => "+finish-date"
"description" => "ID_TASK_SCHEDULER_CALCULATE_APP_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_LDAP",
@@ -283,25 +279,10 @@ class TaskSchedulerBM
$task->description = $service["description"];
$task->startingTime = $service["startingTime"];
$task->endingTime = $service["endingTime"];
$activity = $service["service"];
//for init date and finish date parameters
$currentDate = date("Y-m-d H:i:s");
$setOfActivities = ["report_by_user", "report_by_process"];
if (!empty($service["initDate"]) && in_array($activity, $setOfActivities)) {
$oneMonthAgo = $currentDate . " -1 month";
$timestamp = strtotime($oneMonthAgo);
$oneMonthAgo = date("Y-m-d H:i:s", $timestamp);
$activity = $activity . ' ' . $service["initDate"] . '"' . $oneMonthAgo . '"';
}
if (!empty($service["finishDate"]) && in_array($activity, $setOfActivities)) {
$activity = $activity . ' ' . $service["initDate"] . '"' . $currentDate . '"';
}
if ($win) {
$task->body = 'php "' . PATH_TRUNK . $service["filew"] . '" ' . $activity . ' +w' . config("system.workspace") . ' +force +async';
$task->body = 'php "' . PATH_TRUNK . $service["filew"] . '" ' . $service["service"] . ' +w' . config("system.workspace") . ' +force +async';
} else {
$task->body = 'su -s /bin/sh -c "php ' . PATH_TRUNK . $service["file"] . " " . $activity . ' +w' . config("system.workspace") . ' +force +async"';
$task->body = 'su -s /bin/sh -c "php ' . PATH_TRUNK . $service["file"] . " " . $service["service"] . ' +w' . config("system.workspace") . ' +force +async"';
}
$task->expression = $service["expression"];
$task->type = "shell";