Commit 9eff677f7b4988a243bb7043ece21c36ff09b3d5

Authored by kevin_fourie
1 parent fba0f530

Merged in from DEV trunk...

BBS-1011
"Auto Workflow Assignment: When a document is move from within KTE to the assigned linked folder the correct worklfow is not initiated."
Implemented. Copied the mechanics for the move mechanism.

Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7068 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktstandard/KTWorkflowAssociation.php
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 * License Version 1.1.2 ("License"); You may not use this file except in 6 * License Version 1.1.2 ("License"); You may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at 7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.knowledgetree.com/KPL 8 * http://www.knowledgetree.com/KPL
9 - * 9 + *
10 * Software distributed under the License is distributed on an "AS IS" 10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12 * See the License for the specific language governing rights and 12 * See the License for the specific language governing rights and
@@ -17,9 +17,9 @@ @@ -17,9 +17,9 @@
17 * (ii) the KnowledgeTree copyright notice 17 * (ii) the KnowledgeTree copyright notice
18 * in the same form as they appear in the distribution. See the License for 18 * in the same form as they appear in the distribution. See the License for
19 * requirements. 19 * requirements.
20 - * 20 + *
21 * The Original Code is: KnowledgeTree Open Source 21 * The Original Code is: KnowledgeTree Open Source
22 - * 22 + *
23 * The Initial Developer of the Original Code is The Jam Warehouse Software 23 * The Initial Developer of the Original Code is The Jam Warehouse Software
24 * (Pty) Ltd, trading as KnowledgeTree. 24 * (Pty) Ltd, trading as KnowledgeTree.
25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright 25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
@@ -44,18 +44,20 @@ class KTWorkflowAssociationPlugin extends KTPlugin { @@ -44,18 +44,20 @@ class KTWorkflowAssociationPlugin extends KTPlugin {
44 $res = parent::KTPlugin($sFilename); 44 $res = parent::KTPlugin($sFilename);
45 $this->sFriendlyName = _kt('Workflow Association Plugin'); 45 $this->sFriendlyName = _kt('Workflow Association Plugin');
46 return $res; 46 return $res;
47 - } 47 + }
48 48
49 function setup() { 49 function setup() {
50 $this->registerTrigger('add', 'postValidate', 'KTWADAddTrigger', 50 $this->registerTrigger('add', 'postValidate', 'KTWADAddTrigger',
51 - 'ktstandard.triggers.workflowassociation.addDocument'); 51 + 'ktstandard.triggers.workflowassociation.addDocument');
52 $this->registerTrigger('moveDocument', 'postValidate', 'KTWADMoveTrigger', 52 $this->registerTrigger('moveDocument', 'postValidate', 'KTWADMoveTrigger',
53 'ktstandard.triggers.workflowassociation.moveDocument'); 53 'ktstandard.triggers.workflowassociation.moveDocument');
  54 + $this->registerTrigger('copyDocument', 'postValidate', 'KTWADCopyTrigger',
  55 + 'ktstandard.triggers.workflowassociation.copyDocument');
54 $this->registerTrigger('edit', 'postValidate', 'KTWADEditTrigger', 56 $this->registerTrigger('edit', 'postValidate', 'KTWADEditTrigger',
55 'ktstandard.triggers.workflowassociation.editDocument'); 57 'ktstandard.triggers.workflowassociation.editDocument');
56 - $this->registerAdminPage('workflow_allocation', 'WorkflowAllocationSelection',  
57 - 'documents', _kt('Automatic Workflow Assignments'),  
58 - _kt('Configure how documents are allocated to workflows.'), 'workflow/adminpage.php'); 58 + $this->registerAdminPage('workflow_allocation', 'WorkflowAllocationSelection',
  59 + 'documents', _kt('Automatic Workflow Assignments'),
  60 + _kt('Configure how documents are allocated to workflows.'), 'workflow/adminpage.php');
59 $this->registeri18n('knowledgeTree', KT_DIR . '/i18n'); 61 $this->registeri18n('knowledgeTree', KT_DIR . '/i18n');
60 } 62 }
61 } 63 }
@@ -68,36 +70,36 @@ class KTWorkflowAssociationDelegator { @@ -68,36 +70,36 @@ class KTWorkflowAssociationDelegator {
68 function KTWorkflowAssociationDelegator() { 70 function KTWorkflowAssociationDelegator() {
69 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 71 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
70 $aTriggers = $oKTTriggerRegistry->getTriggers('workflow', 'objectModification'); 72 $aTriggers = $oKTTriggerRegistry->getTriggers('workflow', 'objectModification');
71 - 73 +
72 // if we have _some_ triggers. 74 // if we have _some_ triggers.
73 if (!empty($aTriggers)) { 75 if (!empty($aTriggers)) {
74 $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection'); 76 $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection');
75 $sQuery .= ' WHERE event_ns = ?'; 77 $sQuery .= ' WHERE event_ns = ?';
76 $aParams = array('ktstandard.workflowassociation.handler'); 78 $aParams = array('ktstandard.workflowassociation.handler');
77 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns'); 79 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns');
78 - 80 +
79 if (PEAR::isError($res)) { $this->_handler = new KTWorkflowAssociationHandler(); } 81 if (PEAR::isError($res)) { $this->_handler = new KTWorkflowAssociationHandler(); }
80 - 82 +
81 if (array_key_exists($res, $aTriggers)) { 83 if (array_key_exists($res, $aTriggers)) {
82 $this->_handler = new $aTriggers[$res][0]; 84 $this->_handler = new $aTriggers[$res][0];
83 } 85 }
84 else { 86 else {
85 - $this->_handler = new KTWorkflowAssociationHandler(); 87 + $this->_handler = new KTWorkflowAssociationHandler();
86 } 88 }
87 } 89 }
88 else { 90 else {
89 - $this->_handler = new KTWorkflowAssociationHandler(); 91 + $this->_handler = new KTWorkflowAssociationHandler();
90 } 92 }
91 } 93 }
92 - 94 +
93 function applyWorkflow($oWorkflow) { 95 function applyWorkflow($oWorkflow) {
94 return true; 96 return true;
95 } 97 }
96 - 98 +
97 function setInfo($aOptions) { 99 function setInfo($aOptions) {
98 $this->_document = $aOptions['document']; 100 $this->_document = $aOptions['document'];
99 } 101 }
100 - 102 +
101 function postValidate() { 103 function postValidate() {
102 return KTWorkflowUtil::getWorkflowForDocument($this->_document); 104 return KTWorkflowUtil::getWorkflowForDocument($this->_document);
103 } 105 }
@@ -107,12 +109,12 @@ class KTWorkflowAssociationDelegator { @@ -107,12 +109,12 @@ class KTWorkflowAssociationDelegator {
107 class KTWADAddTrigger extends KTWorkflowAssociationDelegator { 109 class KTWADAddTrigger extends KTWorkflowAssociationDelegator {
108 function postValidate() { 110 function postValidate() {
109 $oWorkflow = $this->_handler->addTrigger($this->_document); 111 $oWorkflow = $this->_handler->addTrigger($this->_document);
110 - 112 +
111 // catch disabled workflows. 113 // catch disabled workflows.
112 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) { 114 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) {
113 - return ; 115 + return ;
114 } 116 }
115 - 117 +
116 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document); 118 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document);
117 } 119 }
118 } 120 }
@@ -121,12 +123,12 @@ class KTWADAddTrigger extends KTWorkflowAssociationDelegator { @@ -121,12 +123,12 @@ class KTWADAddTrigger extends KTWorkflowAssociationDelegator {
121 class KTWADEditTrigger extends KTWorkflowAssociationDelegator { 123 class KTWADEditTrigger extends KTWorkflowAssociationDelegator {
122 function postValidate() { 124 function postValidate() {
123 $oWorkflow = $this->_handler->editTrigger($this->_document); 125 $oWorkflow = $this->_handler->editTrigger($this->_document);
124 - 126 +
125 // catch disabled workflows. 127 // catch disabled workflows.
126 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) { 128 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) {
127 - return ; 129 + return ;
128 } 130 }
129 - 131 +
130 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document); 132 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document);
131 } 133 }
132 } 134 }
@@ -135,22 +137,37 @@ class KTWADEditTrigger extends KTWorkflowAssociationDelegator { @@ -135,22 +137,37 @@ class KTWADEditTrigger extends KTWorkflowAssociationDelegator {
135 class KTWADMoveTrigger extends KTWorkflowAssociationDelegator { 137 class KTWADMoveTrigger extends KTWorkflowAssociationDelegator {
136 function postValidate() { 138 function postValidate() {
137 $oWorkflow = $this->_handler->moveTrigger($this->_document); 139 $oWorkflow = $this->_handler->moveTrigger($this->_document);
138 - 140 +
139 // catch disabled workflows. 141 // catch disabled workflows.
140 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) { 142 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) {
141 - return ; 143 + return ;
142 } 144 }
143 - 145 +
  146 + $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document);
  147 + }
  148 +}
  149 +
  150 +// Move
  151 +class KTWADCopyTrigger extends KTWorkflowAssociationDelegator {
  152 + function postValidate() {
  153 + $oWorkflow = $this->_handler->copyTrigger($this->_document);
  154 +
  155 + // catch disabled workflows.
  156 + if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) {
  157 + return ;
  158 + }
  159 +
144 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document); 160 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document);
145 } 161 }
146 } 162 }
147 163
148 -// "base class" for fallback. should be subclassed and cross-referenced, otherwise 164 +// "base class" for fallback. should be subclassed and cross-referenced, otherwise
149 // has no impact when called. 165 // has no impact when called.
150 class KTWorkflowAssociationHandler { 166 class KTWorkflowAssociationHandler {
151 function addTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); } 167 function addTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); }
152 function editTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); } 168 function editTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); }
153 function moveTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); } 169 function moveTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); }
  170 + function copyTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); }
