Commit 08f96c4e1b3670183a0505f320244efc33f6e4cc

Authored by kevin_fourie
1 parent 666804bf

Merged in from DEV trunk...

WSA-22
"Changing document type or editing metadata does not call edit triggers"
Fixed.

Reviewed By: Kevin Fourie


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7051 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 58 additions and 7 deletions
ktapi/KTAPIDocument.inc.php
@@ -682,7 +682,27 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -682,7 +682,27 @@ class KTAPI_Document extends KTAPI_FolderItem
682 DBUtil::rollback(); 682 DBUtil::rollback();
683 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); 683 return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res );
684 } 684 }
685 - DBUtil::commit(); 685 +
  686 +
  687 + $metadata = $this->get_packed_metadata();
  688 +
  689 + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
  690 + $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
  691 +
  692 + foreach ($aTriggers as $aTrigger)
  693 + {
  694 + $sTrigger = $aTrigger[0];
  695 + $oTrigger = new $sTrigger;
  696 + $aInfo = array(
  697 + "document" => $this->document,
  698 + "aOptions" => $packed,
  699 + );
  700 + $oTrigger->setInfo($aInfo);
  701 + $ret = $oTrigger->postValidate();
  702 + }
  703 +
  704 + DBUtil::commit();
  705 +
686 } 706 }
687 } 707 }
688 708
@@ -941,14 +961,15 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -941,14 +961,15 @@ class KTAPI_Document extends KTAPI_FolderItem
941 return $results; 961 return $results;
942 } 962 }
943 963
944 - /**  
945 - * This updates the metadata on the file. This includes the 'title'.  
946 - *  
947 - * @param array This is an array containing the metadata to be associated with the file.  
948 - */  
949 - function update_metadata($metadata) 964 + function get_packed_metadata($metadata=null)
950 { 965 {
951 global $default; 966 global $default;
  967 +
  968 + if (is_null($metadata))
  969 + {
  970 + $metadata = $this->get_metadata();
  971 + }
  972 +
952 $packed = array(); 973 $packed = array();
953 974
954 foreach($metadata as $fieldset_metadata) 975 foreach($metadata as $fieldset_metadata)
@@ -1007,6 +1028,19 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -1007,6 +1028,19 @@ class KTAPI_Document extends KTAPI_FolderItem
1007 } 1028 }
1008 } 1029 }
1009 1030
  1031 + return $packed;
  1032 + }
  1033 +
  1034 + /**
  1035 + * This updates the metadata on the file. This includes the 'title'.
  1036 + *
  1037 + * @param array This is an array containing the metadata to be associated with the file.
  1038 + */
  1039 + function update_metadata($metadata)
  1040 + {
  1041 + global $default;
  1042 + $packed = $this->get_packed_metadata($metadata);
  1043 +
1010 DBUtil::startTransaction(); 1044 DBUtil::startTransaction();
1011 $result = KTDocumentUtil::saveMetadata($this->document, $packed); 1045 $result = KTDocumentUtil::saveMetadata($this->document, $packed);
1012 1046
@@ -1021,6 +1055,22 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -1021,6 +1055,22 @@ class KTAPI_Document extends KTAPI_FolderItem
1021 return new KTAPI_Error(sprintf(_kt("Unexpected validation failure: %s."), $result->getMessage())); 1055 return new KTAPI_Error(sprintf(_kt("Unexpected validation failure: %s."), $result->getMessage()));
1022 } 1056 }
1023 DBUtil::commit(); 1057 DBUtil::commit();
  1058 +
  1059 +
  1060 + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
  1061 + $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
  1062 +
  1063 + foreach ($aTriggers as $aTrigger) {
  1064 + $sTrigger = $aTrigger[0];
  1065 + $oTrigger = new $sTrigger;
  1066 + $aInfo = array(
  1067 + "document" => $this->document,
  1068 + "aOptions" => $packed,
  1069 + );
  1070 + $oTrigger->setInfo($aInfo);
  1071 + $ret = $oTrigger->postValidate();
  1072 + }
  1073 +
1024 } 1074 }
1025 1075
1026 1076
@@ -1328,4 +1378,5 @@ class KTAPI_Document extends KTAPI_FolderItem @@ -1328,4 +1378,5 @@ class KTAPI_Document extends KTAPI_FolderItem
1328 DBUtil::commit(); 1378 DBUtil::commit();
1329 } 1379 }
1330 } 1380 }
  1381 +
1331 ?> 1382 ?>
1332 \ No newline at end of file 1383 \ No newline at end of file