From 067b8e7119e48eb2ccc2fdc265e6907c051887cb Mon Sep 17 00:00:00 2001 From: Mark Holtzhausen Date: Mon, 26 Oct 2009 09:51:23 +0200 Subject: [PATCH] Ongoing changes to Multiple Download Manager --- ktwebservice/KTDownloadManager.inc.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ webservice/clienttools/services/mdownload.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 0 deletions(-) create mode 100644 webservice/clienttools/services/mdownload.php diff --git a/ktwebservice/KTDownloadManager.inc.php b/ktwebservice/KTDownloadManager.inc.php index 81870aa..c1f319e 100644 --- a/ktwebservice/KTDownloadManager.inc.php +++ b/ktwebservice/KTDownloadManager.inc.php @@ -197,6 +197,66 @@ class KTDownloadManager return true; } + + function multipart_download($document_id, $hash, $version = null, $apptype = 'ws', $chunkSize = NULL, $part = 0) { + $oConfig =& KTConfig::getSingleton(); + + $sql = "SELECT 1 FROM download_files WHERE hash=? AND session=? AND document_id=?"; + $rows = DBUtil::getResultArray ( array ($sql, array ($hash, $this->session, $document_id ) ) ); + if (PEAR::isError ( $rows )) { + return $rows; + } + + if (count ( $rows ) == 0) { + return new PEAR_Error ( 'Invalid session.' ); + } + + // If document is being downloaded by an external user bypass the session checking + $check = strstr ( $this->session, 'ktext_' . $document_id ); + if ($check == 0 && $check !== false) { + // Use external download function + return $this->download_ext ( $document_id, $hash, $version = null ); + } + + $storage = & KTStorageManagerUtil::getSingleton (); + + $ktapi = &new KTAPI ( ); + $res = $ktapi->get_active_session ( $this->session, null, $apptype ); + if (PEAR::isError ( $res )) { + return $res; + } + + $document = $ktapi->get_document_by_id ( $document_id ); + if (PEAR::isError ( $document )) { + return $document; + } + + if (! empty ( $version )) { + $version = KTDocumentContentVersion::get ( $version ); + $res = $storage->downloadVersion ( $document->document, $version ); + } else { + $res = $storage->download ( $document->document ); + } + if (PEAR::isError ( $res )) { + return $res; + } + + // Set Default Chunk Size (in KB) + $chunkSize=(int)$chunkSize; + if($chunkSize<1024)$chunkSize=1024; + + //Make sure part is set + $part=(int)$part; + + $fileSize=$document->getFileSize(); + $fileName=$document->getFileName(); + $path=$oConfig->get('urls/documentRoot').'/'.$document->getStoragePath(); + +// $sql = "DELETE FROM download_files WHERE hash='$hash' AND session='$this->session' AND document_id=$document_id"; +// $result = DBUtil::runQuery ( $sql ); + + return true; + } function download_ext($document_id, $hash, $version = null) { diff --git a/webservice/clienttools/services/mdownload.php b/webservice/clienttools/services/mdownload.php new file mode 100644 index 0000000..2202817 --- /dev/null +++ b/webservice/clienttools/services/mdownload.php @@ -0,0 +1,84 @@ +. + * + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, + * California 94120-7775, or email info@knowledgetree.com. + * + * The interactive user interfaces in modified source and object code versions + * of this program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU General Public License version 3. + * + * In accordance with Section 7(b) of the GNU General Public License version 3, + * these Appropriate Legal Notices must retain the display of the "Powered by + * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. + * Contributor( s): ______________________________________ + * + */ + +if (!array_key_exists('code',$_GET)) +{ + $msg = urlencode('Code not specified.'); + print "status_code=1&msg=$msg"; + exit; +} + +$hash = $_GET['code']; + +if (!array_key_exists('d',$_GET)) +{ + $msg = urlencode('Document not specified.'); + print "status_code=2&msg=$msg"; + exit; +} + +$document_id = $_GET['d']; + +if (!array_key_exists('u',$_GET)) +{ + $msg = urlencode('Session not specified.'); + print "status_code=3&msg=$msg"; + exit; +} + +$session = $_GET['u']; +$apptype = (isset($_GET['apptype'])) ? $_GET['apptype'] : 'ws'; + +require_once('../../../config/dmsDefaults.php'); +require_once('../../../ktapi/ktapi.inc.php'); +require_once('../../../ktwebservice/KTDownloadManager.inc.php'); + +$download_manager = new KTDownloadManager(); +$download_manager->set_session($session); + +$response = $download_manager->multipart_download($document_id, $hash, null, $apptype,1024,$_GET['part']); +if (PEAR::isError($response)) +{ + $msg = urlencode($response->getMessage()); + print "status_code=4&msg=$msg:".$_GET["u"].":".$_GET["d"].":".$_GET["code"].":".$_GET["apptype"].":"; + exit; +} + +?> \ No newline at end of file -- libgit2 0.21.4