Commit 8033ac4c809789071a858612bc805d04fef140c3

Authored by kevin_fourie
1 parent 41171017

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."
Fixed. The moveTrigger was not catered for.

Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7061 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktstandard/workflow/FolderAssociator.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
... ... @@ -38,22 +38,22 @@ require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
38 38  
39 39 class KTFolderWorkflowAssociationPlugin extends KTPlugin {
40 40 var $sNamespace = "ktstandard.workflowassociation.folder.plugin";
41   -
  41 +
42 42 function KTFolderWorkflowAssociationPlugin($sFilename = null) {
43 43 $res = parent::KTPlugin($sFilename);
44 44 $this->sFriendlyName = _kt('Workflow allocation by location');
45 45 return $res;
46   - }
  46 + }
47 47  
48 48 function setup() {
49 49 $this->registerTrigger('workflow', 'objectModification', 'FolderWorkflowAssociator',
50 50 'ktstandard.triggers.workflowassociation.folder.handler');
51   -
  51 +
52 52 $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection');
53 53 $sQuery .= ' WHERE event_ns = ?';
54 54 $aParams = array('ktstandard.workflowassociation.handler');
55 55 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns');
56   -
  56 +
57 57 if ($res == 'ktstandard.triggers.workflowassociation.folder.handler') {
58 58 $this->registerAction('folderaction', 'FolderWorkflowAssignmentFolderAction',
59 59 'ktstandard.workflowassociation.folder.action');
... ... @@ -62,23 +62,27 @@ class KTFolderWorkflowAssociationPlugin extends KTPlugin {
62 62 }
63 63  
64 64 class FolderWorkflowAssociator extends KTWorkflowAssociationHandler {
65   - function addTrigger($oDocument) {
66   - return $this->getWorkflowForDoc($oDocument);
  65 + function addTrigger($oDocument) {
  66 + return $this->getWorkflowForDoc($oDocument);
  67 + }
  68 +
  69 + function editTrigger($oDocument) {
  70 + return $this->getWorkflowForDoc($oDocument);
67 71 }
68   -
69   - function editTrigger($oDocument) {
70   - return $this->getWorkflowForDoc($oDocument);
  72 +
  73 + function moveTrigger($oDocument) {
  74 + return $this->getWorkflowForDoc($oDocument);
71 75 }
72   -
  76 +
73 77 function getWorkflowForDoc($oDocument) {
74   -
  78 +
75 79 $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map');
76 80 $sQuery .= ' WHERE `folder_id` = ?';
77 81 $aParams = array($oDocument->getFolderID());
78 82 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id');
79   -
80   -
81   - if (PEAR::isError($res) || (is_null($res))) {
  83 +
  84 +
  85 + if (PEAR::isError($res) || (is_null($res))) {
82 86 return KTWorkflowUtil::getWorkflowForDocument($oDocument); // don't remove if moved out.
83 87 }
84 88 return KTWorkflow::get($res);
... ... @@ -99,15 +103,15 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction {
99 103 $this->oPage->setTitle(_kt("Configure Workflows for Folder"));
100 104 $oTemplate =& $this->oValidator->validateTemplate('ktstandard/workflow/folderconfigure');
101 105 $fields = array();
102   -
  106 +
103 107 $aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL AND enabled = 1');
104 108 $aVocab = array();
105 109 $aVocab[] = _kt('No automatic workflow.');
106 110 foreach ($aWorkflows as $oWorkflow) {
107   - $aVocab[$oWorkflow->getId()] = $oWorkflow->getName();
  111 + $aVocab[$oWorkflow->getId()] = $oWorkflow->getName();
108 112 }
109 113 $fieldOptions = array("vocab" => $aVocab);
110   -
  114 +
111 115 // grab the value.
112 116 $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map');
113 117 $sQuery .= ' WHERE `folder_id` = ?';
... ... @@ -117,8 +121,8 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction {
117 121 $res = null;
118 122 }
119 123 $fields[] = new KTLookupWidget(_kt('Automatic Workflow'), _kt('If you specify an automatic workflow, new documents will automatically enter that workflow\'s starting state. Setting this to "No Automatic Workflow" will mean that users can choose the appropriate workflow.'), 'fWorkflowId', $res, $this->oPage, true, null, $fieldErrors, $fieldOptions);
120   -
121   -
  124 +
  125 +
122 126 $oTemplate->setData(array(
123 127 'context' => &$this,
124 128 'folder_id' => $this->oFolder->getId(),
... ... @@ -129,17 +133,17 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction {
129 133  
130 134 function do_allocate() {
131 135 $fWorkflowId = KTUtil::arrayGet($_REQUEST, 'fWorkflowId', null);
132   -
  136 +
133 137 $this->startTransaction();
134   -
  138 +
135 139 $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folder_workflow_map') . ' WHERE folder_id = ?';
136 140 $aParams = array($this->oFolder->getId());
137 141 DBUtil::runQuery(array($sQuery, $aParams));
138   -
  142 +
139 143 if (is_null($fWorkflowId)) {
140 144 $this->successRedirectToMain(_kt('Workflow assignment removed.'), 'fFolderId='.$this->oFolder->getId());
141 145 }
142   -
  146 +
143 147 $aOptions = array('noid' => true);
144 148 $sTable = KTUtil::getTableName('folder_workflow_map');
145 149 if ($fWorkflowId == null) { $fWorkflowId = null; }
... ... @@ -147,11 +151,11 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction {
147 151 'folder_id' => $this->oFolder->getId(),
148 152 'workflow_id' => $fWorkflowId,
149 153 ), $aOptions);
150   -
  154 +
151 155 if (PEAR::isError($res)) {
152 156 $this->errorRedirectToMain(_kt('Error assigning workflow.'), 'fFolderId='.$this->oFolder->getId());
153 157 }
154   -
  158 +
155 159 $this->successRedirectToMain(_kt('Workflow assignment updated.'), 'fFolderId='.$this->oFolder->getId());
156 160 }
157 161  
... ...
plugins/ktstandard/workflow/TypeAssociator.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
... ... @@ -39,45 +39,49 @@ class KTDocTypeWorkflowAssociationPlugin extends KTPlugin {
39 39 $res = parent::KTPlugin($sFilename);
40 40 $this->sFriendlyName = _kt('Workflow allocation by document type');
41 41 return $res;
42   - }
  42 + }
43 43  
44 44 function setup() {
45 45 $this->registerTrigger('workflow', 'objectModification', 'DocumentTypeWorkflowAssociator',
46 46 'ktstandard.triggers.workflowassociation.documenttype.handler');
47   -
  47 +
48 48 $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection');
49 49 $sQuery .= ' WHERE event_ns = ?';
50 50 $aParams = array('ktstandard.workflowassociation.handler');
51 51 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns');
52   -
  52 +
53 53 if ($res == 'ktstandard.triggers.workflowassociation.documenttype.handler') {
54   - $this->registerAdminPage('workflow_type_allocation', 'WorkflowTypeAllocationDispatcher',
55   - 'documents', _kt('Workflow Allocation by Document Types'),
56   - _kt('This installation assigns workflows by Document Type. Configure this process here.'), __FILE__);
  54 + $this->registerAdminPage('workflow_type_allocation', 'WorkflowTypeAllocationDispatcher',
  55 + 'documents', _kt('Workflow Allocation by Document Types'),
  56 + _kt('This installation assigns workflows by Document Type. Configure this process here.'), __FILE__);
57 57 $this->registeri18n('knowledgeTree', KT_DIR . '/i18n');
58 58 }
59   -
  59 +
60 60 }
61 61 }
62 62  
63 63 class DocumentTypeWorkflowAssociator extends KTWorkflowAssociationHandler {
64   - function addTrigger($oDocument) {
65   - return $oW = $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument);
  64 + function addTrigger($oDocument) {
  65 + return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument);
66 66 }
67   -
68   - function editTrigger($oDocument) {
69   - return $oW = $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument);
  67 +
  68 + function editTrigger($oDocument) {
  69 + return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument);
70 70 }
71   -
  71 +
  72 + function moveTrigger($oDocument) {
  73 + return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument);
  74 + }
  75 +
72 76 function getWorkflowForType($iDocTypeId, $oDocument) {
73 77 if (is_null($iDocTypeId)) { return null; }
74   -
  78 +
75 79 $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('type_workflow_map');
76 80 $sQuery .= ' WHERE `document_type_id` = ?';
77 81 $aParams = array($iDocTypeId);
78 82 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id');
79 83  
80   - if (PEAR::isError($res) || (is_null($res))) {
  84 + if (PEAR::isError($res) || (is_null($res))) {
81 85 return KTWorkflowUtil::getWorkflowForDocument($oDocument); // don't remove if type changed out.
82 86 }
83 87 return KTWorkflow::get($res);
... ... @@ -91,19 +95,19 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher {
91 95 function check() {
92 96 $res = parent::check();
93 97 if (!$res) { return false; }
94   -
  98 +
95 99 $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name'=> _kt('Workflow Allocation by Document Types'));
96   -
  100 +
97 101 return true;
98 102 }
99 103  
100   - function do_main() {
  104 + function do_main() {
101 105 $sQuery = 'SELECT document_type_id, workflow_id FROM ' . KTUtil::getTableName('type_workflow_map');
102 106 $aParams = array();
103 107 $res = DBUtil::getResultArray(array($sQuery, $aParams));
104 108 $aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL AND enabled = 1');
105 109 $aTypes = DocumentType::getList();
106   -
  110 +
107 111 $aTypeMapping = array();
108 112 if (PEAR::isError($res)) {
109 113 $this->oPage->addError(_kt('Failed to get type mapping: ') . $res->getMessage());
... ... @@ -112,7 +116,7 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher {
112 116 $aTypeMapping[$aRow['document_type_id']] = $aRow['workflow_id'];
113 117 }
114 118 }
115   -
  119 +
116 120 $oTemplate =& $this->oValidator->validateTemplate('ktstandard/workflow/type_allocation');
117 121 $oTemplate->setData(array(
118 122 'context' => $this,
... ... @@ -122,24 +126,24 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher {
122 126 ));
123 127 return $oTemplate->render();
124 128 }
125   -
  129 +
126 130 function isActiveWorkflow($oType, $oWorkflow, $types_mapping) {
127 131 if (!array_key_exists($oType->getId(), $types_mapping)) { return false; }
128 132 else {
129 133 return $types_mapping[$oType->getId()] == $oWorkflow->getId();
130 134 }
131 135 }
132   -
  136 +
133 137 function do_update() {
134 138 $types_mapping = (array) KTUtil::arrayGet($_REQUEST, 'fDocumentTypeAssignment');
135   -
  139 +
136 140 $aWorkflows = KTWorkflow::getList();
137 141 $aTypes = DocumentType::getList();
138   -
  142 +
139 143 $sQuery = 'DELETE FROM ' . KTUtil::getTableName('type_workflow_map');
140 144 $aParams = array();
141 145 DBUtil::runQuery(array($sQuery, $aParams));
142   -
  146 +
143 147 $aOptions = array('noid' => true);
144 148 $sTable = KTUtil::getTableName('type_workflow_map');
145 149 foreach ($aTypes as $oType) {
... ... @@ -150,7 +154,7 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher {
150 154 'workflow_id' => $t,
151 155 ), $aOptions);
152 156 }
153   -
  157 +
154 158 $this->successRedirectToMain(_kt('Type mapping updated.'));
155 159 }
156 160 }
... ...