diff --git a/lib/browse/browseutil.inc.php b/lib/browse/browseutil.inc.php index e46d370..1642790 100644 --- a/lib/browse/browseutil.inc.php +++ b/lib/browse/browseutil.inc.php @@ -35,7 +35,7 @@ class KTBrowseUtil { $sFolderPath = dirname($sPath); $aFolderInfo = KTBrowseUtil::_folderOrDocument($sFolderPath); - + if ($aFolderInfo === false) { return $aFolderInfo; } @@ -61,7 +61,12 @@ class KTBrowseUtil { return array($id, null, null); } - $sQuery = "SELECT id FROM documents WHERE folder_id = ? AND filename = ?"; + $sQuery = sprintf("SELECT d.id FROM %s AS d" . + " LEFT JOIN %s AS dm ON (d.metadata_version_id = dm.id) LEFT JOIN %s AS dc ON (dm.content_version_id = dc.id)" . + " WHERE d.folder_id = ? AND dc.filename = ?", + KTUtil::getTableName(documents), + KTUtil::getTableName('document_metadata_version'), + KTUtil::getTableName('document_content_version')); $aParams = array($iFolderID, $sFileName); $iDocumentID = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); @@ -90,7 +95,7 @@ class KTBrowseUtil { $sFolderPath = dirname($sPath); $aFolderNames = split('/', $sFolderPath); - + $iFolderID = 0; $aRemaining = $aFolderNames; @@ -115,10 +120,15 @@ class KTBrowseUtil { $iFolderID = (int)$id; } - $sQuery = "SELECT id FROM documents WHERE folder_id = ? AND filename = ?"; + $sQuery = sprintf("SELECT d.id FROM %s AS d" . + " LEFT JOIN %s AS dm ON (d.metadata_version_id = dm.id) LEFT JOIN %s AS dc ON (dm.content_version_id = dc.id)" . + " WHERE d.folder_id = ? AND dc.filename = ?", + KTUtil::getTableName(documents), + KTUtil::getTableName('document_metadata_version'), + KTUtil::getTableName('document_content_version')); $aParams = array($iFolderID, $sFileName); $iDocumentID = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); - + if (PEAR::isError($iDocumentID)) { // XXX: log error return false; @@ -128,6 +138,7 @@ class KTBrowseUtil { $sQuery = "SELECT id FROM folders WHERE parent_id = ? AND name = ?"; $aParams = array($iFolderID, $sFileName); $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); + if (PEAR::isError($id)) { // XXX: log error return false; @@ -139,9 +150,6 @@ class KTBrowseUtil { // XXX: log error return array($iFolderID, false); } - /* if (substr($path, -1) !== "/") { - header("Location: " . $_SERVER["PHP_SELF"] . "/"); - } */ return array($id, null); } diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php index 4c548ff..1185862 100644 --- a/lib/documentmanagement/documentutil.inc.php +++ b/lib/documentmanagement/documentutil.inc.php @@ -118,6 +118,38 @@ class KTDocumentUtil { return true; } + function checkout($oDocument, $sCheckoutComment, $oUser) { + if ($oDocument->getIsCheckedOut()) { + return PEAR::raiseError('Already checked out.'); + } + + // FIXME at the moment errors this _does not_ rollback. + + $this->oDocument->setIsCheckedOut(true); + $this->oDocument->setCheckedOutUserID($oUser->getId()); + if (!$this->oDocument->update()) { return PEAR::raiseError(_("There was a problem checking out the document.")); } + + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); + $aTriggers = $oKTTriggerRegistry->getTriggers('checkout', 'postValidate'); + foreach ($aTriggers as $aTrigger) { + $sTrigger = $aTrigger[0]; + $oTrigger = new $sTrigger; + $aInfo = array( + "document" => $this->oDocument, + ); + $oTrigger->setInfo($aInfo); + $ret = $oTrigger->postValidate(); + if (PEAR::isError($ret)) { + return $ret; + } + } + + $oDocumentTransaction = & new DocumentTransaction($oDocument, $sCheckoutComment, 'ktcore.transactions.check_out'); + $oDocumentTransaction->create(); + + return true; + } + function &_add($oFolder, $sFilename, $oUser, $aOptions) { global $default; diff --git a/plugins/ktcore/KTDocumentActions.php b/plugins/ktcore/KTDocumentActions.php index 47af6e3..7efe0b5 100644 --- a/plugins/ktcore/KTDocumentActions.php +++ b/plugins/ktcore/KTDocumentActions.php @@ -106,36 +106,13 @@ class KTDocumentCheckOutAction extends KTDocumentAction { $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final'); $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions); - - // flip the checkout status - $this->oDocument->setIsCheckedOut(true); - // set the user checking the document out - $this->oDocument->setCheckedOutUserID($_SESSION["userID"]); - // update it - if (!$this->oDocument->update()) { - $_SESSION['KTErrorMessage'][] = _("There was a problem checking out the document."); - controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); - } - - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); - $aTriggers = $oKTTriggerRegistry->getTriggers('checkout', 'postValidate'); - foreach ($aTriggers as $aTrigger) { - $sTrigger = $aTrigger[0]; - $oTrigger = new $sTrigger; - $aInfo = array( - "document" => $this->oDocument, - ); - $oTrigger->setInfo($aInfo); - $ret = $oTrigger->postValidate(); - if (PEAR::isError($ret)) { - $this->oDocument->delete(); - return $ret; - } + $this->startTransaction(); + $res = KTDocumentUtil::checkout($this->oDocument, $sReason, $this->oUser); + if (PEAR::isError($res)) { + return $this->errorRedirectToMain(sprintf(_('Failed to check out the document: %s'), $res->getMessage())); } - - $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sReason, 'ktcore.transactions.check_out'); - $oDocumentTransaction->create(); - + + $this->commitTransaction(); $oTemplate->setData(array( 'context' => &$this, 'reason' => $sReason, diff --git a/view.php b/view.php index 7b327e5..ba73801 100755 --- a/view.php +++ b/view.php @@ -104,10 +104,6 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { $document_data["field_values"] = $field_values; - - // FIXME generate portlets - // FIXME generate breadcrumb - // Fieldset generation. // // we need to create a set of FieldsetDisplay objects