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