BUG 9709 "Add a new option in ADMIN -> Logs for the cron" SOLVED
- New feature - Add a new option in ADMIN -> Logs for the cron - Added new feature * Available from version 2.0.44
This commit is contained in:
90
workflow/engine/methods/setup/cron.php
Normal file
90
workflow/engine/methods/setup/cron.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
G::LoadClass("system");
|
||||
G::LoadClass("wsTools");
|
||||
G::LoadClass("configuration");
|
||||
|
||||
global $RBAC;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ($RBAC->userCanAccess("PM_SETUP_ADVANCE") != 1) {
|
||||
G::SendTemporalMessage("ID_USER_HAVENT_RIGHTS_PAGE", "error", "labels");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//Cron status
|
||||
$bCronIsRunning = false;
|
||||
$sLastExecution = null;
|
||||
$processcTimeProcess = 0;
|
||||
$processcTimeStart = 0;
|
||||
|
||||
if (file_exists(PATH_DATA . "cron")) {
|
||||
$arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
|
||||
$bCronIsRunning = (boolean)($arrayCron["bCronIsRunning"]);
|
||||
$sLastExecution = $arrayCron["sLastExecution"];
|
||||
$processcTimeProcess = (isset($arrayCron["processcTimeProcess"]))? intval($arrayCron["processcTimeProcess"]) : 10;
|
||||
$processcTimeStart = (isset($arrayCron["processcTimeStart"]))? $arrayCron["processcTimeStart"] : 0;
|
||||
}
|
||||
|
||||
if ($bCronIsRunning && $processcTimeStart != 0) {
|
||||
if ((time() - $processcTimeStart) > ($processcTimeProcess * 60)) {
|
||||
//Cron finished his execution for some reason
|
||||
$bCronIsRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Data
|
||||
$c = new Configurations();
|
||||
$configPage = $c->getConfiguration("cronList", "pageSize", null, $_SESSION["USER_LOGGED"]);
|
||||
|
||||
$config = array();
|
||||
$config["pageSize"] = (isset($configPage["pageSize"]))? $configPage["pageSize"] : 20;
|
||||
|
||||
$cronInfo = array();
|
||||
$fileLog = PATH_DATA . "log" . PATH_SEP . "cron.log";
|
||||
$fileLogSize = (file_exists($fileLog))? number_format(filesize($fileLog) * (1 / 1024) * (1 / 1024), 4, ".", "") : 0;
|
||||
|
||||
$cronInfo["status"] = G::LoadTranslation((($bCronIsRunning)? "ID_CRON_STATUS_ACTIVE" : "ID_CRON_STATUS_INACTIVE"));
|
||||
$cronInfo["lastExecution"] = (!empty($sLastExecution))? $sLastExecution : "";
|
||||
$cronInfo["fileLogName"] = "cron.log";
|
||||
$cronInfo["fileLogSize"] = $fileLogSize;
|
||||
$cronInfo["fileLogPath"] = $fileLog;
|
||||
|
||||
|
||||
//Workspaces
|
||||
$workspaces = System::listWorkspaces();
|
||||
$arrayAux = array();
|
||||
|
||||
foreach ($workspaces as $index => $workspace) {
|
||||
$arrayAux[] = $workspace->name;
|
||||
}
|
||||
|
||||
sort($arrayAux);
|
||||
|
||||
$arrayWorkspace = array();
|
||||
|
||||
foreach ($arrayAux as $index => $value) {
|
||||
$arrayWorkspace[] = array($value, $value);
|
||||
}
|
||||
|
||||
array_unshift($arrayWorkspace, array("ALL", G::LoadTranslation("ID_ALL_WORKSPACES")));
|
||||
|
||||
//Status
|
||||
$arrayStatus = array(
|
||||
array("ALL", G::LoadTranslation("ID_ALL")),
|
||||
array("COMPLETED", G::LoadTranslation("COMPLETED")),
|
||||
array("FAILED", G::LoadTranslation("ID_FAILED"))
|
||||
);
|
||||
|
||||
$oHeadPublisher = &headPublisher::getSingleton();
|
||||
$oHeadPublisher->addContent("setup/cron"); //Adding a html file .html
|
||||
$oHeadPublisher->addExtJsScript("setup/cron", false); //Adding a javascript file .js
|
||||
$oHeadPublisher->assign("CONFIG", $config);
|
||||
$oHeadPublisher->assign("CRON", $cronInfo);
|
||||
$oHeadPublisher->assign("WORKSPACE", $arrayWorkspace);
|
||||
$oHeadPublisher->assign("STATUS", $arrayStatus);
|
||||
|
||||
G::RenderPage("publish", "extJs");
|
||||
|
||||
215
workflow/engine/methods/setup/cronAjax.php
Normal file
215
workflow/engine/methods/setup/cronAjax.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
function mktimeDate($date)
|
||||
{
|
||||
$arrayAux = getdate(strtotime($date));
|
||||
|
||||
$mktDate = mktime(
|
||||
$arrayAux["hours"],
|
||||
$arrayAux["minutes"],
|
||||
$arrayAux["seconds"],
|
||||
$arrayAux["mon"],
|
||||
$arrayAux["mday"],
|
||||
$arrayAux["year"]
|
||||
);
|
||||
|
||||
return $mktDate;
|
||||
}
|
||||
|
||||
function cronArraySet($str, $filter)
|
||||
{
|
||||
$arrayAux = explode("|", $str);
|
||||
|
||||
$date = "";
|
||||
$workspace = "";
|
||||
$action = "";
|
||||
$status = "";
|
||||
$description = trim($arrayAux[0]);
|
||||
|
||||
if (count($arrayAux) > 1) {
|
||||
$date = (isset($arrayAux[0]))? trim($arrayAux[0]) : "";
|
||||
$workspace = (isset($arrayAux[1]))? trim($arrayAux[1]) : "";
|
||||
$action = (isset($arrayAux[2]))? trim($arrayAux[2]) : "";
|
||||
$status = (isset($arrayAux[3]))? trim($arrayAux[3]) : "";
|
||||
$description = (isset($arrayAux[4]))? trim($arrayAux[4]) : "";
|
||||
}
|
||||
|
||||
$mktDate = (!empty($date))? mktimeDate($date) : 0;
|
||||
|
||||
//Filter
|
||||
$sw = 1;
|
||||
|
||||
if ($filter["workspace"] != "ALL" && $workspace != $filter["workspace"]) {
|
||||
$sw = 0;
|
||||
}
|
||||
|
||||
if ($filter["status"] != "ALL") {
|
||||
switch ($filter["status"]) {
|
||||
case "COMPLETED":
|
||||
if ($status != "action") {
|
||||
$sw = 0;
|
||||
}
|
||||
break;
|
||||
case "FAILED":
|
||||
if ($status == "action") {
|
||||
$sw = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($filter["dateFrom"]) && $mktDate > 0) {
|
||||
if (!(mktimeDate($filter["dateFrom"]) <= $mktDate)) {
|
||||
$sw = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($filter["dateTo"]) && $mktDate > 0) {
|
||||
if (!($mktDate <= mktimeDate($filter["dateTo"] . " 23:59:59"))) {
|
||||
$sw = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$arrayData = array();
|
||||
|
||||
if ($sw == 1) {
|
||||
$arrayData = array(
|
||||
"DATE" => $date,
|
||||
"WORKSPACE" => $workspace,
|
||||
"ACTION" => $action,
|
||||
"STATUS" => $status,
|
||||
"DESCRIPTION" => $description
|
||||
);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
}
|
||||
|
||||
function cronDataGet($filter, $r, $i)
|
||||
{
|
||||
$r = $r + 1; //+ 1, to determine the next page
|
||||
$i = $i + 1;
|
||||
|
||||
$arrayData = array();
|
||||
$strAux = null;
|
||||
$numRec = 0;
|
||||
$cont = 0;
|
||||
|
||||
$file = PATH_DATA . "log" . PATH_SEP . "cron.log";
|
||||
|
||||
if (file_exists($file)) {
|
||||
$fh = fopen($file, "r");
|
||||
|
||||
for($pos = 0; fseek($fh, $pos, SEEK_END) !== -1; $pos--) {
|
||||
$char = fgetc($fh);
|
||||
|
||||
if ($char == "\n") {
|
||||
$strAux = trim($strAux);
|
||||
|
||||
if (!empty($strAux)) {
|
||||
$arrayAux = cronArraySet($strAux, $filter);
|
||||
|
||||
if (count($arrayAux) > 0) {
|
||||
$cont = $cont + 1;
|
||||
|
||||
if ($cont >= $i && count($arrayData) + 1 <= $r) {
|
||||
$arrayData[] = $arrayAux;
|
||||
$numRec = $cont;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($arrayData) == $r) {
|
||||
break;
|
||||
}
|
||||
|
||||
$strAux = null;
|
||||
$char = null;
|
||||
}
|
||||
|
||||
$strAux = $char . $strAux;
|
||||
}
|
||||
|
||||
$strAux = trim($strAux);
|
||||
|
||||
if (!empty($strAux)) {
|
||||
$arrayAux = cronArraySet($strAux, $filter);
|
||||
|
||||
if (count($arrayAux) > 0) {
|
||||
$cont = $cont + 1;
|
||||
|
||||
if ($cont >= $i && count($arrayData) + 1 <= $r) {
|
||||
$arrayData[] = $arrayAux;
|
||||
$numRec = $cont;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
//Delete element
|
||||
$r = $r - 1;
|
||||
|
||||
if (count($arrayData) > $r) {
|
||||
$arrayAux = array_pop($arrayData);
|
||||
}
|
||||
|
||||
return array($numRec, $arrayData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$option = (isset($_REQUEST["option"]))? $_REQUEST["option"] : null;
|
||||
|
||||
$response = array();
|
||||
|
||||
switch ($option) {
|
||||
case "LST":
|
||||
$pageSize = $_REQUEST["pageSize"];
|
||||
$workspace = $_REQUEST["workspace"];
|
||||
$status = $_REQUEST["status"];
|
||||
$dateFrom = $_REQUEST["dateFrom"];
|
||||
$dateTo = $_REQUEST["dateTo"];
|
||||
|
||||
$arrayFilter = array(
|
||||
"workspace" => $workspace,
|
||||
"status" => $status,
|
||||
"dateFrom" => str_replace("T00:00:00", null, $dateFrom),
|
||||
"dateTo" => str_replace("T00:00:00", null, $dateTo)
|
||||
);
|
||||
|
||||
$limit = isset($_REQUEST["limit"])? $_REQUEST["limit"] : $pageSize;
|
||||
$start = isset($_REQUEST["start"])? $_REQUEST["start"] : 0;
|
||||
|
||||
list($numRec, $data) = cronDataGet($arrayFilter, $limit, $start);
|
||||
|
||||
$response = array("success" => true, "resultTotal" => $numRec, "resultRoot" => $data);
|
||||
break;
|
||||
|
||||
case "EMPTY":
|
||||
$status = 1;
|
||||
|
||||
try {
|
||||
$file = PATH_DATA . "log" . PATH_SEP . "cron.log";
|
||||
|
||||
if (file_exists($file)) {
|
||||
//file_put_contents($file, null);
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
$response["status"] = "OK";
|
||||
} catch (Exception $e) {
|
||||
$response["message"] = $e->getMessage();
|
||||
$status = 0;
|
||||
}
|
||||
|
||||
if ($status == 0) {
|
||||
$response["status"] = "ERROR";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
echo G::json_encode($response);
|
||||
|
||||
Reference in New Issue
Block a user