154 } 171 }
155 172
156 173
plugins/ktstandard/workflow/FolderAssociator.php
@@ -74,6 +74,10 @@ class FolderWorkflowAssociator extends KTWorkflowAssociationHandler { @@ -74,6 +74,10 @@ class FolderWorkflowAssociator extends KTWorkflowAssociationHandler {
74 return $this->getWorkflowForDoc($oDocument); 74 return $this->getWorkflowForDoc($oDocument);
75 } 75 }
76 76
  77 + function copyTrigger($oDocument) {
  78 + return $this->getWorkflowForDoc($oDocument);
  79 + }
  80 +
77 function getWorkflowForDoc($oDocument) { 81 function getWorkflowForDoc($oDocument) {
78 82
79 $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map'); 83 $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map');
plugins/ktstandard/workflow/TypeAssociator.php
@@ -73,6 +73,11 @@ class DocumentTypeWorkflowAssociator extends KTWorkflowAssociationHandler { @@ -73,6 +73,11 @@ class DocumentTypeWorkflowAssociator extends KTWorkflowAssociationHandler {
73 return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument); 73 return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument);
74 } 74 }
75 75
  76 + function copyTrigger($oDocument) {
  77 + return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument);
  78 + }
  79 +
  80 +
76 function getWorkflowForType($iDocTypeId, $oDocument) { 81 function getWorkflowForType($iDocTypeId, $oDocument) {
77 if (is_null($iDocTypeId)) { return null; } 82 if (is_null($iDocTypeId)) { return null; }
78 83