PMCORE-4120
This commit is contained in:
@@ -22,7 +22,7 @@ class SaveAppDocumentTest extends TestCase
|
||||
$appDocUid = G::generateUniqueID();
|
||||
$pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP;
|
||||
$res = saveAppDocument($files, $appUid, $appDocUid, 1, false);
|
||||
$this->assertTrue($res);
|
||||
$this->assertNotEmpty($res);
|
||||
G::rm_dir($pathCase);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class SaveAppDocumentTest extends TestCase
|
||||
$appDocUid = G::generateUniqueID();
|
||||
$pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP;
|
||||
$res = saveAppDocument($files, $appUid, $appDocUid, 1, false);
|
||||
$this->assertTrue($res);
|
||||
$this->assertNotEmpty($res);
|
||||
G::rm_dir($pathCase);
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@ use Task as ModelTask;
|
||||
use TaskPeer;
|
||||
use Tasks as ClassesTasks;
|
||||
use TaskUserPeer;
|
||||
use uploadDocumentData;
|
||||
use Users as ModelUsers;
|
||||
use UsersPeer;
|
||||
use WsBase;
|
||||
@@ -4173,10 +4174,10 @@ class Cases
|
||||
$appDocUid = G::generateUniqueID();
|
||||
|
||||
// Upload or move the file
|
||||
$isUploaded = saveAppDocument($fileName, $appUid, $appDocUid, 1, $upload);
|
||||
$pathFile = saveAppDocument($fileName, $appUid, $appDocUid, 1, $upload);
|
||||
|
||||
// If the file was uploaded correctly we will to register in the DB
|
||||
if ($isUploaded) {
|
||||
if (!empty($pathFile)) {
|
||||
$attributes = [
|
||||
"DOC_ID" => $noteId,
|
||||
"APP_DOC_UID" => $appDocUid,
|
||||
@@ -4193,6 +4194,29 @@ class Cases
|
||||
|
||||
// List of files uploaded or copy
|
||||
$response['attachments'][$i++] = $attributes;
|
||||
|
||||
//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($appUid, $userUid, $pathFile, $attributes['APP_DOC_FILENAME'], $appDocUid, 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', $appDocUid)->update(['APP_DOC_PLUGIN' => $triggerDetail->getNamespace()]);
|
||||
|
||||
// Remove the file from the server
|
||||
unlink($pathFile);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$response['attachment_errors'][$j++] = [
|
||||
'error' => 'error',
|
||||
|
||||
@@ -676,23 +676,23 @@ function saveAppDocument($file, $appUid, $appDocUid, $version = 1, $upload = tru
|
||||
$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;
|
||||
$pathFile = $pathCase . $fileName;
|
||||
|
||||
$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);
|
||||
if (!copy($file["tmp_name"], $pathCase . $fileName)) {
|
||||
$pathFile = '';
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $pathFile;
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user