function do_main() { $oStorage =& KTStorageManagerUtil::getSingleton(); $aOptions = array(); $iVersion = KTUtil::arrayGet($_REQUEST, 'version'); session_write_close(); if ($iVersion) { $oVersion = KTDocumentContentVersion::get($iVersion); $aOptions['version'] = sprintf('%d.%d', $oVersion->getMajorVersionNumber(), $oVersion->getMinorVersionNumber()); $res = $oStorage->downloadVersion($this->oDocument, $iVersion); } else { $res = $oStorage->download($this->oDocument); } if ($res === false) { $this->addErrorMessage(_kt('The file you requested is not available - please contact the system administrator if this is incorrect.')); redirect(generateControllerLink('viewDocument', sprintf(_kt('fDocumentId=%d'), $this->oDocument->getId()))); exit(0); } $oDocumentTransaction =& new DocumentTransaction($this->oDocument, _kt('Document downloaded'), 'ktcore.transactions.download', $aOptions); $oDocumentTransaction->create(); // fire subscription alerts for the downloaded document $oKTConfig =& KTConfig::getSingleton(); $bNotifications = $oKTConfig->get('export/enablenotifications', 'on') == 'on' ? true : false; if ($bNotifications) { $oSubscriptionEvent = new SubscriptionEvent(); $oFolder = Folder::get($this->oDocument->getFolderID()); $oSubscriptionEvent->DownloadDocument($this->oDocument, $oFolder); } exit(0); }
function download_ext($document_id, $hash, $version = null) { $storage =& KTStorageManagerUtil::getSingleton(); $document = Document::get($document_id); if (PEAR::isError($document)) { return $document; } if (!empty($version)) { $version = KTDocumentContentVersion::get($version); $res = $storage->downloadVersion($document, $version); } else { $res = $storage->download($document); } if (PEAR::isError($res)) { return $res; } $sql = "DELETE FROM download_files WHERE hash='{$hash}' AND session='{$this->session}' AND document_id={$document_id}"; $result = DBUtil::runQuery($sql); return true; }
/** * Completely remove a document version * * return boolean true on successful delete */ function deleteVersion($oVersion) { $oConfig =& KTConfig::getSingleton(); $sDocumentRoot = $oConfig->get('urls/documentRoot'); $iContentId = $oVersion->getContentVersionId(); $oContentVersion = KTDocumentContentVersion::get($iContentId); $sPath = $oContentVersion->getStoragePath(); $sFullPath = sprintf("%s/%s", $sDocumentRoot, $sPath); if (file_exists($sFullPath)) { unlink($sFullPath); } return true; }
/** * Delete a selected version of the document. */ function deleteVersion($oDocument, $iVersionID, $sReason) { $oDocument =& KTUtil::getObject('Document', $oDocument); $oVersion =& KTDocumentMetadataVersion::get($iVersionID); $oStorageManager =& KTStorageManagerUtil::getSingleton(); global $default; if (empty($sReason)) { return PEAR::raiseError(_kt('Deletion requires a reason')); } if (PEAR::isError($oDocument) || $oDocument == false) { return PEAR::raiseError(_kt('Invalid document object.')); } if (PEAR::isError($oVersion) || $oVersion == false) { return PEAR::raiseError(_kt('Invalid document version object.')); } $iContentId = $oVersion->getContentVersionId(); $oContentVersion = KTDocumentContentVersion::get($iContentId); if (PEAR::isError($oContentVersion) || $oContentVersion == false) { return PEAR::raiseError(_kt('Invalid document content version object.')); } // Check that the document content is not the same as the current content version $sDocStoragePath = $oDocument->getStoragePath(); $sVersionStoragePath = $oContentVersion->getStoragePath(); if ($sDocStoragePath == $sVersionStoragePath) { return PEAR::raiseError(_kt("Can't delete version: content is the same as the current document content.")); } DBUtil::startTransaction(); // now delete the document version $res = $oStorageManager->deleteVersion($oVersion); if (PEAR::isError($res) || $res == false) { //could not delete the document version from the file system $default->log->error('Deletion: Filesystem error deleting the metadata version ' . $oVersion->getMetadataVersion() . ' of the document ' . $oDocument->getFileName() . ' from folder ' . Folder::getFolderPath($oDocument->getFolderID()) . ' id=' . $oDocument->getFolderID()); // we use a _real_ transaction here ... DBUtil::rollback(); return PEAR::raiseError(_kt('There was a problem deleting the document from storage.')); } // change status for the metadata version $oVersion->setStatusId(VERSION_DELETED); $oVersion->update(); // set the storage path to empty // $oContentVersion->setStoragePath(''); DBUtil::commit(); }