Commit 881cbbce055c50a55462421600856e5ebd3159cf
1 parent
030ac406
Brad Shuttleworth 2006-02-23 fixes for document-uniqueness, addition, su...
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4996 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
8 changed files
with
65 additions
and
10 deletions
lib/documentmanagement/Document.inc
| ... | ... | @@ -265,6 +265,19 @@ class Document { |
| 265 | 265 | return true; |
| 266 | 266 | } |
| 267 | 267 | // }}} |
| 268 | + | |
| 269 | + function &getByFilenameAndFolder($sFileName, $iFolderID) { | |
| 270 | + $sD = KTUtil::getTableName('documents'); | |
| 271 | + $sDM = KTUtil::getTableName('document_metadata_version'); | |
| 272 | + $sDC = KTUtil::getTableName('document_content_version'); | |
| 273 | + $sQuery = "SELECT D.id AS id FROM $sD AS D | |
| 274 | + LEFT JOIN $sDM AS DM ON D.metadata_version_id = DM.id | |
| 275 | + LEFT JOIN $sDC AS DC ON DM.content_version_id = DC.id | |
| 276 | + WHERE DC.filename = ? AND D.folder_id = ?"; | |
| 277 | + $aParams = array($sFileName, $iFolderID); | |
| 278 | + $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); | |
| 279 | + return Document::get($id); | |
| 280 | + } | |
| 268 | 281 | |
| 269 | 282 | // {{{ nameExists |
| 270 | 283 | /** |
| ... | ... | @@ -293,6 +306,19 @@ class Document { |
| 293 | 306 | } |
| 294 | 307 | // }}} |
| 295 | 308 | |
| 309 | + function &getByNameAndFolder($sName, $iFolderID) { | |
| 310 | + $sD = KTUtil::getTableName('documents'); | |
| 311 | + $sDM = KTUtil::getTableName('document_metadata_version'); | |
| 312 | + $sDC = KTUtil::getTableName('document_content_version'); | |
| 313 | + $sQuery = "SELECT D.id AS id FROM $sD AS D | |
| 314 | + LEFT JOIN $sDM AS DM ON D.metadata_version_id = DM.id | |
| 315 | + LEFT JOIN $sDC AS DC ON DM.content_version_id = DC.id | |
| 316 | + WHERE DM.name = ? AND D.folder_id = ?"; | |
| 317 | + $aParams = array($sName, $iFolderID); | |
| 318 | + $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); | |
| 319 | + return Document::get($id); | |
| 320 | + } | |
| 321 | + | |
| 296 | 322 | // {{{ getDocumentDisplayPath |
| 297 | 323 | /** |
| 298 | 324 | * Static function. | ... | ... |
lib/documentmanagement/documentutil.inc.php
| ... | ... | @@ -135,7 +135,7 @@ class KTDocumentUtil { |
| 135 | 135 | $sTrigger = $aTrigger[0]; |
| 136 | 136 | $oTrigger = new $sTrigger; |
| 137 | 137 | $aInfo = array( |
| 138 | - "document" => $this->oDocument, | |
| 138 | + "document" => $oDocument, | |
| 139 | 139 | ); |
| 140 | 140 | $oTrigger->setInfo($aInfo); |
| 141 | 141 | $ret = $oTrigger->postValidate(); |
| ... | ... | @@ -375,11 +375,30 @@ class KTDocumentUtil { |
| 375 | 375 | // {{{ add |
| 376 | 376 | function &add($oFolder, $sFilename, $oUser, $aOptions) { |
| 377 | 377 | if (KTDocumentUtil::fileExists($oFolder, $sFilename)) { |
| 378 | - return PEAR::raiseError("Document with that filename already exists in this folder"); | |
| 378 | + $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId()); | |
| 379 | + if (PEAR::isError($oDoc)) { | |
| 380 | + return PEAR::raiseError(_("Document with that filename already exists in this folder, and appears to be invalid. Please contact the system administrator.")); | |
| 381 | + } else { | |
| 382 | + if ($oDoc->getStatusID != LIVE) { | |
| 383 | + return PEAR::raiseError(_("Document with that filename already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.")); | |
| 384 | + } else { | |
| 385 | + return PEAR::raiseError(_("Document with that filename already exists in this folder.")); | |
| 386 | + } | |
| 387 | + } | |
| 379 | 388 | } |
| 380 | 389 | $sName = KTUtil::arrayGet($aOptions, 'description', $sFilename); |
| 381 | 390 | if (KTDocumentUtil::nameExists($oFolder, $sName)) { |
| 382 | - return PEAR::raiseError("Document with that name already exists in this folder"); | |
| 391 | + $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId()); | |
| 392 | + if (PEAR::isError($oDoc)) { | |
| 393 | + return PEAR::raiseError(_("Document with that title already exists in this folder, and appears to be invalid. Please contact the system administrator.")); | |
| 394 | + } else { | |
| 395 | + if ($oDoc->getStatusID != LIVE) { | |
| 396 | + return PEAR::raiseError(_("Document with that title already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.")); | |
| 397 | + } else { | |
| 398 | + return PEAR::raiseError(_("Document with that title already exists in this folder.")); | |
| 399 | + } | |
| 400 | + } | |
| 401 | + | |
| 383 | 402 | } |
| 384 | 403 | $oUploadChannel =& KTUploadChannel::getSingleton(); |
| 385 | 404 | $oUploadChannel->sendMessage(new KTUploadNewFile($sFilename)); | ... | ... |
lib/templating/smartytemplate.inc.php
| ... | ... | @@ -207,7 +207,7 @@ class KTSmartyTemplate extends KTTemplate { |
| 207 | 207 | foreach ($entities as $oEntity) { |
| 208 | 208 | $params['values'][] = call_user_func(array(&$oEntity, $idmethod)); |
| 209 | 209 | if ($method != "none") { |
| 210 | - $params['output'][] = call_user_func(array(&$oEntity, $method)); | |
| 210 | + $params['output'][] = ' ' . call_user_func(array(&$oEntity, $method)); | |
| 211 | 211 | } else { |
| 212 | 212 | $params['output'][] = null; |
| 213 | 213 | } | ... | ... |
plugins/ktcore/folder/BulkImport.php
| ... | ... | @@ -22,6 +22,14 @@ class KTBulkImportFolderAction extends KTFolderAction { |
| 22 | 22 | return _('Bulk import'); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | + function getInfo() { | |
| 26 | + if (!Permission::userIsSystemAdministrator($this->oUser->getId())) { | |
| 27 | + return null; | |
| 28 | + | |
| 29 | + } | |
| 30 | + return parent::getInfo(); | |
| 31 | + } | |
| 32 | + | |
| 25 | 33 | function do_main() { |
| 26 | 34 | $this->oPage->setBreadcrumbDetails(_("bulk import")); |
| 27 | 35 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkImport'); | ... | ... |
plugins/ktcore/folder/addDocument.php
| ... | ... | @@ -92,6 +92,8 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 92 | 92 | $sTitle = $this->oValidator->validateString($_REQUEST['title'], $aErrorOptions); |
| 93 | 93 | |
| 94 | 94 | $iFolderId = $this->oFolder->getId(); |
| 95 | + /* | |
| 96 | + // this is now done in ::add | |
| 95 | 97 | if (Document::fileExists(basename($aFile['name']), $iFolderId)) { |
| 96 | 98 | $this->errorRedirectToMain(_('There is already a file with that filename in this folder.'), sprintf('fFolderId=%d', $this->oFolder->getId())); |
| 97 | 99 | exit(0); |
| ... | ... | @@ -101,6 +103,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { |
| 101 | 103 | $this->errorRedirectToMain(_('There is already a file with that title in this folder.'), sprintf('fFolderId=%d', $this->oFolder->getId())); |
| 102 | 104 | exit(0); |
| 103 | 105 | } |
| 106 | + */ | |
| 104 | 107 | |
| 105 | 108 | $matches = array(); |
| 106 | 109 | $aFields = array(); | ... | ... |
plugins/ktstandard/KTSubscriptions.php
| ... | ... | @@ -284,14 +284,14 @@ class KTFolderSubscriptionAction extends KTFolderAction { |
| 284 | 284 | function do_main() { |
| 285 | 285 | $iSubscriptionType = SubscriptionEvent::subTypes('Folder'); |
| 286 | 286 | if (Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) { |
| 287 | - $_SESSION['KTErrorMessage'][] = _("You are already subscribed to that document"); | |
| 287 | + $_SESSION['KTErrorMessage'][] = _("You are already subscribed to that folder"); | |
| 288 | 288 | } else { |
| 289 | 289 | $oSubscription = new Subscription($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType); |
| 290 | 290 | $res = $oSubscription->create(); |
| 291 | 291 | if ($res) { |
| 292 | - $_SESSION['KTInfoMessage'][] = _("You have been subscribed to this document"); | |
| 292 | + $_SESSION['KTInfoMessage'][] = _("You have been subscribed to this folder"); | |
| 293 | 293 | } else { |
| 294 | - $_SESSION['KTErrorMessage'][] = _("There was a problem subscribing you to this document"); | |
| 294 | + $_SESSION['KTErrorMessage'][] = _("There was a problem subscribing you to this folder"); | |
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | controllerRedirect('browse', 'fFolderId=' . $this->oFolder->getId()); | ... | ... |
templates/ktcore/document/add.smarty
| ... | ... | @@ -29,10 +29,8 @@ function handleErrorsInResponse(req) { |
| 29 | 29 | |
| 30 | 30 | function swapElementFromRequest(elementId, url) { |
| 31 | 31 | var deff = doSimpleXMLHttpRequest(url); |
| 32 | - | |
| 33 | 32 | var cp = getElement(elementId); |
| 34 | 33 | cp.innerHTML="loading..."; |
| 35 | - | |
| 36 | 34 | deff.addCallback(partial(swapInItem, elementId)); |
| 37 | 35 | deff.addErrback(handleErrorsInResponse); |
| 38 | 36 | } |
| ... | ... | @@ -82,4 +80,4 @@ addLoadEvent(startupMetadata); |
| 82 | 80 | <input type="submit" name="submit" value="{i18n}Add{/i18n}" /> |
| 83 | 81 | </div> |
| 84 | 82 | <input type="hidden" name="postReceived" value="1" /> |
| 85 | -</form> | |
| 86 | 83 | \ No newline at end of file |
| 84 | +</form> | ... | ... |
view.php
| ... | ... | @@ -458,6 +458,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { |
| 458 | 458 | |
| 459 | 459 | function getUserForId($iUserId) { |
| 460 | 460 | $u = User::get($iUserId); |
| 461 | + if (PEAR::isError($u) || ($u == false)) { return _('User no longer exists'); } | |
| 461 | 462 | return $u->getName(); |
| 462 | 463 | } |
| 463 | 464 | } | ... | ... |