This commit is contained in:
jonathan Quispe
2017-09-15 11:54:39 +00:00
committed by Paula Quispe
parent 94d9fb2b3d
commit 4a9c1b2d39
10 changed files with 340 additions and 181 deletions

View File

@@ -141,6 +141,7 @@ def generateEnviromentVariables()
file = File.read('./config/enviromentvariables.json') file = File.read('./config/enviromentvariables.json')
dataUser = JSON.parse(file) dataUser = JSON.parse(file)
content = content + "__env.USER_GUEST = " + JSON.generate(dataUser['constants']['userguest']) content = content + "__env.USER_GUEST = " + JSON.generate(dataUser['constants']['userguest'])
content = content + "; __env.pmVariable = " + JSON.generate(dataUser['validation']['pmVariable'])
dir = "vendor/colosa/MichelangeloFE/src/enviroment/" dir = "vendor/colosa/MichelangeloFE/src/enviroment/"
# create a directory enviroment # create a directory enviroment
FileUtils.mkdir_p(dir) FileUtils.mkdir_p(dir)

10
config/constants.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
return [
'validation' => [
'pmVariable' => [
'regEx' => '/^[a-zA-Z\_]{1}\w+$/'
]
]
];

View File

@@ -8,5 +8,10 @@
"lastname": "Guest", "lastname": "Guest",
"username": "guest" "username": "guest"
} }
},
"validation": {
"pmVariable": {
"regEx": "/^[a-zA-Z\\_]{1}\\w+$/"
}
} }
} }

View File

@@ -471,6 +471,37 @@ gulp.task('clean', function () {
cleanDirectory('workflow/public_html/lib'); cleanDirectory('workflow/public_html/lib');
}); });
/**
* Exports from the config/constants.php the configuration constants to the
* enviromentvariables.json file
*/
gulp.task('exportBackendConstants', function () {
var runner = require('child_process');
gutil.log(gutil.colors.green('Export ProcessMaker constants...'));
var envVarsJsonFile = 'config/enviromentvariables.json';
var code = 'require_once "gulliver/system/class.g.php";' +
'require_once "bootstrap/autoload.php";' +
'require_once "bootstrap/app.php";' +
'app()->make(Illuminate\\Foundation\\Http\\Kernel::class)->bootstrap();' +
'print(json_encode(config("constants", JSON_UNESCAPED_SLASHES)));';
runner.exec(
'php -r \'' + code + '\'',
function (err, stdout, stderr) {
var pmConstants = JSON.parse(stdout);
var envVar = JSON.parse(fs.readFileSync(envVarsJsonFile));
for (var attr in pmConstants) {
envVar[attr] = pmConstants[attr];
}
fs.writeFileSync(envVarsJsonFile, JSON.stringify(envVar, null, 2));
return pmConstants;
});
});
/** /**
* This scheduled task is to be able to create the guest user constants * This scheduled task is to be able to create the guest user constants
*/ */
@@ -490,7 +521,7 @@ gulp.task('__env', function (cb) {
); );
}); });
gulp.task('default', ['clean', '__env'], function (cb) { gulp.task('default', ['clean', 'exportBackendConstants', '__env'], function (cb) {
var i, tasks = []; var i, tasks = [];
gutil.log(gutil.colors.green('Initializing ProcessMaker building...')); gutil.log(gutil.colors.green('Initializing ProcessMaker building...'));
@@ -500,3 +531,4 @@ gulp.task('default', ['clean', '__env'], function (cb) {
} }
executeSequence(tasks, cb); executeSequence(tasks, cb);
}); });

View File

@@ -8945,6 +8945,12 @@ msgstr "No skins to display"
msgid "No users to display" msgid "No users to display"
msgstr "No users to display" msgstr "No users to display"
# TRANSLATION
# LABEL/ID_GRID_VARIABLE_NAME_ERROR
#: LABEL/ID_GRID_VARIABLE_NAME_ERROR
msgid "A valid variable starts with a letter or underscore, followed by any number of letters, numbers, or underscores. Variables with wrong names: {0}"
msgstr "A valid variable starts with a letter or underscore, followed by any number of letters, numbers, or underscores. Variables with wrong names: {0}"
# TRANSLATION # TRANSLATION
# LABEL/ID_GRID_WIZARD # LABEL/ID_GRID_WIZARD
#: LABEL/ID_GRID_WIZARD #: LABEL/ID_GRID_WIZARD
@@ -20675,6 +20681,12 @@ msgstr "File \"{0}\" imported but with errors:"
msgid "The following fields cannot be created because they contain the reserved words \"{0}\"" msgid "The following fields cannot be created because they contain the reserved words \"{0}\""
msgstr "The following fields cannot be created because they contain the reserved words \"{0}\"" msgstr "The following fields cannot be created because they contain the reserved words \"{0}\""
# TRANSLATION
# LABEL/ID_PMTABLE_INVALID_FIELD_NAME_VARIABLE
#: LABEL/ID_PMTABLE_INVALID_FIELD_NAME_VARIABLE
msgid "There is a conflict with some field names: \"{0}\", please rename them avoiding the use of numbers and considering that underscores are ignored when validating unique field names."
msgstr "There is a conflict with some field names: \"{0}\", please rename them avoiding the use of numbers and considering that underscores are ignored when validating unique field names."
# TRANSLATION # TRANSLATION
# LABEL/ID_PMTABLE_INVALID_FILE # LABEL/ID_PMTABLE_INVALID_FILE
#: LABEL/ID_PMTABLE_INVALID_FILE #: LABEL/ID_PMTABLE_INVALID_FILE

View File

