This commit is contained in:
Roly Rudy Gutierrez Pinto
2018-06-05 10:57:53 -04:00
parent cb2e85a77e
commit 5a5457b5b6
6 changed files with 473 additions and 71 deletions

View File

@@ -3379,7 +3379,6 @@ class Cases
public function executeTriggers($sTasUid, $sStepType, $sStepUidObj, $sTriggerType, $aFields = array())
{
ChangeLog::getChangeLog()
->setStepTypeObject($sStepType)
->setObjectUid($sStepUidObj)
->getExecutedAtIdByTriggerType($sTriggerType);

View File

@@ -2249,7 +2249,7 @@ class WsBase
unset($appFields['APP_PROC_STATUS']);
unset($appFields['APP_PROC_CODE']);
unset($appFields['APP_PIN']);
$fieldsUpdated = $oCase->updateCase($caseId, $appFields);
$oCase->updateCase($caseId, $appFields);
//We need to update the variable $appData for use the new variables in the next trigger
$appData = array_merge($appData, $appFields['APP_DATA']);
@@ -2258,15 +2258,14 @@ class WsBase
}
ChangeLog::getChangeLog()
->setDate($fieldsUpdated['APP_UPDATE_DATE'])
->setAppNumber($fieldsUpdated['APP_NUMBER'])
->setDelIndex($fieldsUpdated['DEL_INDEX'])
->setDate('now')
->setAppNumber($appData['APP_NUMBER'])
->setDelIndex($appData['INDEX'])
->getProIdByProUid($appData['PROCESS'])
->getTasIdByTasUid($appData['TASK'])
->setStepTypeObject($stepType)
->setObjectUid($stepUidObj)
->setData($fieldsUpdated['APP_DATA'])
->getExecutedAtIdByTriggerType($triggerType);
->setData(serialize($appData))
->getExecutedAtIdByTriggerType($triggerType)
->getObjectIdByUidAndObjType($stepUidObj, $stepType);
return $varTriggers;
}

View File

