diff --git a/class.paperless.php b/class.paperless.php index c5410f8..50b30f1 100644 --- a/class.paperless.php +++ b/class.paperless.php @@ -147,9 +147,9 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ * @param bool $full set to true for content from the file instead of the index */ protected function __getDocumentData($document, $truncate_content=false, $full=false) { /* {{{ */ - $fulltextservice = $this->container->fulltextservice; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; + $fulltextservice = $this->container->get('fulltextservice'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); $lc = $document->getLatestContent(); $dms = $document->getDMS(); @@ -277,9 +277,9 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function token($request, $response) { /* {{{ */ - $settings = $this->container->config; - $authenticator = $this->container->authenticator; - $logger = $this->container->logger; + $settings = $this->container->get('config'); + $authenticator = $this->container->get('authenticator'); + $logger = $this->container->get('logger'); $data = $request->getParsedBody(); if(empty($data['username'])) { @@ -310,11 +310,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function tags($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $fulltextservice = $this->container->fulltextservice; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $fulltextservice = $this->container->get('fulltextservice'); + $logger = $this->container->get('logger'); if(false === ($categories = $dms->getDocumentCategories())) { return $response->withJson(array('results'=>null), 500); @@ -351,12 +351,12 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function post_tag($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; - $fulltextservice = $this->container->fulltextservice; - $notifier = $this->container->notifier; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); + $fulltextservice = $this->container->get('fulltextservice'); + $notifier = $this->container->get('notifier'); if(!$userobj->isAdmin()) return $response->withStatus(404); @@ -374,13 +374,13 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function delete_tag($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; - $notifier = $this->container->notifier; - $fulltextservice = $this->container->fulltextservice; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); + $notifier = $this->container->get('notifier'); + $fulltextservice = $this->container->get('fulltextservice'); if(!$userobj->isAdmin()) return $response->withStatus(404); @@ -407,10 +407,10 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ * instead of calling getStatistics() */ function correspondents($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); //file_put_contents("php://stdout", var_dump($request, true)); @@ -437,10 +437,10 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function document_types($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); $types = array(); if(!empty($settings->_extensions['paperless']['documenttypesattr']) && $attrdef = $dms->getAttributeDefinition($settings->_extensions['paperless']['documenttypesattr'])) { @@ -463,10 +463,10 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function saved_views($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); require_once('class.PaperlessView.php'); @@ -481,12 +481,12 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function post_saved_views($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; - $fulltextservice = $this->container->fulltextservice; - $notifier = $this->container->notifier; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); + $fulltextservice = $this->container->get('fulltextservice'); + $notifier = $this->container->get('notifier'); require_once('class.PaperlessView.php'); @@ -505,12 +505,12 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function delete_saved_views($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; - $notifier = $this->container->notifier; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); + $notifier = $this->container->get('notifier'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -526,12 +526,12 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function patch_saved_views($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; - $notifier = $this->container->notifier; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); + $notifier = $this->container->get('notifier'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -551,10 +551,10 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function storage_paths($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); if(!empty($settings->_extensions['paperless']['usehomefolder'])) { if(!($rootfolder = $dms->getFolder((int) $userobj->getHomeFolder()))) @@ -576,11 +576,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function documents($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $fulltextservice = $this->container->fulltextservice; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $fulltextservice = $this->container->get('fulltextservice'); + $logger = $this->container->get('logger'); $params = $request->getQueryParams(); $logger->log(var_export($params, true), PEAR_LOG_DEBUG); @@ -917,11 +917,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function document($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $fulltextservice = $this->container->fulltextservice; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $fulltextservice = $this->container->get('fulltextservice'); + $logger = $this->container->get('logger'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -947,11 +947,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ * etc. */ function autocomplete($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $fulltextservice = $this->container->fulltextservice; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $fulltextservice = $this->container->get('fulltextservice'); + $logger = $this->container->get('logger'); if(!empty($settings->_extensions['paperless']['autocompletefield'])) $field = $settings->_extensions['paperless']['autocompletefield']; @@ -975,10 +975,10 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function ui_settings($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); $data = array( 'user_id'=>$userobj->getId(), @@ -1035,11 +1035,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function statstotal($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $fulltextservice = $this->container->fulltextservice; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $fulltextservice = $this->container->get('fulltextservice'); + $logger = $this->container->get('logger'); if(false === ($categories = $dms->getDocumentCategories())) { return $response->withJson(array('results'=>null), 500); @@ -1095,11 +1095,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function documents_thumb($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -1135,7 +1135,7 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function fetch_doc($request, $response, $args) { /* {{{ */ - $logger = $this->container->logger; + $logger = $this->container->get('logger'); $logger->log('Fetch doc '.$args['id'], PEAR_LOG_INFO); return $response->withRedirect($request->getUri()->getBasePath().'/api/documents/'.$args['id'].'/download/', 302); } /* }}} */ @@ -1145,11 +1145,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ * documents which are not pdf already into pdf */ function documents_preview($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -1213,11 +1213,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function documents_download($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -1290,11 +1290,11 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function documents_metadata($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -1329,12 +1329,12 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function post_document($request, $response) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $logger = $this->container->logger; - $fulltextservice = $this->container->fulltextservice; - $notifier = $this->container->notifier; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); + $fulltextservice = $this->container->get('fulltextservice'); + $notifier = $this->container->get('notifier'); if(isset($settings->_extensions['paperless']['uploadfolder'])) $mfolder = $dms->getFolder($settings->_extensions['paperless']['uploadfolder']); @@ -1502,12 +1502,12 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function patch_documents($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; - $fulltextservice = $this->container->fulltextservice; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); + $fulltextservice = $this->container->get('fulltextservice'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -1547,12 +1547,12 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ * is still disregarded. */ function put_documents($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; - $fulltextservice = $this->container->fulltextservice; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); + $fulltextservice = $this->container->get('fulltextservice'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -1605,13 +1605,13 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ } /* }}} */ function delete_documents($request, $response, $args) { /* {{{ */ - $dms = $this->container->dms; - $userobj = $this->container->userobj; - $settings = $this->container->config; - $conversionmgr = $this->container->conversionmgr; - $logger = $this->container->logger; - $notifier = $this->container->notifier; - $fulltextservice = $this->container->fulltextservice; + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $conversionmgr = $this->container->get('conversionmgr'); + $logger = $this->container->get('logger'); + $notifier = $this->container->get('notifier'); + $fulltextservice = $this->container->get('fulltextservice'); if (!isset($args['id']) || !$args['id']) return $response->withStatus(404); @@ -1671,14 +1671,14 @@ class SeedDMS_ExtPaperless_RestAPI_Auth { /* {{{ */ */ public function __invoke($request, $response, $next) { /* {{{ */ // $this->container has the DI - $dms = $this->container->dms; - $settings = $this->container->config; - $logger = $this->container->logger; + $dms = $this->container->get('dms'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); /* Skip this middleware if the authentication was already successful */ $userobj = null; if($this->container->has('userobj')) - $userobj = $this->container->userobj; + $userobj = $this->container->get('userobj'); if($userobj) { $response = $next($request, $response); @@ -1714,7 +1714,10 @@ class SeedDMS_ExtPaperless_RestAPI_Auth { /* {{{ */ return $response->withJson("No such user", 403); } $dms->setUser($userobj); - $this->container['userobj'] = $userobj; + if($this->container instanceof \Slim\Container) + $this->container['userobj'] = $userobj; + else + $this->container->set('userobj', $userobj); $logger->log("Login with jwt as '".$userobj->getLogin()."' successful", PEAR_LOG_INFO); } else { if(!empty($settings->_apiKey) && !empty($settings->_apiUserId)) { @@ -1727,13 +1730,16 @@ class SeedDMS_ExtPaperless_RestAPI_Auth { /* {{{ */ return $response->withStatus(403); } $dms->setUser($userobj); - $this->container['userobj'] = $userobj; + if($this->container instanceof \Slim\Container) + $this->container['userobj'] = $userobj; + else + $this->container->set('userobj', $userobj); $logger->log("Login with apikey as '".$userobj->getLogin()."' successful", PEAR_LOG_INFO); } } break; case 'Basic': - $authenticator = $this->container->authenticator; + $authenticator = $this->container->get('authenticator'); $kk = explode(':', base64_decode($tmp[1])); $userobj = $authenticator->authenticate($kk[0], $kk[1]); if(!$userobj) { @@ -1741,14 +1747,20 @@ class SeedDMS_ExtPaperless_RestAPI_Auth { /* {{{ */ return $response->withStatus(403); } $dms->setUser($userobj); - $this->container['userobj'] = $userobj; + if($this->container instanceof \Slim\Container) + $this->container['userobj'] = $userobj; + else + $this->container->set('userobj', $userobj); $logger->log("Login with basic authentication as '".$userobj->getLogin()."' successful", PEAR_LOG_INFO); break; } } } else { /* Set userobj to keep other middlewares for authentication from running */ - $this->container['userobj'] = true; + if($this->container instanceof \Slim\Container) + $this->container['userobj'] = true; + else + $this->container->set('userobj', true); } $logger->log("End of paperless middleware for method ".$request->getMethod()." on '".$request->getUri()->getPath()."'", PEAR_LOG_INFO); $response = $next($request, $response);