This commit is contained in:
Paula Quispe
2019-05-07 14:25:07 -04:00
25 changed files with 864 additions and 438 deletions

View File

@@ -2128,6 +2128,11 @@ class Cases
*
* @param string $applicationUid Unique id of Case
*
* @see workflow/engine/src/ProcessMaker/Services/Api/Cases.php
* @see workflow/engine/src/ProcessMaker/Services/Api/Light.php
*
* @link https://wiki.processmaker.com/3.3/REST_API_Cases/Cases#Get_Case.27s_Tasks:_GET_.2Fcases.2F.7Bapp_uid.7D.2Ftasks
*
* @return array Return an array with all Tasks of Case
* @throws Exception
*/
@@ -2151,33 +2156,20 @@ class Cases
$taskUid = "";
//Get data
//SQL
$delimiter = DBAdapter::getStringDelimiter();
//Obtain the list of tasks and their respectives users assigned to each one for an specific case
$case = new ClassesCases();
$rsTasks = $case->getTasksInfoForACase($applicationUid, $processUid);
$criteria = new Criteria("workflow");
while ($rsTasks->next()) {
$row = $rsTasks->getRow();
$criteria->addSelectColumn(TaskPeer::TAS_UID);
$criteria->addSelectColumn(TaskPeer::TAS_TITLE);
$criteria->addSelectColumn(TaskPeer::TAS_DESCRIPTION);
$criteria->addSelectColumn(TaskPeer::TAS_START);
$criteria->addSelectColumn(TaskPeer::TAS_TYPE);
$criteria->addSelectColumn(TaskPeer::TAS_DERIVATION);
$criteria->addSelectColumn(TaskPeer::TAS_ASSIGN_TYPE);
$criteria->addSelectColumn(UsersPeer::USR_UID);
$criteria->addSelectColumn(UsersPeer::USR_USERNAME);
$criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME);
$criteria->addSelectColumn(UsersPeer::USR_LASTNAME);
$criteria->addJoin(TaskPeer::TAS_LAST_ASSIGNED, UsersPeer::USR_UID, Criteria::LEFT_JOIN);
$criteria->add(TaskPeer::PRO_UID, $processUid, Criteria::EQUAL);
$rsCriteria = TaskPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//If the task is a multiple task
if ($row["TAS_ASSIGN_TYPE"] == 'MULTIPLE_INSTANCE' || $row["TAS_ASSIGN_TYPE"] == 'MULTIPLE_INSTANCE_VALUE_BASED') {
$row["USR_UID"] = "";
$row["USR_USERNAME"] = "";
$row["USR_FIRSTNAME"] = "";
$row["USR_LASTNAME"] = "";
}
//Task
if ($row["TAS_TYPE"] == "NORMAL") {
@@ -2189,17 +2181,9 @@ class Cases
$row["TAS_TITLE"] = $task->getTasTitle();
}
} else {
$criteria2 = new Criteria("workflow");
$criteria2->addSelectColumn(SubProcessPeer::PRO_UID);
$criteria2->addSelectColumn(TaskPeer::TAS_TITLE);
$criteria2->addSelectColumn(TaskPeer::TAS_DESCRIPTION);
$criteria2->addJoin(SubProcessPeer::TAS_PARENT, TaskPeer::TAS_UID, Criteria::LEFT_JOIN);
$criteria2->add(SubProcessPeer::PRO_PARENT, $processUid);
$criteria2->add(SubProcessPeer::TAS_PARENT, $row["TAS_UID"]);
$rsCriteria2 = SubProcessPeer::doSelectRS($criteria2);
$rsCriteria2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
//Get the task information when the task type is different from normal
$rsCriteria2 = $case->getTaskInfoForSubProcess($processUid, $row["TAS_UID"]);
$rsCriteria2->next();
@@ -2215,18 +2199,8 @@ class Cases
$routeType = "";
$arrayRoute = array();
$criteria2 = new Criteria("workflow");
$criteria2->addAsColumn("ROU_NUMBER", RoutePeer::ROU_CASE);
$criteria2->addSelectColumn(RoutePeer::ROU_TYPE);
$criteria2->addSelectColumn(RoutePeer::ROU_CONDITION);
$criteria2->addAsColumn("TAS_UID", RoutePeer::ROU_NEXT_TASK);
$criteria2->add(RoutePeer::PRO_UID, $processUid, Criteria::EQUAL);
$criteria2->add(RoutePeer::TAS_UID, $row["TAS_UID"], Criteria::EQUAL);
$criteria2->addAscendingOrderByColumn("ROU_NUMBER");
$rsCriteria2 = RoutePeer::doSelectRS($criteria2);
$rsCriteria2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
//Get the routes of a task
$rsCriteria2 = $case->getTaskRoutes($processUid, $row["TAS_UID"]);
while ($rsCriteria2->next()) {
$row2 = $rsCriteria2->getRow();
@@ -2243,25 +2217,7 @@ class Cases
//Delegations
$arrayAppDelegation = array();
$criteria2 = new Criteria("workflow");
$criteria2->addSelectColumn(AppDelegationPeer::DEL_INDEX);
$criteria2->addSelectColumn(AppDelegationPeer::DEL_INIT_DATE);
$criteria2->addSelectColumn(AppDelegationPeer::DEL_TASK_DUE_DATE);
$criteria2->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
$criteria2->addSelectColumn(UsersPeer::USR_UID);
$criteria2->addSelectColumn(UsersPeer::USR_USERNAME);
$criteria2->addSelectColumn(UsersPeer::USR_FIRSTNAME);
$criteria2->addSelectColumn(UsersPeer::USR_LASTNAME);
$criteria2->addJoin(AppDelegationPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN);
$criteria2->add(AppDelegationPeer::APP_UID, $applicationUid, Criteria::EQUAL);
$criteria2->add(AppDelegationPeer::TAS_UID, $row["TAS_UID"], Criteria::EQUAL);
$criteria2->addAscendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
$rsCriteria2 = AppDelegationPeer::doSelectRS($criteria2);
$rsCriteria2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$rsCriteria2 = $case->getCaseDelegations($applicationUid, $row["TAS_UID"]);
while ($rsCriteria2->next()) {
$row2 = $rsCriteria2->getRow();
@@ -2292,8 +2248,10 @@ class Cases
$appDelegationDuration = G::LoadTranslation("ID_NOT_FINISHED");
if (!empty($row2["DEL_FINISH_DATE"]) && !empty($row2["DEL_INIT_DATE"])) {
$t = strtotime($row2["DEL_FINISH_DATE"]) - strtotime($row2["DEL_INIT_DATE"]);
$date = empty($row2["DEL_INIT_DATE"]) ? $row2["DEL_DELEGATE_DATE"] : $row2["DEL_INIT_DATE"];
if (!empty($row2["DEL_FINISH_DATE"]) && !empty($date)) {
$t = strtotime($row2["DEL_FINISH_DATE"]) - strtotime($date);
$h = $t * (1 / 60) * (1 / 60);
$m = ($h - (int)($h)) * (60 / 1);
@@ -2314,40 +2272,22 @@ class Cases
$this->getFieldNameByFormatFieldName("DEL_FINISH_DATE") => $arrayAppDelegationDate["DEL_FINISH_DATE"]["dateFormated"],
$this->getFieldNameByFormatFieldName("DEL_DURATION") => $appDelegationDuration,
$this->getFieldNameByFormatFieldName("USR_UID") => $row2["USR_UID"],
$this->getFieldNameByFormatFieldName("USR_USERNAME") => $row2["USR_USERNAME"] . "",
$this->getFieldNameByFormatFieldName("USR_FIRSTNAME") => $row2["USR_FIRSTNAME"] . "",
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $row2["USR_LASTNAME"] . ""
$this->getFieldNameByFormatFieldName("USR_USERNAME") => $row2["USR_USERNAME"],
$this->getFieldNameByFormatFieldName("USR_FIRSTNAME") => $row2["USR_FIRSTNAME"],
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $row2["USR_LASTNAME"]
);
}
//Status
$status = "";
//$criteria2
$criteria2 = new Criteria("workflow");
$criteria2->addAsColumn("CANT", "COUNT(" . AppDelegationPeer::APP_UID . ")");
$criteria2->addAsColumn("FINISH", "MIN(" . AppDelegationPeer::DEL_FINISH_DATE . ")");
$criteria2->add(AppDelegationPeer::APP_UID, $applicationUid, Criteria::EQUAL);
$criteria2->add(AppDelegationPeer::TAS_UID, $row["TAS_UID"], Criteria::EQUAL);
$rsCriteria2 = AppDelegationPeer::doSelectRS($criteria2);
$rsCriteria2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$rsCriteria2 = $case->getTotalAndMinDateForACase($applicationUid, $row["TAS_UID"]);
$rsCriteria2->next();
$row2 = $rsCriteria2->getRow();
//$criteria3
$criteria3 = new Criteria("workflow");
$criteria3->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
$criteria3->add(AppDelegationPeer::APP_UID, $applicationUid, Criteria::EQUAL);
$criteria3->add(AppDelegationPeer::TAS_UID, $row["TAS_UID"], Criteria::EQUAL);
$criteria3->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
$rsCriteria3 = AppDelegationPeer::doSelectRS($criteria3);
$rsCriteria3->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$rsCriteria3 = $case->getDelegationFinishDate($applicationUid, $row["TAS_UID"]);
$rsCriteria3->next();

View File

@@ -1,7 +1,10 @@
<?php
namespace ProcessMaker\BusinessModel;
use G;
use Exception;
use PmDynaform;
use ProcessMaker\Util\PhpShorthandByte;
class InputDocument
{
@@ -288,7 +291,10 @@ class InputDocument
* @param string $processUid Unique id of Process
* @param array $arrayData Data
*
* return array Return data of the new InputDocument created
* @return array Return data of the new InputDocument created
*
* @see \ProcessMaker\Services\Api\Project\InputDocument->doPostInputDocument()
* @link https://wiki.processmaker.com/3.0/Input_Documents#Creating_Input_Documents
*/
public function create($processUid, $arrayData)
{
@@ -310,6 +316,8 @@ class InputDocument
$flagDataDestinationPath = (isset($arrayData["INP_DOC_DESTINATION_PATH"]))? 1 : 0;
$flagDataTags = (isset($arrayData["INP_DOC_TAGS"]))? 1 : 0;
$this->throwExceptionIfMaximumFileSizeExceed(intval($arrayData["INP_DOC_MAX_FILESIZE"]), $arrayData["INP_DOC_MAX_FILESIZE_UNIT"]);
//Create
$inputDocument = new \InputDocument();
@@ -348,8 +356,11 @@ class InputDocument
*
* @param string $inputDocumentUid Unique id of InputDocument
* @param array $arrayData Data
*
* return array Return data of the InputDocument updated
*
* @return array Return data of the InputDocument updated
*
* @see \ProcessMaker\Services\Api\Project\InputDocument->doPutInputDocument()
* @link https://wiki.processmaker.com/3.0/Input_Documents#Creating_Input_Documents
*/
public function update($inputDocumentUid, $arrayData)
{
@@ -374,6 +385,8 @@ class InputDocument
if (isset($arrayData["INP_DOC_TITLE"])) {
$this->throwExceptionIfExistsTitle($processUid, $arrayData["INP_DOC_TITLE"], $this->arrayFieldNameForException["inputDocumentTitle"], $inputDocumentUid);
}
$this->throwExceptionIfMaximumFileSizeExceed(intval($arrayData["INP_DOC_MAX_FILESIZE"]), $arrayData["INP_DOC_MAX_FILESIZE_UNIT"]);
//Update
$arrayData["INP_DOC_UID"] = $inputDocumentUid;
@@ -519,7 +532,7 @@ class InputDocument
*
* @param string $inputDocumentUid Unique id of InputDocument
*
* return array Return an array with data of an InputDocument
* @return array Return an array with data of an InputDocument
*/
public function getInputDocument($inputDocumentUid)
{
@@ -544,5 +557,71 @@ class InputDocument
throw $e;
}
}
/**
* Throw exception if maximum file size exceed to php directives.
*
* @param int $value
* @param string $unit
* @throws Exception
*
* @see ProcessMaker\BusinessModel\InputDocument->create()
* @see ProcessMaker\BusinessModel\InputDocument->update()
* @link https://wiki.processmaker.com/3.2/Input_Documents
*/
public function throwExceptionIfMaximumFileSizeExceed($value, $unit)
{
//The value of 'INP_DOC_MAX_FILESIZE_UNIT' can only take two values: 'KB'and 'MB'.
if ($unit === "MB") {
$value = $value * (1024 ** 2);
}
if ($unit === "KB") {
$value = $value * (1024 ** 1);
}
$object = $this->getMaxFileSize();
if ($object->uploadMaxFileSizeBytes < $value) {
throw new Exception(G::LoadTranslation("ID_THE_MAXIMUM_VALUE_OF_THIS_FIELD_IS", [$object->uploadMaxFileSize]));
}
}
/**
* To upload large files, post_max_size value must be larger than upload_max_filesize.
* Generally speaking, memory_limit should be larger than post_max_size. When an integer
* is used, the value is measured in bytes. The shorthand notation may also be used.
* If the size of post data is greater than post_max_size, the $_POST and $_FILES
* superglobals are empty.
*
* @return object
*
* @see ProcessMaker\BusinessModel\InputDocument->throwExceptionIfMaximumFileSizeExceed()
* @link https://wiki.processmaker.com/3.2/Input_Documents
* @link http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
*/
public function getMaxFileSize()
{
$phpShorthandByte = new PhpShorthandByte();
$postMaxSize = ini_get("post_max_size");
$postMaxSizeBytes = $phpShorthandByte->valueToBytes($postMaxSize);
$uploadMaxFileSize = ini_get("upload_max_filesize");
$uploadMaxFileSizeBytes = $phpShorthandByte->valueToBytes($uploadMaxFileSize);
if ($postMaxSizeBytes < $uploadMaxFileSizeBytes) {
$uploadMaxFileSize = $postMaxSize;
$uploadMaxFileSizeBytes = $postMaxSizeBytes;
}
//according to the acceptance criteria the information is always shown in MBytes
$uploadMaxFileSizeMBytes = $uploadMaxFileSizeBytes / (1024 ** 2); //conversion constant
$uploadMaxFileSizeUnit = "MB"; //short processmaker notation, https://wiki.processmaker.com/3.0/File_control#Size_Unity
$uploadMaxFileSizePhpUnit = "M"; //short php notation, http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
$result = [
"uploadMaxFileSize" => $phpShorthandByte->getFormatBytes($uploadMaxFileSizeMBytes . $uploadMaxFileSizePhpUnit),
"uploadMaxFileSizeBytes" => $uploadMaxFileSizeBytes,
"uploadMaxFileSizeMBytes" => $uploadMaxFileSizeMBytes,
"uploadMaxFileSizeUnit" => $uploadMaxFileSizeUnit
];
return (object) $result;
}
}

View File

@@ -1490,6 +1490,7 @@ class Light
}
$response['listLanguage'] = $languagesList;
if (isset($params['fileLimit']) && $params['fileLimit']) {
//to do: ProcessMaker\BusinessModel\InputDocument->getMaxFileSize()
$postMaxSize = $this->return_bytes(ini_get('post_max_size'));
$uploadMaxFileSize = $this->return_bytes(ini_get('upload_max_filesize'));
if ($postMaxSize < $uploadMaxFileSize) {

View File

@@ -117,7 +117,7 @@ class ProcessMap
$tmpData[5] = "";
$tmpData[6] = $lanes['lan_name'];
$tmpData[7] = "";
$tmpData[8] = $lanes['lan_uid'];
$tmpData[8] = array_key_exists('lan_uid', $lanes) ? $lanes['lan_uid']: "";
$tmpData[9] = "";
$tmpData[10] = $lanes['bou_container'];
@@ -719,7 +719,7 @@ class ProcessMap
if($element['bou_container'] != "bpmnDiagram"){
$resRec = $this->getNewPoints($element['bou_element'],$element['bou_container']);
}
if($element['lns_uid'] == $idElement || $element['lan_uid'] == $idElement){
if ($element['lns_uid'] == $idElement || (array_key_exists('lan_uid', $element) ? $element['lan_uid'] == $idElement : false)) {
$result = array($element['bou_x'] + $resRec[0],$element['bou_y'] + $resRec[1]);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace ProcessMaker\Util;
class PhpShorthandByte
{
private $units;
private $terminal;
/**
* Constructor.
* Supported format php directives:
* [number]G
* [number]K
* [number]M
*/
function __construct()
{
$this->units = ['K', 'M', 'G'];
$this->terminal = "bytes";
}
/**
* Convert value string to bytes, for directives php.ini
*
* @param string $value
* @return integer
*
* @see ProcessMaker\BusinessModel\InputDocument->getMaxFileSize()
* @link http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
*/
public function valueToBytes($value)
{
foreach ($this->units as $i => $unit) {
$number = $this->getNumberValue($value, $unit);
if ($number !== null) {
$result = $number * (1024 ** ($i + 1));
return $result;
}
}
return intval($value);
}
/**
* Get number value and validate expresion.
* Valid expresion is: [number][unit]
*
* @param string $string
* @param string $unit
* @return integer|null
*
* @see ProcessMaker\Util\PhpShorthandByte->valueToBytes()
* @link http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
*/
public function getNumberValue($string, $unit)
{
$string = preg_replace('/\s+/', '', $string);
$isCorrect = preg_match("/\d+{$unit}/", $string);
if ($isCorrect === 1) {
$result = rtrim($string, $unit);
return intval($result);
}
return null;
}
/**
* Get format bytes.
*
* @param string $value
* @return string
*/
public function getFormatBytes($value)
{
foreach ($this->units as $i => $unit) {
$number = $this->getNumberValue($value, $unit);
if ($number !== null) {
return $number . " " . $unit . $this->terminal;
}
}
return $value;
}
}

View File

@@ -8,6 +8,7 @@ use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Cache;
use ProcessMaker\Core\System;
use ProcessMaker\Services\OAuth2\Server;
use ProcessMaker\Util\PhpShorthandByte;
use Symfony\Component\HttpFoundation\File\File;
class ValidationUploadedFiles
@@ -169,6 +170,8 @@ class ValidationUploadedFiles
* File upload validation.
*
* @return $this
*
* @see workflow/public_html/sysGeneric.php
*/
public function runRulesToAllUploadedFiles()
{
@@ -177,6 +180,12 @@ class ValidationUploadedFiles
return;
}
$this->fails = [];
$validator = $this->runRulesForFileEmpty();
if ($validator->fails()) {
$this->fails[] = $validator;
}
foreach ($files as $file) {
$data = (object) $file;
if (!is_array($data->name) || !is_array($data->tmp_name)) {
@@ -207,9 +216,70 @@ class ValidationUploadedFiles
}
}
}
return $this;
}
/**
* Run rules if files is empty.
*
* @see ProcessMaker\Validation\ValidationUploadedFiles->runRulesToAllUploadedFiles()
* @see Luracast\Restler\Format\UploadFormat->decode()
*/
public function runRulesForFileEmpty()
{
$validator = new Validator();
//rule: validate $_SERVER['CONTENT_LENGTH']
$rule = $validator->addRule();
$rule->validate(null, function($file) use ($rule) {
//according to the acceptance criteria the information is always shown in MBytes
$phpShorthandByte = new PhpShorthandByte();
$postMaxSize = ini_get("post_max_size");
$postMaxSizeBytes = $phpShorthandByte->valueToBytes($postMaxSize);
$uploadMaxFileSize = ini_get("upload_max_filesize");
$uploadMaxFileSizeBytes = $phpShorthandByte->valueToBytes($uploadMaxFileSize);
if ($postMaxSizeBytes < $uploadMaxFileSizeBytes) {
$uploadMaxFileSize = $postMaxSize;
$uploadMaxFileSizeBytes = $postMaxSizeBytes;
}
//according to the acceptance criteria the information is always shown in MBytes
$uploadMaxFileSizeMBytes = $uploadMaxFileSizeBytes / (1024 ** 2); //conversion constant
$message = G::LoadTranslation('ID_THE_FILE_SIZE_IS_BIGGER_THAN_THE_MAXIMUM_ALLOWED', [$uploadMaxFileSizeMBytes]);
$rule->message($message);
/**
* If you can, you may want to set post_max_size to a low value (say 1M) to make
* testing easier. First test to see how your script behaves. Try uploading a file
* that is larger than post_max_size. If you do you will get a message like this
* in your error log:
*
* [09-Jun-2010 19:28:01] PHP Warning: POST Content-Length of 30980857 bytes exceeds
* the limit of 2097152 bytes in Unknown on line 0
*
* This makes the script is not completed.
*
* Solving the problem:
* The PHP documentation http://php.net/manual/en/ini.core.php#ini.post-max-size
* provides a hack to solve this problem:
*
* If the size of post data is greater than post_max_size, the $_POST and $_FILES
* superglobals are empty.
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0) {
return true;
}
return false;
})
->status(400)
->log(function($rule) {
Bootstrap::registerMonologPhpUploadExecution('phpUpload', 400, $rule->getMessage(), "");
});
return $validator->validate();
}
/**
* Get the first error and call the argument function.
*