Commit bca43dd2ca0ffa4d68de09d4a14a442eece6d580
1 parent
63f9be44
WSA-55
"Allow users to be able to update the 'creator', 'created date', and other system fields via the KTAPI and web services" Updated. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7656 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
295 additions
and
48 deletions
ktapi/KTAPIDocument.inc.php
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -56,7 +56,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 56 | 56 | */ |
| 57 | 57 | var $ktapi_folder; |
| 58 | 58 | |
| 59 | - function get_documentid() | |
| 59 | + public function get_documentid() | |
| 60 | 60 | { |
| 61 | 61 | return $this->documentid; |
| 62 | 62 | } |
| ... | ... | @@ -70,7 +70,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 70 | 70 | * @param int $documentid |
| 71 | 71 | * @return KTAPI_Document |
| 72 | 72 | */ |
| 73 | - function &get(&$ktapi, $documentid) | |
| 73 | + public static function &get(&$ktapi, $documentid) | |
| 74 | 74 | { |
| 75 | 75 | assert(!is_null($ktapi)); |
| 76 | 76 | assert(is_a($ktapi, 'KTAPI')); |
| ... | ... | @@ -106,7 +106,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 106 | 106 | return new KTAPI_Document($ktapi, $ktapi_folder, $document); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - function is_deleted() | |
| 109 | + public function is_deleted() | |
| 110 | 110 | { |
| 111 | 111 | return ($this->document->getStatusID() == 3); |
| 112 | 112 | } |
| ... | ... | @@ -119,7 +119,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 119 | 119 | * @param Document $document |
| 120 | 120 | * @return KTAPI_Document |
| 121 | 121 | */ |
| 122 | - function KTAPI_Document(&$ktapi, &$ktapi_folder, &$document) | |
| 122 | + public function KTAPI_Document(&$ktapi, &$ktapi_folder, &$document) | |
| 123 | 123 | { |
| 124 | 124 | assert(is_a($ktapi,'KTAPI')); |
| 125 | 125 | assert(is_null($ktapi_folder) || is_a($ktapi_folder,'KTAPI_Folder')); |
| ... | ... | @@ -138,7 +138,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 138 | 138 | * @param string $tempfilename |
| 139 | 139 | * @param bool $major_update |
| 140 | 140 | */ |
| 141 | - function checkin($filename, $reason, $tempfilename, $major_update=false) | |
| 141 | + public function checkin($filename, $reason, $tempfilename, $major_update=false) | |
| 142 | 142 | { |
| 143 | 143 | if (!is_file($tempfilename)) |
| 144 | 144 | { |
| ... | ... | @@ -190,7 +190,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 190 | 190 | * |
| 191 | 191 | * @param KTAPI_Document $document |
| 192 | 192 | */ |
| 193 | - function link_document($document, $type) | |
| 193 | + public function link_document($document, $type) | |
| 194 | 194 | { |
| 195 | 195 | $typeid = $this->ktapi->get_link_type_id($type); |
| 196 | 196 | if (PEAR::isError($typeid)) |
| ... | ... | @@ -211,7 +211,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 211 | 211 | * |
| 212 | 212 | * @param KTAPI_Document $document |
| 213 | 213 | */ |
| 214 | - function unlink_document($document) | |
| 214 | + public function unlink_document($document) | |
| 215 | 215 | { |
| 216 | 216 | $sql = "DELETE FROM document_link WHERE parent_document_id=$this->documentid AND child_document_id=$document->documentid"; |
| 217 | 217 | $result = DBUtil::runQuery($sql); |
| ... | ... | @@ -226,7 +226,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 226 | 226 | * |
| 227 | 227 | * @return boolean |
| 228 | 228 | */ |
| 229 | - function is_checked_out() | |
| 229 | + public function is_checked_out() | |
| 230 | 230 | { |
| 231 | 231 | return ($this->document->getIsCheckedOut()); |
| 232 | 232 | } |
| ... | ... | @@ -236,7 +236,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 236 | 236 | * |
| 237 | 237 | * @param string $reason |
| 238 | 238 | */ |
| 239 | - function undo_checkout($reason) | |
| 239 | + public function undo_checkout($reason) | |
| 240 | 240 | { |
| 241 | 241 | $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); |
| 242 | 242 | |
| ... | ... | @@ -271,7 +271,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 271 | 271 | DBUtil::commit(); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - function get_linked_documents() | |
| 274 | + public function get_linked_documents() | |
| 275 | 275 | { |
| 276 | 276 | $sql = " |
| 277 | 277 | SELECT |
| ... | ... | @@ -314,13 +314,16 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 314 | 314 | { |
| 315 | 315 | continue; |
| 316 | 316 | } |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 317 | 320 | $result[] = array( |
| 318 | 321 | 'document_id'=>(int)$row['document_id'], |
| 319 | 322 | 'title'=> $row['title'], |
| 320 | 323 | 'size'=>(int)$row['size'], |
| 321 | - 'workflow'=>$row['workflow'], | |
| 322 | - 'workflow_state'=>$row['workflow_state'], | |
| 323 | - 'link_type'=>$row['link_type'], | |
| 324 | + 'workflow'=>empty($row['workflow'])?'n/a':$row['workflow'], | |
| 325 | + 'workflow_state'=>empty($row['workflow_state'])?'n/a':$row['workflow_state'], | |
| 326 | + 'link_type'=>empty($row['link_type'])?'unknown':$row['link_type'], | |
| 324 | 327 | ); |
| 325 | 328 | } |
| 326 | 329 | |
| ... | ... | @@ -333,7 +336,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 333 | 336 | * |
| 334 | 337 | * @param string $reason |
| 335 | 338 | */ |
| 336 | - function checkout($reason) | |
| 339 | + public function checkout($reason) | |
| 337 | 340 | { |
| 338 | 341 | $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); |
| 339 | 342 | |
| ... | ... | @@ -363,7 +366,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 363 | 366 | * |
| 364 | 367 | * @param string $reason |
| 365 | 368 | */ |
| 366 | - function delete($reason) | |
| 369 | + public function delete($reason) | |
| 367 | 370 | { |
| 368 | 371 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_DELETE); |
| 369 | 372 | |
| ... | ... | @@ -393,7 +396,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 393 | 396 | * |
| 394 | 397 | * @param string $ktapi_newuser |
| 395 | 398 | */ |
| 396 | - function change_owner($newusername, $reason='Changing of owner.') | |
| 399 | + public function change_owner($newusername, $reason='Changing of owner.') | |
| 397 | 400 | { |
| 398 | 401 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_CHANGE_OWNERSHIP); |
| 399 | 402 | |
| ... | ... | @@ -448,7 +451,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 448 | 451 | * @param string $newname |
| 449 | 452 | * @param string $newfilename |
| 450 | 453 | */ |
| 451 | - function copy(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null) | |
| 454 | + public function copy(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null) | |
| 452 | 455 | { |
| 453 | 456 | assert(!is_null($ktapi_target_folder)); |
| 454 | 457 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); |
| ... | ... | @@ -549,7 +552,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 549 | 552 | * @param string $newname |
| 550 | 553 | * @param string $newfilename |
| 551 | 554 | */ |
| 552 | - function move(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null) | |
| 555 | + public function move(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null) | |
| 553 | 556 | { |
| 554 | 557 | assert(!is_null($ktapi_target_folder)); |
| 555 | 558 | assert(is_a($ktapi_target_folder,'KTAPI_Folder')); |
| ... | ... | @@ -642,7 +645,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 642 | 645 | * |
| 643 | 646 | * @param string $newname |
| 644 | 647 | */ |
| 645 | - function renameFile($newname) | |
| 648 | + public function renameFile($newname) | |
| 646 | 649 | { |
| 647 | 650 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); |
| 648 | 651 | |
| ... | ... | @@ -666,7 +669,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 666 | 669 | * |
| 667 | 670 | * @param string $newname |
| 668 | 671 | */ |
| 669 | - function change_document_type($documenttype) | |
| 672 | + public function change_document_type($documenttype) | |
| 670 | 673 | { |
| 671 | 674 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); |
| 672 | 675 | |
| ... | ... | @@ -676,6 +679,10 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 676 | 679 | } |
| 677 | 680 | |
| 678 | 681 | $doctypeid = KTAPI::get_documenttypeid($documenttype); |
| 682 | + if (PEAR::isError($doctypeid)) | |
| 683 | + { | |
| 684 | + return $doctypeid; | |
| 685 | + } | |
| 679 | 686 | |
| 680 | 687 | if ($this->document->getDocumentTypeId() != $doctypeid) |
| 681 | 688 | { |
| ... | ... | @@ -717,7 +724,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 717 | 724 | * |
| 718 | 725 | * @param string $newname |
| 719 | 726 | */ |
| 720 | - function rename($newname) | |
| 727 | + public function rename($newname) | |
| 721 | 728 | { |
| 722 | 729 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); |
| 723 | 730 | |
| ... | ... | @@ -747,7 +754,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 747 | 754 | * |
| 748 | 755 | * @param string $reason |
| 749 | 756 | */ |
| 750 | - function archive($reason) | |
| 757 | + public function archive($reason) | |
| 751 | 758 | { |
| 752 | 759 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WRITE); |
| 753 | 760 | |
| ... | ... | @@ -790,7 +797,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 790 | 797 | * |
| 791 | 798 | * @param string $workflow |
| 792 | 799 | */ |
| 793 | - function start_workflow($workflow) | |
| 800 | + public function start_workflow($workflow) | |
| 794 | 801 | { |
| 795 | 802 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); |
| 796 | 803 | |
| ... | ... | @@ -826,7 +833,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 826 | 833 | * This deletes the workflow on the document. |
| 827 | 834 | * |
| 828 | 835 | */ |
| 829 | - function delete_workflow() | |
| 836 | + public function delete_workflow() | |
| 830 | 837 | { |
| 831 | 838 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); |
| 832 | 839 | |
| ... | ... | @@ -836,7 +843,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 836 | 843 | } |
| 837 | 844 | |
| 838 | 845 | $workflowid=$this->document->getWorkflowId(); |
| 839 | - if (!empty($workflowid)) | |
| 846 | + if (empty($workflowid)) | |
| 840 | 847 | { |
| 841 | 848 | return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); |
| 842 | 849 | } |
| ... | ... | @@ -857,7 +864,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 857 | 864 | * @param string $transition |
| 858 | 865 | * @param string $reason |
| 859 | 866 | */ |
| 860 | - function perform_workflow_transition($transition, $reason) | |
| 867 | + public function perform_workflow_transition($transition, $reason) | |
| 861 | 868 | { |
| 862 | 869 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); |
| 863 | 870 | |
| ... | ... | @@ -895,7 +902,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 895 | 902 | * |
| 896 | 903 | * @return array |
| 897 | 904 | */ |
| 898 | - function get_metadata() | |
| 905 | + public function get_metadata() | |
| 899 | 906 | { |
| 900 | 907 | $doctypeid = $this->document->getDocumentTypeID(); |
| 901 | 908 | $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->document, $doctypeid); |
| ... | ... | @@ -967,7 +974,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 967 | 974 | return $results; |
| 968 | 975 | } |
| 969 | 976 | |
| 970 | - function get_packed_metadata($metadata=null) | |
| 977 | + public function get_packed_metadata($metadata=null) | |
| 971 | 978 | { |
| 972 | 979 | global $default; |
| 973 | 980 | |
| ... | ... | @@ -1042,7 +1049,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1042 | 1049 | * |
| 1043 | 1050 | * @param array This is an array containing the metadata to be associated with the file. |
| 1044 | 1051 | */ |
| 1045 | - function update_metadata($metadata) | |
| 1052 | + public function update_metadata($metadata) | |
| 1046 | 1053 | { |
| 1047 | 1054 | global $default; |
| 1048 | 1055 | $packed = $this->get_packed_metadata($metadata); |
| ... | ... | @@ -1079,13 +1086,229 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1079 | 1086 | |
| 1080 | 1087 | } |
| 1081 | 1088 | |
| 1089 | + /** | |
| 1090 | + * This updates the system metadata on the document. | |
| 1091 | + * | |
| 1092 | + * @param array $sysdata | |
| 1093 | + */ | |
| 1094 | + public function update_sysdata($sysdata) | |
| 1095 | + { | |
| 1096 | + if (empty($sysdata)) | |
| 1097 | + { | |
| 1098 | + return; | |
| 1099 | + } | |
| 1100 | + $owner_mapping = array( | |
| 1101 | + 'created_by'=>'creator_id', | |
| 1102 | + 'modified_by'=>'modified_user_id', | |
| 1103 | + 'owner'=>'owner' | |
| 1104 | + ); | |
| 1105 | + | |
| 1106 | + $documents = array(); | |
| 1107 | + $document_content = array(); | |
| 1108 | + | |
| 1109 | + foreach($sysdata as $rec) | |
| 1110 | + { | |
| 1111 | + if (is_object($rec)) | |
| 1112 | + { | |
| 1113 | + $name = $rec->name; | |
| 1114 | + $value = sanitizeForSQL($rec->value); | |
| 1115 | + } | |
| 1116 | + elseif(is_array($rec)) | |
| 1117 | + { | |
| 1118 | + $name = $rec['name']; | |
| 1119 | + $value = sanitizeForSQL($rec['value']); | |
| 1120 | + } | |
| 1121 | + else | |
| 1122 | + { | |
| 1123 | + // just ignore | |
| 1124 | + continue; | |
| 1125 | + } | |
| 1126 | + switch($name) | |
| 1127 | + { | |
| 1128 | + case 'created_date': | |
| 1129 | + $documents['created'] = $value; | |
| 1130 | + break; | |
| 1131 | + case 'modified_date': | |
| 1132 | + $documents['modified'] = $value; | |
| 1133 | + break; | |
| 1134 | + case 'is_immutable': | |
| 1135 | + $documents['immutable'] = KTUtil::strToBool($value, false); | |
| 1136 | + break; | |
| 1137 | + case 'filename': | |
| 1138 | + $document_content['filename'] = $value; | |
| 1139 | + break; | |
| 1140 | + case 'major_version': | |
| 1141 | + $document_content['major_version'] = $value; | |
| 1142 | + break; | |
| 1143 | + case 'minor_version': | |
| 1144 | + $document_content['minor_version'] = $value; | |
| 1145 | + break; | |
| 1146 | + case 'version': | |
| 1147 | + $version = number_format($value + 0,5); | |
| 1148 | + list($major_version, $minor_version) = explode('.', $version); | |
| 1149 | + $document_content['major_version'] = $major_version; | |
| 1150 | + $document_content['minor_version'] = $minor_version; | |
| 1151 | + break; | |
| 1152 | + case 'mime_type': | |
| 1153 | + $value = KTMime::getMimeIdByName($value); | |
| 1154 | + if (PEAR::isError($value)) | |
| 1155 | + { | |
| 1156 | + return $value; | |
| 1157 | + } | |
| 1158 | + $document_content['mime_id'] = $value; | |
| 1159 | + break; | |
| 1160 | + case 'owner': | |
| 1161 | + case 'created_by': | |
| 1162 | + case 'modified_by': | |
| 1163 | + $sql = "select id from users where name='$value'"; | |
| 1164 | + $userId = DBUtil::getResultArray($sql); | |
| 1165 | + if (PEAR::isError($userId)) | |
| 1166 | + { | |
| 1167 | + return $userId; | |
| 1168 | + } | |
| 1169 | + if (empty($userId)) | |
| 1170 | + { | |
| 1171 | + $sql = "select id from users where username='$value'"; | |
| 1172 | + $userId = DBUtil::getResultArray($sql); | |
| 1173 | + if (PEAR::isError($value)) | |
| 1174 | + { | |
| 1175 | + return $value; | |
| 1176 | + } | |
| 1177 | + } | |
| 1178 | + if (empty($userId)) | |
| 1179 | + { | |
| 1180 | + // if not found, not much we can do | |
| 1181 | + break; | |
| 1182 | + } | |
| 1183 | + $userId=$userId[0]; | |
| 1184 | + $userId=$userId['id']; | |
| 1185 | + | |
| 1186 | + $name = $owner_mapping[$name]; | |
| 1187 | + $documents[$name] = $userId; | |
| 1188 | + break; | |
| 1189 | + default: | |
| 1190 | + return new PEAR_Error('Unexpected field: ' . $name); | |
| 1191 | + } | |
| 1192 | + } | |
| 1193 | + | |
| 1194 | + if (count($documents) > 0) | |
| 1195 | + { | |
| 1196 | + $sql = "UPDATE documents SET "; | |
| 1197 | + $i=0; | |
| 1198 | + foreach($documents as $name=>$value) | |
| 1199 | + { | |
| 1200 | + if ($i++ > 0) $sql .= ","; | |
| 1201 | + $sql .= "$name='$value'"; | |
| 1202 | + } | |
| 1203 | + $sql .= " WHERE id=$this->documentid"; | |
| 1204 | + $result = DBUtil::runQuery($sql); | |
| 1205 | + if (PEAR::isError($result)) | |
| 1206 | + { | |
| 1207 | + return $result; | |
| 1208 | + } | |
| 1209 | + } | |
| 1210 | + if (count($document_content) > 0) | |
| 1211 | + { | |
| 1212 | + $content_id = $this->document->getContentVersionId(); | |
| 1213 | + $sql = "UPDATE document_content_version SET "; | |
| 1214 | + $i=0; | |
| 1215 | + foreach($documents as $name=>$value) | |
| 1216 | + { | |
| 1217 | + if ($i++ > 0) $sql .= ","; | |
| 1218 | + $sql .= "$name='$value'"; | |
| 1219 | + } | |
| 1220 | + $sql .= " WHERE id=$content_id"; | |
| 1221 | + $result = DBUtil::runQuery($sql); | |
| 1222 | + if (PEAR::isError($result)) | |
| 1223 | + { | |
| 1224 | + return $result; | |
| 1225 | + } | |
| 1226 | + } | |
| 1227 | + } | |
| 1228 | + | |
| 1229 | + private function clearCache() | |
| 1230 | + { | |
| 1231 | + // TODO: we should only clear the cache for the document we are working on | |
| 1232 | + // this is a quick fix but not optimal!! | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + $metadataid = $this->document->getMetadataVersionId(); | |
| 1236 | + $contentid = $this->document->getContentVersionId(); | |
| 1237 | + | |
| 1238 | + $cache = KTCache::getSingleton(); | |
| 1239 | + | |
| 1240 | + $cache->remove('KTDocumentMetadataVersion/id', $metadataid); | |
| 1241 | + $cache->remove('KTDocumentContentVersion/id', $contentid); | |
| 1242 | + $cache->remove('KTDocumentCore/id', $this->documentid); | |
| 1243 | + $cache->remove('Document/id', $this->documentid); | |
| 1244 | + unset($GLOBALS['_OBJECTCACHE']['KTDocumentMetadataVersion'][$metadataid]); | |
| 1245 | + unset($GLOBALS['_OBJECTCACHE']['KTDocumentContentVersion'][$contentid]); | |
| 1246 | + unset($GLOBALS['_OBJECTCACHE']['KTDocumentCore'][$this->documentid]); | |
| 1247 | + | |
| 1248 | + $this->document = &Document::get($this->documentid); | |
| 1249 | + } | |
| 1250 | + | |
| 1251 | + public function mergeWithLastMetadataVersion() | |
| 1252 | + { | |
| 1253 | + // keep latest metadata version | |
| 1254 | + $metadata_version = $this->document->getMetadataVersion(); | |
| 1255 | + if ($metadata_version == 0) | |
| 1256 | + { | |
| 1257 | + return new PEAR_Error('MetadataVersion cannot be merged'); | |
| 1258 | + } | |
| 1259 | + | |
| 1260 | + $metadata_id = $this->document->getMetadataVersionId(); | |
| 1261 | + | |
| 1262 | + // get previous version | |
| 1263 | + $sql = "SELECT id, metadata_version FROM document_metadata_version WHERE id<$metadata_id AND document_id=$this->documentid order by id desc"; | |
| 1264 | + $old = DBUtil::getResultArray($sql); | |
| 1265 | + if (is_null($old) || PEAR::isError($old)) | |
| 1266 | + { | |
| 1267 | + return new PEAR_Error('Previous version could not be resolved'); | |
| 1268 | + } | |
| 1269 | + // only interested in the first one | |
| 1270 | + $old=$old[0]; | |
| 1271 | + $old_metadata_id = $old['id']; | |
| 1272 | + $old_metadata_version = $old['metadata_version']; | |
| 1273 | + | |
| 1274 | + DBUtil::startTransaction(); | |
| 1275 | + | |
| 1276 | + // delete previous metadata version | |
| 1277 | + | |
| 1278 | + $sql = "DELETE FROM document_metadata_version WHERE id=$old_metadata_id"; | |
| 1279 | + $rs = DBUtil::runQuery($sql); | |
| 1280 | + if (PEAR::isError($rs)) | |
| 1281 | + { | |
| 1282 | + DBUtil::rollback(); | |
| 1283 | + return $rs; | |
| 1284 | + } | |
| 1285 | + | |
| 1286 | + // make latest equal to previous | |
| 1287 | + $sql = "UPDATE document_metadata_version SET metadata_version=$old_metadata_version WHERE id=$metadata_id"; | |
| 1288 | + $rs = DBUtil::runQuery($sql); | |
| 1289 | + if (PEAR::isError($rs)) | |
| 1290 | + { | |
| 1291 | + DBUtil::rollback(); | |
| 1292 | + return $rs; | |
| 1293 | + } | |
| 1294 | + $sql = "UPDATE documents SET metadata_version=$old_metadata_version WHERE id=$this->documentid"; | |
| 1295 | + $rs = DBUtil::runQuery($sql); | |
| 1296 | + if (PEAR::isError($rs)) | |
| 1297 | + { | |
| 1298 | + DBUtil::rollback(); | |
| 1299 | + return $rs; | |
| 1300 | + } | |
| 1301 | + DBUtil::commit(); | |
| 1302 | + | |
| 1303 | + $this->clearCache(); | |
| 1304 | + } | |
| 1082 | 1305 | |
| 1083 | 1306 | /** |
| 1084 | 1307 | * This returns a workflow transition |
| 1085 | 1308 | * |
| 1086 | 1309 | * @return array |
| 1087 | 1310 | */ |
| 1088 | - function get_workflow_transitions() | |
| 1311 | + public function get_workflow_transitions() | |
| 1089 | 1312 | { |
| 1090 | 1313 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); |
| 1091 | 1314 | |
| ... | ... | @@ -1120,7 +1343,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1120 | 1343 | * |
| 1121 | 1344 | * @return string |
| 1122 | 1345 | */ |
| 1123 | - function get_workflow_state() | |
| 1346 | + public function get_workflow_state() | |
| 1124 | 1347 | { |
| 1125 | 1348 | $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_WORKFLOW); |
| 1126 | 1349 | |
| ... | ... | @@ -1154,8 +1377,11 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1154 | 1377 | * |
| 1155 | 1378 | * @return array |
| 1156 | 1379 | */ |
| 1157 | - function get_detail() | |
| 1380 | + public function get_detail() | |
| 1158 | 1381 | { |
| 1382 | + // make sure we ge tthe latest | |
| 1383 | + $this->clearCache(); | |
| 1384 | + | |
| 1159 | 1385 | $detail = array(); |
| 1160 | 1386 | $document = $this->document; |
| 1161 | 1387 | |
| ... | ... | @@ -1191,6 +1417,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1191 | 1417 | } |
| 1192 | 1418 | $detail['created_by'] = $username; |
| 1193 | 1419 | $detail['updated_date'] = $document->getLastModifiedDate(); |
| 1420 | + $detail['modified_date'] = $document->getLastModifiedDate(); | |
| 1194 | 1421 | |
| 1195 | 1422 | $userid = $document->getModifiedUserId(); |
| 1196 | 1423 | if (is_numeric($userid)) |
| ... | ... | @@ -1202,6 +1429,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1202 | 1429 | { |
| 1203 | 1430 | $username='n/a'; |
| 1204 | 1431 | } |
| 1432 | + $detail['modified_by'] = $username; | |
| 1205 | 1433 | $detail['updated_by'] = $username; |
| 1206 | 1434 | $detail['document_id'] = (int) $document->getId(); |
| 1207 | 1435 | $detail['folder_id'] = (int) $document->getFolderID(); |
| ... | ... | @@ -1230,6 +1458,22 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1230 | 1458 | } |
| 1231 | 1459 | $detail['workflow_state']=$workflowstate; |
| 1232 | 1460 | |
| 1461 | + $userid = $document->getOwnerID(); | |
| 1462 | + | |
| 1463 | + if (is_numeric($userid)) | |
| 1464 | + { | |
| 1465 | + $user = User::get($userid); | |
| 1466 | + $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); | |
| 1467 | + } | |
| 1468 | + else | |
| 1469 | + { | |
| 1470 | + $username = 'n/a'; | |
| 1471 | + } | |
| 1472 | + $detail['owner'] = $username; | |
| 1473 | + | |
| 1474 | + $detail['is_immutable'] = (bool) $document->getImmutable(); | |
| 1475 | + | |
| 1476 | + | |
| 1233 | 1477 | $userid = $document->getCheckedOutUserID(); |
| 1234 | 1478 | |
| 1235 | 1479 | if (is_numeric($userid)) |
| ... | ... | @@ -1241,14 +1485,17 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1241 | 1485 | { |
| 1242 | 1486 | $username = 'n/a'; |
| 1243 | 1487 | } |
| 1244 | - $detail['checkout_by'] = $username; | |
| 1488 | + $detail['checked_out_by'] = $username; | |
| 1489 | + | |
| 1490 | + $detail['checked_out_date'] = $document->getCheckedOutDate(); | |
| 1491 | + if (is_null($detail['checked_out_date'])) $detail['checked_out_date'] = 'n/a'; | |
| 1245 | 1492 | |
| 1246 | 1493 | $detail['full_path'] = $this->ktapi_folder->get_full_path() . '/' . $this->get_title(); |
| 1247 | 1494 | |
| 1248 | 1495 | return $detail; |
| 1249 | 1496 | } |
| 1250 | 1497 | |
| 1251 | - function get_title() | |
| 1498 | + public function get_title() | |
| 1252 | 1499 | { |
| 1253 | 1500 | return $this->document->getDescription(); |
| 1254 | 1501 | } |
| ... | ... | @@ -1258,7 +1505,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1258 | 1505 | * |
| 1259 | 1506 | * @param string $version |
| 1260 | 1507 | */ |
| 1261 | - function download($version=null) | |
| 1508 | + public function download($version=null) | |
| 1262 | 1509 | { |
| 1263 | 1510 | $storage =& KTStorageManagerUtil::getSingleton(); |
| 1264 | 1511 | $options = array(); |
| ... | ... | @@ -1273,7 +1520,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1273 | 1520 | * |
| 1274 | 1521 | * @return array |
| 1275 | 1522 | */ |
| 1276 | - function get_transaction_history() | |
| 1523 | + public function get_transaction_history() | |
| 1277 | 1524 | { |
| 1278 | 1525 | $sQuery = 'SELECT DTT.name AS transaction_name, U.name AS username, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime ' . |
| 1279 | 1526 | 'FROM ' . KTUtil::getTableName('document_transactions') . ' AS DT INNER JOIN ' . KTUtil::getTableName('users') . ' AS U ON DT.user_id = U.id ' . |
| ... | ... | @@ -1295,7 +1542,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1295 | 1542 | * |
| 1296 | 1543 | * @return array |
| 1297 | 1544 | */ |
| 1298 | - function get_version_history() | |
| 1545 | + public function get_version_history() | |
| 1299 | 1546 | { |
| 1300 | 1547 | $metadata_versions = KTDocumentMetadataVersion::getByDocument($this->document); |
| 1301 | 1548 | |
| ... | ... | @@ -1331,7 +1578,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1331 | 1578 | * |
| 1332 | 1579 | * @access public |
| 1333 | 1580 | */ |
| 1334 | - function expunge() | |
| 1581 | + public function expunge() | |
| 1335 | 1582 | { |
| 1336 | 1583 | if ($this->document->getStatusID() != 3) |
| 1337 | 1584 | { |
| ... | ... | @@ -1359,7 +1606,7 @@ class KTAPI_Document extends KTAPI_FolderItem |
| 1359 | 1606 | * |
| 1360 | 1607 | * @access public |
| 1361 | 1608 | */ |
| 1362 | - function restore() | |
| 1609 | + public function restore() | |
| 1363 | 1610 | { |
| 1364 | 1611 | DBUtil::startTransaction(); |
| 1365 | 1612 | ... | ... |