This commit is contained in:
Andrea Adamczyk
2019-05-15 21:12:33 -04:00
parent 5d8949255b
commit 7055872083
3 changed files with 598 additions and 37 deletions

View File

@@ -11,8 +11,9 @@ use ProcessMaker\Core\System;
use ProcessMaker\Validation\ExceptionRestApi;
use ProcessMaker\Validation\ValidationUploadedFiles;
header("Content-type: text/html;charset=utf-8");
require_once 'classes/model/AdditionalTables.php';
//We need to suppress the error for the unittest that use this function
@header("Content-type: text/html;charset=utf-8");
class pmTablesProxy extends HttpProxyController
{
@@ -404,7 +405,6 @@ class pmTablesProxy extends HttpProxyController
$this->className = $table['ADD_TAB_CLASS_NAME'];
$this->classPeerName = $this->className . 'Peer';
$sPath = PATH_DB . config("system.workspace") . PATH_SEP . 'classes' . PATH_SEP;
if (! file_exists( $sPath . $this->className . '.php' )) {
throw new Exception( 'Update:: ' . G::loadTranslation( 'ID_PMTABLE_CLASS_DOESNT_EXIST', $this->className ) );
}
@@ -427,7 +427,6 @@ class pmTablesProxy extends HttpProxyController
if ($result) {
G::auditLog("UpdateDataPmtable", "Table Name: ".$table['ADD_TAB_NAME']." Table ID: (".$table['ADD_TAB_UID'].") ");
}
$this->success = $result;
$this->message = $result ? G::loadTranslation( 'ID_UPDATED_SUCCESSFULLY' ) : G::loadTranslation( 'ID_UPDATE_FAILED' );
}
@@ -1094,32 +1093,38 @@ class pmTablesProxy extends HttpProxyController
/**
* Update data from a addTable record
*
* @param $row
* @param array $row
* @param array $primaryKeys
* @return boolean
* @throws Exception
*
* @see workflow/engine/controllers/pmTablesProxy::dataUpdate()
* @link https://wiki.processmaker.com/3.2/PM_Tables
*/
public function _dataUpdate ($row, $primaryKeys)
public function _dataUpdate($row, $primaryKeys)
{
$keys = G::decrypt( $row['__index__'], 'pmtable' );
$keys = explode( ',', $keys );
unset( $row['__index__'] );
$keys = G::decrypt($row['__index__'], 'pmtable');
$keys = explode(',', $keys);
unset($row['__index__']);
$params = array ();
$params = [];
foreach ($keys as $key) {
$params[] = is_numeric( $key ) ? $key : "'$key'";
$params[] = is_int($key) ? (int)$key : (string)$key;
}
$obj = null;
eval( '$obj = ' . $this->classPeerName . '::retrieveByPk(' . implode( ',', $params ) . ');' );
if (is_object( $obj )) {
$className = $this->classPeerName;
$obj = call_user_func_array($className . "::retrieveByPk", $params);
if (is_object($obj)) {
foreach ($row as $key => $value) {
// validation, don't modify primary keys
if (in_array( $key, $primaryKeys )) {
throw new Exception( G::loadTranslation( 'ID_DONT_MODIFY_PK_VALUE', array ($key
) ) );
if (in_array($key, $primaryKeys)) {
throw new Exception(G::loadTranslation('ID_DONT_MODIFY_PK_VALUE', [
$key
]));
}
$action = 'set' . AdditionalTables::getPHPName( $key );
$obj->$action( $value );
$action = 'set' . AdditionalTables::getPHPName($key);
$obj->$action($value);
}
if ($r = $obj->validate()) {
$obj->save();
@@ -1129,7 +1134,7 @@ class pmTablesProxy extends HttpProxyController
foreach ($obj->getValidationFailures() as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage() . "\n";
}
throw new Exception( $msg );
throw new Exception($msg);
}
} else {
$result = false;
@@ -1141,22 +1146,25 @@ class pmTablesProxy extends HttpProxyController
/**
* Update data from a addTable record
*
* @param $row
* @param array $row
* @return boolean
* @see workflow/engine/controllers/pmTablesProxy::dataDestroy()
* @link https://wiki.processmaker.com/3.2/PM_Tables
*/
public function _dataDestroy ($row)
public function _dataDestroy($row)
{
$row = G::decrypt( $row, 'pmtable' );
$row = str_replace( '"', '', $row );
$keys = explode( ',', $row );
$params = array ();
$row = G::decrypt($row, 'pmtable');
$row = str_replace('"', '', $row);
$keys = explode(',', $row);
$params = [];
foreach ($keys as $key) {
$params[] = is_numeric( $key ) ? $key : "'$key'";
$params[] = is_int($key) ? (int)$key : (string)$key;
}
$obj = null;
eval( '$obj = ' . $this->classPeerName . '::retrieveByPk(' . implode( ',', $params ) . ');' );
$className = $this->classPeerName;
$obj = call_user_func_array($className . "::retrieveByPk", $params);
if (is_object( $obj )) {
if (is_object($obj)) {
$obj->delete();
return true;
} else {