mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-11 09:35:00 +00:00
add logging and fix status codes in setDocumentAttribute()
This commit is contained in:
parent
8484d38974
commit
6d13883e8f
|
@ -1584,6 +1584,7 @@ class RestapiController { /* {{{ */
|
|||
function setDocumentAttribute($request, $response, $args) { /* {{{ */
|
||||
$dms = $this->container->dms;
|
||||
$userobj = $this->container->userobj;
|
||||
$logger = $this->container->logger;
|
||||
|
||||
if(!$userobj) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403);
|
||||
|
@ -1602,16 +1603,20 @@ class RestapiController { /* {{{ */
|
|||
$doc = $dms->getDocument($args['id']);
|
||||
if($doc && $attrdef) {
|
||||
if($attrdef->getObjType() !== SeedDMS_Core_AttributeDefinition::objtype_document) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Attribute definition not suitable for documents', 'data'=>''), 500);
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Attribute definition not suitable for documents', 'data'=>''), 409);
|
||||
}
|
||||
|
||||
$params = $request->getParsedBody();
|
||||
if(!isset($params['value'])) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Attribute value not set', 'data'=>''), 400);
|
||||
}
|
||||
$new = $doc->getAttributeValue($attrdef) ? true : false;
|
||||
if(!$attrdef->validate($params['value'], $doc, $new)) {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''), 500);
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Validation of attribute value failed: '.$attrdef->getValidationError(), 'data'=>''), 400);
|
||||
}
|
||||
if($doc->getAccessMode($userobj, 'setDocumentAttribute') > M_READ) {
|
||||
if ($doc->setAttributeValue($attrdef, $params['value'])) {
|
||||
$logger->log("Setting attribute '".$attrdef->getName()."' (".$attrdef->getId().") to '".$params['value']."' successful", PEAR_LOG_INFO);
|
||||
return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 201);
|
||||
} else {
|
||||
return $response->withJson(array('success'=>false, 'message'=>'Could not set attribute value of document', 'data'=>''), 500);
|
||||
|
|
Loading…
Reference in New Issue
Block a user