Commit 1d336588042699a56300aa9aa57cd7c9475398d9

Authored by kevin_fourie
1 parent 53898ac4

Merged in from STABLE trunk...

KTC-417
"A license file (once uploaded) is seen as a binary file"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.3a-Release-Branch@9277 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/documentutil.inc.php
... ... @@ -76,16 +76,10 @@ class KTDocumentUtil {
76 76  
77 77 KTDocumentUtil::copyMetadata($oDocument, $iPreviousMetadataVersion);
78 78  
79   - $md5hash = md5_file($sFilename);
80   - $content = $oDocument->_oDocumentContentVersion;
81   - $content->setStorageHash($md5hash);
82   - $content->update();
83   -
84   - if (empty($aOptions)) $aOptions = array();
85   - $aOptions['md5hash'] = $md5hash;
86   -
87   - if (!$oStorage->upload($oDocument, $sFilename, $aOptions)) {
88   - return PEAR::raiseError(_kt('An error occurred while storing the new file'));
  79 + $aOptions['temp_file'] = $sFilename;
  80 + $res = KTDocumentUtil::storeContents($oDocument, '', $aOptions);
  81 + if (PEAR::isError($res)) {
  82 + return $res;
89 83 }
90 84  
91 85 $oDocument->setLastModifiedDate(getCurrentDateTime());
... ... @@ -107,6 +101,7 @@ class KTDocumentUtil {
107 101 $oDocument->setFileName($sFilename);
108 102 $default->log->info('renamed document ' . $oDocument->getId() . ' to ' . $sFilename);
109 103  
  104 + // detection of mime types needs to be refactored. this stuff is damn messy!
110 105 // If the filename has changed then update the mime type
111 106 $iMimeTypeId = KTMime::getMimeTypeID('', $sFilename);
112 107 $oDocument->setMimeTypeId($iMimeTypeId);
... ... @@ -871,14 +866,6 @@ $sourceDocument->getName(),
871 866  
872 867 $sFilename = (isset($aOptions['temp_file'])) ? $aOptions['temp_file'] : '';
873 868  
874   -// $oOutputFile = new KTFSFileLike($sFilename);
875   -// $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile);
876   -// if (($res === false)) {
877   -// return PEAR::raiseError(_kt("Couldn't store contents, and no reason given."));
878   -// } else if (PEAR::isError($res)) {
879   -// return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage()));
880   -// }
881   -
882 869 if(empty($sFilename)){
883 870 return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('The uploaded file does not exist.')));
884 871 }
... ... @@ -891,8 +878,9 @@ $sourceDocument->getName(),
891 878 if (empty($aOptions)) $aOptions = array();
892 879 $aOptions['md5hash'] = $md5hash;
893 880  
  881 + // detection of mime types needs to be refactored. this stuff is damn messy!
894 882 $sType = KTMime::getMimeTypeFromFile($sFilename);
895   - $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());
  883 + $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName(), $sFilename);
896 884 $oDocument->setMimeTypeId($iMimeTypeId);
897 885  
898 886 $res = $oStorage->upload($oDocument, $sFilename, $aOptions);
... ...
lib/mime.inc.php
... ... @@ -6,31 +6,31 @@
6 6 * Document Management Made Simple
7 7 * Copyright (C) 2008 KnowledgeTree Inc.
8 8 * Portions copyright The Jam Warehouse Software (Pty) Limited
9   - *
  9 + *
10 10 * This program is free software; you can redistribute it and/or modify it under
11 11 * the terms of the GNU General Public License version 3 as published by the
12 12 * Free Software Foundation.
13   - *
  13 + *
14 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 17 * details.
18   - *
  18 + *
19 19 * You should have received a copy of the GNU General Public License
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - *
22   - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
  21 + *
  22 + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
23 23 * California 94120-7775, or email info@knowledgetree.com.
24   - *
  24 + *
25 25 * The interactive user interfaces in modified source and object code versions
26 26 * of this program must display Appropriate Legal Notices, as required under
27 27 * Section 5 of the GNU General Public License version 3.
28   - *
  28 + *
29 29 * In accordance with Section 7(b) of the GNU General Public License version 3,
30 30 * these Appropriate Legal Notices must retain the display of the "Powered by
31   - * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
32 32 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
33   - * must display the words "Powered by KnowledgeTree" and retain the original
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
34 34 * copyright notice.
35 35 * Contributor( s): ______________________________________
36 36 *
... ... @@ -48,12 +48,10 @@ class KTMime {
48 48 * @param string filename
49 49 * @return int mime type primary key if found, else default mime type primary key (text/plain)
50 50 */
51   - function getMimeTypeID($sMimeType, $sFileName) {
  51 + function getMimeTypeID($sMimeType, $sFileName, $sTempFile = null) {
52 52 global $default;
53 53 $sTable = KTUtil::getTableName('mimetypes');
54 54  
55   -
56   -
57 55 // check by file extension
58 56 $sExtension = KTMime::stripAllButExtension($sFileName);
59 57 $res = DBUtil::getOneResultKey(array("SELECT id FROM " . $sTable . " WHERE LOWER(filetypes) = ?", array($sExtension)),'id');
... ... @@ -65,7 +63,6 @@ class KTMime {
65 63 return $res;
66 64 }
67 65  
68   -
69 66 // get the mime type id
70 67 if (isset($sMimeType)) {
71 68 $res = DBUtil::getResultArray(array("SELECT id FROM " . $sTable . " WHERE mimetypes = ?", array($sMimeType)));
... ... @@ -77,6 +74,22 @@ class KTMime {
77 74 }
78 75 }
79 76  
  77 + if (!is_null($sTempFile))
  78 + {
  79 + // The default is a binary file, so if mime magic can resolve better, lets try...
  80 + $sMimeType = KTMime::getMimeTypeFromFile($sTempFile);
  81 + if (!empty($sMimeType))
  82 + {
  83 + $res = DBUtil::getResultArray(array("SELECT id FROM " . $sTable . " WHERE mimetypes = ?", array($sMimeType)));
  84 + if (PEAR::isError($res)) {
  85 + ; // pass ?!
  86 + }
  87 + if (count($res) != 0) {
  88 + return $res[0]['id'];
  89 + }
  90 + }
  91 + }
  92 +
80 93 //otherwise return the default mime type
81 94 return KTMime::getDefaultMimeTypeID();
82 95 }
... ... @@ -159,6 +172,11 @@ class KTMime {
159 172 }
160 173  
161 174 if ($sType) {
  175 + $iSpacePos = strpos($sType, ' ');
  176 + if ($iSpacePos !== false)
  177 + {
  178 + $sType = substr($sType, 0, $iSpacePos);
  179 + }
162 180 return preg_replace('/;.*$/', '', $sType);
163 181 }
164 182  
... ...