Commit 6c54cd8b448e399a7fc312fb3ac6b134f0dc45f7
1 parent
55c50ed3
changed deleted method to move deleted files to the Deleted folder for admin exp…
…unging or restoration git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2101 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
86 additions
and
18 deletions
lib/documentmanagement/PhysicalDocumentManager.inc
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | -* | |
| 5 | -* Class PhysicalDocumentManager.inc | |
| 6 | -* | |
| 7 | -* Contains all functions required to upload, alter and | |
| 8 | -* delete a physical document. | |
| 9 | -* | |
| 10 | -* Form variables that will be required: | |
| 11 | -* o When calling uploadDocument: | |
| 12 | -* o $fDescription - description of uploaded file | |
| 13 | -* o $fFolderID - primary key of folder into which file will be placed | |
| 14 | -* o When calling deleteDocument: | |
| 15 | -* | |
| 16 | -* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 17 | -* @date 13 January 2003 | |
| 18 | -* @package lib.documentmanagement | |
| 19 | -*/ | |
| 20 | - | |
| 3 | + * $Id$ | |
| 4 | + * | |
| 5 | + * Contains all functions required to upload, alter and | |
| 6 | + * delete a physical document. | |
| 7 | + * | |
| 8 | + * Form variables that will be required: | |
| 9 | + * o When calling uploadDocument: | |
| 10 | + * o $fDescription - description of uploaded file | |
| 11 | + * o $fFolderID - primary key of folder into which file will be placed | |
| 12 | + * o When calling deleteDocument: | |
| 13 | + * | |
| 14 | + * Licensed under the GNU GPL. For full terms see the file DOCS/COPYING. | |
| 15 | + * | |
| 16 | + * @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | |
| 17 | + * @version $Revision$ | |
| 18 | + * @date 13 January 2003 | |
| 19 | + * @package lib.documentmanagement | |
| 20 | + */ | |
| 21 | 21 | |
| 22 | 22 | class PhysicalDocumentManager { |
| 23 | 23 | |
| ... | ... | @@ -130,6 +130,74 @@ class PhysicalDocumentManager { |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | + * Deletes a document- moves it to the Deleted/ folder | |
| 134 | + * | |
| 135 | + * return boolean true on successful move, false otherwhise | |
| 136 | + */ | |
| 137 | + function delete($oDocument) { | |
| 138 | + global $default; | |
| 139 | + // current document path (includes old versions) | |
| 140 | + $sCurrentPath = $oDocument->getPath(); | |
| 141 | + | |
| 142 | + // check if the deleted folder exists and create it if not | |
| 143 | + $sDeletedPrefix = $default->documentRoot . "/Deleted"; | |
| 144 | + if (!file_exists($sDeletedPrefix)) { | |
| 145 | + mkdir($sDeletedPrefix, 0755); | |
| 146 | + } | |
| 147 | + | |
| 148 | + // move the file to the deleted folder, prefixed by its document id | |
| 149 | + $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); | |
| 150 | + | |
| 151 | + // find all the previous versions of this document and rename them | |
| 152 | + // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions | |
| 153 | + $aDocumentTransactions = DocumentTransaction::getList("document_id=" . $oDocument->getID() . " AND transaction_id=" . CHECKOUT); | |
| 154 | + for ($i=0; $i<count($aDocumentTransactions); $i++) { | |
| 155 | + $sVersionedPath = $sCurrentPath . "-" . $aDocumentTransactions[$i]->getVersion(); | |
| 156 | + $sDeletedPath = $sDeletedPrefix . "-" . $aDocumentTransactions[$i]->getVersion(); | |
| 157 | + // move it to the deleted folder | |
| 158 | + $default->log->info("delete: moving $sVersionedPath to $sDeletedPath"); | |
| 159 | + if (!PhysicalDocumentManager::move($sVersionedPath, $sDeletedPath)) { | |
| 160 | + $default->log->error("PhysicalDocumentManager::delete error moving $sVersionedPath to $sDeletedPath; documentID=" . $oDocument->getID()); | |
| 161 | + // FIXME: can't bail now since we don't have transactions- so we doggedly continue deleting and logging errors | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 165 | + // now move the current version | |
| 166 | + if (PhysicalDocumentManager::move($sCurrentPath, $sDeletedPrefix)) { | |
| 167 | + return true; | |
| 168 | + } else { | |
| 169 | + $default->log->error("PhysicalDocumentManager::delete couldn't move $sCurrentPath to $sDeletedPath, documentID=" . $oDocument->getID()); | |
| 170 | + return false; | |
| 171 | + } | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Completely remove a document from the Deleted/ folder | |
| 176 | + * | |
| 177 | + * return boolean true on successful move, false otherwhise | |
| 178 | + */ | |
| 179 | + function expunge($oDocument) { | |
| 180 | + // deleted document path (includes previous versions) | |
| 181 | + $sDeletedPath = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName() . "*"; | |
| 182 | + // zap 'em | |
| 183 | + // FIXME: same problem as delete, can't use wildcards, must step through checkin transactions | |
| 184 | + } | |
| 185 | + | |
| 186 | + /** | |
| 187 | + * Completely remove a document from the Deleted/ folder to the specified folder | |
| 188 | + * | |
| 189 | + * return boolean true on successful move, false otherwhise | |
| 190 | + */ | |
| 191 | + function restore($oDocument) { | |
| 192 | + // deleted document path (includes previous versions) | |
| 193 | + $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); | |
| 194 | + // move the document to the folder | |
| 195 | + $sNewDocumentFileSystemPath = Folder::getFolderPath($oDocument->getFolderID()) . "/" . $oDocument->getFileName(); | |
| 196 | + // FIXME: same problem as delete, can't use wildcards, must step through checkin transactions | |
| 197 | + } | |
| 198 | + | |
| 199 | + | |
| 200 | + /** | |
| 133 | 201 | * View a document using an inline viewer |
| 134 | 202 | * |
| 135 | 203 | * @param Primary key of document to view | ... | ... |