Commit f04d1be4ab2d74ca50320d487d640a8c832ebfa9
1 parent
fbc05e08
fix for KTS-1362: state delete.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5962 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
125 additions
and
5 deletions
docs/VERSION.txt
lib/workflow/workflowutil.inc.php
| ... | ... | @@ -788,7 +788,44 @@ class KTWorkflowUtil { |
| 788 | 788 | } |
| 789 | 789 | return $aGuards; |
| 790 | 790 | } |
| 791 | -} | |
| 791 | + | |
| 792 | + | |
| 793 | + function replaceState($oState, $oReplacement) { | |
| 794 | + $state_id = KTUtil::getId($oState); | |
| 795 | + $replacement_id = KTUtil::getId($oReplacement); | |
| 796 | + | |
| 797 | + // we need to convert: | |
| 798 | + // - documents | |
| 799 | + // - transitions | |
| 800 | + // before we do a delete. | |
| 801 | + $doc = KTUtil::getTableName('document_metadata_version'); | |
| 802 | + $aDocQuery = array( | |
| 803 | + 'UPDATE $doc SET workflow_state_id = ? WHERE workflow_state_id = ?', | |
| 804 | + array($state_id, $replacement_id), | |
| 805 | + ); | |
| 806 | + $res = DBUtil::runQuery($aDocQuery); | |
| 807 | + if (PEAR::isError($res)) { return $res; } | |
| 808 | + | |
| 809 | + $wf = KTUtil::getTableName('workflow_transitions'); | |
| 810 | + $aTransitionQuery = array( | |
| 811 | + 'UPDATE $wf SET target_state_id = ? WHERE workflow_state_id = ?', | |
| 812 | + array($state_id, $replacement_id), | |
| 813 | + ); | |
| 814 | + $res = DBUtil::runQuery($aTransitionQuery); | |
| 815 | + if (PEAR::isError($res)) { return $res; } | |
| 816 | + | |
| 817 | + $wf = KTUtil::getTableName('workflow_state_transitions'); | |
| 818 | + $aTransitionQuery = array( | |
| 819 | + 'DELETE FROM $wf WHERE state_id = ?', | |
| 820 | + array($state_id), | |
| 821 | + ); | |
| 822 | + $res = DBUtil::runQuery($aTransitionQuery); | |
| 823 | + if (PEAR::isError($res)) { return $res; } | |
| 824 | + | |
| 825 | + Document::clearAllCaches(); | |
| 826 | + KTWorkflowTransitions::clearAllCaches(); | |
| 827 | + } | |
| 828 | +} | |
| 792 | 829 | |
| 793 | 830 | class KTWorkflowTriggerRegistry { |
| 794 | 831 | var $triggers; |
| ... | ... | @@ -832,5 +869,5 @@ class KTWorkflowTriggerRegistry { |
| 832 | 869 | // FIXME do we want to order this alphabetically? |
| 833 | 870 | return $triggerlist; |
| 834 | 871 | } |
| 835 | -} | |
| 872 | +} | |
| 836 | 873 | ... | ... |
plugins/ktcore/admin/workflowsv2.php
| ... | ... | @@ -803,8 +803,83 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher { |
| 803 | 803 | $this->errorRedirectTo("basic", sprintf(_kt("Failed to clear transition: %s"), $res->getMessage())); |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - $this->successRedirectTo('basic', _kt("Transition updated.")); | |
| 806 | + $this->successRedirectTo('basic', _kt("Transition deleted.")); | |
| 807 | 807 | } |
| 808 | + | |
| 809 | + function form_deletestate() { | |
| 810 | + $oForm = new KTForm; | |
| 811 | + $oForm->setOptions(array( | |
| 812 | + 'label' => _kt("Delete Existing State"), | |
| 813 | + 'identifier' => 'ktcore.workflow.deletestate', | |
| 814 | + 'action' => 'deletestate', | |
| 815 | + 'cancel_action' => 'basic', | |
| 816 | + 'fail_action' => 'replacestate', | |
| 817 | + 'submit_label' => _kt("Delete State"), | |
| 818 | + 'context' => $this, | |
| 819 | + )); | |
| 820 | + $other_states = sprintf('id != %d', $this->oState->getId()); | |
| 821 | + $oForm->setWidgets(array( | |
| 822 | + array('ktcore.widgets.entityselection', array( | |
| 823 | + 'vocab' => KTWorkflowState::getList($other_states), | |
| 824 | + 'label' => _kt("Replacement State"), | |
| 825 | + 'description' => _kt("In order to remove this state from the system, please select a new state which will take its place. All references to the state you are deleting will be replaced by this new state."), | |
| 826 | + 'important_description' => _kt("All references will be changed, including on old documents."), | |
| 827 | + 'label_method' => 'getName', | |
| 828 | + 'name' => 'replacement', | |
| 829 | + 'required' => true, | |
| 830 | + )), | |
| 831 | + )); | |
| 832 | + $oForm->setValidators(array( | |
| 833 | + array('ktcore.validators.entity', array( | |
| 834 | + 'test' => 'replacement', | |
| 835 | + 'output' => 'replacement', | |
| 836 | + 'class' => 'KTWorkflowState', | |
| 837 | + )), | |
| 838 | + )); | |
| 839 | + return $oForm; | |
| 840 | + } | |
| 841 | + | |
| 842 | + function do_replacestate() { | |
| 843 | + $oForm = $this->form_deletestate(); | |
| 844 | + return $oForm->renderPage(_kt("Delete State")); | |
| 845 | + } | |
| 846 | + | |
| 847 | + function do_deletestate() { | |
| 848 | + $oForm = $this->form_deletestate(); | |
| 849 | + $res = $oForm->validate(); | |
| 850 | + | |
| 851 | + $errors = $res['errors']; | |
| 852 | + $data = $res['results']; | |
| 853 | + | |
| 854 | + if (!empty($errors)) { | |
| 855 | + return $oForm->handleError(); | |
| 856 | + } | |
| 857 | + | |
| 858 | + $this->startTransaction(); | |
| 859 | + | |
| 860 | + if (is_null($this->oState)) { | |
| 861 | + return $this->errorRedirectTo("basic", _kt("No state selected")); | |
| 862 | + } | |
| 863 | + | |
| 864 | + $replacement = $data['replacement']; | |
| 865 | + | |
| 866 | + KTWorkflowUtil::replaceState($this->oState, $replacement); | |
| 867 | + | |
| 868 | + if ($this->oWorkflow->getStartStateId() == $this->oState->getId()) { | |
| 869 | + $this->oWorkflow->setStartStateId($replacement->getId()); | |
| 870 | + $res = $this->oWorkflow->update(); | |
| 871 | + if (PEAR::isError($res)) { | |
| 872 | + $this->errorRedirectTo("basic", sprintf(_kt("Failed to update workflow: %s"), $res->getMessage())); | |
| 873 | + } | |
| 874 | + } | |
| 875 | + | |
| 876 | + $res = $this->oState->delete(); | |
| 877 | + if (PEAR::isError($res)) { | |
| 878 | + $this->errorRedirectTo("basic", sprintf(_kt("Failed to delete state: %s"), $res->getMessage())); | |
| 879 | + } | |
| 880 | + | |
| 881 | + $this->successRedirectTo('basic', _kt("State deleted.")); | |
| 882 | + } | |
| 808 | 883 | |
| 809 | 884 | // ----------------- Security --------------------- |
| 810 | 885 | function do_security() { | ... | ... |
sql/mysql/upgrade/3.1.6.5/workflow-state-referencefixes.sql
0 → 100644
| 1 | +ALTER TABLE `workflow_state_permission_assignments` | |
| 2 | + DROP FOREIGN KEY `workflow_state_permission_assignments_ibfk_7`, | |
| 3 | + DROP FOREIGN KEY `workflow_state_permission_assignments_ibfk_8`; | |
| 4 | + | |
| 5 | + | |
| 6 | +ALTER TABLE `workflow_state_permission_assignments` | |
| 7 | + ADD CONSTRAINT `workflow_state_permission_assignments_ibfk_7` FOREIGN KEY (`permission_id`) REFERENCES `permissions` (`id`) ON DELETE CASCADE, | |
| 8 | + ADD CONSTRAINT `workflow_state_permission_assignments_ibfk_8` FOREIGN KEY (`permission_descriptor_id`) REFERENCES `permission_descriptors` (`id`) ON DELETE CASCADE; | ... | ... |
templates/ktcore/workflow/admin/basic_overview.smarty
| ... | ... | @@ -33,7 +33,7 @@ which documents follow (e.g. "submit for review" or "publish").</p> |
| 33 | 33 | <a class="ktAction ktEdit" href="{addQS context=$context}action=editstate&fStateId={$oState->getId()}{/addQS}">Edit State</a> |
| 34 | 34 | </td> |
| 35 | 35 | <td> |
| 36 | - <a class="ktAction ktDelete" href="{addQS context=$context}action=deletestate&fStateId={$oState->getId()}{/addQS}">Delete State</a> | |
| 36 | + <a class="ktAction ktDelete" href="{addQS context=$context}action=replacestate&fStateId={$oState->getId()}{/addQS}">Delete State</a> | |
| 37 | 37 | </td> |
| 38 | 38 | </tr> |
| 39 | 39 | {/foreach} | ... | ... |