Commit 86032501596eba96fe0855dd82e636460d8b691a

Authored by Neil Blakey-Milner
1 parent 949ba264

Use dispatcher-wide transactions, use the dispatcher validator, and use

errorRedirect rather than errorPage for problems.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3903 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocument.php
@@ -46,34 +46,20 @@ require_once(KT_DIR . '/presentation/webpageTemplate.inc'); @@ -46,34 +46,20 @@ require_once(KT_DIR . '/presentation/webpageTemplate.inc');
46 $oStorage =& KTStorageManagerUtil::getSingleton(); 46 $oStorage =& KTStorageManagerUtil::getSingleton();
47 47
48 class KTAddDocumentDispatcher extends KTStandardDispatcher { 48 class KTAddDocumentDispatcher extends KTStandardDispatcher {
  49 + var $bAutomaticTransaction = true;
  50 +
49 function check() { 51 function check() {
50 if ($_REQUEST['fFolderID']) { 52 if ($_REQUEST['fFolderID']) {
51 $_REQUEST['fFolderId'] = $_REQUEST['fFolderID']; 53 $_REQUEST['fFolderId'] = $_REQUEST['fFolderID'];
52 unset($_REQUEST['fFolderID']); 54 unset($_REQUEST['fFolderID']);
53 } 55 }
54 - $this->validateFolder($_REQUEST['fFolderId']);  
55 - $this->validatePermission('ktcore.permissions.write'); 56 + $this->oFolder =& $this->oValidator->validateFolder($_REQUEST['fFolderId']);
  57 + $this->oPermission =& $this->oValidator->validatePermissionByName('ktcore.permissions.write');
56 $this->validateFolderPermission(); 58 $this->validateFolderPermission();
57 $this->validatePost(); 59 $this->validatePost();
58 return true; 60 return true;
59 } 61 }
60 62
61 - function validateFolder($iFolderId) {  
62 - $this->oFolder =& Folder::get($iFolderId);  
63 - if (PEAR::isError($this->oFolder) || ($this->oFolder === false)) {  
64 - $this->errorPage(_("Invalid folder given"));  
65 - exit(0);  
66 - }  
67 - }  
68 -  
69 - function validatePermission($sPermission) {  
70 - $this->oPermission =& KTPermission::getByName($sPermission);  
71 - if (PEAR::isError($this->oPermission) || ($this->oPermission === false)) {  
72 - $this->errorPage(_("Permission not found"));  
73 - exit(0);  
74 - }  
75 - }  
76 -  
77 function validateDocumentType($iId) { 63 function validateDocumentType($iId) {
78 $this->oDocumentType =& DocumentType::get($iId); 64 $this->oDocumentType =& DocumentType::get($iId);
79 if (PEAR::isError($this->oDocumentType) || ($this->oDocumentType === false)) { 65 if (PEAR::isError($this->oDocumentType) || ($this->oDocumentType === false)) {
@@ -196,12 +182,10 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher { @@ -196,12 +182,10 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher {
196 $message = _("File uploads are disabled in your PHP configuration"); 182 $message = _("File uploads are disabled in your PHP configuration");
197 } 183 }
198 184
199 - $this->errorPage($message); 185 + $this->errorRedirectToMain($message, 'fFolderId=' . $this->oFolder->getId());
200 exit(0); 186 exit(0);
201 } 187 }
202 188
203 - DBUtil::startTransaction();  
204 -  
205 $matches = array(); 189 $matches = array();
206 $aFields = array(); 190 $aFields = array();
207 foreach ($_REQUEST as $k => $v) { 191 foreach ($_REQUEST as $k => $v) {
@@ -222,7 +206,8 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher { @@ -222,7 +206,8 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher {
222 $oUser =& User::get($_SESSION["userID"]); 206 $oUser =& User::get($_SESSION["userID"]);
223 $oDocument =& KTDocumentUtil::add($this->oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions); 207 $oDocument =& KTDocumentUtil::add($this->oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions);
224 if (PEAR::isError($oDocument)) { 208 if (PEAR::isError($oDocument)) {
225 - localRenderError($oDocument); 209 + $message = $oDocument->getMessage();
  210 + $this->errorRedirectToMain($message, 'fFolderId=' . $this->oFolder->getId());
226 exit(0); 211 exit(0);
227 } 212 }
228 213
@@ -255,7 +240,7 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher { @@ -255,7 +240,7 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher {
255 } 240 }
256 } 241 }
257 242
258 - DBUtil::commit(); 243 + $this->commitTransaction();
259 //redirect to the document details page 244 //redirect to the document details page
260 controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); 245 controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID());
261 } 246 }