Commit 39081d1e15a98a0b23fbdbe0dde829ea74683170
1 parent
f9046d22
- fix folderOrDocument
- move checkout to KTDocumentUtil - tidy up some extraneous fixmes. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4870 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
54 additions
and
41 deletions
lib/browse/browseutil.inc.php
| @@ -35,7 +35,7 @@ class KTBrowseUtil { | @@ -35,7 +35,7 @@ class KTBrowseUtil { | ||
| 35 | $sFolderPath = dirname($sPath); | 35 | $sFolderPath = dirname($sPath); |
| 36 | 36 | ||
| 37 | $aFolderInfo = KTBrowseUtil::_folderOrDocument($sFolderPath); | 37 | $aFolderInfo = KTBrowseUtil::_folderOrDocument($sFolderPath); |
| 38 | - | 38 | + |
| 39 | if ($aFolderInfo === false) { | 39 | if ($aFolderInfo === false) { |
| 40 | return $aFolderInfo; | 40 | return $aFolderInfo; |
| 41 | } | 41 | } |
| @@ -61,7 +61,12 @@ class KTBrowseUtil { | @@ -61,7 +61,12 @@ class KTBrowseUtil { | ||
| 61 | return array($id, null, null); | 61 | return array($id, null, null); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | - $sQuery = "SELECT id FROM documents WHERE folder_id = ? AND filename = ?"; | 64 | + $sQuery = sprintf("SELECT d.id FROM %s AS d" . |
| 65 | + " LEFT JOIN %s AS dm ON (d.metadata_version_id = dm.id) LEFT JOIN %s AS dc ON (dm.content_version_id = dc.id)" . | ||
| 66 | + " WHERE d.folder_id = ? AND dc.filename = ?", | ||
| 67 | + KTUtil::getTableName(documents), | ||
| 68 | + KTUtil::getTableName('document_metadata_version'), | ||
| 69 | + KTUtil::getTableName('document_content_version')); | ||
| 65 | $aParams = array($iFolderID, $sFileName); | 70 | $aParams = array($iFolderID, $sFileName); |
| 66 | $iDocumentID = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); | 71 | $iDocumentID = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); |
| 67 | 72 | ||
| @@ -90,7 +95,7 @@ class KTBrowseUtil { | @@ -90,7 +95,7 @@ class KTBrowseUtil { | ||
| 90 | $sFolderPath = dirname($sPath); | 95 | $sFolderPath = dirname($sPath); |
| 91 | 96 | ||
| 92 | $aFolderNames = split('/', $sFolderPath); | 97 | $aFolderNames = split('/', $sFolderPath); |
| 93 | - | 98 | + |
| 94 | $iFolderID = 0; | 99 | $iFolderID = 0; |
| 95 | 100 | ||
| 96 | $aRemaining = $aFolderNames; | 101 | $aRemaining = $aFolderNames; |
| @@ -115,10 +120,15 @@ class KTBrowseUtil { | @@ -115,10 +120,15 @@ class KTBrowseUtil { | ||
| 115 | $iFolderID = (int)$id; | 120 | $iFolderID = (int)$id; |
| 116 | } | 121 | } |
| 117 | 122 | ||
| 118 | - $sQuery = "SELECT id FROM documents WHERE folder_id = ? AND filename = ?"; | 123 | + $sQuery = sprintf("SELECT d.id FROM %s AS d" . |
| 124 | + " LEFT JOIN %s AS dm ON (d.metadata_version_id = dm.id) LEFT JOIN %s AS dc ON (dm.content_version_id = dc.id)" . | ||
| 125 | + " WHERE d.folder_id = ? AND dc.filename = ?", | ||
| 126 | + KTUtil::getTableName(documents), | ||
| 127 | + KTUtil::getTableName('document_metadata_version'), | ||
| 128 | + KTUtil::getTableName('document_content_version')); | ||
| 119 | $aParams = array($iFolderID, $sFileName); | 129 | $aParams = array($iFolderID, $sFileName); |
| 120 | $iDocumentID = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); | 130 | $iDocumentID = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); |
| 121 | - | 131 | + |
| 122 | if (PEAR::isError($iDocumentID)) { | 132 | if (PEAR::isError($iDocumentID)) { |
| 123 | // XXX: log error | 133 | // XXX: log error |
| 124 | return false; | 134 | return false; |
| @@ -128,6 +138,7 @@ class KTBrowseUtil { | @@ -128,6 +138,7 @@ class KTBrowseUtil { | ||
| 128 | $sQuery = "SELECT id FROM folders WHERE parent_id = ? AND name = ?"; | 138 | $sQuery = "SELECT id FROM folders WHERE parent_id = ? AND name = ?"; |
| 129 | $aParams = array($iFolderID, $sFileName); | 139 | $aParams = array($iFolderID, $sFileName); |
| 130 | $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); | 140 | $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); |
| 141 | + | ||
| 131 | if (PEAR::isError($id)) { | 142 | if (PEAR::isError($id)) { |
| 132 | // XXX: log error | 143 | // XXX: log error |
| 133 | return false; | 144 | return false; |
| @@ -139,9 +150,6 @@ class KTBrowseUtil { | @@ -139,9 +150,6 @@ class KTBrowseUtil { | ||
| 139 | // XXX: log error | 150 | // XXX: log error |
| 140 | return array($iFolderID, false); | 151 | return array($iFolderID, false); |
| 141 | } | 152 | } |
| 142 | - /* if (substr($path, -1) !== "/") { | ||
| 143 | - header("Location: " . $_SERVER["PHP_SELF"] . "/"); | ||
| 144 | - } */ | ||
| 145 | return array($id, null); | 153 | return array($id, null); |
| 146 | } | 154 | } |
| 147 | 155 |
lib/documentmanagement/documentutil.inc.php
| @@ -118,6 +118,38 @@ class KTDocumentUtil { | @@ -118,6 +118,38 @@ class KTDocumentUtil { | ||
| 118 | return true; | 118 | return true; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | + function checkout($oDocument, $sCheckoutComment, $oUser) { | ||
| 122 | + if ($oDocument->getIsCheckedOut()) { | ||
| 123 | + return PEAR::raiseError('Already checked out.'); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + // FIXME at the moment errors this _does not_ rollback. | ||
| 127 | + | ||
| 128 | + $this->oDocument->setIsCheckedOut(true); | ||
| 129 | + $this->oDocument->setCheckedOutUserID($oUser->getId()); | ||
| 130 | + if (!$this->oDocument->update()) { return PEAR::raiseError(_("There was a problem checking out the document.")); } | ||
| 131 | + | ||
| 132 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | ||
| 133 | + $aTriggers = $oKTTriggerRegistry->getTriggers('checkout', 'postValidate'); | ||
| 134 | + foreach ($aTriggers as $aTrigger) { | ||
| 135 | + $sTrigger = $aTrigger[0]; | ||
| 136 | + $oTrigger = new $sTrigger; | ||
| 137 | + $aInfo = array( | ||
| 138 | + "document" => $this->oDocument, | ||
| 139 | + ); | ||
| 140 | + $oTrigger->setInfo($aInfo); | ||
| 141 | + $ret = $oTrigger->postValidate(); | ||
| 142 | + if (PEAR::isError($ret)) { | ||
| 143 | + return $ret; | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + $oDocumentTransaction = & new DocumentTransaction($oDocument, $sCheckoutComment, 'ktcore.transactions.check_out'); | ||
| 148 | + $oDocumentTransaction->create(); | ||
| 149 | + | ||
| 150 | + return true; | ||
| 151 | + } | ||
| 152 | + | ||
| 121 | function &_add($oFolder, $sFilename, $oUser, $aOptions) { | 153 | function &_add($oFolder, $sFilename, $oUser, $aOptions) { |
| 122 | global $default; | 154 | global $default; |
| 123 | 155 |
plugins/ktcore/KTDocumentActions.php
| @@ -106,36 +106,13 @@ class KTDocumentCheckOutAction extends KTDocumentAction { | @@ -106,36 +106,13 @@ class KTDocumentCheckOutAction extends KTDocumentAction { | ||
| 106 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final'); | 106 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final'); |
| 107 | $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions); | 107 | $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions); |
| 108 | 108 | ||
| 109 | - | ||
| 110 | - // flip the checkout status | ||
| 111 | - $this->oDocument->setIsCheckedOut(true); | ||
| 112 | - // set the user checking the document out | ||
| 113 | - $this->oDocument->setCheckedOutUserID($_SESSION["userID"]); | ||
| 114 | - // update it | ||
| 115 | - if (!$this->oDocument->update()) { | ||
| 116 | - $_SESSION['KTErrorMessage'][] = _("There was a problem checking out the document."); | ||
| 117 | - controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | ||
| 121 | - $aTriggers = $oKTTriggerRegistry->getTriggers('checkout', 'postValidate'); | ||
| 122 | - foreach ($aTriggers as $aTrigger) { | ||
| 123 | - $sTrigger = $aTrigger[0]; | ||
| 124 | - $oTrigger = new $sTrigger; | ||
| 125 | - $aInfo = array( | ||
| 126 | - "document" => $this->oDocument, | ||
| 127 | - ); | ||
| 128 | - $oTrigger->setInfo($aInfo); | ||
| 129 | - $ret = $oTrigger->postValidate(); | ||
| 130 | - if (PEAR::isError($ret)) { | ||
| 131 | - $this->oDocument->delete(); | ||
| 132 | - return $ret; | ||
| 133 | - } | 109 | + $this->startTransaction(); |
| 110 | + $res = KTDocumentUtil::checkout($this->oDocument, $sReason, $this->oUser); | ||
| 111 | + if (PEAR::isError($res)) { | ||
| 112 | + return $this->errorRedirectToMain(sprintf(_('Failed to check out the document: %s'), $res->getMessage())); | ||
| 134 | } | 113 | } |
| 135 | - | ||
| 136 | - $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sReason, 'ktcore.transactions.check_out'); | ||
| 137 | - $oDocumentTransaction->create(); | ||
| 138 | - | 114 | + |
| 115 | + $this->commitTransaction(); | ||
| 139 | $oTemplate->setData(array( | 116 | $oTemplate->setData(array( |
| 140 | 'context' => &$this, | 117 | 'context' => &$this, |
| 141 | 'reason' => $sReason, | 118 | 'reason' => $sReason, |
view.php
| @@ -104,10 +104,6 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { | @@ -104,10 +104,6 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { | ||
| 104 | 104 | ||
| 105 | $document_data["field_values"] = $field_values; | 105 | $document_data["field_values"] = $field_values; |
| 106 | 106 | ||
| 107 | - | ||
| 108 | - // FIXME generate portlets | ||
| 109 | - // FIXME generate breadcrumb | ||
| 110 | - | ||
| 111 | // Fieldset generation. | 107 | // Fieldset generation. |
| 112 | // | 108 | // |
| 113 | // we need to create a set of FieldsetDisplay objects | 109 | // we need to create a set of FieldsetDisplay objects |