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 6 * License Version 1.1.2 ("License"); You may not use this file except in
7 7 * compliance with the License. You may obtain a copy of the License at
8 8 * http://www.knowledgetree.com/KPL
9   - *
  9 + *
10 10 * Software distributed under the License is distributed on an "AS IS"
11 11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12 12 * See the License for the specific language governing rights and
... ... @@ -17,9 +17,9 @@
17 17 * (ii) the KnowledgeTree copyright notice
18 18 * in the same form as they appear in the distribution. See the License for
19 19 * requirements.
20   - *
  20 + *
21 21 * The Original Code is: KnowledgeTree Open Source
22   - *
  22 + *
23 23 * The Initial Developer of the Original Code is The Jam Warehouse Software
24 24 * (Pty) Ltd, trading as KnowledgeTree.
25 25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
... ... @@ -44,18 +44,20 @@ class KTWorkflowAssociationPlugin extends KTPlugin {
44 44 $res = parent::KTPlugin($sFilename);
45 45 $this->sFriendlyName = _kt('Workflow Association Plugin');
46 46 return $res;
47   - }
  47 + }
48 48  
49 49 function setup() {
50 50 $this->registerTrigger('add', 'postValidate', 'KTWADAddTrigger',
51   - 'ktstandard.triggers.workflowassociation.addDocument');
  51 + 'ktstandard.triggers.workflowassociation.addDocument');
52 52 $this->registerTrigger('moveDocument', 'postValidate', 'KTWADMoveTrigger',
53 53 'ktstandard.triggers.workflowassociation.moveDocument');
  54 + $this->registerTrigger('copyDocument', 'postValidate', 'KTWADCopyTrigger',
  55 + 'ktstandard.triggers.workflowassociation.copyDocument');
54 56 $this->registerTrigger('edit', 'postValidate', 'KTWADEditTrigger',
55 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 61 $this->registeri18n('knowledgeTree', KT_DIR . '/i18n');
60 62 }
61 63 }
... ... @@ -68,36 +70,36 @@ class KTWorkflowAssociationDelegator {
68 70 function KTWorkflowAssociationDelegator() {
69 71 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
70 72 $aTriggers = $oKTTriggerRegistry->getTriggers('workflow', 'objectModification');
71   -
  73 +
72 74 // if we have _some_ triggers.
73 75 if (!empty($aTriggers)) {
74 76 $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection');
75 77 $sQuery .= ' WHERE event_ns = ?';
76 78 $aParams = array('ktstandard.workflowassociation.handler');
77 79 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns');
78   -
  80 +
79 81 if (PEAR::isError($res)) { $this->_handler = new KTWorkflowAssociationHandler(); }
80   -
  82 +
81 83 if (array_key_exists($res, $aTriggers)) {
82 84 $this->_handler = new $aTriggers[$res][0];
83 85 }
84 86 else {
85   - $this->_handler = new KTWorkflowAssociationHandler();
  87 + $this->_handler = new KTWorkflowAssociationHandler();
86 88 }
87 89 }
88 90 else {
89   - $this->_handler = new KTWorkflowAssociationHandler();
  91 + $this->_handler = new KTWorkflowAssociationHandler();
90 92 }
91 93 }
92   -
  94 +
93 95 function applyWorkflow($oWorkflow) {
94 96 return true;
95 97 }
96   -
  98 +
97 99 function setInfo($aOptions) {
98 100 $this->_document = $aOptions['document'];
99 101 }
100   -
  102 +
101 103 function postValidate() {
102 104 return KTWorkflowUtil::getWorkflowForDocument($this->_document);
103 105 }
... ... @@ -107,12 +109,12 @@ class KTWorkflowAssociationDelegator {
107 109 class KTWADAddTrigger extends KTWorkflowAssociationDelegator {
108 110 function postValidate() {
109 111 $oWorkflow = $this->_handler->addTrigger($this->_document);
110   -
  112 +
111 113 // catch disabled workflows.
112 114 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) {
113   - return ;
  115 + return ;
114 116 }
115   -
  117 +
116 118 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document);
117 119 }
118 120 }
... ... @@ -121,12 +123,12 @@ class KTWADAddTrigger extends KTWorkflowAssociationDelegator {
121 123 class KTWADEditTrigger extends KTWorkflowAssociationDelegator {
122 124 function postValidate() {
123 125 $oWorkflow = $this->_handler->editTrigger($this->_document);
124   -
  126 +
125 127 // catch disabled workflows.
126 128 if (!is_null($oWorkflow) && (PEAR::isError($oWorkflow) || ($oWorkflow->getStartStateId() === null))) {
127   - return ;
  129 + return ;
128 130 }
129   -
  131 +
130 132 $ret = KTWorkflowUtil::changeWorkflowOnDocument($oWorkflow, $this->_document);
131 133 }
132 134 }
... ... @@ -135,22 +137,37 @@ class KTWADEditTrigger extends KTWorkflowAssociationDelegator {
135 137 class KTWADMoveTrigger extends KTWorkflowAssociationDelegator {
136 138 function postValidate() {
137 139 $oWorkflow = $this->_handler->moveTrigger($this->_document);
138   -
  140 +
139 141 // catch disabled workflows.
140 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 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 165 // has no impact when called.
150 166 class KTWorkflowAssociationHandler {
151 167 function addTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); }
152 168 function editTrigger($oDocument) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); }
153 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 74 return $this->getWorkflowForDoc($oDocument);
75 75 }
76 76  
  77 + function copyTrigger($oDocument) {
  78 + return $this->getWorkflowForDoc($oDocument);
  79 + }
  80 +
77 81 function getWorkflowForDoc($oDocument) {
78 82  
79 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 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 81 function getWorkflowForType($iDocTypeId, $oDocument) {
77 82 if (is_null($iDocTypeId)) { return null; }
78 83  
... ...