Solving conflicts merginf with last merge in develop branch
This commit is contained in:
@@ -13,16 +13,16 @@ try {
|
||||
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != 'WIN';
|
||||
|
||||
$arrayCronConfig = [
|
||||
'cron' => ['title' => 'CRON'],
|
||||
'ldapcron' => ['title' => 'LDAP Advanced CRON'],
|
||||
'cron' => ['title' => 'CRON'],
|
||||
'ldapcron' => ['title' => 'LDAP Advanced CRON'],
|
||||
'messageeventcron' => ['title' => 'Message-Event CRON'],
|
||||
'timereventcron' => ['title' => 'Timer-Event CRON'],
|
||||
'sendnotificationscron' => ['title' => 'Send-Notifications CRON'],
|
||||
'webentriescron' => ['title' => 'Wen Entries CRON']
|
||||
'webentriescron' => ['title' => 'Web Entries CRON']
|
||||
];
|
||||
|
||||
//Define constants
|
||||
define('PATH_SEP', ($osIsLinux)? '/' : '\\');
|
||||
define('PATH_SEP', ($osIsLinux) ? '/' : '\\');
|
||||
|
||||
$arrayPathToCron = [];
|
||||
$flagPathToCron = false;
|
||||
@@ -52,8 +52,8 @@ try {
|
||||
|
||||
$pathOutTrunk = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
|
||||
|
||||
define('PATH_HOME', $pathHome);
|
||||
define('PATH_TRUNK', $pathTrunk);
|
||||
define('PATH_HOME', $pathHome);
|
||||
define('PATH_TRUNK', $pathTrunk);
|
||||
define('PATH_OUTTRUNK', $pathOutTrunk);
|
||||
|
||||
//Check deprecated files
|
||||
@@ -87,20 +87,20 @@ try {
|
||||
|
||||
$arraySystemConfiguration = System::getSystemConfiguration();
|
||||
|
||||
$e_all = (defined('E_DEPRECATED'))? E_ALL & ~E_DEPRECATED : E_ALL;
|
||||
$e_all = (defined('E_STRICT'))? $e_all & ~E_STRICT : $e_all;
|
||||
$e_all = ($arraySystemConfiguration['debug'])? $e_all : $e_all & ~E_NOTICE;
|
||||
$e_all = (defined('E_DEPRECATED')) ? E_ALL & ~E_DEPRECATED : E_ALL;
|
||||
$e_all = (defined('E_STRICT')) ? $e_all & ~E_STRICT : $e_all;
|
||||
$e_all = ($arraySystemConfiguration['debug']) ? $e_all : $e_all & ~E_NOTICE;
|
||||
|
||||
//In community version the default value is 0
|
||||
$systemUtcTimeZone = (int)($arraySystemConfiguration['system_utc_time_zone']) == 1;
|
||||
$systemUtcTimeZone = (int) ($arraySystemConfiguration['system_utc_time_zone']) == 1;
|
||||
|
||||
app()->useStoragePath(realpath(PATH_DATA));
|
||||
app()->make(Kernel::class)->bootstrap();
|
||||
restore_error_handler();
|
||||
//Do not change any of these settings directly, use env.ini instead
|
||||
ini_set('display_errors', $arraySystemConfiguration['debug']);
|
||||
ini_set('display_errors', $arraySystemConfiguration['debug']);
|
||||
ini_set('error_reporting', $e_all);
|
||||
ini_set('short_open_tag', 'On');
|
||||
ini_set('short_open_tag', 'On');
|
||||
ini_set('default_charset', 'UTF-8');
|
||||
ini_set('soap.wsdl_cache_enabled', $arraySystemConfiguration['wsdl_cache']);
|
||||
ini_set('date.timezone', $systemUtcTimeZone ? 'UTC' : $arraySystemConfiguration['time_zone']);
|
||||
@@ -129,7 +129,8 @@ try {
|
||||
|
||||
if (in_array($arrayCommandOption['force'], $argv)) {
|
||||
unset($argv[array_search($arrayCommandOption['force'], $argv)]);
|
||||
|
||||
//reindex keys
|
||||
$argv = array_values($argv);
|
||||
$force = true;
|
||||
}
|
||||
|
||||
@@ -138,8 +139,8 @@ try {
|
||||
//Get data of CRON file
|
||||
$arrayCron = unserialize(trim(file_get_contents(PATH_DATA . $cronName)));
|
||||
|
||||
$flagIsRunning = (bool)((isset($arrayCron['flagIsRunning']))? $arrayCron['flagIsRunning'] : $arrayCron['bCronIsRunning']);
|
||||
$lastExecution = (isset($arrayCron['lastExecution']))? $arrayCron['lastExecution'] : $arrayCron['sLastExecution'];
|
||||
$flagIsRunning = (bool) ((isset($arrayCron['flagIsRunning'])) ? $arrayCron['flagIsRunning'] : $arrayCron['bCronIsRunning']);
|
||||
$lastExecution = (isset($arrayCron['lastExecution'])) ? $arrayCron['lastExecution'] : $arrayCron['sLastExecution'];
|
||||
}
|
||||
|
||||
if (!$force && $osIsLinux) {
|
||||
@@ -169,9 +170,9 @@ try {
|
||||
|
||||
try {
|
||||
$cronSinglePath = PATH_CORE . 'bin' . PATH_SEP . 'cron_single.php';
|
||||
$workspace = '';
|
||||
$date = '';
|
||||
$argvx = '';
|
||||
$workspace = '';
|
||||
$date = '';
|
||||
$argvx = '';
|
||||
|
||||
for ($i = 1; $i <= count($argv) - 1; $i++) {
|
||||
if (!isset($argv[$i])) {
|
||||
@@ -190,7 +191,7 @@ try {
|
||||
}
|
||||
|
||||
if (!$flagDate) {
|
||||
$argvx = $argvx . (($argvx != '')? ' ' : '') . $argv[$i];
|
||||
$argvx = $argvx . (($argvx != '') ? ' ' : '') . $argv[$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,8 +210,8 @@ try {
|
||||
if (is_dir(PATH_DB . $entry)) {
|
||||
if (file_exists(PATH_DB . $entry . PATH_SEP . 'db.php')) {
|
||||
$counterw++;
|
||||
|
||||
passthru('php -f "' . $cronSinglePath . '" "' . base64_encode(PATH_HOME) . '" "' . base64_encode(PATH_TRUNK) . '" "' . base64_encode(PATH_OUTTRUNK) . '" ' . $cronName . ' ' . $entry . ' "' . $date . '" ' . $argvx);
|
||||
$command = 'php -f "' . $cronSinglePath . '" "' . base64_encode(PATH_HOME) . '" "' . base64_encode(PATH_TRUNK) . '" "' . base64_encode(PATH_OUTTRUNK) . '" ' . $cronName . ' ' . $entry . ' "' . $date . '" ' . $argvx;
|
||||
passthru($command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,8 +222,8 @@ try {
|
||||
}
|
||||
|
||||
$counterw++;
|
||||
|
||||
passthru('php -f "' . $cronSinglePath . '" "' . base64_encode(PATH_HOME) . '" "' . base64_encode(PATH_TRUNK) . '" "' . base64_encode(PATH_OUTTRUNK) . '" ' . $cronName . ' ' . $workspace . ' "' . $date . '" ' . $argvx);
|
||||
$command = 'php -f "' . $cronSinglePath . '" "' . base64_encode(PATH_HOME) . '" "' . base64_encode(PATH_TRUNK) . '" "' . base64_encode(PATH_OUTTRUNK) . '" ' . $cronName . ' ' . $workspace . ' "' . $date . '" ' . $argvx;
|
||||
passthru($command);
|
||||
}
|
||||
|
||||
eprintln('Finished ' . $counterw . ' workspaces processed');
|
||||
@@ -235,13 +236,13 @@ try {
|
||||
file_put_contents(PATH_DATA . $cronName, serialize($arrayCron));
|
||||
} else {
|
||||
eprintln('The ' . $arrayCronConfig[$cronName]['title'] . ' is running, please wait for it to finish' . "\n" . 'Started in ' . $lastExecution);
|
||||
eprintln('If do you want force the execution use the option "' . $arrayCommandOption['force'] . '", example: php -f ' . $cronName . '.php +wworkflow ' . $arrayCommandOption['force'] ,'green');
|
||||
eprintln('If do you want force the execution use the option "' . $arrayCommandOption['force'] . '", example: php -f ' . $cronName . '.php +wworkflow ' . $arrayCommandOption['force'], 'green');
|
||||
}
|
||||
|
||||
echo 'Done!' . "\n";
|
||||
} catch (Exception $e) {
|
||||
$token = strtotime("now");
|
||||
PMException::registerErrorLog($e, $token);
|
||||
G::outRes( G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) . "\n" );
|
||||
G::outRes(G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", [$token]) . "\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* cron_single.php
|
||||
*
|
||||
* @see workflow/engine/bin/cron.php
|
||||
* @see workflow/engine/bin/messageeventcron.php
|
||||
* @see workflow/engine/bin/timereventcron.php
|
||||
* @see workflow/engine/bin/ldapcron.php
|
||||
* @see workflow/engine/bin/sendnotificationscron.php
|
||||
@@ -15,9 +14,7 @@
|
||||
*/
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
use ProcessMaker\BusinessModel\ActionsByEmail\ResponseReader;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
use ProcessMaker\BusinessModel\Cases;
|
||||
|
||||
require_once __DIR__ . '/../../../gulliver/system/class.g.php';
|
||||
require_once __DIR__ . '/../../../bootstrap/autoload.php';
|
||||
@@ -27,6 +24,7 @@ use ProcessMaker\BusinessModel\WebEntry;
|
||||
use ProcessMaker\Core\JobsManager;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
use ProcessMaker\TaskScheduler\Task;
|
||||
|
||||
register_shutdown_function(function () {
|
||||
if (class_exists("Propel")) {
|
||||
@@ -57,6 +55,14 @@ try {
|
||||
$cronName = $argv[4];
|
||||
$workspace = $argv[5];
|
||||
$now = $argv[6]; //date
|
||||
//asynchronous flag
|
||||
$asynchronous = false;
|
||||
$result = array_search('+async', $argv);
|
||||
if ($result !== false && is_int($result)) {
|
||||
$asynchronous = true;
|
||||
unset($argv[$result]);
|
||||
$argv = array_values($argv);
|
||||
}
|
||||
//Defines constants
|
||||
define('PATH_SEP', ($osIsLinux) ? '/' : '\\');
|
||||
|
||||
@@ -282,27 +288,65 @@ try {
|
||||
try {
|
||||
switch ($cronName) {
|
||||
case 'cron':
|
||||
processWorkspace();
|
||||
try {
|
||||
$task = new Task($asynchronous, $sObject);
|
||||
if (empty($argvx) || strpos($argvx, "emails") !== false) {
|
||||
$task->resendEmails($now, $dateSystem);
|
||||
}
|
||||
if (empty($argvx) || strpos($argvx, "unpause") !== false) {
|
||||
$task->unpauseApplications($now);
|
||||
}
|
||||
if (empty($argvx) || strpos($argvx, "calculate") !== false) {
|
||||
$task->calculateDuration();
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
if (empty($argvx) || strpos($argvx, "calculateapp") !== false) {
|
||||
$task->calculateAppDuration();
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
executeEvents();
|
||||
executeScheduledCases();
|
||||
executeUpdateAppTitle();
|
||||
if (empty($argvx) || strpos($argvx, "unassigned-case") !== false) {
|
||||
$task->executeCaseSelfService();
|
||||
}
|
||||
if (empty($argvx) || strpos($argvx, "clean-self-service-tables") !== false) {
|
||||
$task->cleanSelfServiceTables();
|
||||
}
|
||||
if (empty($argvx) || strpos($argvx, "plugins") !== false) {
|
||||
$task->executePlugins();
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
if (strpos($argvx, "report_by_user") !== false) {
|
||||
$task->fillReportByUser($dateInit, $dateFinish);
|
||||
}
|
||||
if (strpos($argvx, "report_by_process") !== false) {
|
||||
$task->fillReportByProcess($dateInit, $dateFinish);
|
||||
}
|
||||
synchronizeDrive();
|
||||
synchronizeGmailLabels();
|
||||
/*----------------------------------********---------------------------------*/
|
||||
} catch (Exception $oError) {
|
||||
saveLog("main", "error", "Error processing workspace : " . $oError->getMessage() . "\n");
|
||||
}
|
||||
break;
|
||||
case 'ldapcron':
|
||||
require_once(PATH_HOME . 'engine' . PATH_SEP . 'methods' . PATH_SEP . 'services' . PATH_SEP . 'ldapadvanced.php');
|
||||
|
||||
$ldapadvancedClassCron = new ldapadvancedClassCron();
|
||||
|
||||
$ldapadvancedClassCron->executeCron(in_array('+debug', $argv));
|
||||
$task = new Task($asynchronous, $sObject);
|
||||
$task->ldapcron(in_array('+debug', $argv));
|
||||
break;
|
||||
case 'messageeventcron':
|
||||
$messageApplication = new \ProcessMaker\BusinessModel\MessageApplication();
|
||||
|
||||
$messageApplication->catchMessageEvent(true);
|
||||
$task = new Task($asynchronous, $sObject);
|
||||
$task->messageeventcron();
|
||||
break;
|
||||
case 'timereventcron':
|
||||
$timerEvent = new \ProcessMaker\BusinessModel\TimerEvent();
|
||||
|
||||
$timerEvent->startContinueCaseByTimerEvent($now, true);
|
||||
$task = new Task($asynchronous, $sObject);
|
||||
$task->timerEventCron($now, true);
|
||||
break;
|
||||
case 'sendnotificationscron':
|
||||
sendNotifications();
|
||||
if (empty($argvx) || strpos($argvx, "send-notifications") !== false) {
|
||||
$task = new Task($asynchronous, $sObject);
|
||||
$task->sendNotifications();
|
||||
}
|
||||
break;
|
||||
case 'webentriescron':
|
||||
setExecutionMessage('Deleting web entry cases created one week ago or more');
|
||||
@@ -311,7 +355,8 @@ try {
|
||||
break;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
case 'actionsByEmailEmailResponse':
|
||||
(new ResponseReader)->actionsByEmailEmailResponse();
|
||||
$task = new Task($asynchronous, $sObject);
|
||||
$task->actionsByEmailResponse();
|
||||
break;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
}
|
||||
@@ -335,250 +380,9 @@ try {
|
||||
G::outRes(G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) . "\n");
|
||||
}
|
||||
|
||||
//Functions
|
||||
function processWorkspace()
|
||||
{
|
||||
try {
|
||||
global $sObject;
|
||||
global $sLastExecution;
|
||||
|
||||
resendEmails();
|
||||
unpauseApplications();
|
||||
calculateDuration();
|
||||
/*----------------------------------********---------------------------------*/
|
||||
calculateAppDuration();
|
||||
/*----------------------------------********---------------------------------*/
|
||||
executeEvents($sLastExecution);
|
||||
executeScheduledCases();
|
||||
executeUpdateAppTitle();
|
||||
executeCaseSelfService();
|
||||
cleanSelfServiceTables();
|
||||
executePlugins();
|
||||
/*----------------------------------********---------------------------------*/
|
||||
fillReportByUser();
|
||||
fillReportByProcess();
|
||||
synchronizeDrive();
|
||||
synchronizeGmailLabels();
|
||||
/*----------------------------------********---------------------------------*/
|
||||
} catch (Exception $oError) {
|
||||
saveLog("main", "error", "Error processing workspace : " . $oError->getMessage() . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
function resendEmails()
|
||||
{
|
||||
global $argvx;
|
||||
global $now;
|
||||
global $dateSystem;
|
||||
|
||||
if ($argvx != "" && strpos($argvx, "emails") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setExecutionMessage("Resending emails");
|
||||
|
||||
try {
|
||||
$dateResend = $now;
|
||||
|
||||
if ($now == $dateSystem) {
|
||||
$arrayDateSystem = getdate(strtotime($dateSystem));
|
||||
|
||||
$mktDateSystem = mktime(
|
||||
$arrayDateSystem["hours"],
|
||||
$arrayDateSystem["minutes"],
|
||||
$arrayDateSystem["seconds"],
|
||||
$arrayDateSystem["mon"],
|
||||
$arrayDateSystem["mday"],
|
||||
$arrayDateSystem["year"]
|
||||
);
|
||||
|
||||
$dateResend = date("Y-m-d H:i:s", $mktDateSystem - (7 * 24 * 60 * 60));
|
||||
}
|
||||
|
||||
$oSpool = new SpoolRun();
|
||||
$oSpool->resendEmails($dateResend, 1);
|
||||
|
||||
saveLog("resendEmails", "action", "Resending Emails", "c");
|
||||
|
||||
$aSpoolWarnings = $oSpool->getWarnings();
|
||||
|
||||
if ($aSpoolWarnings !== false) {
|
||||
foreach ($aSpoolWarnings as $sWarning) {
|
||||
print("MAIL SPOOL WARNING: " . $sWarning . "\n");
|
||||
saveLog("resendEmails", "warning", "MAIL SPOOL WARNING: " . $sWarning);
|
||||
}
|
||||
}
|
||||
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
$c = new Criteria("workflow");
|
||||
$c->clearSelectColumns();
|
||||
$c->addSelectColumn(ConfigurationPeer::CFG_UID);
|
||||
$c->add(ConfigurationPeer::CFG_UID, "Emails");
|
||||
$result = ConfigurationPeer::doSelectRS($c);
|
||||
$result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
if ($result->next()) {
|
||||
setExecutionResultMessage("WARNING", "warning");
|
||||
$message = "Emails won't be sent, but the cron will continue its execution";
|
||||
eprintln(" '-" . $message, "yellow");
|
||||
} else {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
}
|
||||
|
||||
saveLog("resendEmails", "error", "Error Resending Emails: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function unpauseApplications()
|
||||
{
|
||||
global $argvx;
|
||||
global $now;
|
||||
|
||||
if ($argvx != "" && strpos($argvx, "unpause") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setExecutionMessage("Unpausing applications");
|
||||
|
||||
try {
|
||||
$oCases = new Cases();
|
||||
$oCases->ThrowUnpauseDaemon($now, 1);
|
||||
|
||||
setExecutionResultMessage('DONE');
|
||||
saveLog('unpauseApplications', 'action', 'Unpausing Applications');
|
||||
} catch (Exception $oError) {
|
||||
setExecutionResultMessage('WITH ERRORS', 'error');
|
||||
eprintln(" '-" . $oError->getMessage(), 'red');
|
||||
saveLog('unpauseApplications', 'error', 'Error Unpausing Applications: ' . $oError->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function executePlugins()
|
||||
{
|
||||
global $argvx;
|
||||
|
||||
if ($argvx != "" && strpos($argvx, "plugins") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pathCronPlugins = PATH_CORE . 'bin' . PATH_SEP . 'plugins' . PATH_SEP;
|
||||
|
||||
// Executing cron files in bin/plugins directory
|
||||
if (!is_dir($pathCronPlugins)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($handle = opendir($pathCronPlugins)) {
|
||||
setExecutionMessage('Executing cron files in bin/plugins directory in Workspace: ' . config("system.workspace"));
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (strpos($file, '.php', 1) && is_file($pathCronPlugins . $file)) {
|
||||
$filename = str_replace('.php', '', $file);
|
||||
$className = $filename . 'ClassCron';
|
||||
|
||||
// Execute custom cron function
|
||||
executeCustomCronFunction($pathCronPlugins . $file, $className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Executing registered cron files
|
||||
// -> Get registered cron files
|
||||
$oPluginRegistry = PluginRegistry::loadSingleton();
|
||||
$cronFiles = $oPluginRegistry->getCronFiles();
|
||||
|
||||
// -> Execute functions
|
||||
if (!empty($cronFiles)) {
|
||||
setExecutionMessage('Executing registered cron files for Workspace: ' . config('system.workspace'));
|
||||
/**
|
||||
* @var \ProcessMaker\Plugins\Interfaces\CronFile $cronFile
|
||||
*/
|
||||
foreach ($cronFiles as $cronFile) {
|
||||
$path = PATH_PLUGINS . $cronFile->getNamespace() . PATH_SEP . 'bin' . PATH_SEP . $cronFile->getCronFile() . '.php';
|
||||
if (file_exists($path)) {
|
||||
executeCustomCronFunction($path, $cronFile->getCronFile());
|
||||
} else {
|
||||
setExecutionMessage('File ' . $cronFile->getCronFile() . '.php ' . 'does not exist.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function executeCustomCronFunction($pathFile, $className)
|
||||
{
|
||||
include_once $pathFile;
|
||||
|
||||
$oPlugin = new $className();
|
||||
|
||||
if (method_exists($oPlugin, 'executeCron')) {
|
||||
$arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
|
||||
$arrayCron["processcTimeProcess"] = 60; //Minutes
|
||||
$arrayCron["processcTimeStart"] = time();
|
||||
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
|
||||
|
||||
//Try to execute Plugin Cron. If there is an error then continue with the next file
|
||||
setExecutionMessage("\n--- Executing cron file: $pathFile");
|
||||
try {
|
||||
$oPlugin->executeCron();
|
||||
setExecutionResultMessage('DONE');
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage('FAILED', 'error');
|
||||
eprintln(" '-" . $e->getMessage(), 'red');
|
||||
saveLog('executePlugins', 'error', 'Error executing cron file: ' . $pathFile . ' - ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculateDuration()
|
||||
{
|
||||
global $argvx;
|
||||
|
||||
if ($argvx != "" && strpos($argvx, "calculate") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setExecutionMessage("Calculating Duration");
|
||||
|
||||
try {
|
||||
$oAppDelegation = new AppDelegation();
|
||||
$oAppDelegation->calculateDuration(1);
|
||||
|
||||
setExecutionResultMessage('DONE');
|
||||
saveLog('calculateDuration', 'action', 'Calculating Duration');
|
||||
} catch (Exception $oError) {
|
||||
setExecutionResultMessage('WITH ERRORS', 'error');
|
||||
eprintln(" '-" . $oError->getMessage(), 'red');
|
||||
saveLog('calculateDuration', 'error', 'Error Calculating Duration: ' . $oError->getMessage());
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
function calculateAppDuration()
|
||||
{
|
||||
global $argvx;
|
||||
|
||||
if ($argvx != "" && strpos($argvx, "calculateapp") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setExecutionMessage("Calculating Duration by Application");
|
||||
|
||||
try {
|
||||
$oApplication = new Application();
|
||||
$oApplication->calculateAppDuration(1);
|
||||
|
||||
setExecutionResultMessage('DONE');
|
||||
saveLog('calculateDurationByApp', 'action', 'Calculating Duration by Application');
|
||||
} catch (Exception $oError) {
|
||||
setExecutionResultMessage('WITH ERRORS', 'error');
|
||||
eprintln(" '-" . $oError->getMessage(), 'red');
|
||||
saveLog('calculateDurationByApp', 'error', 'Error Calculating Duration: ' . $oError->getMessage());
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
function executeEvents($sLastExecution, $now = null)
|
||||
function executeEvents()
|
||||
{
|
||||
global $sLastExecution;
|
||||
global $argvx;
|
||||
global $now;
|
||||
|
||||
@@ -696,176 +500,14 @@ function executeUpdateAppTitle()
|
||||
}
|
||||
}
|
||||
|
||||
function executeCaseSelfService()
|
||||
{
|
||||
try {
|
||||
global $argvx;
|
||||
|
||||
if ($argvx != "" && strpos($argvx, "unassigned-case") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$criteria = new Criteria("workflow");
|
||||
|
||||
//SELECT
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::APP_UID);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::DEL_INDEX);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::DEL_DELEGATE_DATE);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::APP_NUMBER);
|
||||
$criteria->addSelectColumn(AppCacheViewPeer::PRO_UID);
|
||||
$criteria->addSelectColumn(TaskPeer::TAS_UID);
|
||||
$criteria->addSelectColumn(TaskPeer::TAS_SELFSERVICE_TIME);
|
||||
$criteria->addSelectColumn(TaskPeer::TAS_SELFSERVICE_TIME_UNIT);
|
||||
$criteria->addSelectColumn(TaskPeer::TAS_SELFSERVICE_TRIGGER_UID);
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$criteria->addSelectColumn(TaskPeer::TAS_SELFSERVICE_EXECUTION);
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
//FROM
|
||||
$condition = array();
|
||||
$condition[] = array(AppCacheViewPeer::TAS_UID, TaskPeer::TAS_UID);
|
||||
$condition[] = array(TaskPeer::TAS_SELFSERVICE_TIMEOUT, 1);
|
||||
$criteria->addJoinMC($condition, Criteria::LEFT_JOIN);
|
||||
|
||||
//WHERE
|
||||
$criteria->add(AppCacheViewPeer::USR_UID, "");
|
||||
$criteria->add(AppCacheViewPeer::DEL_THREAD_STATUS, "OPEN");
|
||||
|
||||
//QUERY
|
||||
$rsCriteria = AppCacheViewPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
setExecutionMessage("Unassigned case");
|
||||
saveLog("unassignedCase", "action", "Unassigned case", "c");
|
||||
|
||||
$calendar = new Calendar();
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
$flag = false;
|
||||
|
||||
$appcacheAppUid = $row["APP_UID"];
|
||||
$appcacheDelIndex = $row["DEL_INDEX"];
|
||||
$appcacheDelDelegateDate = $row["DEL_DELEGATE_DATE"];
|
||||
$appcacheAppNumber = $row["APP_NUMBER"];
|
||||
$appcacheProUid = $row["PRO_UID"];
|
||||
$taskUid = $row["TAS_UID"];
|
||||
$taskSelfServiceTime = intval($row["TAS_SELFSERVICE_TIME"]);
|
||||
$taskSelfServiceTimeUnit = $row["TAS_SELFSERVICE_TIME_UNIT"];
|
||||
$taskSelfServiceTriggerUid = $row["TAS_SELFSERVICE_TRIGGER_UID"];
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$taskSelfServiceJustOneExecution = $row["TAS_SELFSERVICE_EXECUTION"];
|
||||
|
||||
if ($taskSelfServiceJustOneExecution == 'ONCE') {
|
||||
$criteriaSelfService = new Criteria("workflow");
|
||||
|
||||
$criteriaSelfService->add(AppTimeoutActionExecutedPeer::APP_UID, $appcacheAppUid);
|
||||
$criteriaSelfService->add(AppTimeoutActionExecutedPeer::DEL_INDEX, $appcacheDelIndex);
|
||||
|
||||
$querySelfService = AppTimeoutActionExecutedPeer::doSelectRS($criteriaSelfService);
|
||||
$querySelfService->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($querySelfService->next()) {
|
||||
$row = $querySelfService->getRow();
|
||||
$flag = true; //already executed
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
if ($calendar->pmCalendarUid == '') {
|
||||
$calendar->getCalendar(null, $appcacheProUid, $taskUid);
|
||||
$calendar->getCalendarData();
|
||||
}
|
||||
|
||||
$dueDate = $calendar->calculateDate(
|
||||
$appcacheDelDelegateDate,
|
||||
$taskSelfServiceTime,
|
||||
$taskSelfServiceTimeUnit //HOURS|DAYS|MINUTES
|
||||
//1
|
||||
);
|
||||
|
||||
if (time() > $dueDate["DUE_DATE_SECONDS"] && $flag == false) {
|
||||
$sessProcess = null;
|
||||
$sessProcessSw = 0;
|
||||
|
||||
//Load data
|
||||
$case = new Cases();
|
||||
$appFields = $case->loadCase($appcacheAppUid);
|
||||
|
||||
$appFields["APP_DATA"]["APPLICATION"] = $appcacheAppUid;
|
||||
|
||||
if (isset($_SESSION["PROCESS"])) {
|
||||
$sessProcess = $_SESSION["PROCESS"];
|
||||
$sessProcessSw = 1;
|
||||
}
|
||||
|
||||
$_SESSION["PROCESS"] = $appFields["PRO_UID"];
|
||||
|
||||
//Execute trigger
|
||||
$criteriaTgr = new Criteria();
|
||||
$criteriaTgr->add(TriggersPeer::TRI_UID, $taskSelfServiceTriggerUid);
|
||||
|
||||
$rsCriteriaTgr = TriggersPeer::doSelectRS($criteriaTgr);
|
||||
$rsCriteriaTgr->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteriaTgr->next()) {
|
||||
$row = $rsCriteriaTgr->getRow();
|
||||
|
||||
if (is_array($row) && $row["TRI_TYPE"] == "SCRIPT") {
|
||||
$arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
|
||||
$arrayCron["processcTimeProcess"] = 60; //Minutes
|
||||
$arrayCron["processcTimeStart"] = time();
|
||||
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
|
||||
|
||||
//Trigger
|
||||
global $oPMScript;
|
||||
|
||||
$oPMScript = new PMScript();
|
||||
$oPMScript->setDataTrigger($row);
|
||||
$oPMScript->setFields($appFields["APP_DATA"]);
|
||||
$oPMScript->setScript($row["TRI_WEBBOT"]);
|
||||
$oPMScript->setExecutedOn(PMScript::SELF_SERVICE_TIMEOUT);
|
||||
$oPMScript->execute();
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
//saving the case`s data if the 'Execution' is set in ONCE.
|
||||
if ($taskSelfServiceJustOneExecution == "ONCE") {
|
||||
$oAppTimeoutActionExecuted = new AppTimeoutActionExecuted();
|
||||
$dataSelf = array();
|
||||
$dataSelf["APP_UID"] = $appcacheAppUid;
|
||||
$dataSelf["DEL_INDEX"] = $appcacheDelIndex;
|
||||
$dataSelf["EXECUTION_DATE"] = time();
|
||||
$oAppTimeoutActionExecuted->create($dataSelf);
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$appFields["APP_DATA"] = array_merge($appFields["APP_DATA"], $oPMScript->aFields);
|
||||
|
||||
unset($appFields['APP_STATUS']);
|
||||
unset($appFields['APP_PROC_STATUS']);
|
||||
unset($appFields['APP_PROC_CODE']);
|
||||
unset($appFields['APP_PIN']);
|
||||
$case->updateCase($appFields["APP_UID"], $appFields);
|
||||
|
||||
saveLog("unassignedCase", "action", "OK Executed trigger to the case $appcacheAppNumber");
|
||||
}
|
||||
}
|
||||
|
||||
unset($_SESSION["PROCESS"]);
|
||||
|
||||
if ($sessProcessSw == 1) {
|
||||
$_SESSION["PROCESS"] = $sessProcess;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("unassignedCase", "error", "Error in unassigned case: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This function is only used in this file and must be deleted.
|
||||
* @global string $sObject
|
||||
* @global string $isDebug
|
||||
* @param string $sSource
|
||||
* @param string $sType
|
||||
* @param string $sDescription
|
||||
*/
|
||||
function saveLog($sSource, $sType, $sDescription)
|
||||
{
|
||||
try {
|
||||
@@ -883,6 +525,10 @@ function saveLog($sSource, $sType, $sDescription)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This function is only used in this file and must be deleted.
|
||||
* @param string $m
|
||||
*/
|
||||
function setExecutionMessage($m)
|
||||
{
|
||||
$len = strlen($m);
|
||||
@@ -896,6 +542,11 @@ function setExecutionMessage($m)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This function is only used in this file and must be deleted.
|
||||
* @param string $m
|
||||
* @param string $t
|
||||
*/
|
||||
function setExecutionResultMessage($m, $t = '')
|
||||
{
|
||||
$c = 'green';
|
||||
@@ -916,67 +567,6 @@ function setExecutionResultMessage($m, $t = '')
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
function fillReportByUser()
|
||||
{
|
||||
try {
|
||||
global $argvx;
|
||||
global $dateInit;
|
||||
global $dateFinish;
|
||||
|
||||
if (strpos($argvx, "report_by_user") === false) {
|
||||
return false;
|
||||
}
|
||||
if ($dateInit == null) {
|
||||
eprintln("You must enter the starting date.", "red");
|
||||
eprintln('Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"', "red");
|
||||
return false;
|
||||
}
|
||||
|
||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||
|
||||
$appcv = new AppCacheView();
|
||||
$appcv->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||
setExecutionMessage("Calculating data to fill the 'User Reporting'...");
|
||||
$appcv->fillReportByUser($dateInit, $dateFinish);
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("fillReportByUser", "error", "Error in fill report by user: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function fillReportByProcess()
|
||||
{
|
||||
try {
|
||||
global $argvx;
|
||||
global $dateInit;
|
||||
global $dateFinish;
|
||||
|
||||
if (strpos($argvx, "report_by_process") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($dateInit == null) {
|
||||
eprintln("You must enter the starting date.", "red");
|
||||
eprintln('Example: +init-date"YYYY-MM-DD HH:MM:SS" +finish-date"YYYY-MM-DD HH:MM:SS"', "red");
|
||||
return false;
|
||||
}
|
||||
|
||||
$dateFinish = ($dateFinish != null) ? $dateFinish : date("Y-m-d H:i:s");
|
||||
$appcv = new AppCacheView();
|
||||
$appcv->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
||||
|
||||
setExecutionMessage("Calculating data to fill the 'Process Reporting'...");
|
||||
$appcv->fillReportByProcess($dateInit, $dateFinish);
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("fillReportByProcess", "error", "Error in fill report by process: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function synchronizeDrive()
|
||||
{
|
||||
try {
|
||||
@@ -1034,94 +624,3 @@ function synchronizeGmailLabels()
|
||||
}
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
function sendNotifications()
|
||||
{
|
||||
try {
|
||||
global $argvx;
|
||||
if ($argvx != "" && strpos($argvx, "send-notifications") === false) {
|
||||
return false;
|
||||
}
|
||||
setExecutionMessage("Resending Notifications");
|
||||
setExecutionResultMessage("PROCESSING");
|
||||
$notQueue = new \NotificationQueue();
|
||||
$notQueue->checkIfCasesOpenForResendingNotification();
|
||||
$notificationsAndroid = $notQueue->loadStatusDeviceType('pending', 'android');
|
||||
if ($notificationsAndroid) {
|
||||
setExecutionMessage("|-- Send Android's Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsAndroid as $key => $item) {
|
||||
$oNotification = new \ProcessMaker\BusinessModel\Light\PushMessageAndroid();
|
||||
$oNotification->setSettingNotification();
|
||||
$oNotification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['android'] = $oNotification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new \NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $oNotification->getNumberDevices();
|
||||
}
|
||||
setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
$notificationsApple = $notQueue->loadStatusDeviceType('pending', 'apple');
|
||||
if ($notificationsApple) {
|
||||
setExecutionMessage("|-- Send Apple Notifications");
|
||||
$n = 0;
|
||||
foreach ($notificationsApple as $key => $item) {
|
||||
$oNotification = new \ProcessMaker\BusinessModel\Light\PushMessageIOS();
|
||||
$oNotification->setSettingNotification();
|
||||
$oNotification->setDevices(unserialize($item['DEV_UID']));
|
||||
$response['apple'] = $oNotification->send($item['NOT_MSG'], unserialize($item['NOT_DATA']));
|
||||
$notQueue = new \NotificationQueue();
|
||||
$notQueue->changeStatusSent($item['NOT_UID']);
|
||||
$n += $oNotification->getNumberDevices();
|
||||
}
|
||||
setExecutionResultMessage("Processed $n");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("ExecuteSendNotifications", "error", "Error when sending notifications " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean unused records in tables related to the Self-Service Value Based feature
|
||||
*
|
||||
* @see processWorkspace()
|
||||
*
|
||||
* @link https://wiki.processmaker.com/3.2/Executing_cron.php#Syntax_of_cron.php_Options
|
||||
*/
|
||||
function cleanSelfServiceTables()
|
||||
{
|
||||
try {
|
||||
global $argvx;
|
||||
|
||||
// Check if the action can be executed
|
||||
if ($argvx !== "" && strpos($argvx, "clean-self-service-tables") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Start message
|
||||
setExecutionMessage("Clean unused records for Self-Service Value Based feature");
|
||||
|
||||
// Get Propel connection
|
||||
$cnn = Propel::getConnection(AppAssignSelfServiceValueGroupPeer::DATABASE_NAME);
|
||||
|
||||
// Delete related rows and missing relations, criteria don't execute delete with joins
|
||||
$cnn->begin();
|
||||
$stmt = $cnn->createStatement();
|
||||
$stmt->executeQuery("DELETE " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
|
||||
FROM " . AppAssignSelfServiceValueGroupPeer::TABLE_NAME . "
|
||||
LEFT JOIN " . AppAssignSelfServiceValuePeer::TABLE_NAME . "
|
||||
ON (" . AppAssignSelfServiceValueGroupPeer::ID . " = " . AppAssignSelfServiceValuePeer::ID . ")
|
||||
WHERE " . AppAssignSelfServiceValuePeer::ID . " IS NULL");
|
||||
$cnn->commit();
|
||||
|
||||
// Success message
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
$cnn->rollback();
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("ExecuteCleanSelfServiceTables", "error", "Error when try to clean self-service tables " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,6 +429,17 @@ EOT
|
||||
CLI::taskArg('fontFileName', false);
|
||||
CLI::taskRun('documents_remove_font');
|
||||
|
||||
/**
|
||||
* Add +async option to scheduler commands in table SCHEDULER.
|
||||
*/
|
||||
CLI::taskName('add-async-option-to-scheduler-commands');
|
||||
CLI::taskDescription(<<<EOT
|
||||
Add +async option to scheduler commands in table SCHEDULER.
|
||||
EOT
|
||||
);
|
||||
CLI::taskArg('workspace');
|
||||
CLI::taskRun('add_async_option_to_scheduler_commands');
|
||||
|
||||
/**
|
||||
* Convert Web Entries v1.0 to v2.0 for BPMN processes in order to deprecate the old version.
|
||||
*/
|
||||
@@ -1618,6 +1629,29 @@ function documents_remove_font($args)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add +async option to scheduler commands in table SCHEDULER.
|
||||
* @param array $args
|
||||
* @param string $opts
|
||||
*/
|
||||
function add_async_option_to_scheduler_commands($args, $opts)
|
||||
{
|
||||
if (count($args) === 1) {
|
||||
Bootstrap::setConstantsRelatedWs($args[0]);
|
||||
$workspaceTools = new WorkspaceTools($args[0]);
|
||||
|
||||
CLI::logging("> Adding +async option to scheduler commands...\n");
|
||||
$start = microtime(true);
|
||||
$workspaceTools->addAsyncOptionToSchedulerCommands(true);
|
||||
CLI::logging("<*> Adding +async option to scheduler commands took " . (microtime(true) - $start) . " seconds.\n");
|
||||
} else {
|
||||
$workspaces = get_workspaces_from_args($args);
|
||||
foreach ($workspaces as $workspace) {
|
||||
passthru(PHP_BINARY . ' processmaker add-async-option-to-scheduler-commands ' . $workspace->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Web Entries v1.0 to v2.0 for BPMN processes in order to deprecate the old version.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user