Commit 4df1bbd47602ecb8d9118dae0114965172689a89
1 parent
e241c495
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
Showing
1 changed file
with
8 additions
and
23 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocument.php
| ... | ... | @@ -46,34 +46,20 @@ require_once(KT_DIR . '/presentation/webpageTemplate.inc'); |
| 46 | 46 | $oStorage =& KTStorageManagerUtil::getSingleton(); |
| 47 | 47 | |
| 48 | 48 | class KTAddDocumentDispatcher extends KTStandardDispatcher { |
| 49 | + var $bAutomaticTransaction = true; | |
| 50 | + | |
| 49 | 51 | function check() { |
| 50 | 52 | if ($_REQUEST['fFolderID']) { |
| 51 | 53 | $_REQUEST['fFolderId'] = $_REQUEST['fFolderID']; |
| 52 | 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 | 58 | $this->validateFolderPermission(); |
| 57 | 59 | $this->validatePost(); |
| 58 | 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 | 63 | function validateDocumentType($iId) { |
| 78 | 64 | $this->oDocumentType =& DocumentType::get($iId); |
| 79 | 65 | if (PEAR::isError($this->oDocumentType) || ($this->oDocumentType === false)) { |
| ... | ... | @@ -196,12 +182,10 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher { |
| 196 | 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 | 186 | exit(0); |
| 201 | 187 | } |
| 202 | 188 | |
| 203 | - DBUtil::startTransaction(); | |
| 204 | - | |
| 205 | 189 | $matches = array(); |
| 206 | 190 | $aFields = array(); |
| 207 | 191 | foreach ($_REQUEST as $k => $v) { |
| ... | ... | @@ -222,7 +206,8 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher { |
| 222 | 206 | $oUser =& User::get($_SESSION["userID"]); |
| 223 | 207 | $oDocument =& KTDocumentUtil::add($this->oFolder, basename($_FILES['fFile']['name']), $oUser, $aOptions); |
| 224 | 208 | if (PEAR::isError($oDocument)) { |
| 225 | - localRenderError($oDocument); | |
| 209 | + $message = $oDocument->getMessage(); | |
| 210 | + $this->errorRedirectToMain($message, 'fFolderId=' . $this->oFolder->getId()); | |
| 226 | 211 | exit(0); |
| 227 | 212 | } |
| 228 | 213 | |
| ... | ... | @@ -255,7 +240,7 @@ class KTAddDocumentDispatcher extends KTStandardDispatcher { |
| 255 | 240 | } |
| 256 | 241 | } |
| 257 | 242 | |
| 258 | - DBUtil::commit(); | |
| 243 | + $this->commitTransaction(); | |
| 259 | 244 | //redirect to the document details page |
| 260 | 245 | controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); |
| 261 | 246 | } | ... | ... |