physicaldocumentmanager.inc.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 405 行 · 第 1/2 页
SVN-BASE
405 行
} } else { $default->log->error("PhysicalDocumentManager::delete error looking up document versions, id=" . $oDocument->getID()); } // 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) { global $default; // deleted document path $sDeletedPrefix = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); // find all the previous versions of this document and delete them // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions // FIXME: refactor $sql = $default->db; $sQuery = "SELECT DISTINCT version FROM $default->document_transactions_table WHERE document_id = ? AND transaction_id = ?";/*ok*/ $aParams = array($oDocument->getID(), CHECKOUT); $result = $sql->query(array($sQuery, $aParams)); if ($result) { while ($sql->next_record()) { $sVersion = $sql->f("version"); if ($sVersion <> $oDocument->getVersion()) { $sExpungePath = $sDeletedPrefix . "-" . $sVersion; // zap it $default->log->info("PhysicalDocumentManager::expunge rm'ing $sExpungePath"); if (file_exists($sExpungePath)) { if (!@unlink($sExpungePath)) { $default->log->error("PhysicalDocumentManager::expunge error deleting $sExpungePath; documentID=" . $oDocument->getID()); // FIXME: can't bail now since we don't have transactions- so we doggedly continue deleting and logging errors } } else { $default->log->error("PhysicalDocumentManager::expunge can't rm $sExpungePath because it doesn't exist"); } } } } else { $default->log->error("PhysicalDocumentManager::expunge error looking up document versions, id=" . $oDocument->getID()); } if (file_exists($sDeletedPrefix)) { // now delete the current version if (@unlink($sDeletedPrefix)) { $default->log->info("PhysicalDocumentManager::expunge unlinkied $sDeletedPrefix"); return true; } else { $default->log->info("PhysicalDocumentManager::expunge couldn't unlink $sDeletedPrefix"); if (file_exists($sDeletedPrefix)) { return false; } else { return true; } } } else { $default->log->info("PhysicalDocumentManager::expunge can't rm $sDeletedPrefix because it doesn't exist"); return true; } } /** * Delete a single version of a document * * return boolean true on successful delete, false otherwise */ function deleteVersion($oVersion) { global $default; $iContentId = $oVersion->getContentVersionId(); $oContentVersion = KTDocumentContentVersion::get($iContentId); $sFullPath = $default->documentRoot.'/'.$oContentVersion->getStoragePath(); if (file_exists($sFullPath)) { if(@unlink($sFullPath)){ $default->log->info("PhysicalDocumentManager::deleteVersion unlinked $sFullPath"); return true; }else{ $default->log->info("PhysicalDocumentManager::deleteVersion couldn't unlink $sFullPath"); if (file_exists($sFullPath)) { return false; } else { return true; } } }else{ $default->log->info("PhysicalDocumentManager::deleteVersion can't rm $sFullPath because it doesn't exist"); return true; } } /** * Restore a document from the Deleted/ folder to the specified folder * * return boolean true on successful move, false otherwhise */ function restore($oDocument) { global $default; // deleted document path (includes previous versions) $sDeletedPath = $default->documentRoot . "/Deleted/" . $oDocument->getID() . "-" . $oDocument->getFileName(); // NEW FOLDER REALLY NEEDS TO BE / if (is_null($oDocument->getFolderID())) { $oDocument->setFolderID(1); } //var_dump($oDocument->getFolderID()); $sRestorePath = Folder::getFolderPath($oDocument->getFolderID()) . "/" . $oDocument->getFileName(); // find all the previous versions of this document and move them // ie. interrogate transaction history for all CHECKIN transactions and retrieve the versions // FIXME: refactor $sql = $default->db; $sQuery = "SELECT DISTINCT version FROM $default->document_transactions_table WHERE document_id = ? AND transaction_id = ?";/*ok*/ $aParams = array($oDocument->getID(), CHECKOUT); $result = $sql->query(array($sQuery, $aParams)); if ($result) { while ($sql->next_record()) { $sVersion = $sql->f("version"); if ($sVersion <> $oDocument->getVersion()) { $sVersionedDeletedPath = $sDeletedPath . "-" . $sVersion; $sVersionedRestorePath = $sRestorePath . "-" . $sVersion; // move it to the new folder $default->log->info("PhysicalDocumentManager::restore moving $sVersionedDeletedPath to $sVersionedRestorePath"); if (!PhysicalDocumentManager::move($sVersionedDeletedPath, $sVersionedRestorePath)) { $default->log->error("PhysicalDocumentManager::restore error moving $sVersionedDeletedPath to $sVersionedRestorePath; documentID=" . $oDocument->getID()); // FIXME: can't bail now since we don't have transactions- so we doggedly continue restoring and logging errors } } } } else { $default->log->error("PhysicalDocumentManager::expunge error looking up document versions, id=" . $oDocument->getID()); } // now move the current version if (PhysicalDocumentManager::move($sDeletedPath, $sRestorePath)) { return true; } else { $default->log->error("PhysicalDocumentManager::restore couldn't move $sDeletedPath to $sRestorePath, documentID=" . $oDocument->getID()); return false; } } /** * View a document using an inline viewer * * @param Primary key of document to view * * @return int number of bytes read from file on success or false otherwise; * * @todo investigate possible problem in MSIE 5.5 concerning Content-Disposition header */ function inlineViewPhysicalDocument($iDocumentID) { //get the document $oDocument = & Document::get($iDocumentID); //get the path to the document on the server $sDocumentFileSystemPath = $oDocument->getPath(); if (file_exists($sDocumentFileSystemPath)) { header("Content-Type: application/octet-stream"); header("Content-Length: ". $oDocument->getFileSize()); // prefix the filename presented to the browser to preserve the document extension header('Content-Disposition: inline; filename="' . $oDocument->getFileName() . '"'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: must-revalidate"); header("Content-Location: ".$oDocument->getFileName()); return readfile($sDocumentFileSystemPath); } else { return false; } } /** * Get the uploaded file information and place it into a document object * * @param Array containing uploaded file information (use $aFileArray) * par Primary key of folder into which document will be placed * * @return Document Document object containing uploaded file information */ function & createDocumentFromUploadedFile($aFileArray, $iFolderID) { //get the uploaded document information and put it into a document object $oDocument = new Document($aFileArray['name'], $aFileArray['name'], $aFileArray['size'], $_SESSION["userID"], KTMime::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID); return $oDocument; }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?