From 4854be9eea0d5a051c82f0df21e9b0b76eaced96 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Tue, 7 Aug 2012 18:19:58 +1200 Subject: [PATCH] ENHANCEMENT: adding the ability to extend a DMSDocument's file querying mechanism. --- code/DMSDocument.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/DMSDocument.php b/code/DMSDocument.php index e17bce4..aefc35e 100644 --- a/code/DMSDocument.php +++ b/code/DMSDocument.php @@ -586,16 +586,26 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { } class DMSDocument_Controller extends Controller { + static $allowed_actions = array( 'index' ); + /** + * Returns the document object from the request object's ID parameter. + * Returns null, if no document found + */ + protected function getDocumentFromID($request) { + $id = Convert::raw2sql($request->param('ID')); + return DataObject::get_by_id('DMSDocument', $id); + } + /** * Access the file download without redirecting user, so we can block direct access to documents. */ function index(SS_HTTPRequest $request) { - $id = Convert::raw2sql($this->getRequest()->param('ID')); - if (!empty($id)) $doc = DataObject::get_by_id('DMSDocument', $id); + $doc = $this->getDocumentFromID($request); + if (!empty($doc)) { $canView = false;