PMCORE-2974 Review the WARNING in the file workflow/engine/methods/triggers/triggers_WizardSave.php

This commit is contained in:
Roly Rudy Gutierrez Pinto
2021-04-16 13:15:09 -04:00
parent 758f194639
commit c1db79a521
2 changed files with 84 additions and 121 deletions

View File

@@ -1,46 +1,26 @@
<?php <?php
/**
* triggers_WizardSave.php
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.23
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) { if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) {
return $RBAC_Response; return $RBAC_Response;
} }
require_once ('classes/model/Triggers.php'); if (!class_exists('Triggers')) {
$oTrigger = new Triggers(); require_once ('classes/model/Triggers.php');
}
$triggers = new Triggers();
$oProcessMap = new ProcessMap(new DBConnection()); $processMap = new ProcessMap(new DBConnection());
$aDataTriggers = $_POST; $post = $_POST;
$aInfoFunction = explode(",", $aDataTriggers['ALLFUNCTION']); $allFunction = explode(",", $post['ALLFUNCTION']);
$aInfoFunctionType = explode(",", $aDataTriggers['ALLFUNCTION_TYPE']); $allFunctionType = explode(",", $post['ALLFUNCTION_TYPE']);
$sPMfunction = " $template = "
/*************************************************** /***************************************************
* *
* Generated by ProcessMaker Trigger Wizard * Generated by ProcessMaker Trigger Wizard
* Library: " . $aDataTriggers['LIBRARY_NAME'] . " * Library: " . $post['LIBRARY_NAME'] . "
* Method: " . $aDataTriggers['PMFUNTION_LABEL'] . " * Method: " . $post['PMFUNTION_LABEL'] . "
* Date: " . date("Y-m-d H:i:s") . " * Date: " . date("Y-m-d H:i:s") . "
* *
* ProcessMaker " . date("Y") . " * ProcessMaker " . date("Y") . "
@@ -49,65 +29,69 @@ $sPMfunction = "
"; ";
$methodParamsFinal = array(); $params = [];
//Generate params to send //Generate params to send
$i = 0; $i = 0;
foreach ($aInfoFunction as $k => $v) { foreach ($allFunction as $k => $v) {
if ($v != '') { if ($v != '') {
$sOptionTrigger = trim(str_replace("$", "", $v)); $key = trim(str_replace("$", "", $v));
if (strstr($sOptionTrigger, "=")) { if (strstr($key, "=")) {
$aOptionParameters = explode("=", $sOptionTrigger); $parameter = explode("=", $key);
$sOptionTrigger = trim($aOptionParameters[0]); $key = trim($parameter[0]);
} }
if ($aDataTriggers[$sOptionTrigger] != '') { if ($post[$key] != '') {
if ((strstr($aDataTriggers[$sOptionTrigger], "@@")) || ($aDataTriggers['PMFUNTION_NAME'] == 'evaluateFunction' && $k == 0 && strstr($aDataTriggers[$sOptionTrigger], "@="))) { if ((strstr($post[$key], "@@")) || ($post['PMFUNTION_NAME'] == 'evaluateFunction' && $k == 0 && strstr($post[$key], "@="))) {
$option = trim($aDataTriggers[$sOptionTrigger]); $option = trim($post[$key]);
} else { } else {
$aDataTriggers[$sOptionTrigger] = (strstr($aDataTriggers[$sOptionTrigger], 'array')) ? str_replace("'", '"', $aDataTriggers[$sOptionTrigger]) : str_replace("'", "\'", $aDataTriggers[$sOptionTrigger]); $post[$key] = strstr($post[$key], 'array') !== false ? str_replace("'", '"', $post[$key]) : str_replace("'", "\'", $post[$key]);
switch (trim($aInfoFunctionType[$i])) { switch (trim($allFunctionType[$i])) {
case 'boolean': case 'boolean':
$option = $aDataTriggers[$sOptionTrigger]; $option = $post[$key];
break; break;
case 'int': case 'int':
$option = intval($aDataTriggers[$sOptionTrigger]); $option = intval($post[$key]);
break; break;
case 'float': case 'float':
case 'real': case 'real':
case 'double': case 'double':
$option = floatval($aDataTriggers[$sOptionTrigger]); $option = floatval($post[$key]);
break; break;
default: default:
$option = (is_numeric($aDataTriggers[$sOptionTrigger]) || is_bool($aDataTriggers[$sOptionTrigger]) ) ? trim($aDataTriggers[$sOptionTrigger]) : (strstr($aDataTriggers[$sOptionTrigger], "'.array.'")) ? trim($aDataTriggers[$sOptionTrigger]) : '"' . trim($aDataTriggers[$sOptionTrigger]) . '"'; if (is_numeric($post[$key]) || is_bool($post[$key]) || (strstr($post[$key], "'.array.'") !== false)) {
$option = trim($post[$key]);
} else {
$option = '"' . trim($post[$key]) . '"';
}
break; break;
} }
} }
} else { } else {
$option = "''"; $option = "''";
} }
$methodParamsFinal[] = $option; $params[] = $option;
} }
$i++; $i++;
} }
//G::pr($methodParamsFinal);die;
$sPMfunction .= (isset($aDataTriggers['TRI_ANSWER']) && $aDataTriggers['TRI_ANSWER'] != '') ? $aDataTriggers['TRI_ANSWER'] . " = " : ""; $template .= (isset($post['TRI_ANSWER']) && $post['TRI_ANSWER'] != '') ? $post['TRI_ANSWER'] . " = " : "";
$sPMfunction .= $aDataTriggers['PMFUNTION_NAME'] . " (" . implode(",", $methodParamsFinal) . ");"; $template .= $post['PMFUNTION_NAME'] . " (" . implode(",", $params) . ");";
//Create Trigger //Create Trigger
$aDataTriggers['TRI_WEBBOT'] = $sPMfunction; $post['TRI_WEBBOT'] = $template;
$aDataTriggersParams = array(); $postParams = [];
$aDataTriggersParams['hash'] = G::encryptOld($sPMfunction); $postParams['hash'] = G::encryptOld($template);
$aDataTriggersParams['params'] = $aDataTriggers; $postParams['params'] = $post;
$aDataTriggers['TRI_PARAM'] = serialize($aDataTriggersParams); $post['TRI_PARAM'] = serialize($postParams);
$oTrigger->create($aDataTriggers); $triggers->create($post);
//Update Info //Update Info
$aDataTriggers['TRI_UID'] = $oTrigger->getTriUid(); $post['TRI_UID'] = $triggers->getTriUid();
$oTrigger->update($aDataTriggers); $triggers->update($post);
//Update Trigger Array //Update Trigger Array
$oProcessMap->triggersList($aDataTriggers['PRO_UID']); $processMap->triggersList($post['PRO_UID']);

View File

@@ -1,48 +1,26 @@
<?php <?php
/**
* triggers_WizardUpdate.php
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.23
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*/
if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) { if (($RBAC_Response = $RBAC->userCanAccess("PM_FACTORY")) != 1) {
return $RBAC_Response; return $RBAC_Response;
} }
if (!class_exists('Triggers')) { if (!class_exists('Triggers')) {
require_once ('classes/model/Triggers.php'); require_once ('classes/model/Triggers.php');
} }
$oTrigger = new Triggers(); $triggers = new Triggers();
$oProcessMap = new ProcessMap(new DBConnection()); $processMap = new ProcessMap(new DBConnection());
$aDataTriggers = $_POST; $post = $_POST;
$triUid = $_POST['TRI_UID'];
$aInfoFunction = explode(",", $aDataTriggers['ALLFUNCTION']); $allFunction = explode(",", $post['ALLFUNCTION']);
$aInfoFunctionType = explode(",", $aDataTriggers['ALLFUNCTION_TYPE']); $allFunctionType = explode(",", $post['ALLFUNCTION_TYPE']);
$sPMfunction = "
$template = "
/*************************************************** /***************************************************
* *
* Generated by ProcessMaker Trigger Wizard * Generated by ProcessMaker Trigger Wizard
* Library: " . $aDataTriggers['LIBRARY_NAME'] . " * Library: " . $post['LIBRARY_NAME'] . "
* Method: " . $aDataTriggers['PMFUNTION_LABEL'] . " * Method: " . $post['PMFUNTION_LABEL'] . "
* Date: " . date("Y-m-d H:i:s") . " * Date: " . date("Y-m-d H:i:s") . "
* *
* ProcessMaker " . date("Y") . " * ProcessMaker " . date("Y") . "
@@ -51,68 +29,69 @@ $sPMfunction = "
"; ";
$params = [];
$methodParamsFinal = array();
//Generate params to send //Generate params to send
$i = 0; $i = 0;
foreach ($aInfoFunction as $k => $v) { foreach ($allFunction as $k => $v) {
if ($v != '') { if ($v != '') {
$sOptionTrigger = trim(str_replace("$", "", $v)); $key = trim(str_replace("$", "", $v));
if (strstr($sOptionTrigger, "=")) { if (strstr($key, "=")) {
$aOptionParameters = explode("=", $sOptionTrigger); $parameter = explode("=", $key);
$sOptionTrigger = trim($aOptionParameters[0]); $key = trim($parameter[0]);
} }
if ($aDataTriggers[$sOptionTrigger] != '') { if ($post[$key] != '') {
if ((strstr($aDataTriggers[$sOptionTrigger], "@@")) || ($aDataTriggers['PMFUNTION_NAME'] == 'evaluateFunction' && $k == 0 && strstr($aDataTriggers[$sOptionTrigger], "@="))) { if ((strstr($post[$key], "@@")) || ($post['PMFUNTION_NAME'] == 'evaluateFunction' && $k == 0 && strstr($post[$key], "@="))) {
$option = $aDataTriggers[$sOptionTrigger]; $option = trim($post[$key]);
} else { } else {
$aDataTriggers[$sOptionTrigger] = (strstr($aDataTriggers[$sOptionTrigger], 'array')) ? str_replace("'", '"', $aDataTriggers[$sOptionTrigger]) : str_replace("'", "\'", $aDataTriggers[$sOptionTrigger]); $post[$key] = strstr($post[$key], 'array') !== false ? str_replace("'", '"', $post[$key]) : str_replace("'", "\'", $post[$key]);
switch (trim($aInfoFunctionType[$i])) { switch (trim($allFunctionType[$i])) {
case 'boolean': case 'boolean':
$option = $aDataTriggers[$sOptionTrigger]; $option = $post[$key];
break; break;
case 'int': case 'int':
$option = intval($aDataTriggers[$sOptionTrigger]); $option = intval($post[$key]);
break; break;
case 'float': case 'float':
case 'real': case 'real':
case 'double': case 'double':
$option = floatval($aDataTriggers[$sOptionTrigger]); $option = floatval($post[$key]);
break; break;
default: default:
$option = (is_numeric($aDataTriggers[$sOptionTrigger]) || is_bool($aDataTriggers[$sOptionTrigger]) ) ? trim($aDataTriggers[$sOptionTrigger]) : (strstr($aDataTriggers[$sOptionTrigger], "array")) ? trim($aDataTriggers[$sOptionTrigger]) : '"' . trim($aDataTriggers[$sOptionTrigger]) . '"'; if (is_numeric($post[$key]) || is_bool($post[$key]) || (strstr($post[$key], "array") !== false)) {
$option = trim($post[$key]);
} else {
$option = '"' . trim($post[$key]) . '"';
}
break; break;
} }
} }
} else { } else {
$option = "' '"; $option = "' '";
} }
$methodParamsFinal[] = $option; $params[] = $option;
} }
$i++; $i++;
} }
$sPMfunction .= (isset($aDataTriggers['TRI_ANSWER']) && $aDataTriggers['TRI_ANSWER'] != '') ? $aDataTriggers['TRI_ANSWER'] . " = " : ""; $template .= (isset($post['TRI_ANSWER']) && $post['TRI_ANSWER'] != '') ? $post['TRI_ANSWER'] . " = " : "";
$sPMfunction .= $aDataTriggers['PMFUNTION_NAME'] . " (" . implode(",", $methodParamsFinal) . ");"; $template .= $post['PMFUNTION_NAME'] . " (" . implode(",", $params) . ");";
//Create Trigger //Create Trigger
$aDataTriggers['TRI_WEBBOT'] = $sPMfunction; $post['TRI_WEBBOT'] = $template;
$aDataTriggersParams = array(); $postParams = [];
$aDataTriggersParams['hash'] = G::encryptOld($sPMfunction); $postParams['hash'] = G::encryptOld($template);
$aDataTriggersParams['params'] = $aDataTriggers; $postParams['params'] = $post;
$post['TRI_PARAM'] = serialize($postParams);
$triggers->load($_POST['TRI_UID']);
$aDataTriggers['TRI_PARAM'] = serialize($aDataTriggersParams);
//$oTrigger->create ( $aDataTriggers );
$aDataTriggerLoaded = $oTrigger->load($triUid);
//var_dump($aDataTriggerLoaded);
//die;
//Update Info //Update Info
$aDataTriggers['TRI_UID'] = $oTrigger->getTriUid(); $post['TRI_UID'] = $triggers->getTriUid();
$oTrigger->update($aDataTriggers); $triggers->update($post);
//Update Trigger Array //Update Trigger Array
$oProcessMap->triggersList($aDataTriggers['PRO_UID']); $processMap->triggersList($post['PRO_UID']);