Merge branch 'develop' of https://bitbucket.org/colosa/processmaker into feature/PMCORE-1444
This commit is contained in:
@@ -14,6 +14,7 @@ use AppHistoryPeer;
|
||||
use Application;
|
||||
use ApplicationPeer;
|
||||
use Applications;
|
||||
use AppNotes;
|
||||
use AppNotesPeer;
|
||||
use AppSolr;
|
||||
use BasePeer;
|
||||
@@ -40,12 +41,16 @@ use ProcessMaker\BusinessModel\Task as BmTask;
|
||||
use ProcessMaker\BusinessModel\User as BmUser;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Exception\UploadException;
|
||||
use ProcessMaker\Exception\CaseNoteUploadFile;
|
||||
use ProcessMaker\Model\Application as ModelApplication;
|
||||
use ProcessMaker\Model\AppNotes as Notes;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Documents;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
use ProcessMaker\Services\OAuth2\Server;
|
||||
use ProcessMaker\Util\DateTime as UtilDateTime;
|
||||
use ProcessMaker\Validation\ExceptionRestApi;
|
||||
use ProcessMaker\Validation\ValidationUploadedFiles;
|
||||
use ProcessMaker\Validation\Validator as FileValidator;
|
||||
use ProcessPeer;
|
||||
use ProcessUser;
|
||||
@@ -3843,6 +3848,186 @@ class Cases
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a case note
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param string $userUid
|
||||
* @param string $note
|
||||
* @param bool $sendMail
|
||||
* @param array $files
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function addNote($appUid, $userUid, $note, $sendMail = false, $files = [])
|
||||
{
|
||||
// Register the note
|
||||
$attributes = [
|
||||
"APP_UID" => $appUid,
|
||||
"USR_UID" => $userUid,
|
||||
"NOTE_DATE" => date("Y-m-d H:i:s"),
|
||||
"NOTE_CONTENT" => $note,
|
||||
"NOTE_TYPE" => "USER",
|
||||
"NOTE_AVAILABILITY" => "PUBLIC",
|
||||
"NOTE_RECIPIENTS" => ""
|
||||
];
|
||||
$newNote = Notes::create($attributes);
|
||||
// Get the FK
|
||||
$noteId = $newNote->NOTE_ID;
|
||||
|
||||
$attachments = [];
|
||||
// Register the files related to the note
|
||||
if (!empty($files) || !empty($_FILES["filesToUpload"])) {
|
||||
$filesResponse = $this->uploadFilesInCaseNotes($userUid, $appUid, $files, $noteId);
|
||||
foreach ($filesResponse['attachments'] as $key => $value) {
|
||||
$attachments[$key] = [];
|
||||
$attachments[$key]['APP_DOC_FILENAME'] = $value['APP_DOC_FILENAME'];
|
||||
$attachments[$key]['LINK'] = "../cases/casesShowCaseNotes?a=" . $value["APP_DOC_UID"] . "&v=" . $value["DOC_VERSION"];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Send the email
|
||||
if ($sendMail) {
|
||||
// Get the recipients
|
||||
$case = new ClassesCases();
|
||||
$p = $case->getUsersParticipatedInCase($appUid, 'ACTIVE');
|
||||
$noteRecipientsList = [];
|
||||
|
||||
foreach ($p["array"] as $key => $userParticipated) {
|
||||
if ($key != '') {
|
||||
$noteRecipientsList[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$noteRecipients = implode(",", $noteRecipientsList);
|
||||
$note = stripslashes($note);
|
||||
|
||||
// Send the notification
|
||||
$appNote = new AppNotes();
|
||||
$appNote->sendNoteNotification($appUid, $userUid, $note, $noteRecipients, '', 0, $noteId);
|
||||
}
|
||||
|
||||
// Prepare the response
|
||||
$result = [];
|
||||
$result['success'] = 'success';
|
||||
$result['message'] = '';
|
||||
$result['attachments'] = $attachments;
|
||||
$result['attachment_errors'] = [];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload file related to the case notes
|
||||
*
|
||||
* @param string $userUid
|
||||
* @param string $appUid
|
||||
* @param array $filesReferences
|
||||
* @param int $noteId
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function uploadFilesInCaseNotes($userUid, $appUid, $filesReferences = [], $noteId = 0)
|
||||
{
|
||||
$files = [];
|
||||
if (!empty($_FILES["filesToUpload"])) {
|
||||
$upload = true;
|
||||
// This format is from ext-js multipart
|
||||
$filesName = !empty($_FILES["filesToUpload"]["name"]) ? $_FILES["filesToUpload"]["name"] : [];
|
||||
$filesTmpName = !empty($_FILES["filesToUpload"]["tmp_name"]) ? $_FILES["filesToUpload"]["tmp_name"] : [];
|
||||
$filesError = !empty($_FILES["filesToUpload"]["error"]) ? $_FILES["filesToUpload"]["error"] : [];
|
||||
|
||||
foreach ($filesName as $index => $value) {
|
||||
if (!empty($value)) {
|
||||
$files[] = [
|
||||
'name' => $filesName[$index],
|
||||
'tmp_name' => $filesTmpName[$index],
|
||||
'error' => $filesError[$index]
|
||||
];
|
||||
}
|
||||
}
|
||||
} elseif (!empty($filesReferences)) {
|
||||
$upload = false;
|
||||
// Array with path references
|
||||
foreach ($filesReferences as $fileIndex => $fileName) {
|
||||
$nameFile = !is_numeric($fileIndex) ? basename($fileIndex) : basename($fileName);
|
||||
$files[] = [
|
||||
'name' => $nameFile,
|
||||
'tmp_name' => $fileName,
|
||||
'error' => UPLOAD_ERR_OK
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
//rules validation
|
||||
foreach ($files as $key => $value) {
|
||||
$entry = [
|
||||
"filename" => $value['name'],
|
||||
"path" => $value['tmp_name']
|
||||
];
|
||||
$validator = ValidationUploadedFiles::getValidationUploadedFiles()
|
||||
->runRulesForPostFilesOfNote($entry);
|
||||
if ($validator->fails()) {
|
||||
Notes::where('NOTE_ID', '=', $noteId)->delete();
|
||||
$messageError = G::LoadTranslation('ID_THE_FILE_COULDNT_BE_UPLOADED');
|
||||
throw new CaseNoteUploadFile($messageError . ' ' . $validator->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Get the delIndex related to the case
|
||||
$cases = new ClassesCases();
|
||||
$delIndex = $cases->getCurrentDelegation($appUid);
|
||||
|
||||
// We will to register the files in the database
|
||||
$response = [];
|
||||
$response['attachments'] = [];
|
||||
$response['attachment_errors'] = [];
|
||||
if (!empty($files)) {
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
foreach ($files as $fileIndex => $fileName) {
|
||||
// There is no error, the file uploaded with success
|
||||
if ($fileName["error"] === UPLOAD_ERR_OK) {
|
||||
$appDocUid = G::generateUniqueID();
|
||||
|
||||
// Upload or move the file
|
||||
$isUploaded = saveAppDocument($fileName, $appUid, $appDocUid, 1, $upload);
|
||||
|
||||
// If the file was uploaded correctly we will to register in the DB
|
||||
if ($isUploaded) {
|
||||
$attributes = [
|
||||
"DOC_ID" => $noteId,
|
||||
"APP_DOC_UID" => $appDocUid,
|
||||
"DOC_VERSION" => 1,
|
||||
"APP_UID" => $appUid,
|
||||
"DEL_INDEX" => $delIndex,
|
||||
"USR_UID" => $userUid,
|
||||
"DOC_UID" => -1,
|
||||
"APP_DOC_TYPE" => 'CASE_NOTE',
|
||||
"APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"),
|
||||
"APP_DOC_FILENAME" => $fileName["name"]
|
||||
];
|
||||
Documents::create($attributes);
|
||||
|
||||
// List of files uploaded or copy
|
||||
$response['attachments'][$i++] = $attributes;
|
||||
} else {
|
||||
$response['attachment_errors'][$j++] = [
|
||||
'error' => 'error',
|
||||
'file' => $fileName["name"]
|
||||
];
|
||||
}
|
||||
} else {
|
||||
throw new UploadException($fileName['error']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the validations related to an Input Document
|
||||
*
|
||||
|
||||
@@ -1178,7 +1178,9 @@ class DynaForm
|
||||
}
|
||||
foreach ($oldColumns as $oldColumn) {
|
||||
if (strtolower(AdditionalTables::getPHPName($column->id)) === strtolower(AdditionalTables::getPHPName($oldColumn->id))) {
|
||||
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
|
||||
if (strtolower(AdditionalTables::getPHPName($column->var_name)) === strtolower(AdditionalTables::getPHPName($oldColumn->var_name))) {
|
||||
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel\Factories;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
|
||||
class Jobs
|
||||
{
|
||||
const CLASS_NAMESPACE = "App\\Jobs\\";
|
||||
|
||||
/**
|
||||
* Gets the full name of the class, if the class does not exist, an exception is thrown.
|
||||
* @param string $name
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getClassName($name)
|
||||
{
|
||||
$className = self::CLASS_NAMESPACE . $name;
|
||||
|
||||
if (!class_exists($className)) {
|
||||
throw new Exception("{$className} not exists.");
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets an instance of some Job defined in App\Jobs and dispatch this job.
|
||||
* @param string $name
|
||||
* @param Closure $closure
|
||||
* @return object
|
||||
*/
|
||||
public static function create($name, Closure $closure)
|
||||
{
|
||||
$jobName = self::getClassName($name);
|
||||
|
||||
$instance = $jobName::dispatch($closure);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,16 @@ class Variable
|
||||
'object' => 10
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the variables types accepted
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariableTypes()
|
||||
{
|
||||
return $this->variableTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Variable for a Process
|
||||
*
|
||||
@@ -355,6 +365,33 @@ class Variable
|
||||
return $arrayVariables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of Variables related to the specific type
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param int $typeVarId
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
* @param string $search
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return array, return an array with varaibles filter by type
|
||||
*/
|
||||
public function getVariablesByType($processUid, $typeVarId = 0, $start = null, $limit = null, $search = null, $prefix = null)
|
||||
{
|
||||
//Verify data
|
||||
$proId = Validator::proUid($processUid, '$prj_uid');
|
||||
$variables = ProcessVariables::getVariablesByType($proId, $typeVarId, $start, $limit, $search);
|
||||
$arrayVariables = [];
|
||||
foreach ($variables as $var) {
|
||||
$arrayVariables[] = [
|
||||
'value' => is_null($prefix) ? $var['VAR_NAME'] : $prefix . $var['VAR_NAME'],
|
||||
];
|
||||
}
|
||||
|
||||
return $arrayVariables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify field definition
|
||||
*
|
||||
|
||||
332
workflow/engine/src/ProcessMaker/Cases/CasesTrait.php
Normal file
332
workflow/engine/src/ProcessMaker/Cases/CasesTrait.php
Normal file
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Cases;
|
||||
|
||||
use AbeResponses;
|
||||
use AppDelegation;
|
||||
use AppDelegationPeer;
|
||||
use AppDocumentDrive;
|
||||
use BasePeer;
|
||||
use Cases;
|
||||
use Derivation;
|
||||
use Event;
|
||||
use Exception;
|
||||
use G;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use PMLicensedFeatures;
|
||||
use ProcessMaker\BusinessModel\Cases\InputDocument;
|
||||
use ProcessMaker\BusinessModel\Pmgmail;
|
||||
use ProcessMaker\ChangeLog\ChangeLog;
|
||||
use stdClass;
|
||||
use Users;
|
||||
use WsBase;
|
||||
|
||||
trait CasesTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* This initiates the routing of the case given the application and the form
|
||||
* data in the web application interface.
|
||||
* @param string $processUid
|
||||
* @param string $application
|
||||
* @param array $postForm
|
||||
* @param string $status
|
||||
* @param boolean $flagGmail
|
||||
* @param string $tasUid
|
||||
* @param integer $index
|
||||
* @param string $userLogged
|
||||
* @return stdClass
|
||||
*/
|
||||
public function routeCase($processUid, $application, $postForm, $status, $flagGmail, $tasUid, $index, $userLogged): stdClass
|
||||
{
|
||||
//warning: we are not using the result value of function thisIsTheCurrentUser, so I'm commenting to optimize speed.
|
||||
$appFields = $this->loadCase($application);
|
||||
$appFields['APP_DATA'] = array_merge($appFields['APP_DATA'], G::getSystemConstants());
|
||||
|
||||
$triggerDebug = [];
|
||||
$triggers = $this->loadTriggers($tasUid, 'ASSIGN_TASK', -2, 'BEFORE');
|
||||
|
||||
//if there are some triggers to execute
|
||||
if (sizeof($triggers) > 0) {
|
||||
//Execute triggers before derivation
|
||||
$appFields['APP_DATA'] = $this->executeTriggers($tasUid, 'ASSIGN_TASK', -2, 'BEFORE', $appFields['APP_DATA']);
|
||||
|
||||
//save trigger variables for debugger
|
||||
$triggerDebug[] = [
|
||||
'NUM_TRIGGERS' => sizeof($triggers),
|
||||
'TIME' => G::toUpper(G::loadTranslation('ID_BEFORE')),
|
||||
'TRIGGERS_NAMES' => array_column($triggers, 'TRI_TITLE'),
|
||||
'TRIGGERS_VALUES' => $triggers,
|
||||
'TRIGGERS_EXECUTION_TIME' => $this->arrayTriggerExecutionTime
|
||||
];
|
||||
}
|
||||
|
||||
unset($appFields['APP_STATUS']);
|
||||
unset($appFields['APP_PROC_STATUS']);
|
||||
unset($appFields['APP_PROC_CODE']);
|
||||
unset($appFields['APP_PIN']);
|
||||
|
||||
$appFields["DEL_INDEX"] = $index;
|
||||
$appFields["TAS_UID"] = $tasUid;
|
||||
$appFields["USER_UID"] = $userLogged;
|
||||
$appFields["CURRENT_DYNAFORM"] = "-2";
|
||||
$appFields["OBJECT_TYPE"] = "ASSIGN_TASK";
|
||||
|
||||
//save data
|
||||
$this->updateCase($application, $appFields);
|
||||
|
||||
//prepare information for the derivation
|
||||
$derivation = new Derivation();
|
||||
$currentDerivation = [
|
||||
'APP_UID' => $application,
|
||||
'DEL_INDEX' => $index,
|
||||
'APP_STATUS' => $status,
|
||||
'TAS_UID' => $tasUid,
|
||||
'ROU_TYPE' => $postForm['ROU_TYPE']
|
||||
];
|
||||
$dataForPrepareInfo = [
|
||||
'USER_UID' => $userLogged,
|
||||
'APP_UID' => $application,
|
||||
'DEL_INDEX' => $index
|
||||
];
|
||||
|
||||
//we define some parameters in the before the derivation
|
||||
//then this function will be route the case
|
||||
$arrayDerivationResult = $derivation->beforeDerivate(
|
||||
$dataForPrepareInfo,
|
||||
$postForm['TASKS'],
|
||||
$postForm['ROU_TYPE'],
|
||||
$currentDerivation
|
||||
);
|
||||
|
||||
if (!empty($arrayDerivationResult)) {
|
||||
foreach ($postForm['TASKS'] as $key => $value) {
|
||||
if (isset($value['TAS_UID'])) {
|
||||
foreach ($arrayDerivationResult as $value2) {
|
||||
if ($value2['TAS_UID'] == $value['TAS_UID']) {
|
||||
$postForm['TASKS'][$key]['DEL_INDEX'] = $value2['DEL_INDEX'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$appFields = $this->loadCase($application); //refresh appFields, because in derivations should change some values
|
||||
$triggers = $this->loadTriggers($tasUid, 'ASSIGN_TASK', -2, 'AFTER'); //load the triggers after derivation
|
||||
if (sizeof($triggers) > 0) {
|
||||
$appFields['APP_DATA'] = $this->ExecuteTriggers($tasUid, 'ASSIGN_TASK', -2, 'AFTER', $appFields['APP_DATA']); //Execute triggers after derivation
|
||||
|
||||
$triggerDebug[] = [
|
||||
'NUM_TRIGGERS' => sizeof($triggers),
|
||||
'TIME' => G::toUpper(G::loadTranslation('ID_AFTER')),
|
||||
'TRIGGERS_NAMES' => array_column($triggers, 'TRI_TITLE'),
|
||||
'TRIGGERS_VALUES' => $triggers,
|
||||
'TRIGGERS_EXECUTION_TIME' => $this->arrayTriggerExecutionTime
|
||||
];
|
||||
}
|
||||
unset($appFields['APP_STATUS']);
|
||||
unset($appFields['APP_PROC_STATUS']);
|
||||
unset($appFields['APP_PROC_CODE']);
|
||||
unset($appFields['APP_PIN']);
|
||||
|
||||
$appFields["DEL_INDEX"] = $index;
|
||||
$appFields["TAS_UID"] = $tasUid;
|
||||
$appFields["USER_UID"] = $userLogged;
|
||||
$appFields["CURRENT_DYNAFORM"] = "-2";
|
||||
$appFields["OBJECT_TYPE"] = "ASSIGN_TASK";
|
||||
|
||||
$this->updateCase($application, $appFields);
|
||||
|
||||
// Send notifications - Start
|
||||
$user = new Users();
|
||||
$userInfo = $user->load($userLogged);
|
||||
$fromName = $userInfo['USR_FIRSTNAME'] . ' ' . $userInfo['USR_LASTNAME'];
|
||||
|
||||
$fromData = $fromName . ($userInfo['USR_EMAIL'] != '' ? ' <' . $userInfo['USR_EMAIL'] . '>' : '');
|
||||
|
||||
if ($flagGmail === true) {
|
||||
$appDel = new AppDelegation();
|
||||
$actualThread = $appDel->Load($application, $index);
|
||||
|
||||
$appDelPrev = $appDel->LoadParallel($application);
|
||||
$pmGmail = new Pmgmail();
|
||||
foreach ($appDelPrev as $app) {
|
||||
if (($app['DEL_INDEX'] != $index) && ($app['DEL_PREVIOUS'] != $actualThread['DEL_PREVIOUS'])) {
|
||||
$pmGmail->gmailsIfSelfServiceValueBased($application, $app['DEL_INDEX'], $postForm['TASKS'], $appFields['APP_DATA']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$this->sendNotifications($tasUid, $postForm['TASKS'], $appFields['APP_DATA'], $application, $index, $fromData);
|
||||
} catch (Exception $e) {
|
||||
G::SendTemporalMessage(G::loadTranslation('ID_NOTIFICATION_ERROR') . ' - ' . $e->getMessage(), 'warning', 'string', null, '100%');
|
||||
}
|
||||
// Send notifications - End
|
||||
// Events - Start
|
||||
$event = new Event();
|
||||
|
||||
$event->closeAppEvents($processUid, $application, $index, $tasUid);
|
||||
$currentAppDel = AppDelegationPeer::retrieveByPk($application, $index + 1);
|
||||
$multipleDelegation = false;
|
||||
// check if there are multiple derivations
|
||||
if (count($postForm['TASKS']) > 1) {
|
||||
$multipleDelegation = true;
|
||||
}
|
||||
// If the case has been delegated
|
||||
if (isset($currentAppDel)) {
|
||||
// if there is just a single derivation the TASK_UID can be set by the delegation data
|
||||
if (!$multipleDelegation) {
|
||||
$arrayResult = $currentAppDel->toArray(BasePeer::TYPE_FIELDNAME);
|
||||
$event->createAppEvents($arrayResult['PRO_UID'], $arrayResult['APP_UID'], $arrayResult['DEL_INDEX'], $arrayResult['TAS_UID']);
|
||||
} else {
|
||||
// else we need to check every task and create the events if it have any
|
||||
foreach ($postForm['TASKS'] as $taskDelegated) {
|
||||
$arrayResult = $currentAppDel->toArray(BasePeer::TYPE_FIELDNAME);
|
||||
$event->createAppEvents($arrayResult['PRO_UID'], $arrayResult['APP_UID'], $arrayResult['DEL_INDEX'], $taskDelegated['TAS_UID']);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Events - End
|
||||
|
||||
/*----------------------------------********---------------------------------*/
|
||||
// Set users drive - start
|
||||
$licensedFeatures = PMLicensedFeatures::getSingleton();
|
||||
if ($licensedFeatures->verifyfeature('AhKNjBEVXZlWUFpWE8wVTREQ0FObmo0aTdhVzhvalFic1M=')) {
|
||||
$drive = new AppDocumentDrive();
|
||||
if ($drive->getStatusDrive()) {
|
||||
//add users email next task
|
||||
$drive->addUsersDocumentDrive($appFields['APP_UID']);
|
||||
}
|
||||
}
|
||||
// Set users drive - End
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
$result = [
|
||||
'appFields' => $appFields,
|
||||
'triggerDebug' => $triggerDebug
|
||||
];
|
||||
return (object) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This initiates the routing of the case given the application and the form
|
||||
* data in the email application interface.
|
||||
* @param string $appUid
|
||||
* @param int $delIndex
|
||||
* @param string $aber
|
||||
* @param string $dynUid
|
||||
* @param array $forms
|
||||
* @param string $remoteAddr
|
||||
* @param array $files
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function routeCaseActionByEmail($appUid, $delIndex, $aber, $dynUid, $forms, $remoteAddr, $files): array
|
||||
{
|
||||
//Load data related to the case
|
||||
$case = new Cases();
|
||||
$fields = $case->loadCase($appUid, $delIndex);
|
||||
|
||||
// Check if the current thread is not finished
|
||||
if (!is_null($fields['DEL_FINISH_DATE'])) {
|
||||
$message = G::loadTranslation('ID_ABE_FORM_ALREADY_FILLED');
|
||||
Log::error($message);
|
||||
throw new Exception($message);
|
||||
}
|
||||
// Merge the data
|
||||
$fields['APP_DATA'] = array_merge($fields['APP_DATA'], $forms);
|
||||
|
||||
//Get current user info
|
||||
$delegation = new AppDelegation();
|
||||
$currentUsrUid = $delegation->getUserAssignedInThread($appUid, $delIndex);
|
||||
if (!is_null($currentUsrUid)) {
|
||||
$users = new Users();
|
||||
$userInfo = $users->loadDetails($currentUsrUid);
|
||||
$fields["APP_DATA"]["USER_LOGGED"] = $currentUsrUid;
|
||||
$fields["APP_DATA"]["USR_USERNAME"] = $userInfo['USR_USERNAME'];
|
||||
}
|
||||
|
||||
foreach ($fields["APP_DATA"] as $index => $value) {
|
||||
$_SESSION[$index] = $value;
|
||||
}
|
||||
|
||||
$fields['CURRENT_DYNAFORM'] = $dynUid;
|
||||
$fields['USER_UID'] = $fields['CURRENT_USER_UID'];
|
||||
|
||||
ChangeLog::getChangeLog()
|
||||
->getUsrIdByUsrUid($fields['USER_UID'], true)
|
||||
->setSourceId(ChangeLog::FromABE);
|
||||
|
||||
//Update case info
|
||||
$case->updateCase($appUid, $fields);
|
||||
if (isset($files['form'])) {
|
||||
if (isset($files["form"]["name"]) && count($files["form"]["name"]) > 0) {
|
||||
$inputDocument = new InputDocument();
|
||||
$inputDocument->uploadFileCase($files, $case, $fields, $currentUsrUid, $appUid, $delIndex);
|
||||
}
|
||||
}
|
||||
$wsBase = new WsBase();
|
||||
$result = $wsBase->derivateCase($fields['CURRENT_USER_UID'], $appUid, $delIndex, true);
|
||||
$code = is_array($result) ? $result['status_code'] : $result->status_code;
|
||||
|
||||
$dataResponses = [];
|
||||
$dataResponses['ABE_REQ_UID'] = $aber;
|
||||
$dataResponses['ABE_RES_CLIENT_IP'] = $remoteAddr;
|
||||
$dataResponses['ABE_RES_DATA'] = serialize($forms);
|
||||
$dataResponses['ABE_RES_STATUS'] = 'PENDING';
|
||||
$dataResponses['ABE_RES_MESSAGE'] = '';
|
||||
|
||||
try {
|
||||
require_once 'classes/model/AbeResponses.php';
|
||||
$abeResponses = new AbeResponses();
|
||||
$dataResponses['ABE_RES_UID'] = $abeResponses->createOrUpdate($dataResponses);
|
||||
} catch (Exception $error) {
|
||||
$message = $error->getMessage();
|
||||
Log::error($message);
|
||||
throw $error;
|
||||
}
|
||||
|
||||
if ($code == 0) {
|
||||
//Save Cases Notes
|
||||
$abeRequest = loadAbeRequest($aber);
|
||||
$abeConfiguration = loadAbeConfiguration($abeRequest['ABE_UID']);
|
||||
|
||||
if ($abeConfiguration['ABE_CASE_NOTE_IN_RESPONSE'] == 1) {
|
||||
$response = new stdclass();
|
||||
$response->usrUid = $fields['APP_DATA']['USER_LOGGED'];
|
||||
$response->appUid = $appUid;
|
||||
$response->delIndex = $delIndex;
|
||||
$response->noteText = "Check the information that was sent for the receiver: " . $abeRequest['ABE_REQ_SENT_TO'];
|
||||
postNote($response);
|
||||
}
|
||||
|
||||
$abeRequest['ABE_REQ_ANSWERED'] = 1;
|
||||
$code == 0 ? uploadAbeRequest($abeRequest) : '';
|
||||
} else {
|
||||
$resStatusCode = is_array($result) ? $result['status_code'] : $result->status_code;
|
||||
$resMessage = is_array($result) ? $result['message'] : $result->message;
|
||||
$message = 'An error occurred while the application was being processed.<br /><br />
|
||||
Error code: ' . $resStatusCode . '<br />
|
||||
Error message: ' . $resMessage . '<br /><br />';
|
||||
Log::error($message);
|
||||
throw new Exception($message);
|
||||
}
|
||||
|
||||
// Update
|
||||
$resMessage = is_array($result) ? $result['message'] : $result->message;
|
||||
$dataResponses['ABE_RES_STATUS'] = ($code == 0 ? 'SENT' : 'ERROR');
|
||||
$dataResponses['ABE_RES_MESSAGE'] = ($code == 0 ? '-' : $resMessage);
|
||||
|
||||
try {
|
||||
$abeResponses = new AbeResponses();
|
||||
$abeResponses->createOrUpdate($dataResponses);
|
||||
} catch (Exception $error) {
|
||||
$message = $error->getMessage();
|
||||
Log::error($message);
|
||||
throw $error;
|
||||
}
|
||||
return $dataResponses;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Commands;
|
||||
|
||||
use ProcessMaker\Core\ProcOpen;
|
||||
|
||||
class GenerateDataReport extends ProcOpen
|
||||
{
|
||||
private $workspace;
|
||||
private $tableName;
|
||||
private $type;
|
||||
private $processUid;
|
||||
private $gridKey;
|
||||
private $addTabUid;
|
||||
private $className;
|
||||
private $pathWorkspace;
|
||||
private $start;
|
||||
private $limit;
|
||||
|
||||
/**
|
||||
* Initializes the command parameters.
|
||||
* @param string $workspace
|
||||
* @param string $tableName
|
||||
* @param string $type
|
||||
* @param string $processUid
|
||||
* @param string $gridKey
|
||||
* @param string $addTabUid
|
||||
* @param string $className
|
||||
* @param string $pathWorkspace
|
||||
* @param integer $start
|
||||
* @param integer $limit
|
||||
*/
|
||||
public function __construct(
|
||||
$workspace,
|
||||
$tableName,
|
||||
$type = 'NORMAL',
|
||||
$processUid = '',
|
||||
$gridKey = '',
|
||||
$addTabUid = '',
|
||||
$className = '',
|
||||
$pathWorkspace,
|
||||
$start = 0,
|
||||
$limit = 10)
|
||||
{
|
||||
$this->workspace = $workspace;
|
||||
$this->tableName = $tableName;
|
||||
$this->type = $type;
|
||||
$this->processUid = $processUid;
|
||||
$this->gridKey = $gridKey;
|
||||
$this->addTabUid = $addTabUid;
|
||||
$this->className = $className;
|
||||
$this->pathWorkspace = $pathWorkspace;
|
||||
$this->start = $start;
|
||||
$this->limit = $limit;
|
||||
$this->setCwd(PATH_TRUNK);
|
||||
parent::__construct($this->buildCommand());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command to execute.
|
||||
* @return string
|
||||
*/
|
||||
private function buildCommand(): string
|
||||
{
|
||||
$command = PHP_BINDIR . "/php "
|
||||
. "./processmaker "
|
||||
. "'generate-data-report' "
|
||||
. "'{$this->workspace}' "
|
||||
. "'tableName={$this->tableName}' "
|
||||
. "'type={$this->type}' "
|
||||
. "'process={$this->processUid}' "
|
||||
. "'gridKey={$this->gridKey}' "
|
||||
. "'additionalTable={$this->addTabUid}' "
|
||||
. "'className={$this->className}' "
|
||||
. "'pathWorkspace={$this->pathWorkspace}' "
|
||||
. "'start={$this->start}' "
|
||||
. "'limit={$this->limit}' ";
|
||||
return $command;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Commands;
|
||||
|
||||
use ProcessMaker\Core\ProcOpen;
|
||||
|
||||
class PopulateTableReport extends ProcOpen
|
||||
{
|
||||
private $workspace;
|
||||
private $sql;
|
||||
private $isRbac;
|
||||
|
||||
/**
|
||||
* Initializes the command parameters.
|
||||
* @param string $workspace
|
||||
* @param string $sql
|
||||
* @param boolean $isRbac
|
||||
*/
|
||||
public function __construct($workspace, $sql, $isRbac = false)
|
||||
{
|
||||
$this->workspace = $workspace;
|
||||
$this->sql = $sql;
|
||||
$this->isRbac = $isRbac;
|
||||
$this->setCwd(PATH_TRUNK);
|
||||
parent::__construct($this->buildCommand());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command to execute.
|
||||
* @return string
|
||||
*/
|
||||
public function buildCommand()
|
||||
{
|
||||
$command = PHP_BINDIR . "/php "
|
||||
. "./processmaker "
|
||||
. "'populate-table' "
|
||||
. "'{$this->workspace}' "
|
||||
. base64_encode($this->sql) . " "
|
||||
. ($this->isRbac ? "'1'" : "'0'");
|
||||
return $command;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ namespace ProcessMaker\Core;
|
||||
use Bootstrap;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use ProcessMaker\BusinessModel\Factories\Jobs;
|
||||
use ProcessMaker\Core\System;
|
||||
use Propel;
|
||||
|
||||
@@ -187,7 +186,7 @@ class JobsManager
|
||||
{
|
||||
$environment = $this->getDataSnapshot();
|
||||
|
||||
$instance = Jobs::create($name, function() use ($callback, $environment) {
|
||||
$instance = $name::dispatch(function() use ($callback, $environment) {
|
||||
try {
|
||||
$this->recoverDataSnapshot($environment);
|
||||
$callback($environment);
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Core;
|
||||
|
||||
class MultiProcOpen
|
||||
{
|
||||
/**
|
||||
* Represents the waiting time before starting the process monitoring.
|
||||
* @var integer
|
||||
*/
|
||||
private $sleepTime = 1;
|
||||
|
||||
/**
|
||||
* This method obtains a paging by returning the start and limit indexes
|
||||
* compatible with the mysql pagination in its call function.
|
||||
* The return function must return an instance of the object "ProcessMaker\Core\ProcOpen".
|
||||
* Returns an array containing the status, content, and errors generated by
|
||||
* the open process.
|
||||
* @param int $size
|
||||
* @param int $chunk
|
||||
* @param callable $callback
|
||||
* @return array
|
||||
*/
|
||||
public function chunk(int $size, int $chunk, callable $callback): array
|
||||
{
|
||||
$start = 0;
|
||||
$limit = $chunk;
|
||||
$queries = [];
|
||||
for ($i = 1; $start < $size; $i++) {
|
||||
$queries[] = $callback($size, $start, $limit);
|
||||
$start = $i * $limit;
|
||||
}
|
||||
return $this->run($queries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a set of background processes.
|
||||
* The array must contain one or more instances of the object inherited from
|
||||
* the class "ProcessMaker\Core\ProcOpen"
|
||||
* Returns an array containing the status, content, and errors generated by
|
||||
* the open process.
|
||||
* @param array $processes
|
||||
* @return array
|
||||
*/
|
||||
public function run(array $processes): array
|
||||
{
|
||||
foreach ($processes as $procOpen) {
|
||||
$procOpen->open();
|
||||
}
|
||||
return $this->processMonitoring($processes);
|
||||
}
|
||||
|
||||
/**
|
||||
* It monitors the open processes, verifying if they have ended or thrown an
|
||||
* error and later closing the resources related to the process.
|
||||
* Returns an array containing the status, content, and errors generated by
|
||||
* the open process.
|
||||
* @param array $processes
|
||||
* @return array
|
||||
*/
|
||||
private function processMonitoring(array $processes): array
|
||||
{
|
||||
sleep($this->sleepTime); //this sleep is very important
|
||||
$i = 0;
|
||||
$n = count($processes);
|
||||
if ($n === 0) {
|
||||
return [];
|
||||
}
|
||||
$outputs = [];
|
||||
do {
|
||||
$index = $i % $n;
|
||||
if (isset($processes[$index])) {
|
||||
$procOpen = $processes[$index];
|
||||
$status = $procOpen->getStatus();
|
||||
$contents = $procOpen->getContents();
|
||||
$errors = $procOpen->getErrors();
|
||||
if ($status->running === false || !empty($errors)) {
|
||||
$outputs[] = [
|
||||
"status" => $status,
|
||||
"contents" => $contents,
|
||||
"errors" => $errors,
|
||||
];
|
||||
$procOpen->terminate();
|
||||
$procOpen->close();
|
||||
unset($processes[$index]);
|
||||
}
|
||||
}
|
||||
$i = $i + 1;
|
||||
} while (!empty($processes));
|
||||
return $outputs;
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Core;
|
||||
|
||||
class ProcOpen
|
||||
{
|
||||
private $command;
|
||||
private $resource;
|
||||
private $descriptorspec;
|
||||
private $pipes;
|
||||
private $cwd;
|
||||
|
||||
/**
|
||||
* This initializes the descriptors and the command for the open process.
|
||||
* @param string $command
|
||||
*/
|
||||
public function __construct(string $command)
|
||||
{
|
||||
$this->descriptorspec = [
|
||||
['pipe', 'r'],
|
||||
['pipe', 'w'],
|
||||
['pipe', 'w']
|
||||
];
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resource that represents the process.
|
||||
* @return resource
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the process execution directory.
|
||||
* @param string $cwd
|
||||
*/
|
||||
public function setCwd(string $cwd)
|
||||
{
|
||||
$this->cwd = $cwd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a background process.
|
||||
*/
|
||||
public function open()
|
||||
{
|
||||
if (empty($this->cwd)) {
|
||||
$this->resource = proc_open($this->command, $this->descriptorspec, $this->pipes);
|
||||
} else {
|
||||
$this->resource = proc_open($this->command, $this->descriptorspec, $this->pipes, $this->cwd);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of the process when it is finished.
|
||||
* @return string
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
if (is_resource($this->pipes[1])) {
|
||||
return stream_get_contents($this->pipes[1]);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the process errors when it is finished.
|
||||
* @return string
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
if (is_resource($this->pipes[2])) {
|
||||
return stream_get_contents($this->pipes[2]);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the resources related to the open process.
|
||||
* return void
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if (is_resource($this->resource)) {
|
||||
foreach ($this->pipes as $value) {
|
||||
fclose($value);
|
||||
}
|
||||
proc_close($this->resource);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End the process before it ends.
|
||||
*/
|
||||
public function terminate()
|
||||
{
|
||||
if (is_resource($this->resource)) {
|
||||
proc_terminate($this->resource);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status of the process.
|
||||
* @return object
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
$status = [
|
||||
"command" => $this->command,
|
||||
"pid" => null,
|
||||
"running" => false,
|
||||
"signaled" => false,
|
||||
"stopped" => false,
|
||||
"exitcode" => -1,
|
||||
"termsig" => 0,
|
||||
"stopsig" => 0
|
||||
];
|
||||
if (is_resource($this->resource)) {
|
||||
$status = proc_get_status($this->resource);
|
||||
}
|
||||
return (object) $status;
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,9 @@ class System
|
||||
'highlight_home_folder_enable' => 0,
|
||||
'highlight_home_folder_refresh_time' => 10,
|
||||
'highlight_home_folder_scope' => 'unassigned', // For now only this list is supported
|
||||
'disable_advanced_search_case_title_fulltext' => 0
|
||||
'disable_advanced_search_case_title_fulltext' => 0,
|
||||
'pmftotalcalculation_floating_point_number' => 10,
|
||||
'report_table_batch_regeneration' => 1000
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Exception;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
class CaseNoteUploadFile extends Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
* @param Throwable $previous
|
||||
*/
|
||||
public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,101 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AppNotes extends Model
|
||||
{
|
||||
// Set our table name
|
||||
protected $table = 'APP_NOTES';
|
||||
// No timestamps
|
||||
public $timestamps = false;
|
||||
// Primary key
|
||||
protected $primaryKey = 'NOTE_ID';
|
||||
// The IDs are auto-incrementing
|
||||
public $incrementing = true;
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'NOTE_TYPE' => 'USER',
|
||||
'NOTE_ORIGIN_OBJ' => '',
|
||||
'NOTE_AFFECTED_OBJ1' => '',
|
||||
'NOTE_AFFECTED_OBJ2' => ''
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'APP_UID',
|
||||
'USR_UID',
|
||||
'NOTE_DATE',
|
||||
'NOTE_CONTENT',
|
||||
'NOTE_TYPE',
|
||||
'NOTE_AVAILABILITY',
|
||||
'NOTE_ORIGIN_OBJ',
|
||||
'NOTE_AFFECTED_OBJ1',
|
||||
'NOTE_AFFECTED_OBJ2',
|
||||
'NOTE_RECIPIENTS'
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope a query to filter an specific case
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $appUid
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAppUid($query, string $appUid)
|
||||
{
|
||||
return $query->where('APP_UID', $appUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the documents related to the case
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
* @param string $dir
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getNotes(string $appUid, $start = 0, $limit = 25, $dir = 'DESC')
|
||||
{
|
||||
$query = AppNotes::query()->select([
|
||||
'NOTE_ID',
|
||||
'APP_UID',
|
||||
'NOTE_DATE',
|
||||
'NOTE_CONTENT',
|
||||
'NOTE_TYPE',
|
||||
'NOTE_AVAILABILITY',
|
||||
'USERS.USR_UID',
|
||||
'USERS.USR_USERNAME',
|
||||
'USERS.USR_FIRSTNAME',
|
||||
'USERS.USR_LASTNAME'
|
||||
]);
|
||||
$query->leftJoin('USERS', function ($join) {
|
||||
$join->on('USERS.USR_UID', '=', 'APP_NOTES.USR_UID');
|
||||
});
|
||||
$query->appUid($appUid);
|
||||
$query->orderBy('NOTE_DATE', $dir);
|
||||
// Add pagination to the query
|
||||
$query->offset($start)->limit($limit);
|
||||
|
||||
$results = $query->get();
|
||||
$notes = [];
|
||||
$notes['notes'] = [];
|
||||
$results->each(function ($item, $key) use (&$notes) {
|
||||
$row = $item->toArray();
|
||||
$row['NOTE_CONTENT'] = stripslashes($row['NOTE_CONTENT']);
|
||||
$notes['notes'][] = $row;
|
||||
});
|
||||
|
||||
// Add the total of rows to return
|
||||
$notes['totalCount'] = $limit;
|
||||
|
||||
return $notes;
|
||||
}
|
||||
}
|
||||
|
||||
148
workflow/engine/src/ProcessMaker/Model/Documents.php
Normal file
148
workflow/engine/src/ProcessMaker/Model/Documents.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Documents extends Model
|
||||
{
|
||||
// Set our table name
|
||||
protected $table = 'APP_DOCUMENT';
|
||||
// No timestamps
|
||||
public $timestamps = false;
|
||||
// Primary key
|
||||
protected $primaryKey = 'NOTE_ID';
|
||||
// The IDs are auto-incrementing
|
||||
public $incrementing = false;
|
||||
// Valid AppDocType's
|
||||
const DOC_TYPE_ATTACHED = 'ATTACHED';
|
||||
const DOC_TYPE_CASE_NOTE = 'CASE_NOTE';
|
||||
const DOC_TYPE_INPUT = 'INPUT';
|
||||
const DOC_TYPE_OUTPUT = 'OUTPUT';
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'APP_DOC_TITLE' => '',
|
||||
'APP_DOC_COMMENT' => '',
|
||||
'DOC_UID' => '-1',
|
||||
'FOLDER_UID' => '',
|
||||
'APP_DOC_PLUGIN' => '',
|
||||
'APP_DOC_TAGS' => '',
|
||||
'APP_DOC_FIELDNAME' => '',
|
||||
'APP_DOC_DRIVE_DOWNLOAD' => 'a:0:{}',
|
||||
'SYNC_WITH_DRIVE' => 'UNSYNCHRONIZED',
|
||||
'SYNC_PERMISSIONS' => '',
|
||||
'APP_DOC_STATUS_DATE' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'DOC_ID',
|
||||
'APP_DOC_UID',
|
||||
'DOC_VERSION',
|
||||
'APP_DOC_FILENAME',
|
||||
'APP_UID',
|
||||
'DEL_INDEX',
|
||||
'DOC_UID',
|
||||
'USR_UID',
|
||||
'APP_DOC_TYPE',
|
||||
'APP_DOC_CREATE_DATE',
|
||||
'APP_DOC_INDEX',
|
||||
'FOLDER_UID',
|
||||
'APP_DOC_STATUS',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope a query to filter an specific case
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $appUid
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAppUid($query, string $appUid)
|
||||
{
|
||||
return $query->where('APP_UID', $appUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter an specific reference file
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $docId
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeDocId($query, int $docId)
|
||||
{
|
||||
return $query->where('DOC_ID', $docId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the documents related to the case
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAppFiles(string $appUid, $type = 'CASE_NOTES')
|
||||
{
|
||||
$query = Documents::query()->select();
|
||||
$query->appUid($appUid);
|
||||
$query->where('APP_DOC_TYPE', $type);
|
||||
$results = $query->get();
|
||||
$documentList = [];
|
||||
$results->each(function ($item, $key) use (&$documentList) {
|
||||
$documentList[] = $item->toArray();
|
||||
});
|
||||
|
||||
return $documentList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attached files from the case note.
|
||||
*
|
||||
* @param string $appUid
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function getAttachedFilesFromTheCaseNote(string $appUid)
|
||||
{
|
||||
$result = Documents::select('APP_DOCUMENT.APP_DOC_UID', 'APP_DOCUMENT.DOC_VERSION', 'APP_DOCUMENT.APP_DOC_FILENAME')
|
||||
->join('APP_NOTES', function($join) use($appUid) {
|
||||
$join->on('APP_NOTES.NOTE_ID', '=', 'APP_DOCUMENT.DOC_ID')
|
||||
->where('APP_DOCUMENT.APP_UID', '=', $appUid);
|
||||
})
|
||||
->get();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the documents related to the specific DOC_ID
|
||||
*
|
||||
* @param int $docId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getFiles(int $docId)
|
||||
{
|
||||
$query = Documents::query()->select(['APP_DOC_UID', 'APP_DOC_FILENAME', 'DOC_VERSION']);
|
||||
$query->docId($docId);
|
||||
$results = $query->get();
|
||||
$documentList = [];
|
||||
$results->each(function ($item, $key) use (&$documentList) {
|
||||
$row = $item->toArray();
|
||||
$row['LINK'] = "../cases/casesShowCaseNotes?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
|
||||
$documentList[] = $row;
|
||||
});
|
||||
|
||||
return $documentList;
|
||||
}
|
||||
}
|
||||
@@ -72,8 +72,21 @@ class ProcessVariables extends Model
|
||||
*/
|
||||
public function scopeProcessId($query, int $proId)
|
||||
{
|
||||
return $query->where('PRO_ID', $proId);
|
||||
return $query->where('PROCESS_VARIABLES.PRO_ID', $proId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to filter a specific type for variable
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param int $typeId
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeTypeId($query, int $typeId)
|
||||
{
|
||||
return $query->where('VAR_FIELD_TYPE_ID', $typeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the variables list
|
||||
*
|
||||
@@ -96,4 +109,46 @@ class ProcessVariables extends Model
|
||||
|
||||
return $variablesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the variables list
|
||||
*
|
||||
* @param int $proId
|
||||
* @param int $typeId
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
* @param string $search
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getVariablesByType(int $proId, int $typeId = 0, $start = null, $limit = null, $search = null)
|
||||
{
|
||||
$query = ProcessVariables::query()->select();
|
||||
$query->leftJoin('DB_SOURCE', function ($join) {
|
||||
$join->on('DB_SOURCE.PRO_ID', '=', 'PROCESS_VARIABLES.PRO_ID');
|
||||
});
|
||||
$query->processId($proId);
|
||||
// Check if we need to filter the type of variables
|
||||
if ($typeId > 0) {
|
||||
$query->typeId($typeId);
|
||||
}
|
||||
// search a specific variable name
|
||||
if (!empty($search)) {
|
||||
$query->where('VAR_NAME', 'LIKE', "${search}%");
|
||||
}
|
||||
// order by varNane
|
||||
$query->orderBy('VAR_NAME', 'ASC');
|
||||
// Check if we need to add a pagination
|
||||
if(!is_null($start) && !is_null($limit)) {
|
||||
$query->offset($start)->limit($limit);
|
||||
}
|
||||
// Get records
|
||||
$results = $query->get();
|
||||
$variablesList = [];
|
||||
$results->each(function ($item, $key) use (&$variablesList) {
|
||||
$variablesList[] = $item->toArray();
|
||||
});
|
||||
|
||||
return $variablesList;
|
||||
}
|
||||
}
|
||||
14
workflow/engine/src/ProcessMaker/Model/StepTrigger.php
Normal file
14
workflow/engine/src/ProcessMaker/Model/StepTrigger.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StepTrigger extends Model
|
||||
{
|
||||
protected $table = 'STEP_TRIGGER';
|
||||
protected $primaryKey = 'STEP_UID';
|
||||
public $incrementing = false;
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
52
workflow/engine/src/ProcessMaker/Model/SubApplication.php
Normal file
52
workflow/engine/src/ProcessMaker/Model/SubApplication.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Process
|
||||
* @package ProcessMaker\Model
|
||||
*
|
||||
* Represents a business process object in the system.
|
||||
*/
|
||||
class SubApplication extends Model
|
||||
{
|
||||
// Set our table name
|
||||
protected $table = 'SUB_APPLICATION';
|
||||
// No timestamps
|
||||
public $timestamps = false;
|
||||
// Primary key
|
||||
protected $primaryKey = 'APP_UID';
|
||||
// The IDs are auto-incrementing
|
||||
public $incrementing = false;
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'SA_STATUS' => '',
|
||||
'SA_VALUES_OUT' => '',
|
||||
'SA_VALUES_IN' => '',
|
||||
'SA_INIT_DATE' => '',
|
||||
'SA_FINISH_DATE' => ''
|
||||
];
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'APP_UID',
|
||||
'APP_PARENT',
|
||||
'DEL_INDEX_PARENT',
|
||||
'DEL_THREAD_PARENT',
|
||||
'SA_STATUS',
|
||||
'SA_VALUES_OUT',
|
||||
'SA_VALUES_IN',
|
||||
'SA_INIT_DATE',
|
||||
'SA_FINISH_DATE'
|
||||
];
|
||||
}
|
||||
@@ -12,6 +12,8 @@ class Triggers extends Model
|
||||
public $timestamps = false;
|
||||
//primary key
|
||||
protected $primaryKey = 'TRI_UID';
|
||||
//No incrementing
|
||||
public $incrementing = false;
|
||||
|
||||
/**
|
||||
* Scope a query to filter an specific process
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Services\Api\Project;
|
||||
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
use Exception;
|
||||
use G;
|
||||
use Luracast\Restler\RestException;
|
||||
use ProcessMaker\BusinessModel\Variable as BmVariable;
|
||||
use ProcessMaker\Services\Api;
|
||||
|
||||
/**
|
||||
* Project\Variable Api Controller
|
||||
*
|
||||
@@ -28,6 +32,43 @@ class Variable extends Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variables by type
|
||||
*
|
||||
* @url GET /:prj_uid/process-variables/:typeVariable/paged
|
||||
*
|
||||
* @param string $prj_uid {@min 32}{@max 32}
|
||||
* @param string $typeVariable {@from path}
|
||||
* @param int $start {@from path}
|
||||
* @param int $limit {@from path}
|
||||
* @param string $search {@from path}
|
||||
*/
|
||||
public function doGetVariablesByType($prj_uid, $typeVariable, $start = null, $limit = null, $search = null)
|
||||
{
|
||||
try {
|
||||
$variable = new BmVariable();
|
||||
$typesAccepted = $variable::$varTypesValues;
|
||||
if (!empty($typesAccepted[$typeVariable])) {
|
||||
$typeVatId = $typesAccepted[$typeVariable];
|
||||
} else {
|
||||
throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", ['$typeVariable', implode(',', $variable->getVariableTypes())]));
|
||||
}
|
||||
// Review if the word has the prefix
|
||||
$count = preg_match_all('/\@(?:([\@\%\#\?\$\=\&Qq\!])|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/', $search, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
|
||||
// Check if the search has some prefix
|
||||
$prefix = '';
|
||||
if ($count) {
|
||||
$prefix = substr($search,0,2);
|
||||
$search = substr($search,2);
|
||||
}
|
||||
$response = $variable->getVariablesByType($prj_uid, $typeVatId, $start, $limit, $search, $prefix);
|
||||
|
||||
return $response;
|
||||
} catch (Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /:prj_uid/process-variable/:var_uid
|
||||
*
|
||||
|
||||
@@ -601,3 +601,42 @@ function getMysqlVersion()
|
||||
|
||||
return $mysqlVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the uploaded file to the documents folder
|
||||
*
|
||||
* @param array $file
|
||||
* @param string $appUid
|
||||
* @param string $appDocUid
|
||||
* @param int $version
|
||||
* @param bool $upload
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function saveAppDocument($file, $appUid, $appDocUid, $version = 1, $upload = true)
|
||||
{
|
||||
try {
|
||||
$info = pathinfo($file["name"]);
|
||||
$extension = ((isset($info["extension"])) ? $info["extension"] : "");
|
||||
$fileName = $appDocUid . "_" . $version . "." . $extension;
|
||||
|
||||
$pathCase = PATH_DATA_SITE . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP;
|
||||
|
||||
$response = false;
|
||||
if ($upload) {
|
||||
G::uploadFile(
|
||||
$file["tmp_name"],
|
||||
$pathCase,
|
||||
$fileName
|
||||
);
|
||||
$response = true;
|
||||
} else {
|
||||
G::verifyPath($pathCase, true);
|
||||
$response = copy($file["tmp_name"], $pathCase . $fileName);
|
||||
}
|
||||
|
||||
return $response;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ class ValidationUploadedFiles
|
||||
*/
|
||||
private $fails = [];
|
||||
|
||||
/**
|
||||
* Return this constant when rule is invalid.
|
||||
*/
|
||||
private const INVALID = true;
|
||||
|
||||
/**
|
||||
* Return this constant when rule is valid.
|
||||
*/
|
||||
private const VALID = false;
|
||||
|
||||
/**
|
||||
* Check if the loaded files comply with the validation rules, add here if you
|
||||
* want more validation rules.
|
||||
@@ -280,6 +290,110 @@ class ValidationUploadedFiles
|
||||
return $validator->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the loaded files comply with the validation rules, add here if you
|
||||
* want more validation rules.
|
||||
* Accept per argument an array or object that contains a "filename" and "path" values.
|
||||
* The rules are verified in the order in which they have been added.
|
||||
*
|
||||
* @param array|object $file
|
||||
* @return Validator
|
||||
*/
|
||||
public function runRulesForPostFilesOfNote($file)
|
||||
{
|
||||
$validator = new Validator();
|
||||
|
||||
//rule: file exists
|
||||
$rule = $validator->addRule();
|
||||
$rule->validate($file, function($file) use($rule) {
|
||||
$path = isset($file->path) ? $file->path : "";
|
||||
$filesystem = new Filesystem();
|
||||
if (!$filesystem->exists($path)) {
|
||||
$rule->message(G::LoadTranslation('ID_NOT_EXISTS_FILE'));
|
||||
return self::INVALID;
|
||||
}
|
||||
return self::VALID;
|
||||
})
|
||||
->status(400)
|
||||
->log(function($rule) {
|
||||
/**
|
||||
* Levels supported by MonologProvider is:
|
||||
* 100 "DEBUG"
|
||||
* 200 "INFO"
|
||||
* 250 "NOTICE"
|
||||
* 300 "WARNING"
|
||||
* 400 "ERROR"
|
||||
* 500 "CRITICAL"
|
||||
* 550 "ALERT"
|
||||
* 600 "EMERGENCY"
|
||||
*/
|
||||
Bootstrap::registerMonologPhpUploadExecution('phpUpload', $rule->getStatus(), $rule->getMessage(), $rule->getData()->filename);
|
||||
});
|
||||
|
||||
//rule: extensions
|
||||
$rule = $validator->addRule();
|
||||
$rule->validate($file, function($file) use($rule) {
|
||||
$filesystem = new Filesystem();
|
||||
$extension = strtolower($filesystem->extension($file->filename));
|
||||
$extensions = [
|
||||
'pdf', 'gif', 'jpg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'txt', 'mp4', 'mpv', 'mpeg', 'mpg', 'mov'
|
||||
];
|
||||
if (!in_array($extension, $extensions)) {
|
||||
$rule->message(G::LoadTranslation('ID_YOU_UPLOADED_AN_UNSUPPORTED_FILE_EXTENSION'));
|
||||
return self::INVALID;
|
||||
}
|
||||
return self::VALID;
|
||||
})
|
||||
->status(400)
|
||||
->log(function($rule) {
|
||||
/**
|
||||
* Levels supported by MonologProvider is:
|
||||
* 100 "DEBUG"
|
||||
* 200 "INFO"
|
||||
* 250 "NOTICE"
|
||||
* 300 "WARNING"
|
||||
* 400 "ERROR"
|
||||
* 500 "CRITICAL"
|
||||
* 550 "ALERT"
|
||||
* 600 "EMERGENCY"
|
||||
*/
|
||||
Bootstrap::registerMonologPhpUploadExecution('phpUpload', $rule->getStatus(), $rule->getMessage(), $rule->getData()->filename);
|
||||
});
|
||||
|
||||
//rule: file size
|
||||
$rule = $validator->addRule();
|
||||
$rule->validate($file, function($file) use($rule) {
|
||||
$path = isset($file->path) ? $file->path : "";
|
||||
$filesystem = new Filesystem();
|
||||
$limitSize = '10M';
|
||||
$size = $filesystem->size($path);
|
||||
$phpShorthandByte = new PhpShorthandByte();
|
||||
$postMaxSizeBytes = $phpShorthandByte->valueToBytes($limitSize);
|
||||
if ($size > $postMaxSizeBytes) {
|
||||
$rule->message(G::LoadTranslation('ID_YOUR_FILE_HAS_EXCEEDED', [$limitSize]));
|
||||
return self::INVALID;
|
||||
}
|
||||
return self::VALID;
|
||||
})
|
||||
->status(400)
|
||||
->log(function($rule) {
|
||||
/**
|
||||
* Levels supported by MonologProvider is:
|
||||
* 100 "DEBUG"
|
||||
* 200 "INFO"
|
||||
* 250 "NOTICE"
|
||||
* 300 "WARNING"
|
||||
* 400 "ERROR"
|
||||
* 500 "CRITICAL"
|
||||
* 550 "ALERT"
|
||||
* 600 "EMERGENCY"
|
||||
*/
|
||||
Bootstrap::registerMonologPhpUploadExecution('phpUpload', $rule->getStatus(), $rule->getMessage(), $rule->getData()->filename);
|
||||
});
|
||||
|
||||
return $validator->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first error and call the argument function.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user