diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php index db1e547..2f55829 100644 --- a/lib/documentmanagement/documentutil.inc.php +++ b/lib/documentmanagement/documentutil.inc.php @@ -567,9 +567,9 @@ class KTDocumentUtil { // }}} // {{{ delete - function delete($oDocument, $sReason) { + function delete($oDocument, $sReason, $iDestFolderId = null) { $oDocument =& KTUtil::getObject('Document', $oDocument); - + if (is_null($iDestFolderId)) { $iDestFolderId = $oDocument->getFolderID(); } $oStorageManager =& KTStorageManagerUtil::getSingleton(); global $default; @@ -588,7 +588,7 @@ class KTDocumentUtil { // flip the status id $oDocument->setStatusID(DELETED); - + $oDocument->setFolderID($iDestFolderId); // try to keep it in _this_ folder, otherwise move to root. $res = $oDocument->update(); if (PEAR::isError($res) || ($res == false)) { diff --git a/lib/foldermanagement/folderutil.inc.php b/lib/foldermanagement/folderutil.inc.php index 118ef0f..6129274 100644 --- a/lib/foldermanagement/folderutil.inc.php +++ b/lib/foldermanagement/folderutil.inc.php @@ -270,7 +270,7 @@ class KTFolderUtil { // now we can go ahead. foreach ($aDocuments as $oDocument) { - $res = KTDocumentUtil::delete($oDocument, $sReason); + $res = KTDocumentUtil::delete($oDocument, $sReason, 1); // id of destination folder = ROOT if (PEAR::isError($res)) { DBUtil::rollback(); return PEAR::raiseError(_('Delete Aborted. Unexpected failure to delete document: ') . $oDocument->getName() . $res->getMessage()); diff --git a/plugins/ktcore/admin/deletedDocuments.php b/plugins/ktcore/admin/deletedDocuments.php index 93460ef..47fe3ea 100755 --- a/plugins/ktcore/admin/deletedDocuments.php +++ b/plugins/ktcore/admin/deletedDocuments.php @@ -118,6 +118,10 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher { $oStorage =& KTStorageManagerUtil::getSingleton(); foreach ($aDocuments as $oDoc) { + // first evaluate the folder for inconsistencies. + $oFolder = Folder::get($oDoc->getFolderID()); + if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); } + if (!$oStorage->expunge($oDoc)) { $aErrorDocuments[] = $oDoc->getDisplayPath(); } else { $oDocumentTransaction = & new DocumentTransaction($oDoc, "Document expunged", 'ktcore.transactions.expunge'); @@ -191,15 +195,23 @@ class DeletedDocumentsDispatcher extends KTAdminDispatcher { $oStorage =& KTStorageManagerUtil::getSingleton(); foreach ($aDocuments as $oDoc) { - $oDoc->setFolderID(1); + $oFolder = Folder::get($oDoc->getFolderID()); + if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); } // move to root if parent no longer exists. if ($oStorage->restore($oDoc)) { $oDoc->setStatusId(LIVE); $res = $oDoc->update(); if (PEAR::isError($res) || ($res == false)) { - $oStorage->delete($oDoc); $aErrorDocuments[] = $oDoc->getName; continue; // skip transactions, etc. } + + $res = KTPermissionUtil::updatePermissionLookup($oDoc); + + if (PEAR::isError($res)) { + $aErrorDocuments[] = $oDoc->getName; + continue; // skip transactions, etc. + } + // create a doc-transaction. // FIXME does this warrant a transaction-type? $oTransaction = new DocumentTransaction($oDoc, 'Restored from deleted state by ' . $this->oUser->getName(), 'ktcore.transactions.update');