Commit 067b8e7119e48eb2ccc2fdc265e6907c051887cb

Authored by Mark Holtzhausen
1 parent 7768b7ef

Ongoing changes to Multiple Download Manager

ktwebservice/KTDownloadManager.inc.php
... ... @@ -197,6 +197,66 @@ class KTDownloadManager
197 197  
198 198 return true;
199 199 }
  200 +
  201 + function multipart_download($document_id, $hash, $version = null, $apptype = 'ws', $chunkSize = NULL, $part = 0) {
  202 + $oConfig =& KTConfig::getSingleton();
  203 +
  204 + $sql = "SELECT 1 FROM download_files WHERE hash=? AND session=? AND document_id=?";
  205 + $rows = DBUtil::getResultArray ( array ($sql, array ($hash, $this->session, $document_id ) ) );
  206 + if (PEAR::isError ( $rows )) {
  207 + return $rows;
  208 + }
  209 +
  210 + if (count ( $rows ) == 0) {
  211 + return new PEAR_Error ( 'Invalid session.' );
  212 + }
  213 +
  214 + // If document is being downloaded by an external user bypass the session checking
  215 + $check = strstr ( $this->session, 'ktext_' . $document_id );
  216 + if ($check == 0 && $check !== false) {
  217 + // Use external download function
  218 + return $this->download_ext ( $document_id, $hash, $version = null );
  219 + }
  220 +
  221 + $storage = & KTStorageManagerUtil::getSingleton ();
  222 +
  223 + $ktapi = &new KTAPI ( );
  224 + $res = $ktapi->get_active_session ( $this->session, null, $apptype );
  225 + if (PEAR::isError ( $res )) {
  226 + return $res;
  227 + }
  228 +
  229 + $document = $ktapi->get_document_by_id ( $document_id );
  230 + if (PEAR::isError ( $document )) {
  231 + return $document;
  232 + }
  233 +
  234 + if (! empty ( $version )) {
  235 + $version = KTDocumentContentVersion::get ( $version );
  236 + $res = $storage->downloadVersion ( $document->document, $version );
  237 + } else {
  238 + $res = $storage->download ( $document->document );
  239 + }
  240 + if (PEAR::isError ( $res )) {
  241 + return $res;
  242 + }
  243 +
  244 + // Set Default Chunk Size (in KB)
  245 + $chunkSize=(int)$chunkSize;
  246 + if($chunkSize<1024)$chunkSize=1024;
  247 +
  248 + //Make sure part is set
  249 + $part=(int)$part;
  250 +
  251 + $fileSize=$document->getFileSize();
  252 + $fileName=$document->getFileName();
  253 + $path=$oConfig->get('urls/documentRoot').'/'.$document->getStoragePath();
  254 +
  255 +// $sql = "DELETE FROM download_files WHERE hash='$hash' AND session='$this->session' AND document_id=$document_id";
  256 +// $result = DBUtil::runQuery ( $sql );
  257 +
  258 + return true;
  259 + }
200 260  
201 261 function download_ext($document_id, $hash, $version = null)
202 262 {
... ...
webservice/clienttools/services/mdownload.php 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 + *
  5 + * This does the download of a file based on the download_files table.
  6 + *
  7 + * KnowledgeTree Community Edition
  8 + * Document Management Made Simple
  9 + * Copyright (C) 2008, 2009 KnowledgeTree Inc.
  10 + * Portions copyright The Jam Warehouse Software (Pty) Limited
  11 + *
  12 + * This program is free software; you can redistribute it and/or modify it under
  13 + * the terms of the GNU General Public License version 3 as published by the
  14 + * Free Software Foundation.
  15 + *
  16 + * This program is distributed in the hope that it will be useful, but WITHOUT
  17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  19 + * details.
  20 + *
  21 + * You should have received a copy of the GNU General Public License
  22 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23 + *
  24 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  25 + * California 94120-7775, or email info@knowledgetree.com.
  26 + *
  27 + * The interactive user interfaces in modified source and object code versions
  28 + * of this program must display Appropriate Legal Notices, as required under
  29 + * Section 5 of the GNU General Public License version 3.
  30 + *
  31 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  32 + * these Appropriate Legal Notices must retain the display of the "Powered by
  33 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  34 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  35 + * must display the words "Powered by KnowledgeTree" and retain the original
  36 + * copyright notice.
  37 + * Contributor( s): ______________________________________
  38 + *
  39 + */
  40 +
  41 +if (!array_key_exists('code',$_GET))
  42 +{
  43 + $msg = urlencode('Code not specified.');
  44 + print "status_code=1&msg=$msg";
  45 + exit;
  46 +}
  47 +
  48 +$hash = $_GET['code'];
  49 +
  50 +if (!array_key_exists('d',$_GET))
  51 +{
  52 + $msg = urlencode('Document not specified.');
  53 + print "status_code=2&msg=$msg";
  54 + exit;
  55 +}
  56 +
  57 +$document_id = $_GET['d'];
  58 +
  59 +if (!array_key_exists('u',$_GET))
  60 +{
  61 + $msg = urlencode('Session not specified.');
  62 + print "status_code=3&msg=$msg";
  63 + exit;
  64 +}
  65 +
  66 +$session = $_GET['u'];
  67 +$apptype = (isset($_GET['apptype'])) ? $_GET['apptype'] : 'ws';
  68 +
  69 +require_once('../../../config/dmsDefaults.php');
  70 +require_once('../../../ktapi/ktapi.inc.php');
  71 +require_once('../../../ktwebservice/KTDownloadManager.inc.php');
  72 +
  73 +$download_manager = new KTDownloadManager();
  74 +$download_manager->set_session($session);
  75 +
  76 +$response = $download_manager->multipart_download($document_id, $hash, null, $apptype,1024,$_GET['part']);
  77 +if (PEAR::isError($response))
  78 +{
  79 + $msg = urlencode($response->getMessage());
  80 + print "status_code=4&msg=$msg:".$_GET["u"].":".$_GET["d"].":".$_GET["code"].":".$_GET["apptype"].":";
  81 + exit;
  82 +}
  83 +
  84 +?>
0 85 \ No newline at end of file
... ...