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(); 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"; }