Commit 05f4b6f4b84fb9ed23561cfa1933a5afd39c640b
1 parent
70400bbc
Merged in from DEV trunk...
"KTS-1545" "Change of Document Type leaves old metadata fields unchanged." Fixed. Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@6786 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
57 additions
and
1 deletions
plugins/ktcore/document/edit.php
| ... | ... | @@ -283,7 +283,63 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 283 | 283 | $oForm->handleError(); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. Please note that this change has <strong>not</strong> yet been saved - please update the metadata below as necessary, and then save the document to make it a permanent change."), $data['type']->getName()), array('new_type' => $data['type']->getId())); | |
| 286 | + $document_type = $data['type']; | |
| 287 | + | |
| 288 | + | |
| 289 | + $doctypeid = $document_type->getId(); | |
| 290 | + | |
| 291 | + | |
| 292 | + DBUtil::startTransaction(); | |
| 293 | + $this->oDocument->setDocumentTypeId($doctypeid); | |
| 294 | + $res = $this->oDocument->update(); | |
| 295 | + | |
| 296 | + | |
| 297 | + if (PEAR::isError($res)) | |
| 298 | + { | |
| 299 | + DBUtil::rollback(); | |
| 300 | + return $res; | |
| 301 | + } | |
| 302 | + DBUtil::commit(); | |
| 303 | + | |
| 304 | + $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); | |
| 305 | + | |
| 306 | + $fs_ids = array(); | |
| 307 | + | |
| 308 | + $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid); | |
| 309 | + foreach($doctype_fieldsets as $fieldset) | |
| 310 | + { | |
| 311 | + $fs_ids[] = $fieldset->getId(); | |
| 312 | + } | |
| 313 | + $MDPack = array(); | |
| 314 | + foreach ($fieldsets as $oFieldset) | |
| 315 | + { | |
| 316 | + if ($oFieldset->getIsGeneric() || in_array($oFieldset->getId(),$fs_ids)) | |
| 317 | + { | |
| 318 | + //print $oFieldset->getName() . "<br>"; | |
| 319 | + $fields = $oFieldset->getFields(); | |
| 320 | + $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); | |
| 321 | + foreach ($fields as $oField) | |
| 322 | + { | |
| 323 | + $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); | |
| 324 | + | |
| 325 | + // FIXME "null" has strange meanings here. | |
| 326 | + if (!is_null($val)) | |
| 327 | + { | |
| 328 | + $MDPack[] = array( | |
| 329 | + $oField, | |
| 330 | + $val | |
| 331 | + ); | |
| 332 | + } | |
| 333 | + } | |
| 334 | + } | |
| 335 | + | |
| 336 | + } | |
| 337 | + | |
| 338 | + $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack); | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName())); | |
| 287 | 343 | } |
| 288 | 344 | } |
| 289 | 345 | // }}} | ... | ... |