Files
luos/workflow/engine/src/ProcessMaker/BusinessModel/TaskSchedulerBM.php

290 lines
11 KiB
PHP
Raw Normal View History

2020-05-29 18:36:07 +00:00
<?php
2020-07-14 20:20:31 +00:00
2020-05-29 18:36:07 +00:00
namespace ProcessMaker\BusinessModel;
2020-07-14 20:20:31 +00:00
2020-05-29 18:36:07 +00:00
use ProcessMaker\Core\System;
use ProcessMaker\Model\TaskScheduler;
2020-07-14 20:20:31 +00:00
2020-05-29 18:36:07 +00:00
class TaskSchedulerBM
{
public static $services = [
[
"title" => "ID_TASK_SCHEDULER_UNPAUSE",
"enable" => "0",
"service" => "unpause",
"category" => "case_actions",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "0 */1 * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_UNPAUSE_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_CALCULATE_ELAPSED",
"enable" => "0",
"service" => "calculate",
"category" => "case_actions",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => "0:00",
"endingTime" => "0:30",
2020-07-15 13:00:17 -07:00
"timezone" => "default",
"everyOn" => "1",
"interval" => "week",
"expression" => "0 */1 * * 0,1,2,3,4,5,6",
"description" => 'ID_TASK_SCHEDULER_CALCULATE_ELAPSED_DESC'
],
[
"title" => "ID_TASK_SCHEDULER_UNASSIGNED",
"enable" => "0",
"service" => "unassigned-case",
"category" => "case_actions",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "0 */1 * * 0,1,2,3,4,5,6",
"description" => 'ID_TASK_SCHEDULER_UNASSIGNED_DESC'
],
[
"title" => "ID_TASK_SCHEDULER_CLEAN_SELF",
"enable" => "0",
"service" => "clean-self-service-tables",
"category" => "case_actions",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => "0:00",
"endingTime" => "0:30",
2020-07-15 13:00:17 -07:00
"timezone" => "default",
"everyOn" => "1",
"interval" => "week",
"expression" => "0 */1 * * 0,1,2,3,4,5,6",
"description" => 'ID_TASK_SCHEDULER_CLEAN_SELF_DESC'
],
2020-07-09 20:13:49 +00:00
[
"title" => "ID_TIMER_EVENT",
"enable" => "1",
"service" => "",
"category" => "case_actions",
"file" => "workflow/engine/bin/timereventcron.php",
"filew" => "workflow\\engine\bin\\timereventcron.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
2020-07-09 20:13:49 +00:00
"everyOn" => "1",
"interval" => "week",
"expression" => "*/1 * * * 0,1,2,3,4,5,6",
"description" => "ID_TIMER_EVENT_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_CASE_EMAILS",
"enable" => "1",
"service" => "emails",
"category" => "emails_notifications",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "*/5 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_CASE_EMAILS_DESC"
],
[
2020-07-09 20:13:49 +00:00
"title" => "ID_TASK_SCHEDULER_MESSAGE_EVENTS",
"enable" => "1",
"service" => "",
"category" => "emails_notifications",
2020-07-09 20:13:49 +00:00
"file" => "workflow/engine/bin/messageeventcron.php",
"filew" => "workflow\\engine\bin\messageeventcron.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "*/5 * * * 0,1,2,3,4,5,6",
2020-07-09 20:13:49 +00:00
"description" => "ID_TASK_SCHEDULER_MESSAGE_EVENTS_DESC"
]
2020-07-14 20:20:31 +00:00
/*----------------------------------********---------------------------------*/, [
2020-07-09 20:13:49 +00:00
"title" => "ID_TASK_SCHEDULER_ACTION_EMAIL",
"enable" => "1",
"service" => "",
"category" => "emails_notifications",
2020-07-09 20:13:49 +00:00
"file" => "workflow/engine/bin/actionsByEmailEmailResponse.php",
"filew" => "workflow\\engine\bin\actionsByEmailEmailResponse.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "*/5 * * * 0,1,2,3,4,5,6",
2020-07-09 20:13:49 +00:00
"description" => "ID_TASK_SCHEDULER_ACTION_EMAIL_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_SEND_NOT",
"enable" => "1",
"service" => "",
"category" => "emails_notifications",
"file" => "workflow/engine/bin/sendnotificationscron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\sendnotificationscron.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "*/5 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_SEND_NOT_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_REPORT_USERS",
"enable" => "0",
"service" => "report_by_user",
"category" => "reporting",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "*/10 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_REPORT_USERS_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_REPORT_PROCESS",
"enable" => "0",
"service" => "report_by_process",
"category" => "reporting",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => null,
"category" => "reporting",
"startingTime" => null,
"endingTime" => null,
2020-07-15 13:00:17 -07:00
"timezone" => null,
"everyOn" => "1",
"interval" => "week",
"expression" => "*/10 * * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_CALCULATE_APP_DESC"
],
[
"title" => "ID_TASK_SCHEDULER_LDAP",
"enable" => "0",
"service" => "",
"category" => "processmaker_sync",
"file" => "workflow/engine/bin/ldapcron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\ldapcron.php",
"startingTime" => "0:00",
"endingTime" => "0:30",
2020-07-15 13:00:17 -07:00
"timezone" => "default",
"everyOn" => "1",
"interval" => "week",
"expression" => "0 */1 * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_LDAP"
],
[
"title" => "ID_TASK_SCHEDULER_PM_PLUGINS",
"enable" => "0",
"service" => "plugins",
"category" => "plugins",
"file" => "workflow/engine/bin/cron.php",
2020-07-07 16:06:59 +00:00
"filew" => "workflow\\engine\bin\cron.php",
"startingTime" => "0:00",
"endingTime" => "0:30",
2020-07-15 13:00:17 -07:00
"timezone" => "default",
"everyOn" => "1",
"interval" => "week",
"expression" => "0 */1 * * 0,1,2,3,4,5,6",
"description" => "ID_TASK_SCHEDULER_PM_PLUGINS_DESC"
]
2020-07-14 20:20:31 +00:00
/*----------------------------------********---------------------------------*/
];
2020-06-09 14:28:16 +00:00
/**
* Return the records in Schedule Table by category
*/
public static function getSchedule($category)
{
2020-05-29 18:36:07 +00:00
$tasks = TaskScheduler::all();
$count = $tasks->count();
if ($count == 0) {
2020-05-29 18:36:07 +00:00
TaskSchedulerBM::generateInitialData();
$tasks = TaskScheduler::all();
}
if (is_null($category)) {
2020-05-29 18:36:07 +00:00
return $tasks;
} else {
2020-07-14 20:20:31 +00:00
$tasks = TaskScheduler::where('category', $category)->get();
foreach ($tasks as $task) {
$task->default_value = json_decode($task->default_value);
}
return $tasks;
2020-05-29 18:36:07 +00:00
}
}
2020-06-09 14:28:16 +00:00
/**
* Save the record Schedule in Schedule Table
*/
public static function saveSchedule(array $request)
{
$task = TaskScheduler::find($request['id']);
if (isset($request['enable'])) {
$task->enable = $request['enable'];
2020-05-29 18:36:07 +00:00
}
if (isset($request['expression'])) {
$task->expression = $request['expression'];
$task->startingTime = $request['startingTime'];
$task->endingTime = $request['endingTime'];
$task->timezone = $request['timezone'];
$task->everyOn = $request['everyOn'];
$task->interval = $request['interval'];
}
2020-05-29 18:36:07 +00:00
$task->save();
return $task;
2020-05-29 18:36:07 +00:00
}
/**
* Initial data for Schedule Table, with default values
*/
public static function generateInitialData()
{
2020-05-29 18:36:07 +00:00
$arraySystemConfiguration = System::getSystemConfiguration('', '', config("system.workspace"));
$toSave = [];
2020-07-07 16:06:59 +00:00
$win = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
foreach (TaskSchedulerBM::$services as $service) {
2020-05-29 18:36:07 +00:00
$task = new TaskScheduler;
$task->title = $service["title"];
$task->category = $service["category"];
$task->description = $service["description"];
$task->startingTime = $service["startingTime"];
$task->endingTime = $service["endingTime"];
2020-07-07 16:06:59 +00:00
if ($win) {
$task->body = 'php "' . PATH_TRUNK . $service["filew"] . '" ' . $service["service"] . ' +w' . config("system.workspace") . ' +force';
} else {
$task->body = 'su -s /bin/sh -c "php ' . PATH_TRUNK . $service["file"] . " " . $service["service"] . ' +w' . config("system.workspace") . ' +force"';
}
$task->expression = $service["expression"];
2020-05-29 18:36:07 +00:00
$task->type = "shell";
$task->system = 1;
$task->enable = $service["enable"];
$task->everyOn = $service["everyOn"];
$task->interval = $service["interval"];
2020-07-15 13:00:17 -07:00
$task->timezone = $service["timezone"] == "default" ? date_default_timezone_get() : null;
2020-07-14 20:20:31 +00:00
$task->default_value = json_encode([
"startingTime" => $service["startingTime"],
"endingTime" => $service["endingTime"],
"everyOn" => $service["everyOn"],
"interval" => $service["interval"],
"expression" => $service["expression"],
2020-07-15 13:00:17 -07:00
"timezone" => $task->timezone
2020-07-14 20:20:31 +00:00
]);
$task->save();
2020-05-29 18:36:07 +00:00
}
}
2020-07-14 20:20:31 +00:00
}