@@ -58318,6 +58318,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_GRID_PAGE_NO_ROWS_MESSAGE','en','No rows to display','2014-01-15') , ( 'LABEL','ID_GRID_PAGE_NO_ROWS_MESSAGE','en','No rows to display','2014-01-15') ,
( 'LABEL','ID_GRID_PAGE_NO_SKIN_MESSAGE','en','No skins to display','2014-01-15') , ( 'LABEL','ID_GRID_PAGE_NO_SKIN_MESSAGE','en','No skins to display','2014-01-15') ,
( 'LABEL','ID_GRID_PAGE_NO_USERS_MESSAGE','en','No users to display','2014-01-15') , ( 'LABEL','ID_GRID_PAGE_NO_USERS_MESSAGE','en','No users to display','2014-01-15') ,
( 'LABEL','ID_GRID_VARIABLE_NAME_ERROR','en','A valid variable starts with a letter or underscore, followed by any number of letters, numbers, or underscores. Variables with wrong names: {0}','2017-11-16') ,
( 'LABEL','ID_GRID_WIZARD','en','ProcessMaker Grid Wizard','2014-01-15') , ( 'LABEL','ID_GRID_WIZARD','en','ProcessMaker Grid Wizard','2014-01-15') ,
( 'LABEL','ID_GROUP','en','Group','2014-01-15') , ( 'LABEL','ID_GROUP','en','Group','2014-01-15') ,
( 'LABEL','ID_GROUPS','en','Groups','2014-01-15') , ( 'LABEL','ID_GROUPS','en','Groups','2014-01-15') ,
@@ -60295,6 +60296,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_PMTABLE_IMPORT_SUCCESS','en','File "{0}" imported successfully.','2014-01-15') , ( 'LABEL','ID_PMTABLE_IMPORT_SUCCESS','en','File "{0}" imported successfully.','2014-01-15') ,
( 'LABEL','ID_PMTABLE_IMPORT_WITH_ERRORS','en','File "{0}" imported but with errors:','2016-02-18') , ( 'LABEL','ID_PMTABLE_IMPORT_WITH_ERRORS','en','File "{0}" imported but with errors:','2016-02-18') ,
( 'LABEL','ID_PMTABLE_INVALID_FIELD_NAME','en','The following fields cannot be created because they contain the reserved words "{0}"','2014-10-21') , ( 'LABEL','ID_PMTABLE_INVALID_FIELD_NAME','en','The following fields cannot be created because they contain the reserved words "{0}"','2014-10-21') ,
( 'LABEL','ID_PMTABLE_INVALID_FIELD_NAME_VARIABLE','en','There is a conflict with some field names: "{0}", please rename them avoiding the use of numbers and considering that underscores are ignored when validating unique field names.','2018-04-03') ,
( 'LABEL','ID_PMTABLE_INVALID_FILE','en','Invalid PM table(s) file, import aborted!','2014-01-15') , ( 'LABEL','ID_PMTABLE_INVALID_FILE','en','Invalid PM table(s) file, import aborted!','2014-01-15') ,
( 'LABEL','ID_PMTABLE_INVALID_NAME','en','Could not create the table with the name "{0}" because it is a reserved word.','2014-01-15') , ( 'LABEL','ID_PMTABLE_INVALID_NAME','en','Could not create the table with the name "{0}" because it is a reserved word.','2014-01-15') ,
( 'LABEL','ID_PMTABLE_NOT_FOUND','en','The PM Table associated with this DynaForm could not be found.','2014-11-12') , ( 'LABEL','ID_PMTABLE_NOT_FOUND','en','The PM Table associated with this DynaForm could not be found.','2014-11-12') ,

View File

@@ -2,7 +2,11 @@
namespace ProcessMaker\BusinessModel; namespace ProcessMaker\BusinessModel;
use AdditionalTables;
use DynaformHandler; use DynaformHandler;
use Exception;
use G;
use PmDynaform;
class DynaForm class DynaForm
{ {
@@ -407,6 +411,8 @@ class DynaForm
$this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]); $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]);
$this->throwExceptionIfTheColumnIdentifierIsNotValid($arrayData);
//Create //Create
$dynaForm = new \Dynaform(); $dynaForm = new \Dynaform();
@@ -461,6 +467,8 @@ class DynaForm
$this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"], $dynaFormUid); $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"], $dynaFormUid);
} }
$this->throwExceptionIfTheColumnIdentifierIsNotValid($arrayData);
//Update //Update
$arrayData["DYN_UID"] = $dynaFormUid; $arrayData["DYN_UID"] = $dynaFormUid;
@@ -1131,4 +1139,74 @@ class DynaForm
throw $e; throw $e;
} }
} }
/**
* Validates if the grid columns tha will be stored have valid names, otherwise
* it throws an exception.
*
* @param array $arrayData, form data that will be saved
*
* @throws Exception
*/
public function throwExceptionIfTheColumnIdentifierIsNotValid($arrayData)
{
if (isset($arrayData['DYN_CONTENT'])) {
$oldDynaform = $this->getDynaFormRecordByPk($arrayData['DYN_UID'], []);
$oldGrids = PmDynaform::getGridsAndFields($oldDynaform['DYN_CONTENT']);
$oldColumns = $this->getColumnsOfArrayGrids($oldGrids);
$grids = PmDynaform::getGridsAndFields($arrayData['DYN_CONTENT']);
$columns = $this->getColumnsOfArrayGrids($grids);
foreach ($oldColumns as $oldField) {
foreach ($columns as $key => $field) {
if ($oldField->id === $field->id) {
unset($columns[$key]);
break;
}
}
}
$invalids = [];
$identicals = [];
foreach ($columns as $column) {
try {
Validator::isValidVariableName($column->id);
} catch (Exception $e) {
$invalids[] = $column->id;
}
foreach ($oldColumns as $oldColumn) {
if (strtolower(AdditionalTables::getPHPName($column->id)) === strtolower(AdditionalTables::getPHPName($oldColumn->id))) {
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
}
}
}
if (count($invalids) > 0) {
throw (new Exception(G::LoadTranslation("ID_GRID_VARIABLE_NAME_ERROR", [implode(', ', $invalids)])));
}
if (count($identicals) > 0) {
throw (new Exception(G::LoadTranslation("DYNAFIELD_PHPNAME_ALREADY_EXIST", [implode(', ', $identicals)])));
}
}
}
/**
* Gets a list of all columns of the grid array.
*
* @param array $grids
*
* @return array
*/
private function getColumnsOfArrayGrids($grids)
{
$columns = [];
foreach ($grids as $grid) {
if (isset($grid->columns)) {
$columns = array_merge($columns, $grid->columns);
}
}
return $columns;
}
} }

View File

