mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 07:22:11 +00:00
Merge branch 'seeddms-5.1.x' into seeddms-6.0.x
This commit is contained in:
commit
e1a970fb02
|
@ -844,6 +844,7 @@ class RestapiController { /* {{{ */
|
||||||
$userobj = $this->container->userobj;
|
$userobj = $this->container->userobj;
|
||||||
$settings = $this->container->config;
|
$settings = $this->container->config;
|
||||||
$notifier = $this->container->notifier;
|
$notifier = $this->container->notifier;
|
||||||
|
$fulltextservice = $this->container->fulltextservice;
|
||||||
|
|
||||||
if(!$userobj) {
|
if(!$userobj) {
|
||||||
return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403);
|
return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403);
|
||||||
|
@ -862,7 +863,10 @@ class RestapiController { /* {{{ */
|
||||||
|
|
||||||
$document = $dms->getDocument($args['id']);
|
$document = $dms->getDocument($args['id']);
|
||||||
if($document) {
|
if($document) {
|
||||||
if ($document->getAccessMode($userobj, 'updateDocument') >= M_READWRITE) {
|
if ($document->getAccessMode($userobj, 'updateDocument') < M_READWRITE) {
|
||||||
|
return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403);
|
||||||
|
}
|
||||||
|
|
||||||
$params = $request->getParsedBody();
|
$params = $request->getParsedBody();
|
||||||
$origfilename = isset($params['origfilename']) ? $params['origfilename'] : null;
|
$origfilename = isset($params['origfilename']) ? $params['origfilename'] : null;
|
||||||
$comment = isset($params['comment']) ? $params['comment'] : null;
|
$comment = isset($params['comment']) ? $params['comment'] : null;
|
||||||
|
@ -896,31 +900,94 @@ class RestapiController { /* {{{ */
|
||||||
if($lc->getChecksum() == SeedDMS_Core_File::checksum($temp)) {
|
if($lc->getChecksum() == SeedDMS_Core_File::checksum($temp)) {
|
||||||
return $response->withJson(array('success'=>false, 'message'=>'Uploaded file identical to last version', 'data'=>''), 400);
|
return $response->withJson(array('success'=>false, 'message'=>'Uploaded file identical to last version', 'data'=>''), 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($document->isLocked()) {
|
||||||
|
$lockingUser = $document->getLockingUser();
|
||||||
|
if(($lockingUser->getID() != $userobj->getID()) && ($document->getAccessMode($userobj) != M_ALL)) {
|
||||||
|
return $response->withJson(array('success'=>false, 'message'=>'Document is locked', 'data'=>''), 400);
|
||||||
|
}
|
||||||
|
else $document->setLocked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$folder = $document->getFolder();
|
||||||
|
|
||||||
|
// Get the list of reviewers and approvers for this document.
|
||||||
|
$reviewers = array();
|
||||||
|
$approvers = array();
|
||||||
|
$reviewers["i"] = array();
|
||||||
|
$reviewers["g"] = array();
|
||||||
|
$approvers["i"] = array();
|
||||||
|
$approvers["g"] = array();
|
||||||
|
$workflow = null;
|
||||||
|
if($settings->_workflowMode == 'traditional' || $settings->_workflowMode == 'traditional_only_approval') {
|
||||||
|
// add mandatory reviewers/approvers
|
||||||
|
if($settings->_workflowMode == 'traditional') {
|
||||||
|
$mreviewers = getMandatoryReviewers($folder, null, $userobj);
|
||||||
|
if($mreviewers['i'])
|
||||||
|
$reviewers['i'] = array_merge($reviewers['i'], $mreviewers['i']);
|
||||||
|
if($mreviewers['g'])
|
||||||
|
$reviewers['g'] = array_merge($reviewers['g'], $mreviewers['g']);
|
||||||
|
}
|
||||||
|
$mapprovers = getMandatoryApprovers($folder, null, $userobj);
|
||||||
|
if($mapprovers['i'])
|
||||||
|
$approvers['i'] = array_merge($approvers['i'], $mapprovers['i']);
|
||||||
|
if($mapprovers['g'])
|
||||||
|
$approvers['g'] = array_merge($approvers['g'], $mapprovers['g']);
|
||||||
|
} elseif($settings->_workflowMode == 'advanced') {
|
||||||
|
if($workflows = $userobj->getMandatoryWorkflows()) {
|
||||||
|
$workflow = array_shift($workflows);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
$userfiletype = finfo_file($finfo, $temp);
|
$userfiletype = finfo_file($finfo, $temp);
|
||||||
$fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION);
|
$fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION);
|
||||||
finfo_close($finfo);
|
finfo_close($finfo);
|
||||||
$oldexpires = $document->getExpires();
|
|
||||||
$res=$document->addContent($comment, $userobj, $temp, $origfilename, $fileType, $userfiletype, array(), array(), 0, $attributes);
|
|
||||||
|
|
||||||
|
$controller = Controller::factory('UpdateDocument');
|
||||||
|
$controller->setParam('documentsource', 'restapi');
|
||||||
|
$controller->setParam('documentsourcedetails', null);
|
||||||
|
$controller->setParam('dms', $dms);
|
||||||
|
$controller->setParam('user', $userobj);
|
||||||
|
$controller->setParam('folder', $folder);
|
||||||
|
$controller->setParam('document', $document);
|
||||||
|
$controller->setParam('fulltextservice', $fulltextservice);
|
||||||
|
$controller->setParam('comment', $comment);
|
||||||
|
$controller->setParam('userfiletmp', $temp);
|
||||||
|
$controller->setParam('userfilename', $origfilename);
|
||||||
|
$controller->setParam('filetype', $fileType);
|
||||||
|
$controller->setParam('userfiletype', $userfiletype);
|
||||||
|
$controller->setParam('reviewers', $reviewers);
|
||||||
|
$controller->setParam('approvers', $approvers);
|
||||||
|
$controller->setParam('attributes', $attributes);
|
||||||
|
$controller->setParam('workflow', $workflow);
|
||||||
|
$controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText);
|
||||||
|
|
||||||
|
if(!$content = $controller()) {
|
||||||
unlink($temp);
|
unlink($temp);
|
||||||
if($res) {
|
$err = $controller->getErrorMsg();
|
||||||
|
if(is_string($err))
|
||||||
|
$errmsg = getMLText($err);
|
||||||
|
elseif(is_array($err)) {
|
||||||
|
$errmsg = getMLText($err[0], $err[1]);
|
||||||
|
} else {
|
||||||
|
$errmsg = $err;
|
||||||
|
}
|
||||||
|
return $response->withJson(array('success'=>false, 'message'=>'Upload failed: '.$errmsg, 'data'=>''), 500);
|
||||||
|
} else {
|
||||||
|
unlink($temp);
|
||||||
|
if($controller->hasHook('cleanUpDocument')) {
|
||||||
|
$controller->callHook('cleanUpDocument', $document, $file_info);
|
||||||
|
}
|
||||||
|
// Send notification to subscribers.
|
||||||
if($notifier) {
|
if($notifier) {
|
||||||
$notifier->sendNewDocumentVersionMail($document, $userobj);
|
$notifier->sendNewDocumentVersionMail($document, $userobj);
|
||||||
|
|
||||||
/* Actually there is not need to even try sending this mail
|
//$notifier->sendChangedExpiryMail($document, $user, $oldexpires);
|
||||||
* because the expiration date cannot be set when calling
|
|
||||||
* this rest api endpoint.
|
|
||||||
*/
|
|
||||||
$notifier->sendChangedExpiryMail($document, $userobj, $oldexpires);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$rec = array('id'=>(int)$document->getId(), 'name'=>$document->getName(), 'version'=>$document->getLatestContent()->getVersion());
|
$rec = array('id'=>(int)$document->getId(), 'name'=>$document->getName(), 'version'=>$document->getLatestContent()->getVersion());
|
||||||
return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec), 200);
|
return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec), 200);
|
||||||
} else {
|
|
||||||
return $response->withJson(array('success'=>false, 'message'=>'Upload failed', 'data'=>''), 500);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $response->withJson(array('success'=>false, 'message'=>'No access', 'data'=>''), 403);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), 404);
|
return $response->withJson(array('success'=>false, 'message'=>'No document', 'data'=>''), 404);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user