Commit 669fe9275d4cf7b128700c5da45ea219bbb359b0
1 parent
34a38978
"WSA-5"
"Metadata not updating correctly." Fixed. Resolved By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@6818 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
63 additions
and
31 deletions
ktapi/KTAPIDocument.inc.php
| @@ -237,7 +237,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -237,7 +237,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 237 | if (PEAR::isError($user)) | 237 | if (PEAR::isError($user)) |
| 238 | { | 238 | { |
| 239 | return $user; | 239 | return $user; |
| 240 | - } | 240 | + } |
| 241 | 241 | ||
| 242 | if ($this->document->getIsCheckedOut()) | 242 | if ($this->document->getIsCheckedOut()) |
| 243 | { | 243 | { |
| @@ -267,7 +267,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -267,7 +267,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 267 | if (PEAR::isError($user)) | 267 | if (PEAR::isError($user)) |
| 268 | { | 268 | { |
| 269 | return $user; | 269 | return $user; |
| 270 | - } | 270 | + } |
| 271 | 271 | ||
| 272 | DBUtil::startTransaction(); | 272 | DBUtil::startTransaction(); |
| 273 | 273 | ||
| @@ -346,25 +346,25 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -346,25 +346,25 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 346 | } | 346 | } |
| 347 | 347 | ||
| 348 | $name = $this->document->getName(); | 348 | $name = $this->document->getName(); |
| 349 | - $clash = KTDocumentUtil::nameExists($target_folder, $name); | 349 | + $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 350 | if ($clash && !is_null($newname)) | 350 | if ($clash && !is_null($newname)) |
| 351 | { | 351 | { |
| 352 | $name = $newname; | 352 | $name = $newname; |
| 353 | $clash = KTDocumentUtil::nameExists($target_folder, $name); | 353 | $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 354 | - } | 354 | + } |
| 355 | if ($clash) | 355 | if ($clash) |
| 356 | { | 356 | { |
| 357 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); | 357 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | $filename=$this->document->getFilename(); | 360 | $filename=$this->document->getFilename(); |
| 361 | - $clash = KTDocumentUtil::fileExists($target_folder, $filename); | 361 | + $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 362 | 362 | ||
| 363 | if ($clash && !is_null($newname)) | 363 | if ($clash && !is_null($newname)) |
| 364 | { | 364 | { |
| 365 | $filename = $newfilename; | 365 | $filename = $newfilename; |
| 366 | - $clash = KTDocumentUtil::fileExists($target_folder, $filename); | ||
| 367 | - } | 366 | + $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 367 | + } | ||
| 368 | if ($clash) | 368 | if ($clash) |
| 369 | { | 369 | { |
| 370 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); | 370 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); |
| @@ -435,7 +435,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -435,7 +435,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 435 | if (PEAR::isError($user)) | 435 | if (PEAR::isError($user)) |
| 436 | { | 436 | { |
| 437 | return $user; | 437 | return $user; |
| 438 | - } | 438 | + } |
| 439 | 439 | ||
| 440 | if ($this->document->getIsCheckedOut()) | 440 | if ($this->document->getIsCheckedOut()) |
| 441 | { | 441 | { |
| @@ -457,25 +457,25 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -457,25 +457,25 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | $name = $this->document->getName(); | 459 | $name = $this->document->getName(); |
| 460 | - $clash = KTDocumentUtil::nameExists($target_folder, $name); | 460 | + $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 461 | if ($clash && !is_null($newname)) | 461 | if ($clash && !is_null($newname)) |
| 462 | { | 462 | { |
| 463 | $name = $newname; | 463 | $name = $newname; |
| 464 | $clash = KTDocumentUtil::nameExists($target_folder, $name); | 464 | $clash = KTDocumentUtil::nameExists($target_folder, $name); |
| 465 | - } | 465 | + } |
| 466 | if ($clash) | 466 | if ($clash) |
| 467 | { | 467 | { |
| 468 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.'); | 468 | return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.'); |
| 469 | } | 469 | } |
| 470 | 470 | ||
| 471 | $filename=$this->document->getFilename(); | 471 | $filename=$this->document->getFilename(); |
| 472 | - $clash = KTDocumentUtil::fileExists($target_folder, $filename); | 472 | + $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 473 | 473 | ||
| 474 | if ($clash && !is_null($newname)) | 474 | if ($clash && !is_null($newname)) |
| 475 | { | 475 | { |
| 476 | $filename = $newfilename; | 476 | $filename = $newfilename; |
| 477 | - $clash = KTDocumentUtil::fileExists($target_folder, $filename); | ||
| 478 | - } | 477 | + $clash = KTDocumentUtil::fileExists($target_folder, $filename); |
| 478 | + } | ||
| 479 | if ($clash) | 479 | if ($clash) |
| 480 | { | 480 | { |
| 481 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.'); | 481 | return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.'); |
| @@ -516,7 +516,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -516,7 +516,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 516 | if (PEAR::isError($user)) | 516 | if (PEAR::isError($user)) |
| 517 | { | 517 | { |
| 518 | return $user; | 518 | return $user; |
| 519 | - } | 519 | + } |
| 520 | 520 | ||
| 521 | DBUtil::startTransaction(); | 521 | DBUtil::startTransaction(); |
| 522 | $res = KTDocumentUtil::rename($this->document, $newname, $user); | 522 | $res = KTDocumentUtil::rename($this->document, $newname, $user); |
| @@ -525,7 +525,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -525,7 +525,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 525 | DBUtil::rollback(); | 525 | DBUtil::rollback(); |
| 526 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); | 526 | return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res ); |
| 527 | } | 527 | } |
| 528 | - DBUtil::commit(); | 528 | + DBUtil::commit(); |
| 529 | } | 529 | } |
| 530 | 530 | ||
| 531 | /** | 531 | /** |
| @@ -540,7 +540,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -540,7 +540,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 540 | if (PEAR::isError($user)) | 540 | if (PEAR::isError($user)) |
| 541 | { | 541 | { |
| 542 | return $user; | 542 | return $user; |
| 543 | - } | 543 | + } |
| 544 | 544 | ||
| 545 | $doctypeid = KTAPI::get_documenttypeid($documenttype); | 545 | $doctypeid = KTAPI::get_documenttypeid($documenttype); |
| 546 | 546 | ||
| @@ -571,7 +571,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -571,7 +571,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 571 | if (PEAR::isError($user)) | 571 | if (PEAR::isError($user)) |
| 572 | { | 572 | { |
| 573 | return $user; | 573 | return $user; |
| 574 | - } | 574 | + } |
| 575 | 575 | ||
| 576 | if ($this->document->getName() != $newname) | 576 | if ($this->document->getName() != $newname) |
| 577 | { | 577 | { |
| @@ -753,7 +753,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -753,7 +753,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 753 | { | 753 | { |
| 754 | if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; } | 754 | if ($fieldset->getIsConditional()) { /* this is not implemented...*/ continue; } |
| 755 | 755 | ||
| 756 | - $fields = $fieldset->getFields(); | 756 | + $fields = $fieldset->getFields(); |
| 757 | $result = array('fieldset' => $fieldset->getName(), | 757 | $result = array('fieldset' => $fieldset->getName(), |
| 758 | 'description' => $fieldset->getDescription()); | 758 | 'description' => $fieldset->getDescription()); |
| 759 | 759 | ||
| @@ -761,7 +761,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -761,7 +761,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 761 | 761 | ||
| 762 | foreach ($fields as $field) | 762 | foreach ($fields as $field) |
| 763 | { | 763 | { |
| 764 | - $value = 'n/a'; | 764 | + $value = 'n/a'; |
| 765 | 765 | ||
| 766 | $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field); | 766 | $fieldvalue = DocumentFieldLink::getByDocumentAndField($this->document, $field); |
| 767 | if (!is_null($fieldvalue) && (!PEAR::isError($fieldvalue))) | 767 | if (!is_null($fieldvalue) && (!PEAR::isError($fieldvalue))) |
| @@ -777,12 +777,12 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -777,12 +777,12 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 777 | { | 777 | { |
| 778 | $controltype = 'tree'; | 778 | $controltype = 'tree'; |
| 779 | } | 779 | } |
| 780 | - } | 780 | + } |
| 781 | 781 | ||
| 782 | switch ($controltype) | 782 | switch ($controltype) |
| 783 | { | 783 | { |
| 784 | case 'lookup': | 784 | case 'lookup': |
| 785 | - $selection = KTAPI::get_metadata_lookup($field->getId()); | 785 | + $selection = KTAPI::get_metadata_lookup($field->getId()); |
| 786 | break; | 786 | break; |
| 787 | case 'tree': | 787 | case 'tree': |
| 788 | $selection = KTAPI::get_metadata_tree($field->getId()); | 788 | $selection = KTAPI::get_metadata_tree($field->getId()); |
| @@ -807,7 +807,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -807,7 +807,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 807 | $results [] = $result; | 807 | $results [] = $result; |
| 808 | } | 808 | } |
| 809 | 809 | ||
| 810 | - return $results; | 810 | + return $results; |
| 811 | } | 811 | } |
| 812 | 812 | ||
| 813 | /** | 813 | /** |
| @@ -817,28 +817,60 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -817,28 +817,60 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 817 | */ | 817 | */ |
| 818 | function update_metadata($metadata) | 818 | function update_metadata($metadata) |
| 819 | { | 819 | { |
| 820 | + global $default; | ||
| 820 | $packed = array(); | 821 | $packed = array(); |
| 821 | 822 | ||
| 822 | foreach($metadata as $fieldset_metadata) | 823 | foreach($metadata as $fieldset_metadata) |
| 823 | { | 824 | { |
| 824 | - $fieldsetname=$fieldset_metadata['fieldset']; | 825 | + if (is_array($fieldset_metadata)) |
| 826 | + { | ||
| 827 | + $fieldsetname=$fieldset_metadata['fieldset']; | ||
| 828 | + $fields=$fieldset_metadata['fields']; | ||
| 829 | + } | ||
| 830 | + elseif (is_a($fieldset_metadata, 'stdClass')) | ||
| 831 | + { | ||
| 832 | + $fieldsetname=$fieldset_metadata->fieldset; | ||
| 833 | + $fields=$fieldset_metadata->fields; | ||
| 834 | + } | ||
| 835 | + else | ||
| 836 | + { | ||
| 837 | + $default->log->debug("unexpected fieldset type"); | ||
| 838 | + continue; | ||
| 839 | + } | ||
| 840 | + | ||
| 825 | $fieldset = KTFieldset::getByName($fieldsetname); | 841 | $fieldset = KTFieldset::getByName($fieldsetname); |
| 826 | if (is_null($fieldset) || PEAR::isError($fieldset)) | 842 | if (is_null($fieldset) || PEAR::isError($fieldset)) |
| 827 | { | 843 | { |
| 844 | + $default->log->debug("could not resolve fieldset: $fieldsetname"); | ||
| 828 | // exit graciously | 845 | // exit graciously |
| 829 | continue; | 846 | continue; |
| 830 | } | 847 | } |
| 831 | 848 | ||
| 832 | - foreach($fieldset_metadata['fields'] as $fieldinfo) | 849 | + foreach($fields as $fieldinfo) |
| 833 | { | 850 | { |
| 834 | - $fieldname = $fieldinfo['name']; | 851 | + if (is_array($fieldinfo)) |
| 852 | + { | ||
| 853 | + $fieldname = $fieldinfo['name']; | ||
| 854 | + $value = $fieldinfo['value']; | ||
| 855 | + } | ||
| 856 | + elseif (is_a($fieldinfo, 'stdClass')) | ||
| 857 | + { | ||
| 858 | + $fieldname = $fieldinfo->name; | ||
| 859 | + $value = $fieldinfo->value; | ||
| 860 | + } | ||
| 861 | + else | ||
| 862 | + { | ||
| 863 | + $default->log->debug("unexpected fieldinfo type"); | ||
| 864 | + continue; | ||
| 865 | + } | ||
| 866 | + | ||
| 835 | $field = DocumentField::getByFieldsetAndName($fieldset, $fieldname); | 867 | $field = DocumentField::getByFieldsetAndName($fieldset, $fieldname); |
| 836 | if (is_null($field) || PEAR::isError($fieldset)) | 868 | if (is_null($field) || PEAR::isError($fieldset)) |
| 837 | { | 869 | { |
| 870 | + $default->log->debug("could not resolve field: $fieldname"); | ||
| 838 | // exit graciously | 871 | // exit graciously |
| 839 | continue; | 872 | continue; |
| 840 | - } | ||
| 841 | - $value = $fieldinfo['value']; | 873 | + } |
| 842 | 874 | ||
| 843 | $packed[] = array($field, $value); | 875 | $packed[] = array($field, $value); |
| 844 | } | 876 | } |
| @@ -890,7 +922,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -890,7 +922,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 890 | } | 922 | } |
| 891 | foreach($transitions as $transition) | 923 | foreach($transitions as $transition) |
| 892 | { | 924 | { |
| 893 | - $result[] = $transition->getName(); | 925 | + $result[] = $transition->getName(); |
| 894 | } | 926 | } |
| 895 | 927 | ||
| 896 | return $result; | 928 | return $result; |
| @@ -1042,7 +1074,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1042,7 +1074,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1042 | function download($version=null) | 1074 | function download($version=null) |
| 1043 | { | 1075 | { |
| 1044 | $storage =& KTStorageManagerUtil::getSingleton(); | 1076 | $storage =& KTStorageManagerUtil::getSingleton(); |
| 1045 | - $options = array(); | 1077 | + $options = array(); |
| 1046 | 1078 | ||
| 1047 | 1079 | ||
| 1048 | $oDocumentTransaction = & new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions); | 1080 | $oDocumentTransaction = & new DocumentTransaction($this->document, 'Document downloaded', 'ktcore.transactions.download', $aOptions); |
| @@ -1091,7 +1123,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1091,7 +1123,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1091 | $user = User::get($userid); | 1123 | $user = User::get($userid); |
| 1092 | 1124 | ||
| 1093 | $version['user'] = $user->getName(); | 1125 | $version['user'] = $user->getName(); |
| 1094 | - $version['metadata_version'] = $document->getMetadataVersion(); | 1126 | + $version['metadata_version'] = $document->getMetadataVersion(); |
| 1095 | $version['content_version'] = $document->getVersion(); | 1127 | $version['content_version'] = $document->getVersion(); |
| 1096 | 1128 | ||
| 1097 | $versions[] = $version; | 1129 | $versions[] = $version; |
| @@ -1143,7 +1175,7 @@ class KTAPI_Document extends KTAPI_FolderItem | @@ -1143,7 +1175,7 @@ class KTAPI_Document extends KTAPI_FolderItem | ||
| 1143 | { | 1175 | { |
| 1144 | $this->document->setFolderId(1); | 1176 | $this->document->setFolderId(1); |
| 1145 | $folder = Folder::get(1); | 1177 | $folder = Folder::get(1); |
| 1146 | - } | 1178 | + } |
| 1147 | else | 1179 | else |
| 1148 | { | 1180 | { |
| 1149 | $this->document->setFolderId($this->document->getRestoreFolderId()); | 1181 | $this->document->setFolderId($this->document->getRestoreFolderId()); |