From 6c54cd8b448e399a7fc312fb3ac6b134f0dc45f7 Mon Sep 17 00:00:00 2001 From: Michael Joseph Date: Mon, 9 Jun 2003 10:12:43 +0000 Subject: [PATCH] changed deleted method to move deleted files to the Deleted folder for admin expunging or restoration --- lib/documentmanagement/PhysicalDocumentManager.inc | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 18 deletions(-) diff --git a/lib/documentmanagement/PhysicalDocumentManager.inc b/lib/documentmanagement/PhysicalDocumentManager.inc index a582b43..435319c 100644 --- a/lib/documentmanagement/PhysicalDocumentManager.inc +++ b/lib/documentmanagement/PhysicalDocumentManager.inc @@ -1,23 +1,23 @@ getPath(); + + // check if the deleted folder exists and create it if not + $sDeletedPrefix = $default->documentRoot . "/Deleted"; + if (!file_exists($sDeletedPrefix)) { + mkdir($sDeletedPrefix, 0755); + } + + // move the file to the deleted folder, prefixed by its document id + $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); + + // find all the previous versions of this document and rename them + // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions + $aDocumentTransactions = DocumentTransaction::getList("document_id=" . $oDocument->getID() . " AND transaction_id=" . CHECKOUT); + for ($i=0; $igetVersion(); + $sDeletedPath = $sDeletedPrefix . "-" . $aDocumentTransactions[$i]->getVersion(); + // move it to the deleted folder + $default->log->info("delete: moving $sVersionedPath to $sDeletedPath"); + if (!PhysicalDocumentManager::move($sVersionedPath, $sDeletedPath)) { + $default->log->error("PhysicalDocumentManager::delete error moving $sVersionedPath to $sDeletedPath; documentID=" . $oDocument->getID()); + // FIXME: can't bail now since we don't have transactions- so we doggedly continue deleting and logging errors + } + } + + // now move the current version + if (PhysicalDocumentManager::move($sCurrentPath, $sDeletedPrefix)) { + return true; + } else { + $default->log->error("PhysicalDocumentManager::delete couldn't move $sCurrentPath to $sDeletedPath, documentID=" . $oDocument->getID()); + return false; + } + } + + /** + * Completely remove a document from the Deleted/ folder + * + * return boolean true on successful move, false otherwhise + */ + function expunge($oDocument) { + // deleted document path (includes previous versions) + $sDeletedPath = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName() . "*"; + // zap 'em + // FIXME: same problem as delete, can't use wildcards, must step through checkin transactions + } + + /** + * Completely remove a document from the Deleted/ folder to the specified folder + * + * return boolean true on successful move, false otherwhise + */ + function restore($oDocument) { + // deleted document path (includes previous versions) + $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); + // move the document to the folder + $sNewDocumentFileSystemPath = Folder::getFolderPath($oDocument->getFolderID()) . "/" . $oDocument->getFileName(); + // FIXME: same problem as delete, can't use wildcards, must step through checkin transactions + } + + + /** * View a document using an inline viewer * * @param Primary key of document to view -- libgit2 0.21.4