$ cat issue.KTS-1387.patch diff -Naur knowledgeTree/lib/documentmanagement/Document.inc knowledgeTree.new/lib/documentmanagement/Document.inc --- knowledgeTree/lib/documentmanagement/Document.inc 2006-09-19 14:22:15.000000000 +0200 +++ knowledgeTree.new/lib/documentmanagement/Document.inc 2007-06-21 17:58:29.000000000 +0200 @@ -375,15 +375,24 @@ // {{{ cleanupDocumentData /** - * Deletes content from document data tables + * Deletes content from document data tables and links from/to this document */ - function cleanupDocumentData($iDocumentID) { + function cleanupDocumentData() { + $iId = $this->iId; // FIXME this appears to be deprecated, or at least should be - $sTable = KTUtil::getTableName('document_text'); - $sQuery = "DELETE FROM $sTable WHERE document_id = ?"; - $aParams = array($iDocumentID); - $res = DBUtil::runQuery(array($sQuery, $aParams)); - return $res; + $sDocTable = KTUtil::getTableName('document_text'); + $sDocQuery = "DELETE FROM $sDocTable WHERE document_id = ?"; + $aDocParams = array($iId); + $docRes = DBUtil::runQuery(array($sDocQuery, $aDocParams)); + // If deletion was successfull, then we delete all links from/to this document + if ($docRes === DB_OK) { + $sLinkTable = KTUtil::getTableName('document_link'); + $sLinkQuery = "DELETE FROM $sLinkTable WHERE parent_document_id = ? OR child_document_id = ?"; + $aLinkParams = array($iId, $iId); + $linkRes = DBUtil::runQuery(array($sLinkQuery, $aLinkParams)); + return $linkRes; + } + else return $docRes; } // }}} diff -Naur knowledgeTree/plugins/ktcore/admin/deletedDocuments.php knowledgeTree.new/plugins/ktcore/admin/deletedDocuments.php --- knowledgeTree/plugins/ktcore/admin/deletedDocuments.php 2006-09-19 14:22:15.000000000 +0200 +++ knowledgeTree.new/plugins/ktcore/admin/deletedDocuments.php 2007-06-21 17:58:29.000000000 +0200 @@ -135,7 +135,7 @@ $aSuccessDocuments[] = $oDoc->getDisplayPath(); // remove any document data - $oDoc->cleanupDocumentData($oDoc->getId()); // silly - why the redundancy? + $oDoc->cleanupDocumentData(); } } }