@@ -1,8 +1,15 @@
<?php <?php
namespace ProcessMaker\BusinessModel; namespace ProcessMaker\BusinessModel;
use AdditionalTables;
use AdditionalTablesPeer;
use G;
use Exception;
class ReportTable class ReportTable
{ {
/** /**
* Get report table default columns * Get report table default columns
* *
@@ -101,7 +108,7 @@ class ReportTable
if (isset($tableNameMap[$tableName])) { if (isset($tableNameMap[$tableName])) {
$tableName = $tableNameMap[$tableName]; $tableName = $tableNameMap[$tableName];
$additionalTable = new \AdditionalTables(); $additionalTable = new AdditionalTables();
$arrayAdditionalTableData = $additionalTable->loadByName($tableName); $arrayAdditionalTableData = $additionalTable->loadByName($tableName);
@@ -122,13 +129,7 @@ class ReportTable
array_multisort($primaryKeyColumn, SORT_ASC, $contentData); array_multisort($primaryKeyColumn, SORT_ASC, $contentData);
foreach ($contentData as $row) { foreach ($contentData as $row) {
$arrayResult = $this->createRecord( $arrayResult = $this->createRecord(['id' => $arrayAdditionalTableData['ADD_TAB_UID'], 'rows' => base64_encode(serialize($row)),], 'base64');
[
'id' => $arrayAdditionalTableData['ADD_TAB_UID'],
'rows' => base64_encode(serialize($row)),
],
'base64'
);
if (!$arrayResult['success']) { if (!$arrayResult['success']) {
$errors .= $arrayResult['message']; $errors .= $arrayResult['message'];
@@ -141,7 +142,7 @@ class ReportTable
//Return //Return
return $errors; return $errors;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -157,21 +158,20 @@ class ReportTable
public function createRecord(array $arrayData, $codification = 'json') public function createRecord(array $arrayData, $codification = 'json')
{ {
try { try {
$additionalTable = new \AdditionalTables(); $additionalTable = new AdditionalTables();
$arrayAdditionalTableData = $additionalTable->load($arrayData['id'], true); $arrayAdditionalTableData = $additionalTable->load($arrayData['id'], true);
$additionalTableClassName = $arrayAdditionalTableData['ADD_TAB_CLASS_NAME']; $additionalTableClassName = $arrayAdditionalTableData['ADD_TAB_CLASS_NAME'];
$additionalTableClassPeerName = $additionalTableClassName . 'Peer'; $additionalTableClassPeerName = $additionalTableClassName . 'Peer';
$row = ($codification == 'base64')? $row = ($codification == 'base64') ? unserialize(base64_decode($arrayData['rows'])) : G::json_decode($arrayData['rows']);
unserialize(base64_decode($arrayData['rows'])) : \G::json_decode($arrayData['rows']);
$row = (array) ($row); $row = (array) ($row);
$row = array_merge(array_change_key_case($row, CASE_LOWER), array_change_key_case($row, CASE_UPPER)); $row = array_merge(array_change_key_case($row, CASE_LOWER), array_change_key_case($row, CASE_UPPER));
$flagSave = false; $flagSave = false;
if (!file_exists(PATH_WORKSPACE . 'classes' . PATH_SEP . $additionalTableClassName . '.php')) { if (!file_exists(PATH_WORKSPACE . 'classes' . PATH_SEP . $additionalTableClassName . '.php')) {
throw new Exception(\G::LoadTranslation('ID_PMTABLE_CLASS_DOESNT_EXIST', [$additionalTableClassName])); throw new Exception(G::LoadTranslation('ID_PMTABLE_CLASS_DOESNT_EXIST', [$additionalTableClassName]));
} }
require_once(PATH_WORKSPACE . 'classes' . PATH_SEP . $additionalTableClassName . '.php'); require_once(PATH_WORKSPACE . 'classes' . PATH_SEP . $additionalTableClassName . '.php');
@@ -188,17 +188,13 @@ class ReportTable
$primaryKeysValues = []; $primaryKeysValues = [];
foreach ($additionalTable->getPrimaryKeys() as $primaryKey) { foreach ($additionalTable->getPrimaryKeys() as $primaryKey) {
$method = 'get' . \AdditionalTables::getPHPName($primaryKey['FLD_NAME']); $method = 'get' . AdditionalTables::getPHPName($primaryKey['FLD_NAME']);
$primaryKeysValues[] = $obj->$method(); $primaryKeysValues[] = $obj->$method();
} }
$index = \G::encrypt(implode(',', $primaryKeysValues), 'pmtable'); $index = G::encrypt(implode(',', $primaryKeysValues), 'pmtable');
\G::auditLog( G::auditLog('AddDataPmtable', 'Table Name: ' . $arrayAdditionalTableData['ADD_TAB_NAME'] . ' Table ID: (' . $arrayAdditionalTableData['ADD_TAB_UID'] . ')');
'AddDataPmtable',
'Table Name: ' . $arrayAdditionalTableData['ADD_TAB_NAME'] .
' Table ID: (' . $arrayAdditionalTableData['ADD_TAB_UID'] . ')'
);
$flagSave = true; $flagSave = true;
} else { } else {
@@ -208,10 +204,7 @@ class ReportTable
$msg .= $objValidationFailure->getMessage() . "\n"; $msg .= $objValidationFailure->getMessage() . "\n";
} }
throw new Exception( throw new Exception(G::LoadTranslation('ID_ERROR_TRYING_INSERT') . '"' . $arrayAdditionalTableData['ADD_TAB_NAME'] . "\"\n" . $msg);
\G::LoadTranslation('ID_ERROR_TRYING_INSERT') .
'"' . $arrayAdditionalTableData['ADD_TAB_NAME'] . "\"\n" . $msg
);
} }
} else { } else {
$flagSave = false; $flagSave = false;
@@ -220,11 +213,11 @@ class ReportTable
//Return //Return
return [ return [
'success' => $flagSave, 'success' => $flagSave,
'message' => ($flagSave)? \G::LoadTranslation('ID_RECORD_SAVED_SUCCESFULLY') : '', 'message' => ($flagSave) ? G::LoadTranslation('ID_RECORD_SAVED_SUCCESFULLY') : '',
'rows' => ($flagSave) ? $obj->toArray(\BasePeer::TYPE_FIELDNAME) : [], 'rows' => ($flagSave) ? $obj->toArray(\BasePeer::TYPE_FIELDNAME) : [],
'index' => ($flagSave) ? $index : '', 'index' => ($flagSave) ? $index : '',
]; ];
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -240,13 +233,8 @@ class ReportTable
* *
* @return array * @return array
*/ */
public function checkPmtFileThrowErrors( public function checkPmtFileThrowErrors(array $arrayTableSchema, $processUid, $flagFromAdmin, $flagOverwrite, $postProUid)
array $arrayTableSchema, {
$processUid,
$flagFromAdmin,
$flagOverwrite,
$postProUid
) {
try { try {
$arrayError = []; $arrayError = [];
@@ -254,7 +242,7 @@ class ReportTable
$processMap = new \ProcessMap(); $processMap = new \ProcessMap();
$arrayProcessUid = []; $arrayProcessUid = [];
foreach (\G::json_decode($processMap->getAllProcesses()) as $value) { foreach (G::json_decode($processMap->getAllProcesses()) as $value) {
if ($value->value != '') { if ($value->value != '') {
$arrayProcessUid[] = $value->value; $arrayProcessUid[] = $value->value;
} }
@@ -266,7 +254,7 @@ class ReportTable
$contentSchema = $value; $contentSchema = $value;
//The table exists? //The table exists?
$additionalTable = new \AdditionalTables(); $additionalTable = new AdditionalTables();
$arrayAdditionalTableData = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']); $arrayAdditionalTableData = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']);
@@ -278,7 +266,7 @@ class ReportTable
if ($arrayAdditionalTableData && !$flagOverwrite) { if ($arrayAdditionalTableData && !$flagOverwrite) {
$arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME']; $arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$arrayError[$i]['ERROR_TYPE'] = 1; //ERROR_PM_TABLES_OVERWRITE $arrayError[$i]['ERROR_TYPE'] = 1; //ERROR_PM_TABLES_OVERWRITE
$arrayError[$i]['ERROR_MESS'] = \G::LoadTranslation('ID_OVERWRITE_PMTABLE', [$contentSchema['ADD_TAB_NAME']]); $arrayError[$i]['ERROR_MESS'] = G::LoadTranslation('ID_OVERWRITE_PMTABLE', [$contentSchema['ADD_TAB_NAME']]);
$arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable; $arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable;
$arrayError[$i]['PRO_UID'] = $tableProUid; $arrayError[$i]['PRO_UID'] = $tableProUid;
} }
@@ -286,14 +274,14 @@ class ReportTable
if (!in_array($tableProUid, $arrayProcessUid)) { if (!in_array($tableProUid, $arrayProcessUid)) {
$arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME']; $arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$arrayError[$i]['ERROR_TYPE'] = 2; //ERROR_PROCESS_NOT_EXIST $arrayError[$i]['ERROR_TYPE'] = 2; //ERROR_PROCESS_NOT_EXIST
$arrayError[$i]['ERROR_MESS'] = \G::LoadTranslation('ID_PROCESS_NOT_EXIST', [$contentSchema['ADD_TAB_NAME']]); $arrayError[$i]['ERROR_MESS'] = G::LoadTranslation('ID_PROCESS_NOT_EXIST', [$contentSchema['ADD_TAB_NAME']]);
$arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable; $arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable;
$arrayError[$i]['PRO_UID'] = $tableProUid; $arrayError[$i]['PRO_UID'] = $tableProUid;
} else { } else {
if ($arrayAdditionalTableData && !$flagOverwrite) { if ($arrayAdditionalTableData && !$flagOverwrite) {
$arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME']; $arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$arrayError[$i]['ERROR_TYPE'] = 3; //ERROR_RP_TABLES_OVERWRITE $arrayError[$i]['ERROR_TYPE'] = 3; //ERROR_RP_TABLES_OVERWRITE
$arrayError[$i]['ERROR_MESS'] = \G::LoadTranslation('ID_OVERWRITE_RPTABLE', [$contentSchema['ADD_TAB_NAME']]); $arrayError[$i]['ERROR_MESS'] = G::LoadTranslation('ID_OVERWRITE_RPTABLE', [$contentSchema['ADD_TAB_NAME']]);
$arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable; $arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable;
$arrayError[$i]['PRO_UID'] = $tableProUid; $arrayError[$i]['PRO_UID'] = $tableProUid;
} }
@@ -303,21 +291,21 @@ class ReportTable
if ($flagIsPmTable) { if ($flagIsPmTable) {
$arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME']; $arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$arrayError[$i]['ERROR_TYPE'] = 4; //ERROR_NO_REPORT_TABLE $arrayError[$i]['ERROR_TYPE'] = 4; //ERROR_NO_REPORT_TABLE
$arrayError[$i]['ERROR_MESS'] = \G::LoadTranslation('ID_NO_REPORT_TABLE', [$contentSchema['ADD_TAB_NAME']]); $arrayError[$i]['ERROR_MESS'] = G::LoadTranslation('ID_NO_REPORT_TABLE', [$contentSchema['ADD_TAB_NAME']]);
$arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable; $arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable;
$arrayError[$i]['PRO_UID'] = $tableProUid; $arrayError[$i]['PRO_UID'] = $tableProUid;
} else { } else {
if ($tableProUid !== $processUid) { if ($tableProUid !== $processUid) {
$arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME']; $arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$arrayError[$i]['ERROR_TYPE'] = 5; //ERROR_OVERWRITE_RELATED_PROCESS $arrayError[$i]['ERROR_TYPE'] = 5; //ERROR_OVERWRITE_RELATED_PROCESS
$arrayError[$i]['ERROR_MESS'] = \G::LoadTranslation('ID_OVERWRITE_RELATED_PROCESS', [$contentSchema['ADD_TAB_NAME']]); $arrayError[$i]['ERROR_MESS'] = G::LoadTranslation('ID_OVERWRITE_RELATED_PROCESS', [$contentSchema['ADD_TAB_NAME']]);
$arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable; $arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable;
$arrayError[$i]['PRO_UID'] = $tableProUid; $arrayError[$i]['PRO_UID'] = $tableProUid;
} else { } else {
if ($arrayAdditionalTableData && !$flagOverwrite) { if ($arrayAdditionalTableData && !$flagOverwrite) {
$arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME']; $arrayError[$i]['NAME_TABLE'] = $contentSchema['ADD_TAB_NAME'];
$arrayError[$i]['ERROR_TYPE'] = 3; //ERROR_RP_TABLES_OVERWRITE $arrayError[$i]['ERROR_TYPE'] = 3; //ERROR_RP_TABLES_OVERWRITE
$arrayError[$i]['ERROR_MESS'] = \G::LoadTranslation('ID_OVERWRITE_RPTABLE', [$contentSchema['ADD_TAB_NAME']]); $arrayError[$i]['ERROR_MESS'] = G::LoadTranslation('ID_OVERWRITE_RPTABLE', [$contentSchema['ADD_TAB_NAME']]);
$arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable; $arrayError[$i]['IS_PMTABLE'] = $flagIsPmTable;
$arrayError[$i]['PRO_UID'] = $tableProUid; $arrayError[$i]['PRO_UID'] = $tableProUid;
} }
@@ -330,7 +318,7 @@ class ReportTable
//Return //Return
return $arrayError; return $arrayError;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -351,7 +339,7 @@ class ReportTable
$additionalTableUid = $arrayData['REP_TAB_UID']; $additionalTableUid = $arrayData['REP_TAB_UID'];
$flagNew = 0; $flagNew = 0;
$additionalTables = \AdditionalTablesPeer::retrieveByPK($arrayData['REP_TAB_UID']); $additionalTables = AdditionalTablesPeer::retrieveByPK($arrayData['REP_TAB_UID']);
if (!is_null($additionalTables)) { if (!is_null($additionalTables)) {
$arrayData['REP_TAB_NAME'] = 'PMT_' . trim($arrayData['REP_TAB_NAME']); $arrayData['REP_TAB_NAME'] = 'PMT_' . trim($arrayData['REP_TAB_NAME']);
@@ -365,7 +353,7 @@ class ReportTable
ob_start(); ob_start();
$arrayData['PRO_UID'] = trim($arrayData['PRO_UID']); $arrayData['PRO_UID'] = trim($arrayData['PRO_UID']);
$arrayData['columns'] = \G::json_decode(stripslashes($arrayData['columns'])); //Decofing data columns $arrayData['columns'] = G::json_decode(stripslashes($arrayData['columns'])); //Decofing data columns
if ($flagNew == 1) { if ($flagNew == 1) {
$arrayNewColumn = []; $arrayNewColumn = [];
@@ -387,7 +375,7 @@ class ReportTable
$arrayData['columns'] = $arrayNewColumn; $arrayData['columns'] = $arrayNewColumn;
} }
$additionalTable = new \AdditionalTables(); $additionalTable = new AdditionalTables();
$repTabClassName = $additionalTable->getPHPName($arrayData['REP_TAB_NAME']); $repTabClassName = $additionalTable->getPHPName($arrayData['REP_TAB_NAME']);
$flagIsReportTable = ($arrayData['PRO_UID'] != '') ? true : false; $flagIsReportTable = ($arrayData['PRO_UID'] != '') ? true : false;
@@ -407,7 +395,7 @@ class ReportTable
'old_function', 'or', 'throw', 'protected', 'public', 'static', 'switch', 'xor', 'try', 'use', 'var', 'while' 'old_function', 'or', 'throw', 'protected', 'public', 'static', 'switch', 'xor', 'try', 'use', 'var', 'while'
]; ];
$reservedWordsSql = \G::reservedWordsSql(); $reservedWordsSql = G::reservedWordsSql();
//Verify if exists //Verify if exists
if ($arrayData['REP_TAB_UID'] == '' || (isset($arrayData['forceUid']) && $arrayData['forceUid'])) { if ($arrayData['REP_TAB_UID'] == '' || (isset($arrayData['forceUid']) && $arrayData['forceUid'])) {
@@ -419,23 +407,25 @@ class ReportTable
} }
//Validations //Validations
if ($additionalTable->loadByName($arrayData['REP_TAB_NAME'])) { if (is_array($additionalTable->loadByName($arrayData['REP_TAB_NAME']))) {
throw new \Exception(\G::LoadTranslation('ID_PMTABLE_ALREADY_EXISTS', [$arrayData['REP_TAB_NAME']])); throw new Exception(G::LoadTranslation('ID_PMTABLE_ALREADY_EXISTS', [$arrayData['REP_TAB_NAME']]));
} }
if (in_array(strtoupper($arrayData['REP_TAB_NAME']), $reservedWords) || if (in_array(strtoupper($arrayData['REP_TAB_NAME']), $reservedWords) ||
in_array(strtoupper($arrayData['REP_TAB_NAME']), $reservedWordsSql) in_array(strtoupper($arrayData['REP_TAB_NAME']), $reservedWordsSql)
) { ) {
throw new \Exception(\G::LoadTranslation('ID_PMTABLE_INVALID_NAME', [$arrayData['REP_TAB_NAME']])); throw new Exception(G::LoadTranslation('ID_PMTABLE_INVALID_NAME', [$arrayData['REP_TAB_NAME']]));
} }
} }
$this->validateFieldName($columns);
//Backward compatility //Backward compatility
foreach ($columns as $i => $column) { foreach ($columns as $i => $column) {
if (in_array(strtoupper($columns[$i]->field_name), $reservedWordsSql) || if (in_array(strtoupper($columns[$i]->field_name), $reservedWordsSql) ||
in_array(strtolower($columns[$i]->field_name), $reservedWordsPhp) in_array(strtolower($columns[$i]->field_name), $reservedWordsPhp)
) { ) {
throw new \Exception(\G::LoadTranslation('ID_PMTABLE_INVALID_FIELD_NAME', [$columns[$i]->field_name])); throw new Exception(G::LoadTranslation('ID_PMTABLE_INVALID_FIELD_NAME', [$columns[$i]->field_name]));
} }
switch ($column->field_type) { switch ($column->field_type) {
@@ -536,15 +526,8 @@ class ReportTable
if ($flagIsReportTable && $flagAlterTable) { if ($flagIsReportTable && $flagAlterTable) {
//The table was create successfully but we're catching problems while populating table //The table was create successfully but we're catching problems while populating table
try { try {
$additionalTable->populateReportTable( $additionalTable->populateReportTable($arrayData['REP_TAB_NAME'], $pmTable->getDataSource(), $arrayData['REP_TAB_TYPE'], $arrayData['PRO_UID'], $arrayData['REP_TAB_GRID'], $addTabUid);
$arrayData['REP_TAB_NAME'], } catch (Exception $e) {
$pmTable->getDataSource(),
$arrayData['REP_TAB_TYPE'],
$arrayData['PRO_UID'],
$arrayData['REP_TAB_GRID'],
$addTabUid
);
} catch (\Exception $e) {
$result->message = $result->msg = $e->getMessage(); $result->message = $result->msg = $e->getMessage();
} }
} }
@@ -561,10 +544,7 @@ class ReportTable
} }
} }
\G::auditLog( G::auditLog((isset($arrayData['REP_TAB_UID']) && $arrayData['REP_TAB_UID'] == '') ? 'CreatePmtable' : 'UpdatePmtable', 'Fields: ' . $fieldsName);
(isset($arrayData['REP_TAB_UID']) && $arrayData['REP_TAB_UID'] == '')?
'CreatePmtable' : 'UpdatePmtable', 'Fields: ' . $fieldsName
);
$result->success = true; $result->success = true;
$result->message = $result->msg = $buildResult; $result->message = $result->msg = $buildResult;
@@ -575,12 +555,12 @@ class ReportTable
$pmTablesProxy = new \pmTablesProxy(); $pmTablesProxy = new \pmTablesProxy();
$obj = new \stdClass(); $obj = new \stdClass();
$obj->rows = \G::json_encode([['id' => $additionalTableUid, 'type' => '']]); $obj->rows = G::json_encode([['id' => $additionalTableUid, 'type' => '']]);
//Delete Report Table //Delete Report Table
$resultDeleteReportTable = $pmTablesProxy->delete($obj); $resultDeleteReportTable = $pmTablesProxy->delete($obj);
} }
} catch (\Exception $e) { } catch (Exception $e) {
$buildResult = ob_get_contents(); $buildResult = ob_get_contents();
ob_end_clean(); ob_end_clean();
@@ -593,7 +573,7 @@ class ReportTable
$result->type = ucfirst($pmTable->getDbConfig()->adapter); $result->type = ucfirst($pmTable->getDbConfig()->adapter);
} else { } else {
$result->message = $result->msg = $e->getMessage(); $result->message = $result->msg = $e->getMessage();
$result->type = \G::LoadTranslation('ID_EXCEPTION'); $result->type = G::LoadTranslation('ID_EXCEPTION');
} }
$result->trace = $e->getTraceAsString(); $result->trace = $e->getTraceAsString();
@@ -616,15 +596,8 @@ class ReportTable
* *
* @return string * @return string
*/ */
public function createStructureOfTables( public function createStructureOfTables(array $arrayTableSchema, array $arrayTableData, $processUid, $flagFromAdmin, $flagOverwrite = true, array $arrayTablesToExclude = [], array $arrayTablesToCreate = [])
array $arrayTableSchema, {
array $arrayTableData,
$processUid,
$flagFromAdmin,
$flagOverwrite = true,
array $arrayTablesToExclude = [],
array $arrayTablesToCreate = []
) {
try { try {
$errors = ''; $errors = '';
@@ -636,7 +609,7 @@ class ReportTable
$contentSchema = $value; $contentSchema = $value;
if (!in_array($contentSchema['ADD_TAB_NAME'], $arrayTablesToExclude)) { if (!in_array($contentSchema['ADD_TAB_NAME'], $arrayTablesToExclude)) {
$additionalTable = new \AdditionalTables(); $additionalTable = new AdditionalTables();
$arrayAdditionalTableData = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']); $arrayAdditionalTableData = $additionalTable->loadByName($contentSchema['ADD_TAB_NAME']);
@@ -673,9 +646,9 @@ class ReportTable
//renaming... //renaming...
$tNameOld = $contentSchema['ADD_TAB_NAME']; $tNameOld = $contentSchema['ADD_TAB_NAME'];
$newTableName = $contentSchema['ADD_TAB_NAME'] . '_' . date('YmdHis'); $newTableName = $contentSchema['ADD_TAB_NAME'] . '_' . date('YmdHis');
$contentSchema['ADD_TAB_UID'] = \G::generateUniqueID(); $contentSchema['ADD_TAB_UID'] = G::generateUniqueID();
$contentSchema['ADD_TAB_NAME'] = $newTableName; $contentSchema['ADD_TAB_NAME'] = $newTableName;
$contentSchema['ADD_TAB_CLASS_NAME'] = \AdditionalTables::getPHPName($newTableName); $contentSchema['ADD_TAB_CLASS_NAME'] = AdditionalTables::getPHPName($newTableName);
//Mapping the table name for posterior uses //Mapping the table name for posterior uses
$tableNameMap[$tNameOld] = $contentSchema['ADD_TAB_NAME']; $tableNameMap[$tNameOld] = $contentSchema['ADD_TAB_NAME'];
@@ -711,7 +684,7 @@ class ReportTable
$tableData->REP_TAB_CONNECTION = $contentSchema['DBS_UID']; $tableData->REP_TAB_CONNECTION = $contentSchema['DBS_UID'];
$tableData->REP_TAB_TYPE = (isset($contentSchema['ADD_TAB_TYPE'])) ? $contentSchema['ADD_TAB_TYPE'] : ''; $tableData->REP_TAB_TYPE = (isset($contentSchema['ADD_TAB_TYPE'])) ? $contentSchema['ADD_TAB_TYPE'] : '';
$tableData->REP_TAB_GRID = (isset($contentSchema['ADD_TAB_GRID'])) ? $contentSchema['ADD_TAB_GRID'] : ''; $tableData->REP_TAB_GRID = (isset($contentSchema['ADD_TAB_GRID'])) ? $contentSchema['ADD_TAB_GRID'] : '';
$tableData->columns = \G::json_encode($columns); $tableData->columns = G::json_encode($columns);
$tableData->forceUid = true; $tableData->forceUid = true;
//Save the table //Save the table
@@ -719,13 +692,11 @@ class ReportTable
$result = $this->saveStructureOfTable((array) ($tableData), $alterTable); $result = $this->saveStructureOfTable((array) ($tableData), $alterTable);
if ($result->success) { if ($result->success) {
\G::auditLog( G::auditLog('ImportTable', $contentSchema['ADD_TAB_NAME'] . ' (' . $contentSchema['ADD_TAB_UID'] . ')');
'ImportTable', $contentSchema['ADD_TAB_NAME'] . ' (' . $contentSchema['ADD_TAB_UID'] . ')'
);
$processQueueTables[$contentSchema['DBS_UID']][] = $contentSchema['ADD_TAB_NAME']; $processQueueTables[$contentSchema['DBS_UID']][] = $contentSchema['ADD_TAB_NAME'];
} else { } else {
$errors .= \G::LoadTranslation('ID_ERROR_CREATE_TABLE') . $tableData->REP_TAB_NAME . '-> ' . $result->message . '\n\n'; $errors .= G::LoadTranslation('ID_ERROR_CREATE_TABLE') . $tableData->REP_TAB_NAME . '-> ' . $result->message . '\n\n';
} }
} }
} }
@@ -747,9 +718,38 @@ class ReportTable
//Return //Return
return $errors; return $errors;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
}
/**
* Throw an exception if the column is not valid for the creation of the field
* in the classes managed by propel.
*
* @param array $columns
* @throws Exception
*/
private function validateFieldName($columns)
{
$validFields = [];
$invalidFields = [];
foreach ($columns as $column) {
try {
$fieldName = $column->field_name;
Validator::isValidVariableName($fieldName);
$fieldName = strtolower(AdditionalTables::getPHPName($fieldName));
if (in_array($fieldName, $validFields)) {
$invalidFields[] = $fieldName;
} else {
$validFields[] = $fieldName;
}
} catch (Exception $e) {
$invalidFields[] = $fieldName;
}
}
if (!empty($invalidFields)) {
throw new Exception(G::LoadTranslation('ID_PMTABLE_INVALID_FIELD_NAME_VARIABLE', $invalidFields));
}
}
}

View File

@@ -1,6 +1,10 @@
<?php <?php
namespace ProcessMaker\BusinessModel; namespace ProcessMaker\BusinessModel;
use Exception;
use G;
/** /**
* Validator fields * Validator fields
* *
@@ -26,11 +30,11 @@ class Validator
{ {
$dep_uid = trim($dep_uid); $dep_uid = trim($dep_uid);
if ($dep_uid == '') { if ($dep_uid == '') {
throw (new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array($nameField,'')))); throw (new Exception(G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array($nameField, ''))));
} }
$oDepartment = new \Department(); $oDepartment = new \Department();
if (!($oDepartment->existsDepartment($dep_uid))) { if (!($oDepartment->existsDepartment($dep_uid))) {
throw (new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array($nameField,$dep_uid)))); throw (new Exception(G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array($nameField, $dep_uid))));
} }
return $dep_uid; return $dep_uid;
} }
@@ -51,7 +55,7 @@ class Validator
$dep_status = trim($dep_status); $dep_status = trim($dep_status);
$values = array('ACTIVE', 'INACTIVE'); $values = array('ACTIVE', 'INACTIVE');
if (!in_array($dep_status, $values)) { if (!in_array($dep_status, $values)) {
throw (new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array('dep_status',$dep_status)))); throw (new Exception(G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array('dep_status', $dep_status))));
} }
return $dep_status; return $dep_status;
} }
@@ -72,11 +76,11 @@ class Validator
{ {
$usr_uid = trim($usr_uid); $usr_uid = trim($usr_uid);
if ($usr_uid == '') { if ($usr_uid == '') {
throw (new \Exception(\G::LoadTranslation("ID_USER_NOT_EXIST", array($nameField,'')))); throw (new Exception(G::LoadTranslation("ID_USER_NOT_EXIST", array($nameField, ''))));
} }
$oUsers = new \Users(); $oUsers = new \Users();
if (!($oUsers->userExists($usr_uid))) { if (!($oUsers->userExists($usr_uid))) {
throw (new \Exception(\G::LoadTranslation("ID_USER_NOT_EXIST", array($nameField,$usr_uid)))); throw (new Exception(G::LoadTranslation("ID_USER_NOT_EXIST", array($nameField, $usr_uid))));
} }
return $usr_uid; return $usr_uid;
} }
@@ -97,11 +101,11 @@ class Validator
{ {
$app_uid = trim($app_uid); $app_uid = trim($app_uid);
if ($app_uid == '') { if ($app_uid == '') {
throw (new \Exception(\G::LoadTranslation("ID_APPLICATION_NOT_EXIST", array($nameField,'')))); throw (new Exception(G::LoadTranslation("ID_APPLICATION_NOT_EXIST", array($nameField, ''))));
} }
$oApplication = new \Application(); $oApplication = new \Application();
if (!($oApplication->exists($app_uid))) { if (!($oApplication->exists($app_uid))) {
throw (new \Exception(\G::LoadTranslation("ID_APPLICATION_NOT_EXIST", array($nameField,$app_uid)))); throw (new Exception(G::LoadTranslation("ID_APPLICATION_NOT_EXIST", array($nameField, $app_uid))));
} }
return $app_uid; return $app_uid;
} }
@@ -122,11 +126,11 @@ class Validator
{ {
$tri_uid = trim($tri_uid); $tri_uid = trim($tri_uid);
if ($tri_uid == '') { if ($tri_uid == '') {
throw (new \Exception(\G::LoadTranslation("ID_TRIGGER_NOT_EXIST", array($nameField,'')))); throw (new Exception(G::LoadTranslation("ID_TRIGGER_NOT_EXIST", array($nameField, ''))));
} }
$oTriggers = new \Triggers(); $oTriggers = new \Triggers();
if (!($oTriggers->TriggerExists($tri_uid))) { if (!($oTriggers->TriggerExists($tri_uid))) {
throw (new \Exception(\G::LoadTranslation("ID_TRIGGER_NOT_EXIST", array($nameField,$tri_uid)))); throw (new Exception(G::LoadTranslation("ID_TRIGGER_NOT_EXIST", array($nameField, $tri_uid))));
} }
return $tri_uid; return $tri_uid;
} }
@@ -147,11 +151,11 @@ class Validator
{ {
$pro_uid = trim($pro_uid); $pro_uid = trim($pro_uid);
if ($pro_uid == '') { if ($pro_uid == '') {
throw (new \Exception(\G::LoadTranslation("ID_PROCESS_NOT_EXIST", array($nameField,'')))); throw (new Exception(G::LoadTranslation("ID_PROCESS_NOT_EXIST", array($nameField, ''))));
} }
$oProcess = new \Process(); $oProcess = new \Process();
if (!($oProcess->exists($pro_uid))) { if (!($oProcess->exists($pro_uid))) {
throw (new \Exception(\G::LoadTranslation("ID_PROCESS_NOT_EXIST", array($nameField,$pro_uid)))); throw (new Exception(G::LoadTranslation("ID_PROCESS_NOT_EXIST", array($nameField, $pro_uid))));
} }
return $pro_uid; return $pro_uid;
} }
@@ -172,11 +176,11 @@ class Validator
{ {
$cat_uid = trim($cat_uid); $cat_uid = trim($cat_uid);
if ($cat_uid == '') { if ($cat_uid == '') {
throw (new \Exception(\G::LoadTranslation("ID_CATEGORY_NOT_EXIST", array($nameField,'')))); throw (new Exception(G::LoadTranslation("ID_CATEGORY_NOT_EXIST", array($nameField, ''))));
} }
$oCategory = new \ProcessCategory(); $oCategory = new \ProcessCategory();
if (!($oCategory->exists($cat_uid))) { if (!($oCategory->exists($cat_uid))) {
throw (new \Exception(\G::LoadTranslation("ID_CATEGORY_NOT_EXIST", array($nameField,$cat_uid)))); throw (new Exception(G::LoadTranslation("ID_CATEGORY_NOT_EXIST", array($nameField, $cat_uid))));
} }
return $cat_uid; return $cat_uid;
} }
@@ -197,11 +201,11 @@ class Validator
{ {
$date = trim($date); $date = trim($date);
if ($date == '') { if ($date == '') {
throw (new \Exception(\G::LoadTranslation("ID_DATE_NOT_VALID", array('',$format)))); throw (new Exception(G::LoadTranslation("ID_DATE_NOT_VALID", array('', $format))));
} }
$d = \DateTime::createFromFormat($format, $date); $d = \DateTime::createFromFormat($format, $date);
if (!($d && $d->format($format) == $date)) { if (!($d && $d->format($format) == $date)) {
throw (new \Exception(\G::LoadTranslation("ID_DATE_NOT_VALID", array($date,$format)))); throw (new Exception(G::LoadTranslation("ID_DATE_NOT_VALID", array($date, $format))));
} }
return $date; return $date;
} }
@@ -219,7 +223,7 @@ class Validator
static public function isArray($field, $nameField) static public function isArray($field, $nameField)
{ {
if (!is_array($field)) { if (!is_array($field)) {
throw (new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_ARRAY", array($nameField)))); throw (new Exception(G::LoadTranslation("ID_INVALID_VALUE_ARRAY", array($nameField))));
} }
} }
@@ -236,7 +240,7 @@ class Validator
static public function isString($field, $nameField) static public function isString($field, $nameField)
{ {
if (!is_string($field)) { if (!is_string($field)) {
throw (new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_STRING", array($nameField)))); throw (new Exception(G::LoadTranslation("ID_INVALID_VALUE_STRING", array($nameField))));
} }
} }
@@ -253,7 +257,7 @@ class Validator
static public function isInteger($field, $nameField) static public function isInteger($field, $nameField)
{ {
if (!is_integer($field)) { if (!is_integer($field)) {
throw (new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_INTEGER", array($nameField)))); throw (new Exception(G::LoadTranslation("ID_INVALID_VALUE_INTEGER", array($nameField))));
} }
} }
@@ -270,7 +274,7 @@ class Validator
static public function isBoolean($field, $nameField) static public function isBoolean($field, $nameField)
{ {
if (!is_bool($field)) { if (!is_bool($field)) {
throw (new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_BOOLEAN", array($nameField)))); throw (new Exception(G::LoadTranslation("ID_INVALID_VALUE_BOOLEAN", array($nameField))));
} }
} }
@@ -287,7 +291,21 @@ class Validator
static public function isNotEmpty($field, $nameField) static public function isNotEmpty($field, $nameField)
{ {
if (empty($field)) { if (empty($field)) {
throw (new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_IS_EMPTY", array($nameField)))); throw (new Exception(G::LoadTranslation("ID_INVALID_VALUE_IS_EMPTY", array($nameField))));
}
}
/**
* Validate a variable name
* @param $nameField
* @throws \Exception
* @return void
*/
static public function isValidVariableName($nameField)
{
$resp = preg_match(config('constants.validation.pmVariable.regEx'), $nameField, $matches);
if (isset($resp) && $resp === 0) {
throw (new Exception(G::LoadTranslation("ID_INVALID_NAME", array($nameField))));
} }
} }
@@ -303,9 +321,9 @@ class Validator
{ {
try { try {
if (!is_array($data)) { if (!is_array($data)) {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_THIS_MUST_BE_ARRAY", array($dataNameForException))); throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_THIS_MUST_BE_ARRAY", array($dataNameForException)));
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -322,9 +340,9 @@ class Validator
{ {
try { try {
if (empty($data)) { if (empty($data)) {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($dataNameForException))); throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($dataNameForException)));
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -352,7 +370,7 @@ class Validator
switch (gettype($data)) { switch (gettype($data)) {
case 'string': case 'string':
if (trim($data) != '' && !preg_match('/^' . $regexpIso8601 . '$/', $data)) { if (trim($data) != '' && !preg_match('/^' . $regexpIso8601 . '$/', $data)) {
throw new \Exception(\G::LoadTranslation('ID_ISO8601_INVALID_FORMAT', [(!is_null($field) && is_string($field))? $field : $data])); throw new Exception(G::LoadTranslation('ID_ISO8601_INVALID_FORMAT', [(!is_null($field) && is_string($field)) ? $field : $data]));
} }
break; break;
case 'array': case 'array':
@@ -364,13 +382,13 @@ class Validator
$fieldName = (isset($data[strtolower($fieldName)])) ? strtolower($fieldName) : $fieldName; $fieldName = (isset($data[strtolower($fieldName)])) ? strtolower($fieldName) : $fieldName;
if (isset($data[$fieldName]) && trim($data[$fieldName]) != '' && !preg_match('/^' . $regexpIso8601 . '$/', $data[$fieldName])) { if (isset($data[$fieldName]) && trim($data[$fieldName]) != '' && !preg_match('/^' . $regexpIso8601 . '$/', $data[$fieldName])) {
throw new \Exception(\G::LoadTranslation('ID_ISO8601_INVALID_FORMAT', [$fieldName])); throw new Exception(G::LoadTranslation('ID_ISO8601_INVALID_FORMAT', [$fieldName]));
} }
} }
} }
break; break;
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -403,7 +421,7 @@ class Validator
//Return //Return
return true; return true;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }

View File

@@ -405,6 +405,7 @@ class Variable
if (isset($aData["VAR_NAME"])) { if (isset($aData["VAR_NAME"])) {
Validator::isString($aData['VAR_NAME'], '$var_name'); Validator::isString($aData['VAR_NAME'], '$var_name');
Validator::isNotEmpty($aData['VAR_NAME'], '$var_name'); Validator::isNotEmpty($aData['VAR_NAME'], '$var_name');
Validator::isValidVariableName($aData['VAR_NAME']);
} }
if (isset($aData["VAR_FIELD_TYPE"])) { if (isset($aData["VAR_FIELD_TYPE"])) {
Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type'); Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type');
@@ -462,7 +463,7 @@ class Variable
if ($variableName === $row["VAR_NAME"]) { if ($variableName === $row["VAR_NAME"]) {
throw new Exception(G::LoadTranslation("DYNAFIELD_ALREADY_EXIST")); throw new Exception(G::LoadTranslation("DYNAFIELD_ALREADY_EXIST"));
} }
if (AdditionalTables::getPHPName($variableName) === AdditionalTables::getPHPName($row["VAR_NAME"])) { if (strtolower(AdditionalTables::getPHPName($variableName)) === strtolower(AdditionalTables::getPHPName($row["VAR_NAME"]))) {
throw new Exception(G::LoadTranslation("DYNAFIELD_PHPNAME_ALREADY_EXIST", array($row["VAR_NAME"]))); throw new Exception(G::LoadTranslation("DYNAFIELD_PHPNAME_ALREADY_EXIST", array($row["VAR_NAME"])));
} }
} }