diff --git a/restapi/index.php b/restapi/index.php index 13cebfc26..bc0aeba47 100644 --- a/restapi/index.php +++ b/restapi/index.php @@ -629,6 +629,7 @@ class RestapiController { /* {{{ */ $dms = $this->container->dms; $userobj = $this->container->userobj; $settings = $this->container->config; + $notifier = $this->container->notifier; if(!$userobj) { return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); @@ -720,13 +721,12 @@ class RestapiController { /* {{{ */ $fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION); finfo_close($finfo); $res = $mfolder->addDocument($docname, $comment, $expires, $owner ? $owner : $userobj, $keywords, $cats, $temp, $origfilename ? $origfilename : basename($temp), $fileType, $userfiletype, $sequence, array(), array(), $reqversion, $version_comment, $attributes); - // addDocumentCategories($res, $categories); - // setDocumentAttributes($res, $attributes); - unlink($temp); if($res) { $doc = $res[0]; - // $rec = array('id'=>(int)$doc->getId(), 'name'=>$doc->getName(), 'version'=>$doc->getLatestContent()->getVersion()); + if($notifier) { + $notifier->sendNewDocumentMail($doc, $userobj); + } return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$this->__getLatestVersionData($doc->getLatestContent())), 201); } else { return $response->withJson(array('success'=>false, 'message'=>'Upload failed', 'data'=>''), 500); @@ -747,6 +747,7 @@ class RestapiController { /* {{{ */ $dms = $this->container->dms; $userobj = $this->container->userobj; $settings = $this->container->config; + $notifier = $this->container->notifier; if(!$userobj) { return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); @@ -803,10 +804,20 @@ class RestapiController { /* {{{ */ $userfiletype = finfo_file($finfo, $temp); $fileType = ".".pathinfo($origfilename, PATHINFO_EXTENSION); finfo_close($finfo); + $oldexpires = $document->getExpires(); $res=$document->addContent($comment, $userobj, $temp, $origfilename, $fileType, $userfiletype, array(), array(), 0, $attributes); unlink($temp); if($res) { + if($notifier) { + $notifier->sendNewDocumentVersionMail($document, $userobj); + + /* Actually there is not need to even try sending this mail + * 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()); return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec), 200); } else { @@ -827,6 +838,7 @@ class RestapiController { /* {{{ */ $dms = $this->container->dms; $userobj = $this->container->userobj; $settings = $this->container->config; + $notifier = $this->container->notifier; if(!$userobj) { return $response->withJson(array('success'=>false, 'message'=>'Not logged in', 'data'=>''), 403); @@ -869,6 +881,9 @@ class RestapiController { /* {{{ */ unlink($temp); if($res) { $doc = $res[0]; + if($notifier) { + $notifier->sendNewDocumentMail($doc, $userobj); + } $rec = array('id'=>(int)$doc->getId(), 'name'=>$doc->getName()); return $response->withJson(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$rec), 200); } else { @@ -2596,6 +2611,13 @@ class TestController { /* {{{ */ public function echoData($request, $response, $args) { /* {{{ */ return $response->withJson(array('success'=>true, 'message'=>'This is the result of the echo call.', 'data'=>$args['data']), 200); } /* }}} */ + + public function version($request, $response, $args) { /* {{{ */ + $logger = $this->container->logger; + + $v = new SeedDMS_Version(); + return $response->withJson(array('success'=>true, 'message'=>'This is '.$v->banner(), 'data'=>['major'=>$v->majorVersion(), 'minor'=>$v->minorVersion(), 'subminor'=>$v->subminorVersion()]), 200); + } /* }}} */ } /* }}} */ /* Middleware for authentication */ @@ -2645,7 +2667,7 @@ class RestapiAuth { /* {{{ */ */ if($request->getMethod() == 'OPTIONS') { $logger->log("Received preflight options request", PEAR_LOG_DEBUG); - } elseif(!in_array($request->getUri()->getPath(), array('login')) && substr($request->getUri()->getPath(), 0, 5) != 'echo/') { + } elseif(!in_array($request->getUri()->getPath(), array('login')) && substr($request->getUri()->getPath(), 0, 5) != 'echo/' && $request->getUri()->getPath() != 'version') { $userobj = null; if(!empty($this->container->environment['HTTP_AUTHORIZATION']) && !empty($settings->_apiKey) && !empty($settings->_apiUserId)) { $logger->log("Authorization key: ".$this->container->environment['HTTP_AUTHORIZATION'], PEAR_LOG_DEBUG); @@ -2803,6 +2825,7 @@ $app->put('/categories/{id}/name', \RestapiController::class.':changeCategoryNam $app->get('/attributedefinitions', \RestapiController::class.':getAttributeDefinitions'); $app->put('/attributedefinitions/{id}/name', \RestapiController::class.':changeAttributeDefinitionName'); $app->get('/echo/{data}', \TestController::class.':echoData'); +$app->get('/version', \TestController::class.':version'); $app->get('/statstotal', \RestapiController::class.':getStatsTotal'); if(isset($GLOBALS['SEEDDMS_HOOKS']['initRestAPI'])) {