From 0fc7584165600f7f349790b2968773a27ef1d77a Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 1 Aug 2014 10:25:33 -0400 Subject: [PATCH] Se aumenta validacion en delete y se agrega el encode en var_accepted_values. --- .../ProcessMaker/BusinessModel/Variable.php | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php b/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php index 854eef96f..a40a1c986 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php @@ -73,9 +73,9 @@ class Variable $variable->setVarDefault($arrayData["VAR_DEFAULT"]); } if (isset($arrayData["VAR_ACCEPTED_VALUES"])) { - $variable->setVarAcceptedValues($arrayData["VAR_ACCEPTED_VALUES"]); + $encodeAcceptedValues = json_encode($arrayData["VAR_ACCEPTED_VALUES"]); + $variable->setVarAcceptedValues($encodeAcceptedValues); } - $variable->save(); $cnn->commit(); } else { @@ -158,7 +158,8 @@ class Variable $variable->setVarDefault($arrayData["VAR_DEFAULT"]); } if (isset($arrayData["VAR_ACCEPTED_VALUES"])) { - $variable->setVarAcceptedValues($arrayData["VAR_ACCEPTED_VALUES"]); + $encodeAcceptedValues = json_encode($arrayData["VAR_ACCEPTED_VALUES"]); + $variable->setVarAcceptedValues($encodeAcceptedValues); } $variable->save(); $cnn->commit(); @@ -198,6 +199,8 @@ class Variable Validator::proUid($processUid, '$prj_uid'); $this->throwExceptionIfNotExistsVariable($variableUid); + + $this->verifyUse($processUid, $variableUid); //Delete $criteria = new \Criteria("workflow"); @@ -382,7 +385,6 @@ class Variable * * @param string $processUid Unique id of Process * @param string $variableName Name - * @param string $variableUidExclude Unique id of Variable to exclude * */ public function existsName($processUid, $variableName) @@ -537,5 +539,52 @@ class Variable throw $e; } } + + /** + * Verify if the variable is being used in a Dynaform + * + * @param string $processUid Unique id of Process + * @param string $variableUid Unique id of Variable + * + */ + public function verifyUse($processUid, $variableUid) + { + try { + + $criteria = new \Criteria("workflow"); + $criteria->addSelectColumn(\DynaformPeer::DYN_CONTENT); + $criteria->addSelectColumn(\DynaformPeer::DYN_UID); + $criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL); + $rsCriteria = \DynaformPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + while ($rsCriteria->next()) { + + $row = $rsCriteria->getRow(); + + $contentDecode = json_decode($row["DYN_CONTENT"], true); + $content = $contentDecode['items'][0]['items']; + + foreach ($content as $key => $value) { + if (isset($value[0]["variable"])) { + $criteria = new \Criteria("workflow"); + $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME); + $criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL); + $criteria->add(\ProcessVariablesPeer::VAR_NAME, $value[0]["variable"], \Criteria::EQUAL); + $rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + $rsCriteria->next(); + + if ($rsCriteria->getRow()) { + throw new \Exception(\G::LoadTranslation("ID_VARIABLE_IN_USE", array($variableUid, $row["DYN_UID"]))); + } + } + } + } + + } catch (\Exception $e) { + throw $e; + } + } }