Merged in bugfix/PMCORE-4120 (pull request #8701)

PMCORE-4121
This commit is contained in:
Julio Cesar Laura Avendaño
2023-01-20 18:49:46 +00:00
2 changed files with 56 additions and 0 deletions

View File

@@ -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']);
}

View File

@@ -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);
}
}
}
}
}