diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index a62db2ad2..87eec46fe 100755 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -3962,6 +3962,35 @@ class Cases ]; $i++; + + //Plugin Hook PM_UPLOAD_DOCUMENT for upload document + $pluginRegistry = PluginRegistry::loadSingleton(); + + // If the hook exists try to execute + if ($pluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) { + // Get hook details + $triggerDetail = $pluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT); + + // Build path file + $info = pathinfo($arrayFileName['name']); + $extension = (isset($info['extension'])) ? $info['extension'] : ''; + $pathCase = G::getPathFromUID($appUid); + $pathFile = PATH_DOCUMENT . $pathCase . PATH_SEP . $objCreated->getAppDocUid() . '_1.' . $extension; + + // Instance object used by the hook + $documentData = new uploadDocumentData($appUid, $userUid, $pathFile, $objCreated->getAppDocFilename(), $objCreated->getAppDocUid(), 1); + + // Execute hook + $uploadReturn = $pluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData); + + // If the executions is correct, update the record related to the document + if ($uploadReturn) { + Documents::where('APP_DOC_UID', $objCreated->getAppDocUid())->update(['APP_DOC_PLUGIN' => $triggerDetail->getNamespace()]); + + // Remove the file from the server + unlink($pathFile); + } + } } else { throw new UploadException($arrayFileName['error']); } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Light.php b/workflow/engine/src/ProcessMaker/BusinessModel/Light.php index 9d67e883c..82765ce7b 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Light.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Light.php @@ -31,7 +31,9 @@ use ProcessMaker\ChangeLog\ChangeLog; /*----------------------------------********---------------------------------*/ use ProcessMaker\Core\RoutingScreen; use ProcessMaker\Core\System; +use ProcessMaker\Model\Documents; use ProcessMaker\Model\Process as ProcessEloquent; +use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Services\Api\Project\Activity\Step as ActivityStep; use ProcessMaker\Util\DateTime; use ProcessMaker\Validation\ExceptionRestApi; @@ -42,6 +44,7 @@ use RBAC; use ResultSet; use StepPeer; use TaskPeer; +use uploadDocumentData; use Users; use UsersPeer; @@ -1186,8 +1189,32 @@ class Light $pathUID = G::getPathFromUID($app_uid); $sPathName = PATH_DOCUMENT . $pathUID . PATH_SEP; $sFileName = $sAppDocUid . "_" . $iDocVersion . "." . $sExtension; + $pathFile = $sPathName . $sFileName; G::uploadFile($arrayFileTmpName[$i], $sPathName, $sFileName); $response = array("status" => "ok"); + + //Plugin Hook PM_UPLOAD_DOCUMENT for upload document + $pluginRegistry = PluginRegistry::loadSingleton(); + + // If the hook exists try to execute + if ($pluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) { + // Get hook details + $triggerDetail = $pluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT); + + // Instance object used by the hook + $documentData = new uploadDocumentData($app_uid, $userUid, $pathFile, $oAppDocument->getAppDocFilename(), $app_doc_uid, $iDocVersion); + + // Execute hook + $uploadReturn = $pluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData); + + // If the executions is correct, update the record related to the document + if ($uploadReturn) { + Documents::where('APP_DOC_UID', $app_doc_uid)->update(['APP_DOC_PLUGIN' => $triggerDetail->getNamespace()]); + + // Remove the file from the server + unlink($pathFile); + } + } } } }