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