Commit b997ff5d06915f61d2dfb0547e2b7ea097009a19

Authored by Brad Shuttleworth
1 parent c0cdd009

fix for KTS-571 and KTS-554


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5058 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/documentutil.inc.php
... ... @@ -567,9 +567,9 @@ class KTDocumentUtil {
567 567 // }}}
568 568  
569 569 // {{{ delete
570   - function delete($oDocument, $sReason) {
  570 + function delete($oDocument, $sReason, $iDestFolderId = null) {
571 571 $oDocument =& KTUtil::getObject('Document', $oDocument);
572   -
  572 + if (is_null($iDestFolderId)) { $iDestFolderId = $oDocument->getFolderID(); }
573 573 $oStorageManager =& KTStorageManagerUtil::getSingleton();
574 574  
575 575 global $default;
... ... @@ -588,7 +588,7 @@ class KTDocumentUtil {
588 588  
589 589 // flip the status id
590 590 $oDocument->setStatusID(DELETED);
591   -
  591 + $oDocument->setFolderID($iDestFolderId); // try to keep it in _this_ folder, otherwise move to root.
592 592  
593 593 $res = $oDocument->update();
594 594 if (PEAR::isError($res) || ($res == false)) {
... ...
lib/foldermanagement/folderutil.inc.php
... ... @@ -270,7 +270,7 @@ class KTFolderUtil {
270 270  
271 271 // now we can go ahead.
272 272 foreach ($aDocuments as $oDocument) {
273   - $res = KTDocumentUtil::delete($oDocument, $sReason);
  273 + $res = KTDocumentUtil::delete($oDocument, $sReason, 1); // id of destination folder = ROOT
274 274 if (PEAR::isError($res)) {
275 275 DBUtil::rollback();
276 276 return PEAR::raiseError(_('Delete Aborted. Unexpected failure to delete document: ') . $oDocument->getName() . $res->getMessage());
... ...
plugins/ktcore/admin/deletedDocuments.php
... ... @@ -118,6 +118,10 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher {
118 118 $oStorage =& KTStorageManagerUtil::getSingleton();
119 119  
120 120 foreach ($aDocuments as $oDoc) {
  121 + // first evaluate the folder for inconsistencies.
  122 + $oFolder = Folder::get($oDoc->getFolderID());
  123 + if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); }
  124 +
121 125 if (!$oStorage->expunge($oDoc)) { $aErrorDocuments[] = $oDoc->getDisplayPath(); }
122 126 else {
123 127 $oDocumentTransaction = & new DocumentTransaction($oDoc, "Document expunged", 'ktcore.transactions.expunge');
... ... @@ -191,15 +195,23 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher {
191 195 $oStorage =& KTStorageManagerUtil::getSingleton();
192 196  
193 197 foreach ($aDocuments as $oDoc) {
194   - $oDoc->setFolderID(1);
  198 + $oFolder = Folder::get($oDoc->getFolderID());
  199 + if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); } // move to root if parent no longer exists.
195 200 if ($oStorage->restore($oDoc)) {
196 201 $oDoc->setStatusId(LIVE);
197 202 $res = $oDoc->update();
198 203 if (PEAR::isError($res) || ($res == false)) {
199   - $oStorage->delete($oDoc);
200 204 $aErrorDocuments[] = $oDoc->getName;
201 205 continue; // skip transactions, etc.
202 206 }
  207 +
  208 + $res = KTPermissionUtil::updatePermissionLookup($oDoc);
  209 +
  210 + if (PEAR::isError($res)) {
  211 + $aErrorDocuments[] = $oDoc->getName;
  212 + continue; // skip transactions, etc.
  213 + }
  214 +
203 215 // create a doc-transaction.
204 216 // FIXME does this warrant a transaction-type?
205 217 $oTransaction = new DocumentTransaction($oDoc, 'Restored from deleted state by ' . $this->oUser->getName(), 'ktcore.transactions.update');
... ...