Commit a3aababe0020919ef39048c142e448b9a802b5d5

Authored by Megan Watson
1 parent 4baf0077

Dropped WS version to 2. Fixed bug with add_document_with_metadata. Add empty ch…

…eck around sanitize metadata.

Committed by: Megan Watson
config/dmsDefaults.php
@@ -47,7 +47,7 @@ if (defined('DMS_DEFAULTS_INCLUDED')) @@ -47,7 +47,7 @@ if (defined('DMS_DEFAULTS_INCLUDED'))
47 } 47 }
48 48
49 define('DMS_DEFAULTS_INCLUDED',1); 49 define('DMS_DEFAULTS_INCLUDED',1);
50 -define('LATEST_WEBSERVICE_VERSION',3); 50 +define('LATEST_WEBSERVICE_VERSION',2);
51 51
52 52
53 if (function_exists('apd_set_pprof_trace')) { 53 if (function_exists('apd_set_pprof_trace')) {
ktwebservice/webservice.php
@@ -97,7 +97,7 @@ define('KTWS_ERR_DB_PROBLEM', 99); @@ -97,7 +97,7 @@ define('KTWS_ERR_DB_PROBLEM', 99);
97 97
98 if (!defined('LATEST_WEBSERVICE_VERSION')) 98 if (!defined('LATEST_WEBSERVICE_VERSION'))
99 { 99 {
100 - define('LATEST_WEBSERVICE_VERSION', 3); 100 + define('LATEST_WEBSERVICE_VERSION', 2);
101 } 101 }
102 102
103 function bool2str($bool) 103 function bool2str($bool)
@@ -950,7 +950,7 @@ class KTWebService @@ -950,7 +950,7 @@ class KTWebService
950 ); 950 );
951 } 951 }
952 952
953 - if($this->version >= 3) 953 + if($this->version >= 2)
954 { 954 {
955 // add_document 955 // add_document
956 $this->__dispatch_map['add_document'] = 956 $this->__dispatch_map['add_document'] =
@@ -2276,7 +2276,7 @@ class KTWebService @@ -2276,7 +2276,7 @@ class KTWebService
2276 */ 2276 */
2277 function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $unique_file_id = null) 2277 function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $unique_file_id = null)
2278 { 2278 {
2279 - if(empty($tempfilename)){ 2279 + if(empty($tempfilename) && !empty($unique_file_id)){
2280 $upload_manager = new KTUploadManager(); 2280 $upload_manager = new KTUploadManager();
2281 $tempfilename = $upload_manager->get_tempfile_from_unique_id($unique_file_id); 2281 $tempfilename = $upload_manager->get_tempfile_from_unique_id($unique_file_id);
2282 2282
@@ -3765,7 +3765,7 @@ class KTWebService @@ -3765,7 +3765,7 @@ class KTWebService
3765 */ 3765 */
3766 function update_document_metadata($session_id,$document_id,$metadata, $sysdata=null) 3766 function update_document_metadata($session_id,$document_id,$metadata, $sysdata=null)
3767 { 3767 {
3768 - $this->debug("update_document_metadata('$session_id',$document_id,$metadata, $sysdata)"); 3768 + $this->debug("update_document_metadata('$session_id',$document_id," . print_r($metadata, true) . print_r($sysdata, true));
3769 3769
3770 $kt = &$this->get_ktapi($session_id ); 3770 $kt = &$this->get_ktapi($session_id );
3771 $responseType = 'kt_response'; 3771 $responseType = 'kt_response';
lib/documentmanagement/documentutil.inc.php
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 * KnowledgeTree Community Edition 10 * KnowledgeTree Community Edition
11 * Document Management Made Simple 11 * Document Management Made Simple
12 * Copyright (C) 2008, 2009 KnowledgeTree Inc. 12 * Copyright (C) 2008, 2009 KnowledgeTree Inc.
13 - * 13 + *
14 * 14 *
15 * This program is free software; you can redistribute it and/or modify it under 15 * This program is free software; you can redistribute it and/or modify it under
16 * the terms of the GNU General Public License version 3 as published by the 16 * the terms of the GNU General Public License version 3 as published by the
@@ -588,21 +588,21 @@ $sourceDocument->getName(), @@ -588,21 +588,21 @@ $sourceDocument->getName(),
588 * - If still no valid date then takes the integers and separators to produce a best guess. 588 * - If still no valid date then takes the integers and separators to produce a best guess.
589 */ 589 */
590 function sanitizeDate($sDate) { 590 function sanitizeDate($sDate) {
591 - 591 +
592 //Checking for Normal Strings, e.g. 13 August 2009 etc. All formats accepted by strtotime() 592 //Checking for Normal Strings, e.g. 13 August 2009 etc. All formats accepted by strtotime()
593 $datetime = date_create($sDate); 593 $datetime = date_create($sDate);
594 $resDate = date_format($datetime, 'Y-m-d'); 594 $resDate = date_format($datetime, 'Y-m-d');
595 - 595 +
596 if (!trim($resDate) == '') { 596 if (!trim($resDate) == '') {
597 return $resDate; 597 return $resDate;
598 } else { 598 } else {
599 //If null then removing quotes e.g. 14'th doesn't yield a valid date but 14th does 599 //If null then removing quotes e.g. 14'th doesn't yield a valid date but 14th does
600 $sDate = str_replace("'", '', $sDate); 600 $sDate = str_replace("'", '', $sDate);
601 $sDate = str_replace('"', '', $sDate); 601 $sDate = str_replace('"', '', $sDate);
602 - 602 +
603 $datetime = date_create($sDate); 603 $datetime = date_create($sDate);
604 $resDate = date_format($datetime, 'Y-m-d'); 604 $resDate = date_format($datetime, 'Y-m-d');
605 - 605 +
606 if (!trim($resDate) == '') { 606 if (!trim($resDate) == '') {
607 return $resDate; 607 return $resDate;
608 } else { 608 } else {
@@ -610,22 +610,22 @@ $sourceDocument->getName(), @@ -610,22 +610,22 @@ $sourceDocument->getName(),
610 //Stripping non-numerics 610 //Stripping non-numerics
611 $sDate = preg_replace('/[^0-9]/', '-', $sDate); 611 $sDate = preg_replace('/[^0-9]/', '-', $sDate);
612 $token = strpos($sDate, '--'); 612 $token = strpos($sDate, '--');
613 - 613 +
614 while ($token != 0) 614 while ($token != 0)
615 { 615 {
616 $sDate = str_replace('--', '-', $sDate); 616 $sDate = str_replace('--', '-', $sDate);
617 $token = strpos($sDate, '--'); 617 $token = strpos($sDate, '--');
618 } 618 }
619 - 619 +
620 $datetime = date_create($sDate); 620 $datetime = date_create($sDate);
621 $resDate = date_format($datetime, 'Y-m-d'); 621 $resDate = date_format($datetime, 'Y-m-d');
622 - 622 +
623 return $resDate; 623 return $resDate;
624 - 624 +
625 } 625 }
626 } 626 }
627 } 627 }
628 - 628 +
629 // Forcefully sanitize metadata, specifically date values, to account for client tools that submit unvalidated date input 629 // Forcefully sanitize metadata, specifically date values, to account for client tools that submit unvalidated date input
630 // Will produce a best effort match to a valid date format. 630 // Will produce a best effort match to a valid date format.
631 function sanitizeMetadata($oDocument, $aMetadata){ 631 function sanitizeMetadata($oDocument, $aMetadata){
@@ -640,7 +640,7 @@ $sourceDocument->getName(), @@ -640,7 +640,7 @@ $sourceDocument->getName(),
640 } 640 }
641 $aSimpleMetadata[$oField->getId()] = $sValue; 641 $aSimpleMetadata[$oField->getId()] = $sValue;
642 } 642 }
643 - 643 +
644 foreach ($aFieldsets as $oFieldset) { 644 foreach ($aFieldsets as $oFieldset) {
645 $aFields =& $oFieldset->getFields(); 645 $aFields =& $oFieldset->getFields();
646 $aFieldValues = array(); 646 $aFieldValues = array();
@@ -649,32 +649,34 @@ $sourceDocument->getName(), @@ -649,32 +649,34 @@ $sourceDocument->getName(),
649 if (!empty($v)) { 649 if (!empty($v)) {
650 $aFieldValues[$oField->getId()] = $val; 650 $aFieldValues[$oField->getId()] = $val;
651 } 651 }
652 - 652 +
653 //Sanitizing Date Values 653 //Sanitizing Date Values
654 if ($oField->getDataType() == 'DATE') { 654 if ($oField->getDataType() == 'DATE') {
655 $val = KTDocumentUtil::sanitizeDate($val); 655 $val = KTDocumentUtil::sanitizeDate($val);
656 } 656 }
657 - 657 +
658 if (!is_null($val)) { 658 if (!is_null($val)) {
659 $MDPack[] = array( 659 $MDPack[] = array(
660 $oField, 660 $oField,
661 $val 661 $val
662 ); 662 );
663 } 663 }
664 - 664 +
665 } 665 }
666 } 666 }
667 - 667 +
668 return $MDPack; 668 return $MDPack;
669 } 669 }
670 - 670 +
671 // {{{ saveMetadata 671 // {{{ saveMetadata
672 function saveMetadata(&$oDocument, $aMetadata, $aOptions = null) { 672 function saveMetadata(&$oDocument, $aMetadata, $aOptions = null) {
673 $table = 'document_fields_link'; 673 $table = 'document_fields_link';
674 - 674 +
675 //Sanitizing Date Fields 675 //Sanitizing Date Fields
676 - $aMetadata = KTDocumentUtil::sanitizeMetadata($oDocument, $aMetadata);  
677 - 676 + if(!empty($aMetadata)){
  677 + $aMetadata = KTDocumentUtil::sanitizeMetadata($oDocument, $aMetadata);
  678 + }
  679 +
678 $bNoValidate = KTUtil::arrayGet($aOptions, 'novalidate', false); 680 $bNoValidate = KTUtil::arrayGet($aOptions, 'novalidate', false);
679 if ($bNoValidate !== true) 681 if ($bNoValidate !== true)
680 { 682 {
@@ -1655,7 +1657,7 @@ $sourceDocument->getName(), @@ -1655,7 +1657,7 @@ $sourceDocument->getName(),
1655 1657
1656 DBUtil::commit(); 1658 DBUtil::commit();
1657 } 1659 }
1658 - 1660 +
1659 public static function getDocumentContent($oDocument) 1661 public static function getDocumentContent($oDocument)
1660 { 1662 {
1661 global $default; 1663 global $default;
@@ -1686,7 +1688,7 @@ $sourceDocument->getName(), @@ -1686,7 +1688,7 @@ $sourceDocument->getName(),
1686 } 1688 }
1687 1689
1688 $content = file_get_contents($path); 1690 $content = file_get_contents($path);
1689 - 1691 +
1690 return $content; 1692 return $content;
1691 } 1693 }
1692 } 1694 }