@@ -1,6 +1,7 @@
<?php
use ProcessMaker\BusinessModel\Cases as BmCases;
use ProcessMaker\ChangeLog\ChangeLogResult;
use ProcessMaker\Plugins\PluginRegistry;
if (!isset($_SESSION['USER_LOGGED'])) {
@@ -770,15 +771,19 @@ class Ajax
public function changeLogAjax()
{
$changeLog = new ProcessMaker\BusinessModel\Cases\ChangeLog();
$idHistory = $_REQUEST["idHistory"];
$idHistoryArray = explode("_", $idHistory);
$proUid = $idHistoryArray[0];
$appUid = $idHistoryArray[1];
$tasUid = $idHistoryArray[2];
$start = isset($_REQUEST['start']) ? (int) $_REQUEST['start']: 0;
$limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']: 15;
echo G::json_encode($changeLog->getChangeLog($appUid, $proUid, $tasUid, $start, $limit));
$changeLog = new ChangeLogResult();
$result = $changeLog->setAppUid($appUid)
->setUserLogged($_SESSION['USER_LOGGED'])
->setProUid($proUid)
->setTasUid($tasUid)
->getLogs();
echo json_encode($result);
}
public function changeLogTab()

View File

@@ -37,7 +37,7 @@ class ChangeLog
*
* @var array
*/
protected static $applications = ['unknow', 'web', 'ABE', 'mobile'];
protected static $applications = ['Unknow', 'Web', 'Actions by Email', 'Mobile'];
/**
* Identifier for unknow object.
@@ -195,7 +195,7 @@ class ChangeLog
*
* @var string
*/
protected $objectUid = '';
protected $objectUid = '0';
/**
* The value for the executedAt field.
@@ -232,13 +232,6 @@ class ChangeLog
*/
protected $language = '';
/**
* The value for the stepTypeObject field.
*
* @var string
*/
protected $stepTypeObject = '';
/**
* Constructor of de class.
*/
@@ -252,7 +245,7 @@ class ChangeLog
*
* @return datetime
*/
function getDate()
public function getDate()
{
return $this->date;
}
@@ -262,7 +255,7 @@ class ChangeLog
*
* @return int
*/
function getAppNumber()
public function getAppNumber()
{
return $this->appNumber;
}
@@ -272,7 +265,7 @@ class ChangeLog
*
* @return int
*/
function getDelIndex()
public function getDelIndex()
{
return $this->delIndex;
}
@@ -282,7 +275,7 @@ class ChangeLog
*
* @return int
*/
function getProId()
public function getProId()
{
return $this->proId;
}
@@ -292,7 +285,7 @@ class ChangeLog
*
* @return int
*/
function getTasId()
public function getTasId()
{
return $this->tasId;
}
@@ -302,7 +295,7 @@ class ChangeLog
*
* @return int
*/
function getUsrId()
public function getUsrId()
{
return $this->usrId;
}
@@ -312,7 +305,7 @@ class ChangeLog
*
* @return int
*/
function getObjectType()
public function getObjectType()
{
return $this->objectType;
}
@@ -322,7 +315,7 @@ class ChangeLog
*
* @return int
*/
function getObjectId()
public function getObjectId()
{
return $this->objectId;
}
@@ -332,7 +325,7 @@ class ChangeLog
*
* @return type
*/
function getObjectUid()
public function getObjectUid()
{
return $this->objectUid;
}
@@ -342,7 +335,7 @@ class ChangeLog
*
* @return int
*/
function getExecutedAt()
public function getExecutedAt()
{
return $this->executedAt;
}
@@ -352,7 +345,7 @@ class ChangeLog
*
* @return string
*/
function getSourceId()
public function getSourceId()
{
return $this->sourceId;
}
@@ -362,7 +355,7 @@ class ChangeLog
*
* @return array
*/
function getData()
public function getData()
{
return $this->data;
}
@@ -372,7 +365,7 @@ class ChangeLog
*
* @return string
*/
function getSkin()
public function getSkin()
{
return $this->skin;
}
@@ -382,27 +375,18 @@ class ChangeLog
*
* @return string
*/
function getLanguage()
public function getLanguage()
{
return $this->language;
}
/**
* Get stepTypeObject.
* @return string
*/
function getStepTypeObject()
{
return $this->stepTypeObject;
}
/**
* Set date.
*
* @param datetime $date
* @return $this
*/
function setDate($date)
public function setDate($date)
{
$this->date = $date;
return $this;
@@ -414,7 +398,7 @@ class ChangeLog
* @param int $appNumber
* @return $this
*/
function setAppNumber($appNumber)
public function setAppNumber($appNumber)
{
$this->appNumber = $appNumber;
return $this;
@@ -426,7 +410,7 @@ class ChangeLog
* @param int $delIndex
* @return $this
*/
function setDelIndex($delIndex)
public function setDelIndex($delIndex)
{
$this->delIndex = $delIndex;
return $this;
@@ -438,7 +422,7 @@ class ChangeLog
* @param int $proId
* @return $this
*/
function setProId($proId)
public function setProId($proId)
{
$this->proId = $proId;
return $this;
@@ -450,7 +434,7 @@ class ChangeLog
* @param int $tasId
* @return $this
*/
function setTasId($tasId)
public function setTasId($tasId)
{
$this->tasId = $tasId;
return $this;
@@ -462,7 +446,7 @@ class ChangeLog
* @param int $usrId
* @return $this
*/
function setUsrId($usrId)
public function setUsrId($usrId)
{
$this->usrId = $usrId;
return $this;
@@ -474,7 +458,7 @@ class ChangeLog
* @param int $objectType
* @return $this
*/
function setObjectType($objectType)
public function setObjectType($objectType)
{
$this->objectType = $objectType;
return $this;
@@ -486,7 +470,7 @@ class ChangeLog
* @param int $objectId
* @return $this
*/
function setObjectId($objectId)
public function setObjectId($objectId)
{
$this->objectId = $objectId;
return $this;
@@ -498,7 +482,7 @@ class ChangeLog
* @param string $objectUid
* @return $this
*/
function setObjectUid($objectUid)
public function setObjectUid($objectUid)
{
$this->objectUid = $objectUid;
return $this;
@@ -510,7 +494,7 @@ class ChangeLog
* @param int $executedAt
* @return $this
*/
function setExecutedAt($executedAt)
public function setExecutedAt($executedAt)
{
$this->executedAt = $executedAt;
return $this;
@@ -522,7 +506,7 @@ class ChangeLog
* @param string $sourceId
* @return $this
*/
function setSourceId($sourceId)
public function setSourceId($sourceId)
{
$this->sourceId = $sourceId;
return $this;
@@ -534,7 +518,7 @@ class ChangeLog
* @param string $data
* @return $this
*/
function setData($data)
public function setData($data)
{
$this->data = $data;
return $this;
@@ -546,7 +530,7 @@ class ChangeLog
* @param string $skin
* @return $this
*/
function setSkin($skin)
public function setSkin($skin)
{
$this->skin = $skin;
return $this;
@@ -558,24 +542,12 @@ class ChangeLog
* @param string $language
* @return $this
*/
function setLanguage($language)
public function setLanguage($language)
{
$this->language = $language;
return $this;
}
/**
* Set stepTypeObject.
*
* @param string $stepTypeObject
* @return $this
*/
function setStepTypeObject($stepTypeObject)
{
$this->stepTypeObject = $stepTypeObject;
return $this;
}
/**
* Registers an entry in the database with all the data established in the
* object at that moment.
@@ -744,6 +716,9 @@ class ChangeLog
break;
}
switch ($uid) {
case "":
$this->setObjectUid(0);
break;
case "-1":
$this->setObjectUid(0);
$this->setExecutedAt(self::BEFORE_ASSIGNMENT);

View File

@@ -0,0 +1,294 @@
<?php
namespace ProcessMaker\ChangeLog;
use Cases;
use G;
use ProcessMaker\ChangeLog\LogStruct;
use Propel;
class ChangeLogResult
{
/**
* Reserved steps.
*
* @var array
*/
private $reservedSteps = [
-1,
-2,
];
/**
* Variables to exclude.
*
* @var array
*/
private $excludeVariables = [
'SYS_LANG',
'SYS_SKIN',
'SYS_SYS',
'APPLICATION',
'PROCESS',
'TASK',
'INDEX',
'USER_LOGGED',
'USR_USERNAME',
'APP_NUMBER',
'PIN',
'DYN_CONTENT_HISTORY',
'__VAR_CHANGED__',
];
/**
* Permissions.
*
* @var array
*/
private $permissions = [];
/**
* Identifier of the application.
*
* @var string
*/
private $appUid;
/**
* Identifier of the process.
*
* @var string
*/
private $proUid;
/**
* Identifier of the task.
*
* @var string
*/
private $tasUid;
/**
* User logged.
*
* @var string
*/
private $userLogged;
/**
* Set appUid.
*
* @param string $appUid
* @return object
*/
public function setAppUid($appUid)
{
$this->appUid = $appUid;
return $this;
}
/**
* Set proUid.
*
* @param string $proUid
* @return object
*/
public function setProUid($proUid)
{
$this->proUid = $proUid;
return $this;
}
/**
* Set tasUid.
*
* @param string $tasUid
* @return object
*/
public function setTasUid($tasUid)
{
$this->tasUid = $tasUid;
return $this;
}
/**
* Set userLogged.
*
* @param string $userLogged
* @return object
*/
public function setUserLogged($userLogged)
{
$this->userLogged = $userLogged;
return $this;
}
/**
* Get logs.
*
* @return array
*/
public function getLogs()
{
$cases = new Cases();
$this->permissions = $cases->getAllObjects($this->proUid, $this->appUid, $this->tasUid, $this->userLogged);
$logs = [];
$totalCount = 0;
$values = [];
$this->getLogsFromDataBase($this->appUid, function($row) use(&$logs, &$totalCount, &$values) {
$appData = $this->getAppData($row['DATA']);
$this->removeVariables($appData);
$hasPermission = $this->hasPermission($row['DYN_UID']);
if ((int) $row['SOURCE_ID'] === ChangeLog::FromABE) {
$hasPermission = true;
}
$count = 0;
foreach ($appData as $key => $value) {
if ($hasPermission && (!isset($values[$key]) || $values[$key] !== $value)) {
$previousValue = !isset($values[$key]) ? null : $values[$key];
$record = ''
. G::LoadTranslation('ID_TASK') . ': ' . $row['TAS_TITLE'] . ' / '
. G::LoadTranslation('ID_DYNAFORM') . ': ' . $row['DYN_TITLE'] . ' / '
. G::LoadTranslation('ID_LAN_UPDATE_DATE') . ': ' . $row['DATE'] . ' / '
. G::LoadTranslation('ID_USER') . ': ' . $row['USR_USERNAME'] . ' / '
. G::LoadTranslation('ID_FROM') . ': ' . ChangeLog::getChangeLog()->getApplicationNameById($row['SOURCE_ID']);
$struct = new LogStruct();
$struct->setField($key)
->setPreviousValue($this->toString($previousValue))
->setCurrentValue($this->toString($value))
->setPreviousValueType(gettype($previousValue))
->setCurrentValueType(gettype($value))
->setRecord($record);
$logs[] = $struct->getValues();
$count++;
}
$values[$key] = $value;
}
$totalCount = $totalCount + $count;
});
return [
'data' => $logs,
'totalCount' => $totalCount
];
}
/**
* Get logs from Database.
*
* @param type $appUid
* @param type $callback
*/
public function getLogsFromDataBase($appUid, $callback = null)
{
$conn = Propel::getConnection('workflow');
$sql = ""
. "SELECT "
. "A.CHANGE_LOG_ID, "
. "D.TAS_TITLE, "
. "C.PRO_TITLE, "
. "IF(F.DYN_UID IS NULL,'N/A',F.DYN_TITLE) AS 'DYN_TITLE', "
. "F.DYN_UID, "
. "A.DATE, "
. "E.USR_USERNAME, "
. "A.APP_NUMBER, "
. "A.DEL_INDEX, "
. "A.PRO_ID, "
. "A.TAS_ID, "
. "A.USR_ID, "
. "A.OBJECT_ID, "
. "A.OBJECT_UID, "
. "A.EXECUTED_AT, "
. "A.SOURCE_ID, "
. "A.DATA, "
. "A.SKIN, "
. "A.LANGUAGE "
. "FROM APP_DATA_CHANGE_LOG AS A "
. "INNER JOIN APPLICATION AS B ON (B.APP_NUMBER=A.APP_NUMBER AND B.APP_UID=? ) "
. "LEFT JOIN PROCESS AS C ON (C.PRO_ID=A.PRO_ID) "
. "LEFT JOIN TASK AS D ON (D.TAS_ID=A.TAS_ID) "
. "LEFT JOIN USERS AS E ON (E.USR_ID=A.USR_ID) "
. "LEFT JOIN DYNAFORM AS F ON (F.DYN_ID=A.OBJECT_ID AND A.OBJECT_TYPE=" . ChangeLog::DYNAFORM . ") "
. "ORDER BY A.DATE ASC ";
$stmt = $conn->prepareStatement($sql);
$stmt->set(1, $appUid);
$stmt->executeQuery();
$result = $stmt->getResultSet();
while ($result->next()) {
$row = $result->getRow();
if (!empty($callback) && is_callable($callback)) {
$callback($row);
}
}
}
/**
* Get appData from value serialized.
*
* @param string $appDataString
* @return array
*/
private function getAppData($appDataString)
{
$case = new Cases();
$appData = $case->unserializeData($appDataString);
if (!is_array($appData)) {
$appData = [];
}
return $appData;
}
/**
* Remove all values from the array that are in the excludeVariables property.
*
* @param array $appData
*/
private function removeVariables(&$appData)
{
foreach ($this->excludeVariables as $value) {
unset($appData[$value]);
}
}
/**
* Has permission.
*
* @param string $uid
* @return boolean
*/
private function hasPermission($uid)
{
if (array_search($uid, $this->reservedSteps) !== false) {
return false;
}
foreach ($this->permissions as $ids) {
if (is_array($ids) && array_search($uid, $ids) !== false) {
return true;
}
}
return false;
}
/**
* Returns the print string from the value.
*
* @param mixed $value
* @return string
*/
private function toString($value)
{
if (is_array($value)) {
return nl2br(print_r($value, true));
} else {
return (string) $value;
}
}
}

View File

@@ -0,0 +1,130 @@
<?php
namespace ProcessMaker\ChangeLog;
class LogStruct
{
/**
* Name of the variable.
*
* @var string
*/
private $field = '';
/**
* Previous value of the variable.
*
* @var string
*/
private $previousValue = '';
/**
* Current value.
*
* @var string
*/
private $currentValue = '';
/**
* Previous type of variable.
*
* @var string
*/
private $previousValueType = '';
/**
* Type of the variable.
*
* @var string
*/
private $currentValueType = '';
/**
* Group of changes.
*
* @var string
*/
private $record = '';
/**
* Set the field.
*
* @param string $field
* @return $this
*/
public function setField($field)
{
$this->field = $field;
return $this;
}
/**
* Set the previousValue.
*
* @param string $previousValue
* @return $this
*/
public function setPreviousValue($previousValue)
{
$this->previousValue = $previousValue;
return $this;
}
/**
* Set the currentValue.
*
* @param string $currentValue
* @return $this
*/
public function setCurrentValue($currentValue)
{
$this->currentValue = $currentValue;
return $this;
}
/**
* Set the previousValueType.
*
* @param string $previousValueType
* @return $this
*/
public function setPreviousValueType($previousValueType)
{
$this->previousValueType = $previousValueType;
return $this;
}
/**
* Set the currentValueType.
*
* @param string $currentValueType
* @return $this
*/
public function setCurrentValueType($currentValueType)
{
$this->currentValueType = $currentValueType;
return $this;
}
/**
* Set the record.
*
* @param string $record
* @return $this
*/
public function setRecord($record)
{
$this->record = $record;
return $this;
}
/**
* Get values.
*
* @return array
*/
public function getValues()
{
return get_object_vars($this);
}
}