Commit 9137c26ef3a0059efa3e01357b578bc034fc3ea3
1 parent
8549da4e
- add a "move" function to documentutil
- use this in the workflowtrigger. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5757 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
67 additions
and
59 deletions
lib/documentmanagement/documentutil.inc.php
| ... | ... | @@ -863,6 +863,70 @@ class KTDocumentUtil { |
| 863 | 863 | |
| 864 | 864 | return true; |
| 865 | 865 | } |
| 866 | + | |
| 867 | + function move($oDocument, $oToFolder, $oUser = null) { | |
| 868 | + | |
| 869 | + $oFolder = $oToFolder; // alias. | |
| 870 | + | |
| 871 | + $oOriginalFolder = Folder::get($oDocument->getFolderId()); | |
| 872 | + $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId(); | |
| 873 | + $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId(); | |
| 874 | + | |
| 875 | + if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) { | |
| 876 | + $oDocument->setPermissionObjectId($oFolder->getPermissionObjectId()); | |
| 877 | + } | |
| 878 | + | |
| 879 | + //put the document in the new folder | |
| 880 | + $oDocument->setFolderID($oFolder->getId()); | |
| 881 | + $res = $oDocument->update(); | |
| 882 | + if (PEAR::isError($res)) { | |
| 883 | + return $res; | |
| 884 | + } | |
| 885 | + | |
| 886 | + | |
| 887 | + //move the document on the file system | |
| 888 | + $oStorage =& KTStorageManagerUtil::getSingleton(); | |
| 889 | + $res = $oStorage->moveDocument($oDocument, $oFolder, $oOriginalFolder); | |
| 890 | + if (PEAR::isError($res) || ($res === false)) { | |
| 891 | + $oDocument->setFolderID($oOriginalFolder->getId()); | |
| 892 | + $res = $oDocument->update(); | |
| 893 | + if (PEAR::isError($res)) { | |
| 894 | + return $res; | |
| 895 | + } | |
| 896 | + return $res; // we failed, bail. | |
| 897 | + } | |
| 898 | + | |
| 899 | + $sMoveMessage = sprintf("Moved from %s/%s to %s/%s: Workflow trigger.", | |
| 900 | + $oOriginalFolder->getFullPath(), | |
| 901 | + $oOriginalFolder->getName(), | |
| 902 | + $oFolder->getFullPath(), | |
| 903 | + $oFolder->getName()); | |
| 904 | + | |
| 905 | + // create the document transaction record | |
| 906 | + | |
| 907 | + $oDocumentTransaction = & new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move'); | |
| 908 | + $oDocumentTransaction->create(); | |
| 909 | + | |
| 910 | + | |
| 911 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | |
| 912 | + $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate'); | |
| 913 | + foreach ($aTriggers as $aTrigger) { | |
| 914 | + $sTrigger = $aTrigger[0]; | |
| 915 | + $oTrigger = new $sTrigger; | |
| 916 | + $aInfo = array( | |
| 917 | + "document" => $oDocument, | |
| 918 | + "old_folder" => $oOriginalFolder, | |
| 919 | + "new_folder" => $oFolder, | |
| 920 | + ); | |
| 921 | + $oTrigger->setInfo($aInfo); | |
| 922 | + $ret = $oTrigger->postValidate(); | |
| 923 | + if (PEAR::isError($ret)) { | |
| 924 | + return $ret; | |
| 925 | + } | |
| 926 | + } | |
| 927 | + | |
| 928 | + return KTPermissionUtil::updatePermissionLookup($oDocument); | |
| 929 | + } | |
| 866 | 930 | |
| 867 | 931 | } |
| 868 | 932 | ... | ... |
plugins/ktcore/KTWorkflowTriggers.inc.php
| ... | ... | @@ -446,70 +446,14 @@ class CopyActionTrigger extends KTWorkflowTrigger { |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | function performTransition($oDocument, $oUser) { |
| 449 | + | |
| 449 | 450 | $iFolderId = KTUtil::arrayGet($this->aConfig, 'folder_id'); |
| 450 | - $oFolder = Folder::get($iFolderId); | |
| 451 | + $oToFolder = Folder::get($iFolderId); | |
| 451 | 452 | if (PEAR::isError($oFolder)) { |
| 452 | 453 | return PEAR::raiseError(_kt('The folder to which this document should be moved does not exist. Cancelling the transition - please contact a system administrator.')); |
| 453 | 454 | } |
| 454 | 455 | |
| 455 | - // FIXME refactor into documentutil. | |
| 456 | - | |
| 457 | - $oOriginalFolder = Folder::get($oDocument->getFolderId()); | |
| 458 | - $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId(); | |
| 459 | - $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId(); | |
| 460 | - | |
| 461 | - | |
| 462 | - if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) { | |
| 463 | - $oDocument->setPermissionObjectId($oFolder->getPermissionObjectId()); | |
| 464 | - } | |
| 465 | - | |
| 466 | - //put the document in the new folder | |
| 467 | - $oDocument->setFolderID($oFolder->getId()); | |
| 468 | - if (!$oDocument->update(true)) { | |
| 469 | - $this->errorRedirectTo("main", _kt("There was a problem updating the document's location in the database"), sprintf("fDocumentId=%d&fFolderId=%d", $this->oDocument->getId(), $this->oFolder->getId())); | |
| 470 | - } | |
| 471 | - | |
| 472 | - | |
| 473 | - //move the document on the file system | |
| 474 | - $oStorage =& KTStorageManagerUtil::getSingleton(); | |
| 475 | - if (!$oStorage->moveDocument($oDocument, $oFolder, $oOriginalFolder)) { | |
| 476 | - $oDocument->setFolderID($oFolder->getId()); | |
| 477 | - $res = $oDocument->update(true); | |
| 478 | - if (PEAR::isError($res)) { | |
| 479 | - return $res; | |
| 480 | - } | |
| 481 | - } | |
| 482 | - | |
| 483 | - $sMoveMessage = sprintf("Moved from %s/%s to %s/%s: Workflow trigger.", | |
| 484 | - $oOriginalFolder->getFullPath(), | |
| 485 | - $oOriginalFolder->getName(), | |
| 486 | - $oFolder->getFullPath(), | |
| 487 | - $oFolder->getName()); | |
| 488 | - | |
| 489 | - // create the document transaction record | |
| 490 | - | |
| 491 | - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move'); | |
| 492 | - $oDocumentTransaction->create(); | |
| 493 | - | |
| 494 | - | |
| 495 | - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | |
| 496 | - $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate'); | |
| 497 | - foreach ($aTriggers as $aTrigger) { | |
| 498 | - $sTrigger = $aTrigger[0]; | |
| 499 | - $oTrigger = new $sTrigger; | |
| 500 | - $aInfo = array( | |
| 501 | - "document" => $oDocument, | |
| 502 | - "old_folder" => $oOriginalFolder, | |
| 503 | - "new_folder" => $oFolder, | |
| 504 | - ); | |
| 505 | - $oTrigger->setInfo($aInfo); | |
| 506 | - $ret = $oTrigger->postValidate(); | |
| 507 | - if (PEAR::isError($ret)) { | |
| 508 | - return $ret; | |
| 509 | - } | |
| 510 | - } | |
| 511 | - | |
| 512 | - return KTPermissionUtil::updatePermissionLookup($oDocument); | |
| 456 | + return KTDocumentUtil::move($oDocument, $oToFolder, $oUser); | |
| 513 | 457 | } |
| 514 | 458 | |
| 515 | 459 | function displayConfiguration($args) { | ... | ... |