PM-4147 "Problemas con cron" SOLVED

Issue:
    Problemas con cron
Cause:
    Problemas con cron
Solution:
    Se actualizo el codigo de los crones: cron, ldapcron, messageeventcron, timereventcron
    por una version mas actual
This commit is contained in:
Victor Saisa Lopez
2015-11-25 11:54:52 -04:00
parent 3f45e0df02
commit 322f1729ed
8 changed files with 456 additions and 2051 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,167 +1,3 @@
<?php
try {
//Set variables
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
//Defines constants
define("PATH_SEP", ($osIsLinux)? "/" : "\\");
$arrayPathToCron = array();
$flagPathToCron = false;
if (!$flagPathToCron) {
//Path to CRON by __FILE__
$arrayAux = explode(PATH_SEP, str_replace("engine" . PATH_SEP . "bin", "", dirname(__FILE__)));
array_pop($arrayAux);
if (count($arrayAux) > 0 && $arrayAux[count($arrayAux) - 1] == "workflow") {
$arrayPathToCron = $arrayAux;
$flagPathToCron = true;
}
}
if (!$flagPathToCron) {
throw new Exception("Error: Unable to execute the LDAP Advanced CRON, the path is incorrect");
}
$pathHome = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
array_pop($arrayPathToCron);
$pathTrunk = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
array_pop($arrayPathToCron);
$pathOutTrunk = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
define("PATH_HOME", $pathHome);
define("PATH_TRUNK", $pathTrunk);
define("PATH_OUTTRUNK", $pathOutTrunk);
//Check deprecated files
$fileBinDeprecated = PATH_HOME . "engine" . PATH_SEP . "bin" . PATH_SEP . "plugins" . PATH_SEP . "ldapadvanced.php";
if (file_exists($fileBinDeprecated)) {
@unlink($fileBinDeprecated);
if (file_exists($fileBinDeprecated)) {
throw new Exception("Error: LDAP Advanced CRON requires that the \"$fileBinDeprecated\" file has been deleted.");
}
}
//Include files
require_once(PATH_HOME . "engine" . PATH_SEP . "config" . PATH_SEP . "paths.php");
G::LoadClass("system");
$config = System::getSystemConfiguration();
ini_set("date.timezone", $config["time_zone"]);
//CRON command options
$arrayCommandOption = array(
"force" => "+force",
"debug" => "+debug"
);
//CRON status
$flagIsRunning = false;
$lastExecution = "";
$processcTimeProcess = 0;
$processcTimeStart = 0;
$force = in_array($arrayCommandOption["force"], $argv);
$debug = in_array($arrayCommandOption["debug"], $argv);
if (!$force && file_exists(PATH_DATA . "ldapcron")) {
//Windows flag
//Get data of CRON file
$arrayCron = unserialize(trim(file_get_contents(PATH_DATA . "ldapcron")));
$flagIsRunning = (boolean)($arrayCron["flagIsRunning"]);
$lastExecution = $arrayCron["lastExecution"];
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? (int)($arrayCron["processcTimeProcess"]) : 10; //Minutes
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
}
if (!$force && $osIsLinux) {
//Linux flag
//Check if CRON it's running
exec("ps -fea | grep ldapcron.php | grep -v grep", $arrayOutput);
//This validation is when the CRON is called from a symlink
$count = 0;
foreach ($arrayOutput as $value) {
if (preg_match("/^.*ldapcron\.php.*$/", $value)) {
$count++;
}
}
if ($count > 1) {
$flagIsRunning = true;
}
}
if ($force || !$flagIsRunning) {
//Start CRON
$arrayCron = array("flagIsRunning" => "1", "lastExecution" => date("Y-m-d H:i:s"));
file_put_contents(PATH_DATA . "ldapcron", serialize($arrayCron));
try {
$ldapCronSinglePath = PATH_HOME . "engine" . PATH_SEP . "bin" . PATH_SEP . "ldapcron_single.php";
$workspace = "";
for ($i = 1; $i <= count($argv) - 1; $i++) {
if (preg_match("/^\+w(.+)$/", $argv[$i], $arrayMatch)) {
$workspace = $arrayMatch[1];
break;
}
}
$countw = 0;
if ($workspace == "") {
$d = dir(PATH_DB);
while (($entry = $d->read()) !== false) {
if ($entry != "" && $entry != "." && $entry != "..") {
if (is_dir(PATH_DB . $entry)) {
if (file_exists(PATH_DB . $entry . PATH_SEP . "db.php")) {
$countw++;
passthru("php -f \"$ldapCronSinglePath\" " . (($debug)? 1 : 0) . " $entry \"" . base64_encode(PATH_HOME) . "\" \"" . base64_encode(PATH_TRUNK) . "\" \"" . base64_encode(PATH_OUTTRUNK) . "\"");
}
}
}
}
} else {
if (!is_dir(PATH_DB . $workspace) || !file_exists(PATH_DB . $workspace . PATH_SEP . "db.php")) {
throw new Exception("Error: The workspace \"$workspace\" does not exist");
}
$countw++;
passthru("php -f \"$ldapCronSinglePath\" " . (($debug)? 1 : 0) . " $workspace \"" . base64_encode(PATH_HOME) . "\" \"" . base64_encode(PATH_TRUNK) . "\" \"" . base64_encode(PATH_OUTTRUNK) . "\"");
}
eprintln("Finished $countw workspaces processed");
} catch (Exception $e) {
throw $e;
}
//End CRON
$arrayCron = array("flagIsRunning" => "0", "lastExecution" => date("Y-m-d H:i:s"));
file_put_contents(PATH_DATA . "ldapcron", serialize($arrayCron));
} else {
eprintln("The LDAP Advanced CRON is running, please wait for it to finish\nStarted in $lastExecution");
eprintln("If do you want force the execution use the option \"" . $arrayCommandOption["force"] . "\", example: php -f ldapcron.php +wworkflow " . $arrayCommandOption["force"] ,"green");
}
echo "Done!\n";
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
require_once("cron.php");

File diff suppressed because it is too large Load Diff

View File

@@ -1,147 +1,3 @@
<?php
try {
//Set variables
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
//Defines constants
define("PATH_SEP", ($osIsLinux)? "/" : "\\");
$arrayPathToCron = array();
$flagPathToCron = false;
//Path to CRON by __FILE__
$arrayAux = explode(PATH_SEP, str_replace("engine" . PATH_SEP . "bin", "", dirname(__FILE__)));
array_pop($arrayAux);
if (count($arrayAux) > 0 && $arrayAux[count($arrayAux) - 1] == "workflow") {
$arrayPathToCron = $arrayAux;
$flagPathToCron = true;
}
if (!$flagPathToCron) {
throw new Exception("Error: Unable to execute the Message-Event CRON, the path is incorrect");
}
$pathHome = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
array_pop($arrayPathToCron);
$pathTrunk = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
array_pop($arrayPathToCron);
$pathOutTrunk = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
define("PATH_HOME", $pathHome);
define("PATH_TRUNK", $pathTrunk);
define("PATH_OUTTRUNK", $pathOutTrunk);
//Include files
require_once(PATH_HOME . "engine" . PATH_SEP . "config" . PATH_SEP . "paths.php");
G::LoadClass("system");
$config = System::getSystemConfiguration();
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$config['time_zone'] = $filter->validateInput($config['time_zone']);
ini_set("date.timezone", $config["time_zone"]);
//CRON command options
$arrayCommandOption = array(
"force" => "+force"
);
//CRON status
$flagIsRunning = false;
$lastExecution = "";
$processcTimeProcess = 0;
$processcTimeStart = 0;
$force = in_array($arrayCommandOption["force"], $argv);
if (!$force && file_exists(PATH_DATA . "messageeventcron")) {
//Windows flag
//Get data of CRON file
$arrayCron = unserialize(trim(file_get_contents(PATH_DATA . "messageeventcron")));
$flagIsRunning = (boolean)($arrayCron["flagIsRunning"]);
$lastExecution = $arrayCron["lastExecution"];
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? (int)($arrayCron["processcTimeProcess"]) : 10; //Minutes
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
}
if (!$force && $osIsLinux) {
//Linux flag
//Check if CRON it's running
exec("ps -fea | grep messageeventcron.php | grep -v grep", $arrayOutput);
if (count($arrayOutput) > 1) {
$flagIsRunning = true;
}
}
if ($force || !$flagIsRunning) {
//Start CRON
$arrayCron = array("flagIsRunning" => "1", "lastExecution" => date("Y-m-d H:i:s"));
file_put_contents(PATH_DATA . "messageeventcron", serialize($arrayCron));
try {
$messageEventCronSinglePath = PATH_CORE . "bin" . PATH_SEP . "messageeventcron_single.php";
$workspace = "";
for ($i = 1; $i <= count($argv) - 1; $i++) {
if (preg_match("/^\+w(.+)$/", $argv[$i], $arrayMatch)) {
$workspace = $arrayMatch[1];
break;
}
}
$countw = 0;
if ($workspace == "") {
$d = dir(PATH_DB);
while (($entry = $d->read()) !== false) {
if ($entry != "" && $entry != "." && $entry != "..") {
if (is_dir(PATH_DB . $entry)) {
if (file_exists(PATH_DB . $entry . PATH_SEP . "db.php")) {
$countw++;
passthru("php -f \"$messageEventCronSinglePath\" $entry \"" . base64_encode(PATH_HOME) . "\" \"" . base64_encode(PATH_TRUNK) . "\" \"" . base64_encode(PATH_OUTTRUNK) . "\"");
}
}
}
}
} else {
if (!is_dir(PATH_DB . $workspace) || !file_exists(PATH_DB . $workspace . PATH_SEP . "db.php")) {
throw new Exception("Error: The workspace \"$workspace\" does not exist");
}
$countw++;
passthru("php -f \"$messageEventCronSinglePath\" $workspace \"" . base64_encode(PATH_HOME) . "\" \"" . base64_encode(PATH_TRUNK) . "\" \"" . base64_encode(PATH_OUTTRUNK) . "\"");
}
eprintln("Finished $countw workspaces processed");
} catch (Exception $e) {
throw $e;
}
//End CRON
$arrayCron = array("flagIsRunning" => "0", "lastExecution" => date("Y-m-d H:i:s"));
file_put_contents(PATH_DATA . "messageeventcron", serialize($arrayCron));
} else {
eprintln("The Message-Event CRON is running, please wait for it to finish\nStarted in $lastExecution");
eprintln("If do you want force the execution use the option \"" . $arrayCommandOption["force"] . "\", example: php -f messageeventcron.php +wworkflow " . $arrayCommandOption["force"] ,"green");
}
echo "Done!\n";
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
require_once("cron.php");

View File

@@ -1,243 +0,0 @@
<?php
register_shutdown_function(
create_function(
"",
"
if (class_exists(\"Propel\")) {
Propel::close();
}
"
)
);
ini_set("memory_limit", "512M");
try {
//Verify data
if (count($argv) != 5) {
throw new Exception("Error: Invalid number of arguments");
}
for ($i = 2; $i <= count($argv) - 1; $i++) {
$argv[$i] = base64_decode($argv[$i]);
if (!is_dir($argv[$i])) {
throw new Exception("Error: The path \"" . $argv[$i] . "\" is invalid");
}
}
//Set variables
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
$pathHome = $argv[2];
$pathTrunk = $argv[3];
$pathOutTrunk = $argv[4];
//Defines constants
define("PATH_SEP", ($osIsLinux)? "/" : "\\");
define("PATH_HOME", $pathHome);
define("PATH_TRUNK", $pathTrunk);
define("PATH_OUTTRUNK", $pathOutTrunk);
define("PATH_CLASSES", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP);
define("SYS_LANG", "en");
require_once(PATH_HOME . "engine" . PATH_SEP . "config" . PATH_SEP . "paths.php");
require_once(PATH_TRUNK . "framework" . PATH_SEP . "src" . PATH_SEP . "Maveriks" . PATH_SEP . "Util" . PATH_SEP . "ClassLoader.php");
//Class Loader - /ProcessMaker/BusinessModel
$classLoader = \Maveriks\Util\ClassLoader::getInstance();
$classLoader->add(PATH_TRUNK . "framework" . PATH_SEP . "src" . PATH_SEP, "Maveriks");
$classLoader->add(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "src" . PATH_SEP, "ProcessMaker");
$classLoader->add(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "src" . PATH_SEP);
//Add vendors to autoloader
//$classLoader->add(PATH_TRUNK . "vendor" . PATH_SEP . "luracast" . PATH_SEP . "restler" . PATH_SEP . "vendor", "Luracast");
//$classLoader->add(PATH_TRUNK . "vendor" . PATH_SEP . "bshaffer" . PATH_SEP . "oauth2-server-php" . PATH_SEP . "src" . PATH_SEP, "OAuth2");
$classLoader->addClass("Bootstrap", PATH_TRUNK . "gulliver" . PATH_SEP . "system" . PATH_SEP . "class.bootstrap.php");
$classLoader->addModelClassPath(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP);
//Load classes
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");
$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;
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$config['debug'] = $filter->validateInput($config['debug']);
$config['wsdl_cache'] = $filter->validateInput($config['wsdl_cache'],'int');
$config['time_zone'] = $filter->validateInput($config['time_zone']);
//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"]);
//require_once(PATH_GULLIVER . PATH_SEP . "class.bootstrap.php");
//define("PATH_GULLIVER_HOME", PATH_TRUNK . "gulliver" . PATH_SEP);
spl_autoload_register(array("Bootstrap", "autoloadClass"));
//DATABASE propel classes used in "Cases" Options
Bootstrap::registerClass("PMLicensedFeatures", PATH_CLASSES . "class.licensedFeatures.php");
Bootstrap::registerClass("calendar", PATH_CLASSES . "class.calendar.php");
Bootstrap::registerClass("wsResponse", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.wsResponse.php");
G::LoadClass("processes");
G::LoadClass("derivation");
G::LoadClass("dates"); //Load Criteria
//Workflow
$workflow = $argv[1];
if (is_dir(PATH_DB . $workflow) && file_exists(PATH_DB . $workflow . PATH_SEP . "db.php")) {
define("SYS_SYS", $workflow);
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");
}
//DB
$phpCode = "";
$fileDb = fopen(PATH_DB . $workflow . PATH_SEP . "db.php", "r");
if ($fileDb) {
while (!feof($fileDb)) {
$buffer = fgets($fileDb, 4096); //Read a line
$phpCode .= preg_replace("/define\s*\(\s*[\x22\x27](.*)[\x22\x27]\s*,\s*(\x22.*\x22|\x27.*\x27)\s*\)\s*;/i", "\$$1 = $2;", $buffer);
}
fclose($fileDb);
}
$phpCode = str_replace(array("<?php", "<?", "?>"), array("", "", ""), $phpCode);
eval($phpCode);
$dsn = $DB_ADAPTER . "://" . $DB_USER . ":" . $DB_PASS . "@" . $DB_HOST . "/" . $DB_NAME;
$dsnRbac = $DB_ADAPTER . "://" . $DB_RBAC_USER . ":" . $DB_RBAC_PASS . "@" . $DB_RBAC_HOST . "/" . $DB_RBAC_NAME;
$dsnRp = $DB_ADAPTER . "://" . $DB_REPORT_USER . ":" . $DB_REPORT_PASS . "@" . $DB_REPORT_HOST . "/" . $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 = array();
$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" . PATH_SEP . "_databases_.php", "w");
fwrite($oFile, "<?php global \$pro; return \$pro; ?>");
fclose($oFile);
Propel::init(PATH_CORE . "config" . PATH_SEP . "_databases_.php");
//Creole::registerDriver("dbarray", "creole.contrib.DBArrayConnection");
//Enable RBAC
Bootstrap::LoadSystem("rbac");
$rbac = &RBAC::getSingleton(PATH_DATA, session_id());
$rbac->sSystem = "PROCESSMAKER";
if (!defined("DB_ADAPTER")) {
define("DB_ADAPTER", $DB_ADAPTER);
}
eprintln("Processing workspace: " . $workflow, "green");
try {
$messageApplication = new \ProcessMaker\BusinessModel\MessageApplication();
$messageApplication->catchMessageEvent(true);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
eprintln("Problem in workspace: " . $workflow . " it was omitted.", "red");
}
eprintln();
}
if (file_exists(PATH_CORE . "config" . PATH_SEP . "_databases_.php")) {
unlink(PATH_CORE . "config" . PATH_SEP . "_databases_.php");
}
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}

View File

@@ -1,147 +1,3 @@
<?php
try {
//Set variables
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
//Defines constants
define("PATH_SEP", ($osIsLinux)? "/" : "\\");
$arrayPathToCron = array();
$flagPathToCron = false;
//Path to CRON by __FILE__
$arrayAux = explode(PATH_SEP, str_replace("engine" . PATH_SEP . "bin", "", dirname(__FILE__)));
array_pop($arrayAux);
if (count($arrayAux) > 0 && $arrayAux[count($arrayAux) - 1] == "workflow") {
$arrayPathToCron = $arrayAux;
$flagPathToCron = true;
}
if (!$flagPathToCron) {
throw new Exception("Error: Unable to execute the Timer-Event CRON, the path is incorrect");
}
$pathHome = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
array_pop($arrayPathToCron);
$pathTrunk = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
array_pop($arrayPathToCron);
$pathOutTrunk = implode(PATH_SEP, $arrayPathToCron) . PATH_SEP;
define("PATH_HOME", $pathHome);
define("PATH_TRUNK", $pathTrunk);
define("PATH_OUTTRUNK", $pathOutTrunk);
//Include files
require_once(PATH_HOME . "engine" . PATH_SEP . "config" . PATH_SEP . "paths.php");
G::LoadClass("system");
$config = System::getSystemConfiguration();
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$config['time_zone'] = $filter->validateInput($config['time_zone']);
ini_set("date.timezone", $config["time_zone"]);
//CRON command options
$arrayCommandOption = array(
"force" => "+force"
);
//CRON status
$flagIsRunning = false;
$lastExecution = "";
$processcTimeProcess = 0;
$processcTimeStart = 0;
$force = in_array($arrayCommandOption["force"], $argv);
if (!$force && file_exists(PATH_DATA . "timereventcron")) {
//Windows flag
//Get data of CRON file
$arrayCron = unserialize(trim(file_get_contents(PATH_DATA . "timereventcron")));
$flagIsRunning = (boolean)($arrayCron["flagIsRunning"]);
$lastExecution = $arrayCron["lastExecution"];
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? (int)($arrayCron["processcTimeProcess"]) : 10; //Minutes
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
}
if (!$force && $osIsLinux) {
//Linux flag
//Check if CRON it's running
exec("ps -fea | grep timereventcron.php | grep -v grep", $arrayOutput);
if (count($arrayOutput) > 1) {
$flagIsRunning = true;
}
}
if ($force || !$flagIsRunning) {
//Start CRON
$arrayCron = array("flagIsRunning" => "1", "lastExecution" => date("Y-m-d H:i:s"));
file_put_contents(PATH_DATA . "timereventcron", serialize($arrayCron));
try {
$messageEventCronSinglePath = PATH_CORE . "bin" . PATH_SEP . "timereventcron_single.php";
$workspace = "";
for ($i = 1; $i <= count($argv) - 1; $i++) {
if (preg_match("/^\+w(.+)$/", $argv[$i], $arrayMatch)) {
$workspace = $arrayMatch[1];
break;
}
}
$countw = 0;
if ($workspace == "") {
$d = dir(PATH_DB);
while (($entry = $d->read()) !== false) {
if ($entry != "" && $entry != "." && $entry != "..") {
if (is_dir(PATH_DB . $entry)) {
if (file_exists(PATH_DB . $entry . PATH_SEP . "db.php")) {
$countw++;
passthru("php -f \"$messageEventCronSinglePath\" $entry \"" . base64_encode(PATH_HOME) . "\" \"" . base64_encode(PATH_TRUNK) . "\" \"" . base64_encode(PATH_OUTTRUNK) . "\"");
}
}
}
}
} else {
if (!is_dir(PATH_DB . $workspace) || !file_exists(PATH_DB . $workspace . PATH_SEP . "db.php")) {
throw new Exception("Error: The workspace \"$workspace\" does not exist");
}
$countw++;
passthru("php -f \"$messageEventCronSinglePath\" $workspace \"" . base64_encode(PATH_HOME) . "\" \"" . base64_encode(PATH_TRUNK) . "\" \"" . base64_encode(PATH_OUTTRUNK) . "\"");
}
eprintln("Finished $countw workspaces processed");
} catch (Exception $e) {
throw $e;
}
//End CRON
$arrayCron = array("flagIsRunning" => "0", "lastExecution" => date("Y-m-d H:i:s"));
file_put_contents(PATH_DATA . "timereventcron", serialize($arrayCron));
} else {
eprintln("The Timer-Event CRON is running, please wait for it to finish\nStarted in $lastExecution");
eprintln("If do you want force the execution use the option \"" . $arrayCommandOption["force"] . "\", example: php -f timereventcron.php +wworkflow " . $arrayCommandOption["force"] ,"green");
}
echo "Done!\n";
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
require_once("cron.php");

View File

@@ -1,244 +0,0 @@
<?php
register_shutdown_function(
create_function(
"",
"
if (class_exists(\"Propel\")) {
Propel::close();
}
"
)
);
ini_set("memory_limit", "512M");
try {
//Verify data
if (count($argv) != 5) {
throw new Exception("Error: Invalid number of arguments");
}
for ($i = 2; $i <= count($argv) - 1; $i++) {
$argv[$i] = base64_decode($argv[$i]);
if (!is_dir($argv[$i])) {
throw new Exception("Error: The path \"" . $argv[$i] . "\" is invalid");
}
}
//Set variables
$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN";
$pathHome = $argv[2];
$pathTrunk = $argv[3];
$pathOutTrunk = $argv[4];
//Defines constants
define("PATH_SEP", ($osIsLinux)? "/" : "\\");
define("PATH_HOME", $pathHome);
define("PATH_TRUNK", $pathTrunk);
define("PATH_OUTTRUNK", $pathOutTrunk);
define("PATH_CLASSES", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP);
define("SYS_LANG", "en");
require_once(PATH_HOME . "engine" . PATH_SEP . "config" . PATH_SEP . "paths.php");
require_once(PATH_TRUNK . "framework" . PATH_SEP . "src" . PATH_SEP . "Maveriks" . PATH_SEP . "Util" . PATH_SEP . "ClassLoader.php");
//Class Loader - /ProcessMaker/BusinessModel
$classLoader = \Maveriks\Util\ClassLoader::getInstance();
$classLoader->add(PATH_TRUNK . "framework" . PATH_SEP . "src" . PATH_SEP, "Maveriks");
$classLoader->add(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "src" . PATH_SEP, "ProcessMaker");
$classLoader->add(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "src" . PATH_SEP);
//Add vendors to autoloader
//$classLoader->add(PATH_TRUNK . "vendor" . PATH_SEP . "luracast" . PATH_SEP . "restler" . PATH_SEP . "vendor", "Luracast");
//$classLoader->add(PATH_TRUNK . "vendor" . PATH_SEP . "bshaffer" . PATH_SEP . "oauth2-server-php" . PATH_SEP . "src" . PATH_SEP, "OAuth2");
$classLoader->addClass("Bootstrap", PATH_TRUNK . "gulliver" . PATH_SEP . "system" . PATH_SEP . "class.bootstrap.php");
$classLoader->addModelClassPath(PATH_TRUNK . "workflow" . PATH_SEP . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP);
//Load classes
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");
$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;
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$config['debug'] = $filter->validateInput($config['debug']);
$config['wsdl_cache'] = $filter->validateInput($config['wsdl_cache'],'int');
$config['time_zone'] = $filter->validateInput($config['time_zone']);
//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"]);
//require_once(PATH_GULLIVER . PATH_SEP . "class.bootstrap.php");
//define("PATH_GULLIVER_HOME", PATH_TRUNK . "gulliver" . PATH_SEP);
spl_autoload_register(array("Bootstrap", "autoloadClass"));
//DATABASE propel classes used in "Cases" Options
Bootstrap::registerClass("PMLicensedFeatures", PATH_CLASSES . "class.licensedFeatures.php");
Bootstrap::registerClass("calendar", PATH_CLASSES . "class.calendar.php");
Bootstrap::registerClass("wsResponse", PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.wsResponse.php");
G::LoadClass("processes");
G::LoadClass("derivation");
G::LoadClass("spool");
G::LoadClass("dates"); //Load Criteria
//Workflow
$workflow = $argv[1];
if (is_dir(PATH_DB . $workflow) && file_exists(PATH_DB . $workflow . PATH_SEP . "db.php")) {
define("SYS_SYS", $workflow);
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");
}
//DB
$phpCode = "";
$fileDb = fopen(PATH_DB . $workflow . PATH_SEP . "db.php", "r");
if ($fileDb) {
while (!feof($fileDb)) {
$buffer = fgets($fileDb, 4096); //Read a line
$phpCode .= preg_replace("/define\s*\(\s*[\x22\x27](.*)[\x22\x27]\s*,\s*(\x22.*\x22|\x27.*\x27)\s*\)\s*;/i", "\$$1 = $2;", $buffer);
}
fclose($fileDb);
}
$phpCode = str_replace(array("<?php", "<?", "?>"), array("", "", ""), $phpCode);
eval($phpCode);
$dsn = $DB_ADAPTER . "://" . $DB_USER . ":" . $DB_PASS . "@" . $DB_HOST . "/" . $DB_NAME;
$dsnRbac = $DB_ADAPTER . "://" . $DB_RBAC_USER . ":" . $DB_RBAC_PASS . "@" . $DB_RBAC_HOST . "/" . $DB_RBAC_NAME;
$dsnRp = $DB_ADAPTER . "://" . $DB_REPORT_USER . ":" . $DB_REPORT_PASS . "@" . $DB_REPORT_HOST . "/" . $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 = array();
$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" . PATH_SEP . "_databases_.php", "w");
fwrite($oFile, "<?php global \$pro; return \$pro; ?>");
fclose($oFile);
Propel::init(PATH_CORE . "config" . PATH_SEP . "_databases_.php");
//Creole::registerDriver("dbarray", "creole.contrib.DBArrayConnection");
//Enable RBAC
Bootstrap::LoadSystem("rbac");
$rbac = &RBAC::getSingleton(PATH_DATA, session_id());
$rbac->sSystem = "PROCESSMAKER";
if (!defined("DB_ADAPTER")) {
define("DB_ADAPTER", $DB_ADAPTER);
}
eprintln("Processing workspace: " . $workflow, "green");
try {
$timerEvent = new \ProcessMaker\BusinessModel\TimerEvent();
$timerEvent->startContinueCaseByTimerEvent(date("Y-m-d H:i:s"), true);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
eprintln("Problem in workspace: " . $workflow . " it was omitted.", "red");
}
eprintln();
}
if (file_exists(PATH_CORE . "config" . PATH_SEP . "_databases_.php")) {
unlink(PATH_CORE . "config" . PATH_SEP . "_databases_.php");
}
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}