2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2011-01-28 14:16:58 +00:00
|
|
|
/**
|
|
|
|
|
* cron_single.php
|
|
|
|
|
* @package workflow-engine-bin
|
|
|
|
|
*/
|
2011-01-21 22:11:13 +00:00
|
|
|
ini_set('display_errors', 1);
|
|
|
|
|
error_reporting(E_ALL);
|
2010-12-02 23:34:41 +00:00
|
|
|
ini_set('memory_limit', '128M');
|
|
|
|
|
|
|
|
|
|
if (!defined('SYS_LANG')) {
|
2012-07-03 18:20:20 -04:00
|
|
|
define('SYS_LANG', 'en');
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!defined('PATH_HOME')) {
|
2012-07-03 18:20:20 -04:00
|
|
|
if (!defined('PATH_SEP')) {
|
|
|
|
|
define('PATH_SEP', (substr(PHP_OS, 0, 3) == 'WIN') ? '\\' : '/');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pathServices = 'engine' . PATH_SEP . 'methods' . PATH_SEP . 'services';
|
|
|
|
|
$docuroot = explode(PATH_SEP, str_replace($pathServices, '', dirname(__FILE__)));
|
|
|
|
|
|
|
|
|
|
array_pop($docuroot);
|
|
|
|
|
array_pop($docuroot);
|
|
|
|
|
|
|
|
|
|
$pathHome = implode(PATH_SEP, $docuroot) . PATH_SEP;
|
|
|
|
|
|
|
|
|
|
//try to find automatically the trunk directory where are placed the RBAC and Gulliver directories
|
|
|
|
|
//in a normal installation you don't need to change it.
|
|
|
|
|
|
|
|
|
|
array_pop($docuroot);
|
|
|
|
|
|
|
|
|
|
$pathTrunk = implode(PATH_SEP, $docuroot) . PATH_SEP;
|
|
|
|
|
|
|
|
|
|
array_pop($docuroot);
|
|
|
|
|
|
|
|
|
|
$pathOutTrunk = implode(PATH_SEP, $docuroot) . PATH_SEP;
|
|
|
|
|
|
|
|
|
|
//to do: check previous algorith for Windows $pathTrunk = "c:/home/";
|
|
|
|
|
|
|
|
|
|
define('PATH_HOME', $pathHome);
|
|
|
|
|
define('PATH_TRUNK', $pathTrunk);
|
|
|
|
|
define('PATH_OUTTRUNK', $pathOutTrunk);
|
|
|
|
|
|
|
|
|
|
require_once (PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths.php');
|
|
|
|
|
|
|
|
|
|
G::LoadThirdParty('pear/json','class.json');
|
|
|
|
|
G::LoadThirdParty('smarty/libs','Smarty.class');
|
|
|
|
|
G::LoadSystem('error');
|
|
|
|
|
G::LoadSystem('dbconnection');
|
|
|
|
|
G::LoadSystem('dbsession');
|
|
|
|
|
G::LoadSystem('dbrecordset');
|
|
|
|
|
G::LoadSystem('dbtable');
|
|
|
|
|
G::LoadSystem('rbac' );
|
|
|
|
|
G::LoadSystem('publisher');
|
|
|
|
|
G::LoadSystem('templatePower');
|
|
|
|
|
G::LoadSystem('xmlDocument');
|
|
|
|
|
G::LoadSystem('xmlform');
|
|
|
|
|
G::LoadSystem('xmlformExtension');
|
|
|
|
|
G::LoadSystem('form');
|
|
|
|
|
G::LoadSystem('menu');
|
|
|
|
|
G::LoadSystem("xmlMenu");
|
|
|
|
|
G::LoadSystem('dvEditor');
|
|
|
|
|
G::LoadSystem('table');
|
|
|
|
|
G::LoadSystem('pagedTable');
|
|
|
|
|
G::LoadClass ( 'system' );
|
|
|
|
|
require_once ( "propel/Propel.php" );
|
|
|
|
|
require_once ( "creole/Creole.php" );
|
2012-07-20 13:33:28 -04:00
|
|
|
|
|
|
|
|
$config = 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 = $config['debug'] ? $e_all : $e_all & ~E_NOTICE;
|
|
|
|
|
|
|
|
|
|
// Do not change any of these settings directly, use env.ini instead
|
|
|
|
|
ini_set('display_errors', $config['debug']);
|
|
|
|
|
ini_set('error_reporting', $e_all);
|
|
|
|
|
ini_set('short_open_tag', 'On');
|
|
|
|
|
ini_set('default_charset', "UTF-8");
|
|
|
|
|
ini_set('memory_limit', $config['memory_limit']);
|
|
|
|
|
ini_set('soap.wsdl_cache_enabled', $config['wsdl_cache']);
|
|
|
|
|
ini_set('date.timezone', $config['time_zone']);
|
|
|
|
|
|
|
|
|
|
define ('DEBUG_SQL_LOG', $config['debug_sql']);
|
|
|
|
|
define ('DEBUG_TIME_LOG', $config['debug_time']);
|
|
|
|
|
define ('DEBUG_CALENDAR_LOG', $config['debug_calendar']);
|
|
|
|
|
define ('MEMCACHED_ENABLED', $config['memcached']);
|
|
|
|
|
define ('MEMCACHED_SERVER', $config['memcached_server']);
|
|
|
|
|
define ('TIME_ZONE', $config['time_zone']);
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
require_once ("classes/model/Configuration.php");
|
|
|
|
|
require_once ("classes/model/AppCacheView.php");
|
|
|
|
|
require_once ("classes/model/AppDelegation.php");
|
|
|
|
|
require_once ("classes/model/Event.php");
|
|
|
|
|
require_once ("classes/model/AppEvent.php");
|
|
|
|
|
require_once ("classes/model/CaseScheduler.php");
|
|
|
|
|
//G::loadClass("pmScript");
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
//default values
|
2010-12-02 23:34:41 +00:00
|
|
|
$bCronIsRunning = false;
|
|
|
|
|
$sLastExecution = '';
|
2012-07-03 18:20:20 -04:00
|
|
|
|
|
|
|
|
if (file_exists(PATH_DATA . 'cron')) {
|
|
|
|
|
$arrayAux = unserialize(trim(@file_get_contents(PATH_DATA . 'cron')));
|
|
|
|
|
$bCronIsRunning = (boolean)($arrayAux['bCronIsRunning']);
|
|
|
|
|
$sLastExecution = $arrayAux['sLastExecution'];
|
|
|
|
|
} else {
|
|
|
|
|
//if not exists the file, just create a new one with current date
|
|
|
|
|
$arrayAux = array('bCronIsRunning' => '1', 'sLastExecution' => date('Y-m-d H:i:s'));
|
|
|
|
|
|
|
|
|
|
@file_put_contents(PATH_DATA . 'cron', serialize($arrayAux));
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!defined('SYS_SYS')) {
|
2012-07-03 18:20:20 -04:00
|
|
|
$sObject = $argv[1];
|
|
|
|
|
$sNow = $argv[2];
|
2012-08-20 12:33:18 -04:00
|
|
|
$dateSystem = $argv[3];
|
2012-07-03 18:20:20 -04:00
|
|
|
$sFilter = '';
|
|
|
|
|
|
2012-08-20 12:33:18 -04:00
|
|
|
for ($i = 4; $i <= count($argv) - 1; $i++) {
|
2012-07-03 18:20:20 -04:00
|
|
|
$sFilter .= ' ' . $argv[$i];
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-07-03 18:20:20 -04:00
|
|
|
|
|
|
|
|
$oDirectory = dir(PATH_DB);
|
|
|
|
|
|
|
|
|
|
if (is_dir(PATH_DB . $sObject)) {
|
|
|
|
|
saveLog('main', 'action', "checking folder " . PATH_DB . $sObject);
|
|
|
|
|
|
|
|
|
|
if (file_exists(PATH_DB . $sObject . PATH_SEP . 'db.php')) {
|
|
|
|
|
define('SYS_SYS', $sObject);
|
|
|
|
|
|
|
|
|
|
include_once (PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths_installed.php');
|
|
|
|
|
include_once (PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths.php');
|
|
|
|
|
|
|
|
|
|
//***************** PM Paths DATA **************************
|
|
|
|
|
define('PATH_DATA_SITE', PATH_DATA . 'sites/' . SYS_SYS . '/');
|
|
|
|
|
define('PATH_DOCUMENT', PATH_DATA_SITE . 'files/');
|
|
|
|
|
define('PATH_DATA_MAILTEMPLATES', PATH_DATA_SITE . 'mailTemplates/');
|
|
|
|
|
define('PATH_DATA_PUBLIC', PATH_DATA_SITE . 'public/');
|
|
|
|
|
define('PATH_DATA_REPORTS', PATH_DATA_SITE . 'reports/');
|
|
|
|
|
define('PATH_DYNAFORM', PATH_DATA_SITE . 'xmlForms/');
|
|
|
|
|
define('PATH_IMAGES_ENVIRONMENT_FILES', PATH_DATA_SITE . 'usersFiles' . PATH_SEP);
|
|
|
|
|
define('PATH_IMAGES_ENVIRONMENT_USERS', PATH_DATA_SITE . 'usersPhotographies' . PATH_SEP);
|
|
|
|
|
|
|
|
|
|
if (is_file(PATH_DATA_SITE.PATH_SEP . '.server_info')) {
|
|
|
|
|
$SERVER_INFO = file_get_contents(PATH_DATA_SITE.PATH_SEP.'.server_info');
|
|
|
|
|
$SERVER_INFO = unserialize($SERVER_INFO);
|
|
|
|
|
|
|
|
|
|
define('SERVER_NAME', $SERVER_INFO ['SERVER_NAME']);
|
|
|
|
|
define('SERVER_PORT', $SERVER_INFO ['SERVER_PORT']);
|
|
|
|
|
} else {
|
|
|
|
|
eprintln("WARNING! No server info found!", 'red');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sContent = file_get_contents(PATH_DB . $sObject . PATH_SEP . 'db.php');
|
|
|
|
|
|
|
|
|
|
$sContent = str_replace('<?php', '', $sContent);
|
|
|
|
|
$sContent = str_replace('<?', '', $sContent);
|
|
|
|
|
$sContent = str_replace('?>', '', $sContent);
|
|
|
|
|
$sContent = str_replace('define', '', $sContent);
|
|
|
|
|
$sContent = str_replace("('", "$", $sContent);
|
|
|
|
|
$sContent = str_replace("',", '=', $sContent);
|
|
|
|
|
$sContent = str_replace(");", ';', $sContent);
|
|
|
|
|
|
|
|
|
|
eval($sContent);
|
|
|
|
|
|
|
|
|
|
$dsn = $DB_ADAPTER . '://' . $DB_USER . ':' . $DB_PASS . '@' . $DB_HOST . '/' . $DB_NAME;
|
|
|
|
|
|
|
|
|
|
$dsnRbac = $DB_ADAPTER . '://' . $DB_RBAC_USER . ':' . $DB_RBAC_PASS . '@' . $DB_RBAC_HOST . '/';
|
|
|
|
|
$dsnRbac = $dsnRbac . $DB_RBAC_NAME;
|
|
|
|
|
|
|
|
|
|
$dsnRp = $DB_ADAPTER . '://' . $DB_REPORT_USER . ':' . $DB_REPORT_PASS . '@' . $DB_REPORT_HOST . '/';
|
|
|
|
|
$dsnRp = $dsnRp . $DB_REPORT_NAME;
|
|
|
|
|
|
|
|
|
|
switch ($DB_ADAPTER) {
|
|
|
|
|
case 'mysql':
|
|
|
|
|
$dsn .= '?encoding=utf8';
|
|
|
|
|
$dsnRbac .= '?encoding=utf8';
|
|
|
|
|
break;
|
|
|
|
|
case 'mssql':
|
|
|
|
|
//$dsn .= '?sendStringAsUnicode=false';
|
|
|
|
|
//$dsnRbac .= '?sendStringAsUnicode=false';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pro['datasources']['workflow']['connection'] = $dsn;
|
|
|
|
|
$pro['datasources']['workflow']['adapter'] = $DB_ADAPTER;
|
|
|
|
|
$pro['datasources']['rbac']['connection'] = $dsnRbac;
|
|
|
|
|
$pro['datasources']['rbac']['adapter'] = $DB_ADAPTER;
|
|
|
|
|
$pro['datasources']['rp']['connection'] = $dsnRp;
|
|
|
|
|
$pro['datasources']['rp']['adapter'] = $DB_ADAPTER;
|
|
|
|
|
//$pro['datasources']['dbarray']['connection'] = 'dbarray://user:pass@localhost/pm_os';
|
|
|
|
|
//$pro['datasources']['dbarray']['adapter'] = 'dbarray';
|
|
|
|
|
|
|
|
|
|
$oFile = fopen(PATH_CORE . 'config/_databases_.php', 'w');
|
|
|
|
|
fwrite($oFile, '<?php global $pro;return $pro; ?>');
|
|
|
|
|
fclose($oFile);
|
|
|
|
|
|
|
|
|
|
Propel::init(PATH_CORE . 'config/_databases_.php');
|
|
|
|
|
//Creole::registerDriver('dbarray', 'creole.contrib.DBArrayConnection');
|
|
|
|
|
|
|
|
|
|
eprintln("Processing workspace: " . $sObject, "green");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
processWorkspace();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
echo $e->getMessage();
|
|
|
|
|
|
|
|
|
|
eprintln("Probelm in workspace: " . $sObject . " it was omitted.", "red");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eprintln();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unlink(PATH_CORE . 'config/_databases_.php');
|
|
|
|
|
} else {
|
|
|
|
|
processWorkspace();
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//finally update the file
|
2012-07-03 18:20:20 -04:00
|
|
|
$arrayAux = array('bCronIsRunning' => '0', 'sLastExecution' => date('Y-m-d H:i:s'));
|
|
|
|
|
@file_put_contents(PATH_DATA . 'cron', serialize($arrayAux));
|
|
|
|
|
|
|
|
|
|
function processWorkspace()
|
|
|
|
|
{
|
|
|
|
|
global $sLastExecution;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
resendEmails();
|
|
|
|
|
unpauseApplications();
|
|
|
|
|
calculateDuration();
|
|
|
|
|
executePlugins();
|
|
|
|
|
executeEvents($sLastExecution);
|
|
|
|
|
executeScheduledCases();
|
|
|
|
|
executeUpdateAppTitle();
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
saveLog("main", "error", "Error processing workspace : " . $oError->getMessage() . "\n");
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function resendEmails()
|
|
|
|
|
{
|
|
|
|
|
global $sFilter;
|
2012-08-20 12:33:18 -04:00
|
|
|
global $sNow;
|
|
|
|
|
global $dateSystem;
|
2012-07-03 18:20:20 -04:00
|
|
|
|
2012-08-20 12:33:18 -04:00
|
|
|
if ($sFilter != "" && strpos($sFilter, "emails") === false) {
|
2012-07-03 18:20:20 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionMessage("Resending emails");
|
|
|
|
|
|
|
|
|
|
try {
|
2012-08-20 12:33:18 -04:00
|
|
|
G::LoadClass("spool");
|
|
|
|
|
|
|
|
|
|
$dateResend = $sNow;
|
|
|
|
|
|
|
|
|
|
if ($sNow == $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));
|
|
|
|
|
}
|
2012-07-03 18:20:20 -04:00
|
|
|
|
|
|
|
|
$oSpool = new spoolRun();
|
2012-08-20 12:33:18 -04:00
|
|
|
$oSpool->resendEmails($dateResend);
|
2012-07-03 18:20:20 -04:00
|
|
|
|
2012-08-20 12:33:18 -04:00
|
|
|
saveLog("resendEmails", "action", "Resending Emails", "c");
|
2012-07-03 18:20:20 -04:00
|
|
|
|
|
|
|
|
$aSpoolWarnings = $oSpool->getWarnings();
|
|
|
|
|
|
2012-08-20 12:33:18 -04:00
|
|
|
if ($aSpoolWarnings !== false) {
|
2012-07-03 18:20:20 -04:00
|
|
|
foreach ($aSpoolWarnings as $sWarning) {
|
2012-08-20 12:33:18 -04:00
|
|
|
print("MAIL SPOOL WARNING: " . $sWarning."\n");
|
|
|
|
|
saveLog("resendEmails", "warning", "MAIL SPOOL WARNING: " . $sWarning);
|
2012-07-03 18:20:20 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 12:33:18 -04:00
|
|
|
setExecutionResultMessage("DONE");
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
setExecutionResultMessage("WITH ERRORS", "error");
|
|
|
|
|
eprintln(" '-" . $e->getMessage(), "red");
|
|
|
|
|
saveLog("resendEmails", "error", "Error Resending Emails: " . $e->getMessage());
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function unpauseApplications()
|
|
|
|
|
{
|
|
|
|
|
global $sFilter;
|
|
|
|
|
global $sNow;
|
|
|
|
|
|
|
|
|
|
if ($sFilter != '' && strpos($sFilter, 'unpause') === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionMessage("Unpausing applications");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
G::LoadClass('case');
|
|
|
|
|
|
|
|
|
|
$oCases = new Cases();
|
|
|
|
|
$oCases->ThrowUnpauseDaemon($sNow);
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function executePlugins()
|
|
|
|
|
{
|
|
|
|
|
global $sFilter;
|
|
|
|
|
|
|
|
|
|
if ($sFilter!='' && strpos($sFilter, 'plugins') === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pathCronPlugins = PATH_CORE.'bin'.PATH_SEP.'plugins'.PATH_SEP;
|
|
|
|
|
|
|
|
|
|
//erik: verify if the plugin dir exists
|
|
|
|
|
if (!is_dir($pathCronPlugins)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($handle = opendir($pathCronPlugins)) {
|
|
|
|
|
while (false !== ($file = readdir($handle))) {
|
|
|
|
|
if (strpos($file, '.php',1) && is_file($pathCronPlugins . $file)) {
|
|
|
|
|
$filename = str_replace('.php' , '', $file);
|
|
|
|
|
$className = $filename . 'ClassCron';
|
|
|
|
|
|
|
|
|
|
include_once ( $pathCronPlugins . $file ); //$filename. ".php"
|
|
|
|
|
|
|
|
|
|
$oPlugin = new $className();
|
|
|
|
|
|
|
|
|
|
if (method_exists($oPlugin, 'executeCron')) {
|
|
|
|
|
$oPlugin->executeCron();
|
|
|
|
|
setExecutionMessage("Executing Plugins");
|
|
|
|
|
setExecutionResultMessage('DONE');
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-26 15:39:08 -04:00
|
|
|
}
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function calculateDuration()
|
|
|
|
|
{
|
|
|
|
|
global $sFilter;
|
|
|
|
|
|
|
|
|
|
if ($sFilter != '' && strpos($sFilter, 'calculate') === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionMessage("Calculating Duration");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$oAppDelegation = new AppDelegation();
|
|
|
|
|
$oAppDelegation->calculateDuration();
|
|
|
|
|
|
|
|
|
|
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());
|
2012-06-25 12:37:06 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function executeEvents($sLastExecution, $sNow=null)
|
|
|
|
|
{
|
2010-12-02 23:34:41 +00:00
|
|
|
global $sFilter;
|
|
|
|
|
global $sNow;
|
2012-06-25 12:37:06 -04:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
$log = array();
|
|
|
|
|
|
|
|
|
|
if ($sFilter != '' && strpos($sFilter, 'events') === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionMessage("Executing events");
|
2010-12-02 23:34:41 +00:00
|
|
|
setExecutionResultMessage('PROCESSING');
|
2012-07-03 18:20:20 -04:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$oAppEvent = new AppEvent();
|
|
|
|
|
saveLog('executeEvents', 'action', "Executing Events $sLastExecution, $sNow ");
|
|
|
|
|
$n = $oAppEvent->executeEvents($sNow, false, $log);
|
|
|
|
|
|
|
|
|
|
foreach ($log as $value) {
|
|
|
|
|
saveLog('executeEvents', 'action', "Execute Events : $value, $sNow ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionMessage("|- End Execution events");
|
|
|
|
|
setExecutionResultMessage("Processed $n");
|
|
|
|
|
//saveLog('executeEvents', 'action', $res );
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
setExecutionResultMessage('WITH ERRORS', 'error');
|
|
|
|
|
eprintln(" '-".$oError->getMessage(), 'red');
|
|
|
|
|
saveLog('calculateAlertsDueDate', 'Error', 'Error Executing Events: ' . $oError->getMessage());
|
2012-06-21 18:29:13 -04:00
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function executeScheduledCases($sNow=null)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
global $sFilter;
|
|
|
|
|
global $sNow;
|
|
|
|
|
|
|
|
|
|
$log = array();
|
|
|
|
|
|
|
|
|
|
if ($sFilter != '' && strpos($sFilter, 'scheduler') === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionMessage("Executing the scheduled starting cases");
|
|
|
|
|
setExecutionResultMessage('PROCESSING');
|
|
|
|
|
|
|
|
|
|
$sNow = isset($sNow)? $sNow : date('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
|
|
$oCaseScheduler = new CaseScheduler();
|
|
|
|
|
$oCaseScheduler->caseSchedulerCron($sNow, $log);
|
|
|
|
|
|
|
|
|
|
foreach ($log as $value) {
|
|
|
|
|
saveLog('executeScheduledCases', 'action', "OK Case# $value");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionResultMessage('DONE');
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
setExecutionResultMessage('WITH ERRORS', 'error');
|
|
|
|
|
eprintln(" '-".$oError->getMessage(), 'red');
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function executeUpdateAppTitle()
|
|
|
|
|
{
|
2012-08-20 12:33:18 -04:00
|
|
|
global $sFilter;
|
|
|
|
|
|
|
|
|
|
if ($sFilter != "" && strpos($sFilter, "update-case-labels") === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
try {
|
|
|
|
|
$criteriaConf = new Criteria("workflow");
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
$criteriaConf->addSelectColumn(ConfigurationPeer::OBJ_UID);
|
|
|
|
|
$criteriaConf->addSelectColumn(ConfigurationPeer::CFG_VALUE);
|
|
|
|
|
$criteriaConf->add(ConfigurationPeer::CFG_UID, "TAS_APP_TITLE_UPDATE");
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
$rsCriteriaConf = ConfigurationPeer::doSelectRS($criteriaConf);
|
|
|
|
|
$rsCriteriaConf->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
setExecutionMessage("Update case labels");
|
|
|
|
|
saveLog("updateCaseLabels", "action", "Update case labels", "c");
|
|
|
|
|
|
|
|
|
|
while ($rsCriteriaConf->next()) {
|
|
|
|
|
$row = $rsCriteriaConf->getRow();
|
|
|
|
|
|
|
|
|
|
$taskUid = $row["OBJ_UID"];
|
|
|
|
|
$lang = $row["CFG_VALUE"];
|
|
|
|
|
|
|
|
|
|
//Update case labels
|
|
|
|
|
$appcv = new AppCacheView();
|
|
|
|
|
$appcv->appTitleByTaskCaseLabelUpdate($taskUid, $lang);
|
|
|
|
|
|
|
|
|
|
//Delete record
|
|
|
|
|
$criteria = new Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->add(ConfigurationPeer::CFG_UID, "TAS_APP_TITLE_UPDATE");
|
|
|
|
|
$criteria->add(ConfigurationPeer::OBJ_UID, $taskUid);
|
|
|
|
|
$criteria->add(ConfigurationPeer::CFG_VALUE, $lang);
|
|
|
|
|
|
|
|
|
|
$numRowDeleted = ConfigurationPeer::doDelete($criteria);
|
|
|
|
|
|
|
|
|
|
saveLog("updateCaseLabels", "action", "OK Task $taskUid");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExecutionResultMessage("DONE");
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
setExecutionResultMessage("WITH ERRORS", "error");
|
|
|
|
|
eprintln(" '-" . $e->getMessage(), "red");
|
|
|
|
|
saveLog("updateCaseLabels", "error", "Error updating case labels: " . $e->getMessage());
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function saveLog($sSource, $sType, $sDescription)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
global $isDebug;
|
|
|
|
|
|
|
|
|
|
if ($isDebug) {
|
|
|
|
|
print date('H:i:s') ." ($sSource) $sType $sDescription <br />\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@fwrite($oFile, date('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n");
|
|
|
|
|
|
|
|
|
|
G::verifyPath(PATH_DATA . 'log' . PATH_SEP, true);
|
|
|
|
|
|
2012-08-16 17:55:46 -04:00
|
|
|
//setExecutionMessage( PATH_DATA."log".PATH_SEP);
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
if ($sType == 'action') {
|
|
|
|
|
$oFile = @fopen(PATH_DATA . 'log' . PATH_SEP . 'cron.log', 'a+');
|
|
|
|
|
} else {
|
|
|
|
|
$oFile = @fopen(PATH_DATA . 'log' . PATH_SEP . 'cronError.log', 'a+');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@fwrite($oFile, date('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n");
|
|
|
|
|
@fclose($oFile);
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
//CONTINUE
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
function setExecutionMessage($m)
|
|
|
|
|
{
|
|
|
|
|
$len = strlen($m);
|
|
|
|
|
$linesize = 60;
|
|
|
|
|
$rOffset = $linesize - $len;
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
eprint("* $m");
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
for ($i = 0; $i < $rOffset; $i++) {
|
|
|
|
|
eprint('.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setExecutionResultMessage($m, $t='')
|
|
|
|
|
{
|
|
|
|
|
$c = 'green';
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
if ($t == 'error') {
|
|
|
|
|
$c = 'red';
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
if ($t == 'info') {
|
|
|
|
|
$c = 'yellow';
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
2012-07-03 18:20:20 -04:00
|
|
|
eprintln("[$m]", $c);
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|