Commit 6741e8eee5d312d2b45fe4aa6ff8c5e575f509a1
1 parent
78582561
KTS-3381
"Two workflows with the same name can be created" Fixed. Removed extra spacing from workflow names. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.2c-Release-Branch@8490 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
79 additions
and
78 deletions
plugins/ktcore/admin/workflow/newworkflow.inc.php
| 1 | <?php | 1 | <?php |
| 2 | /** | 2 | /** |
| 3 | * $Id$ | 3 | * $Id$ |
| 4 | - * | 4 | + * |
| 5 | * KnowledgeTree Open Source Edition | 5 | * KnowledgeTree Open Source Edition |
| 6 | * Document Management Made Simple | 6 | * Document Management Made Simple |
| 7 | * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited | 7 | * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | 8 | + * |
| 9 | * This program is free software; you can redistribute it and/or modify it under | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU General Public License version 3 as published by the | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | * Free Software Foundation. | 11 | * Free Software Foundation. |
| 12 | - * | 12 | + * |
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | * details. | 16 | * details. |
| 17 | - * | 17 | + * |
| 18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | 20 | + * |
| 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | 23 | + * |
| 24 | * The interactive user interfaces in modified source and object code versions | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | * of this program must display Appropriate Legal Notices, as required under | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | * Section 5 of the GNU General Public License version 3. | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | 27 | + * |
| 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | * these Appropriate Legal Notices must retain the display of the "Powered by | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the |
| 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | ||
| 33 | - * copyright notice. | 32 | + * must display the words "Powered by KnowledgeTree" and retain the original |
| 33 | + * copyright notice. | ||
| 34 | * Contributor( s): ______________________________________ | 34 | * Contributor( s): ______________________________________ |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | // core | 37 | // core |
| 38 | require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | 38 | require_once(KT_LIB_DIR . "/dispatcher.inc.php"); |
| 39 | 39 | ||
| 40 | -// workflow | 40 | +// workflow |
| 41 | require_once(KT_LIB_DIR . '/workflow/workflow.inc.php'); | 41 | require_once(KT_LIB_DIR . '/workflow/workflow.inc.php'); |
| 42 | require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php'); | 42 | require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php'); |
| 43 | require_once(KT_LIB_DIR . '/workflow/workflowtransition.inc.php'); | 43 | require_once(KT_LIB_DIR . '/workflow/workflowtransition.inc.php'); |
| @@ -56,13 +56,13 @@ require_once(KT_LIB_DIR . '/widgets/portlet.inc.php'); | @@ -56,13 +56,13 @@ require_once(KT_LIB_DIR . '/widgets/portlet.inc.php'); | ||
| 56 | require_once(KT_LIB_DIR . '/widgets/forms.inc.php'); | 56 | require_once(KT_LIB_DIR . '/widgets/forms.inc.php'); |
| 57 | 57 | ||
| 58 | class KTNewWorkflowWizard extends KTAdminDispatcher { | 58 | class KTNewWorkflowWizard extends KTAdminDispatcher { |
| 59 | - function predispatch() { | 59 | + function predispatch() { |
| 60 | $this->persistParams(array('fWizardKey')); | 60 | $this->persistParams(array('fWizardKey')); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | function &form_step1() { | 63 | function &form_step1() { |
| 64 | $oForm = new KTForm; | 64 | $oForm = new KTForm; |
| 65 | - | 65 | + |
| 66 | $oForm->setOptions(array( | 66 | $oForm->setOptions(array( |
| 67 | 'action' => 'process_step1', | 67 | 'action' => 'process_step1', |
| 68 | 'cancel_url' => KTUtil::addQueryStringSelf(''), // NBM: is there a cleaner way to reference the parent? | 68 | 'cancel_url' => KTUtil::addQueryStringSelf(''), // NBM: is there a cleaner way to reference the parent? |
| @@ -92,70 +92,71 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -92,70 +92,71 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 92 | 'description' => _kt('In order to move between states, users will cause "transitions" to occur. These transitions represent processes followed, e.g. "review document", "distribute invoice" or "publish". Please enter a list of transitions, one per line. Transition names must be unique. You\'ll assign transitions to states in the next step.'), | 92 | 'description' => _kt('In order to move between states, users will cause "transitions" to occur. These transitions represent processes followed, e.g. "review document", "distribute invoice" or "publish". Please enter a list of transitions, one per line. Transition names must be unique. You\'ll assign transitions to states in the next step.'), |
| 93 | 'required' => false, | 93 | 'required' => false, |
| 94 | 'name' => 'transitions', | 94 | 'name' => 'transitions', |
| 95 | - )), | 95 | + )), |
| 96 | array('ktcore.widgets.hidden',array( | 96 | array('ktcore.widgets.hidden',array( |
| 97 | 'required' => false, | 97 | 'required' => false, |
| 98 | 'name' => 'fWizardKey', | 98 | 'name' => 'fWizardKey', |
| 99 | 'value' => KTUtil::randomString() | 99 | 'value' => KTUtil::randomString() |
| 100 | - )), | 100 | + )), |
| 101 | )); | 101 | )); |
| 102 | - | 102 | + |
| 103 | $oForm->setValidators(array( | 103 | $oForm->setValidators(array( |
| 104 | array('ktcore.validators.string', array( | 104 | array('ktcore.validators.string', array( |
| 105 | 'test' => 'workflow_name', | 105 | 'test' => 'workflow_name', |
| 106 | - 'output' => 'workflow_name', | 106 | + 'output' => 'workflow_name', |
| 107 | )), | 107 | )), |
| 108 | array('ktcore.validators.string', array( | 108 | array('ktcore.validators.string', array( |
| 109 | 'test' => 'fWizardKey', | 109 | 'test' => 'fWizardKey', |
| 110 | - 'output' => 'fWizardKey', | 110 | + 'output' => 'fWizardKey', |
| 111 | )), | 111 | )), |
| 112 | array('ktcore.validators.string', array( | 112 | array('ktcore.validators.string', array( |
| 113 | 'test' => 'states', | 113 | 'test' => 'states', |
| 114 | 'output' => 'states', | 114 | 'output' => 'states', |
| 115 | - 'max_length' => 9999, | 115 | + 'max_length' => 9999, |
| 116 | )), | 116 | )), |
| 117 | array('ktcore.validators.string', array( | 117 | array('ktcore.validators.string', array( |
| 118 | 'test' => 'transitions', | 118 | 'test' => 'transitions', |
| 119 | - 'output' => 'transitions', | ||
| 120 | - 'max_length' => 9999, | ||
| 121 | - )), | 119 | + 'output' => 'transitions', |
| 120 | + 'max_length' => 9999, | ||
| 121 | + )), | ||
| 122 | )); | 122 | )); |
| 123 | - | 123 | + |
| 124 | return $oForm; | 124 | return $oForm; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | function do_main() { | 127 | function do_main() { |
| 128 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/new_wizard_step1'); | 128 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/new_wizard_step1'); |
| 129 | - | 129 | + |
| 130 | $oForm =& $this->form_step1(); | 130 | $oForm =& $this->form_step1(); |
| 131 | - | 131 | + |
| 132 | $oTemplate->setData(array( | 132 | $oTemplate->setData(array( |
| 133 | 'context' => $this, | 133 | 'context' => $this, |
| 134 | 'form' => $oForm, | 134 | 'form' => $oForm, |
| 135 | )); | 135 | )); |
| 136 | return $oTemplate->render(); | 136 | return $oTemplate->render(); |
| 137 | } | 137 | } |
| 138 | - | 138 | + |
| 139 | function do_process_step1() { | 139 | function do_process_step1() { |
| 140 | - | 140 | + |
| 141 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); | 141 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); |
| 142 | if (!empty($fWizardKey)) | 142 | if (!empty($fWizardKey)) |
| 143 | { | 143 | { |
| 144 | $this->errorRedirectToMain(_kt("Could not create workflow.") ); | 144 | $this->errorRedirectToMain(_kt("Could not create workflow.") ); |
| 145 | exit; | 145 | exit; |
| 146 | } | 146 | } |
| 147 | - | 147 | + |
| 148 | $oForm =& $this->form_step1(); | 148 | $oForm =& $this->form_step1(); |
| 149 | $res = $oForm->validate(); | 149 | $res = $oForm->validate(); |
| 150 | $data = $res['results']; | 150 | $data = $res['results']; |
| 151 | // perform additional validation. | 151 | // perform additional validation. |
| 152 | $extra_errors = array(); | 152 | $extra_errors = array(); |
| 153 | - | 153 | + |
| 154 | + $data['workflow_name'] = str_replace(array(' ', ' '), array(' ', ' '), $data['workflow_name']); | ||
| 154 | $oWorkflow = KTWorkflow::getByName($data['workflow_name']); | 155 | $oWorkflow = KTWorkflow::getByName($data['workflow_name']); |
| 155 | if (!PEAR::isError($oWorkflow)) { | 156 | if (!PEAR::isError($oWorkflow)) { |
| 156 | $extra_errors['workflow_name'][] = _kt("A workflow with that name already exists. Please choose a different name for this workflow."); | 157 | $extra_errors['workflow_name'][] = _kt("A workflow with that name already exists. Please choose a different name for this workflow."); |
| 157 | } | 158 | } |
| 158 | - | 159 | + |
| 159 | $initial_states = (array) explode("\n", $data['states']); // must be there, we validated it. | 160 | $initial_states = (array) explode("\n", $data['states']); // must be there, we validated it. |
| 160 | $failed = array(); | 161 | $failed = array(); |
| 161 | $states = array(); | 162 | $states = array(); |
| @@ -166,7 +167,7 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -166,7 +167,7 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 166 | if (empty($state_name)) { | 167 | if (empty($state_name)) { |
| 167 | continue; | 168 | continue; |
| 168 | } | 169 | } |
| 169 | - | 170 | + |
| 170 | if ($states[$state_name]) { | 171 | if ($states[$state_name]) { |
| 171 | $failed[] = $state_name; | 172 | $failed[] = $state_name; |
| 172 | continue; | 173 | continue; |
| @@ -181,11 +182,11 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -181,11 +182,11 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 181 | $extra_errors['states'][] = _kt('You must provide at least one state name.'); | 182 | $extra_errors['states'][] = _kt('You must provide at least one state name.'); |
| 182 | } | 183 | } |
| 183 | if (!empty($failed)) { | 184 | if (!empty($failed)) { |
| 184 | - $extra_errors['states'] = sprintf(_kt("You cannot have duplicate state names: %s"), implode(', ', $failed)); | 185 | + $extra_errors['states'] = sprintf(_kt("You cannot have duplicate state names: %s"), implode(', ', $failed)); |
| 185 | } | 186 | } |
| 186 | $data['states'] = $states; | 187 | $data['states'] = $states; |
| 187 | $data['initial_state'] = $initial_state; | 188 | $data['initial_state'] = $initial_state; |
| 188 | - | 189 | + |
| 189 | $initial_transitions = (array) explode("\n", $data['transitions']); // must be there, we validated it. | 190 | $initial_transitions = (array) explode("\n", $data['transitions']); // must be there, we validated it. |
| 190 | $failed = array(); | 191 | $failed = array(); |
| 191 | $transitions = array(); | 192 | $transitions = array(); |
| @@ -194,38 +195,38 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -194,38 +195,38 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 194 | if (empty($transition_name)) { | 195 | if (empty($transition_name)) { |
| 195 | continue; | 196 | continue; |
| 196 | } | 197 | } |
| 197 | - | 198 | + |
| 198 | if ($transitions[$transition_name]) { | 199 | if ($transitions[$transition_name]) { |
| 199 | $failed[] = $transition_name; | 200 | $failed[] = $transition_name; |
| 200 | continue; | 201 | continue; |
| 201 | } | 202 | } |
| 202 | - | 203 | + |
| 203 | $transitions[$transition_name] = $transition_name; | 204 | $transitions[$transition_name] = $transition_name; |
| 204 | } | 205 | } |
| 205 | 206 | ||
| 206 | if (!empty($failed)) { | 207 | if (!empty($failed)) { |
| 207 | - $extra_errors['transitions'] = sprintf(_kt("You cannot have duplicate transition names: %s"), implode(', ', $failed)); | 208 | + $extra_errors['transitions'] = sprintf(_kt("You cannot have duplicate transition names: %s"), implode(', ', $failed)); |
| 208 | } | 209 | } |
| 209 | $data['transitions'] = $transitions; | 210 | $data['transitions'] = $transitions; |
| 210 | 211 | ||
| 211 | // handle errors. | 212 | // handle errors. |
| 212 | if (!empty($res['errors']) || !empty($extra_errors)) { | 213 | if (!empty($res['errors']) || !empty($extra_errors)) { |
| 213 | - $oForm->handleError(null, $extra_errors); | ||
| 214 | - } | ||
| 215 | - | 214 | + $oForm->handleError(null, $extra_errors); |
| 215 | + } | ||
| 216 | + | ||
| 216 | // store the data for a while. | 217 | // store the data for a while. |
| 217 | - | 218 | + |
| 218 | $wiz_data = (array) $_SESSION['_wiz_data']; | 219 | $wiz_data = (array) $_SESSION['_wiz_data']; |
| 219 | $wiz_data[$fWizardKey] = $data; | 220 | $wiz_data[$fWizardKey] = $data; |
| 220 | $_SESSION['_wiz_data'] =& $wiz_data; | 221 | $_SESSION['_wiz_data'] =& $wiz_data; |
| 221 | - | 222 | + |
| 222 | if (empty($data['transitions'])) { | 223 | if (empty($data['transitions'])) { |
| 223 | return $this->finalise(); // finish and go. | 224 | return $this->finalise(); // finish and go. |
| 224 | } | 225 | } |
| 225 | - | 226 | + |
| 226 | $this->successRedirectTo("step2",_kt("Initial data stored.")); | 227 | $this->successRedirectTo("step2",_kt("Initial data stored.")); |
| 227 | } | 228 | } |
| 228 | - | 229 | + |
| 229 | function do_step2() { | 230 | function do_step2() { |
| 230 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); | 231 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); |
| 231 | if (!empty($fWizardKey)) | 232 | if (!empty($fWizardKey)) |
| @@ -238,22 +239,22 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -238,22 +239,22 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 238 | if (empty($wiz_data)) { | 239 | if (empty($wiz_data)) { |
| 239 | $this->errorRedirectToMain(_kt("Unable to find previous value. Please try again.")); | 240 | $this->errorRedirectToMain(_kt("Unable to find previous value. Please try again.")); |
| 240 | } | 241 | } |
| 241 | - | ||
| 242 | - $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/new_wizard_step2'); | ||
| 243 | - | 242 | + |
| 243 | + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/new_wizard_step2'); | ||
| 244 | + | ||
| 244 | $transitions = (array) $wiz_data['transitions']; | 245 | $transitions = (array) $wiz_data['transitions']; |
| 245 | $args = $this->meldPersistQuery("", "process_step2", true); | 246 | $args = $this->meldPersistQuery("", "process_step2", true); |
| 246 | - | 247 | + |
| 247 | $oTemplate->setData(array( | 248 | $oTemplate->setData(array( |
| 248 | 'context' => $this, | 249 | 'context' => $this, |
| 249 | 'fWizardKey'=>$fWizardKey, | 250 | 'fWizardKey'=>$fWizardKey, |
| 250 | 'args' => $args, | 251 | 'args' => $args, |
| 251 | 'transitions' => $wiz_data['transitions'], | 252 | 'transitions' => $wiz_data['transitions'], |
| 252 | - 'states' => $wiz_data['states'], | 253 | + 'states' => $wiz_data['states'], |
| 253 | )); | 254 | )); |
| 254 | return $oTemplate->render(); | 255 | return $oTemplate->render(); |
| 255 | } | 256 | } |
| 256 | - | 257 | + |
| 257 | function do_process_step2() { | 258 | function do_process_step2() { |
| 258 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); | 259 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); |
| 259 | if (!empty($fWizardKey)) | 260 | if (!empty($fWizardKey)) |
| @@ -265,15 +266,15 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -265,15 +266,15 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 265 | if (empty($wiz_data)) { | 266 | if (empty($wiz_data)) { |
| 266 | $this->errorRedirectToMain(_kt("Unable to locate stored data. Please try again.")); | 267 | $this->errorRedirectToMain(_kt("Unable to locate stored data. Please try again.")); |
| 267 | } | 268 | } |
| 268 | - | 269 | + |
| 269 | // we can't use the form "stuff" here since we don't have a grid widget yet | 270 | // we can't use the form "stuff" here since we don't have a grid widget yet |
| 270 | - // and hopefully never will. | ||
| 271 | - | 271 | + // and hopefully never will. |
| 272 | + | ||
| 272 | $fToData = (array) KTUtil::arrayGet($_REQUEST, 'fTo'); | 273 | $fToData = (array) KTUtil::arrayGet($_REQUEST, 'fTo'); |
| 273 | - $fFromData = (array) KTUtil::arrayGet($_REQUEST, 'fFrom'); | ||
| 274 | - | 274 | + $fFromData = (array) KTUtil::arrayGet($_REQUEST, 'fFrom'); |
| 275 | + | ||
| 275 | // these are data[transition][state] = true | 276 | // these are data[transition][state] = true |
| 276 | - | 277 | + |
| 277 | $fTo = array(); | 278 | $fTo = array(); |
| 278 | $initial_state = $wiz_data['initial_state']; | 279 | $initial_state = $wiz_data['initial_state']; |
| 279 | foreach ($wiz_data['transitions'] as $transition) { | 280 | foreach ($wiz_data['transitions'] as $transition) { |
| @@ -283,7 +284,7 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -283,7 +284,7 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 283 | } | 284 | } |
| 284 | $fTo[$transition] = $candidate; | 285 | $fTo[$transition] = $candidate; |
| 285 | } | 286 | } |
| 286 | - | 287 | + |
| 287 | $fFrom = array(); | 288 | $fFrom = array(); |
| 288 | foreach ($wiz_data['transitions'] as $transition) { | 289 | foreach ($wiz_data['transitions'] as $transition) { |
| 289 | $d = (array) KTUtil::arrayGet($fFromData, $transition); | 290 | $d = (array) KTUtil::arrayGet($fFromData, $transition); |
| @@ -298,12 +299,12 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -298,12 +299,12 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 298 | 299 | ||
| 299 | $wiz_data['from'] = $fFrom; | 300 | $wiz_data['from'] = $fFrom; |
| 300 | $wiz_data['to'] = $fTo; | 301 | $wiz_data['to'] = $fTo; |
| 301 | - | 302 | + |
| 302 | $_SESSION['_wiz_data'][$fWizardKey] = $wiz_data; | 303 | $_SESSION['_wiz_data'][$fWizardKey] = $wiz_data; |
| 303 | - | 304 | + |
| 304 | return $this->finalise(); | 305 | return $this->finalise(); |
| 305 | } | 306 | } |
| 306 | - | 307 | + |
| 307 | function finalise() { | 308 | function finalise() { |
| 308 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); | 309 | $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey'); |
| 309 | if (!empty($fWizardKey)) | 310 | if (!empty($fWizardKey)) |
| @@ -312,23 +313,23 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -312,23 +313,23 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 312 | exit; | 313 | exit; |
| 313 | } | 314 | } |
| 314 | $wiz_data = $_SESSION['_wiz_data'][$fWizardKey]; | 315 | $wiz_data = $_SESSION['_wiz_data'][$fWizardKey]; |
| 315 | - | 316 | + |
| 316 | // gather all our data. we're sure this is all good and healthy. | 317 | // gather all our data. we're sure this is all good and healthy. |
| 317 | - | 318 | + |
| 318 | $states = $wiz_data['states']; | 319 | $states = $wiz_data['states']; |
| 319 | $transitions = $wiz_data['transitions']; | 320 | $transitions = $wiz_data['transitions']; |
| 320 | - $from = $wiz_data['from']; | ||
| 321 | - $to = $wiz_data['to']; | ||
| 322 | - $initial_state = $wiz_data['initial_state']; | ||
| 323 | - $workflow_name = $wiz_data['workflow_name']; | ||
| 324 | - | ||
| 325 | - $this->startTransaction(); | 321 | + $from = $wiz_data['from']; |
| 322 | + $to = $wiz_data['to']; | ||
| 323 | + $initial_state = $wiz_data['initial_state']; | ||
| 324 | + $workflow_name = $wiz_data['workflow_name']; | ||
| 325 | + | ||
| 326 | + $this->startTransaction(); | ||
| 326 | // create the initial workflow | 327 | // create the initial workflow |
| 327 | $oWorkflow = KTWorkflow::createFromArray(array( | 328 | $oWorkflow = KTWorkflow::createFromArray(array( |
| 328 | 'name' => $workflow_name, | 329 | 'name' => $workflow_name, |
| 329 | 'humanname' => $workflow_name, | 330 | 'humanname' => $workflow_name, |
| 330 | 'enabled' => true, | 331 | 'enabled' => true, |
| 331 | - )); | 332 | + )); |
| 332 | if (PEAR::isError($oWorkflow)) { | 333 | if (PEAR::isError($oWorkflow)) { |
| 333 | $this->errorRedirectToMain(sprintf(_kt("Failed to create workflow: %s"), $oWorkflow->getMessage())); | 334 | $this->errorRedirectToMain(sprintf(_kt("Failed to create workflow: %s"), $oWorkflow->getMessage())); |
| 334 | } | 335 | } |
| @@ -342,11 +343,11 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -342,11 +343,11 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 342 | 'humanname' => $state_name, | 343 | 'humanname' => $state_name, |
| 343 | )); | 344 | )); |
| 344 | if (PEAR::isError($oState)) { | 345 | if (PEAR::isError($oState)) { |
| 345 | - $this->errorRedirectToMain(sprintf(_kt("Failed to create state: %s"), $oState->getMessage())); | 346 | + $this->errorRedirectToMain(sprintf(_kt("Failed to create state: %s"), $oState->getMessage())); |
| 346 | } | 347 | } |
| 347 | $aStates[$state_name] = $oState; | 348 | $aStates[$state_name] = $oState; |
| 348 | } | 349 | } |
| 349 | - | 350 | + |
| 350 | // update the initial state on workflow | 351 | // update the initial state on workflow |
| 351 | $oInitialState = $aStates[$initial_state]; | 352 | $oInitialState = $aStates[$initial_state]; |
| 352 | $oWorkflow->setStartStateId($oInitialState->getId()); | 353 | $oWorkflow->setStartStateId($oInitialState->getId()); |
| @@ -354,7 +355,7 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -354,7 +355,7 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 354 | if (PEAR::isError($res)) { | 355 | if (PEAR::isError($res)) { |
| 355 | $this->errorRedirectToMain(sprintf(_kt("Failed to update workflow: %s"), $res->getMessage())); | 356 | $this->errorRedirectToMain(sprintf(_kt("Failed to update workflow: %s"), $res->getMessage())); |
| 356 | } | 357 | } |
| 357 | - | 358 | + |
| 358 | // next, we create and hook up the transitions. | 359 | // next, we create and hook up the transitions. |
| 359 | $aTransitions = array(); | 360 | $aTransitions = array(); |
| 360 | foreach ($transitions as $transition) { | 361 | foreach ($transitions as $transition) { |
| @@ -369,12 +370,12 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -369,12 +370,12 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 369 | "GuardPermissionId" => null, | 370 | "GuardPermissionId" => null, |
| 370 | "GuardGroupId" => null, | 371 | "GuardGroupId" => null, |
| 371 | "GuardRoleId" => null, | 372 | "GuardRoleId" => null, |
| 372 | - "GuardConditionId" => null, | 373 | + "GuardConditionId" => null, |
| 373 | )); | 374 | )); |
| 374 | if (PEAR::isError($oTransition)) { | 375 | if (PEAR::isError($oTransition)) { |
| 375 | - $this->errorRedirectToMain(sprintf(_kt("Failed to create transition: %s"), $oTransition->getMessage())); | 376 | + $this->errorRedirectToMain(sprintf(_kt("Failed to create transition: %s"), $oTransition->getMessage())); |
| 376 | } | 377 | } |
| 377 | - | 378 | + |
| 378 | // hook up source states. | 379 | // hook up source states. |
| 379 | $state_ids = array(); | 380 | $state_ids = array(); |
| 380 | $sources = (array) $from[$transition]; | 381 | $sources = (array) $from[$transition]; |
| @@ -384,18 +385,18 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | @@ -384,18 +385,18 @@ class KTNewWorkflowWizard extends KTAdminDispatcher { | ||
| 384 | $oState = $aStates[$state_name]; | 385 | $oState = $aStates[$state_name]; |
| 385 | $state_ids[] = $oState->getId(); | 386 | $state_ids[] = $oState->getId(); |
| 386 | } | 387 | } |
| 387 | - | 388 | + |
| 388 | $res = KTWorkflowAdminUtil::saveTransitionSources($oTransition, $state_ids); | 389 | $res = KTWorkflowAdminUtil::saveTransitionSources($oTransition, $state_ids); |
| 389 | if (PEAR::isError($res)) { | 390 | if (PEAR::isError($res)) { |
| 390 | - $this->errorRedirectToMain(sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage())); | 391 | + $this->errorRedirectToMain(sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage())); |
| 391 | } | 392 | } |
| 392 | } | 393 | } |
| 393 | 394 | ||
| 394 | $this->commitTransaction(); | 395 | $this->commitTransaction(); |
| 395 | - | 396 | + |
| 396 | // finally, we want to redirect the user to the parent dispatcher somehow. | 397 | // finally, we want to redirect the user to the parent dispatcher somehow. |
| 397 | // FIXME nbm: how do you recommend we do this? | 398 | // FIXME nbm: how do you recommend we do this? |
| 398 | - | 399 | + |
| 399 | $base = $_SERVER['PHP_SELF']; | 400 | $base = $_SERVER['PHP_SELF']; |
| 400 | $qs = sprintf("action=view&fWorkflowId=%d",$oWorkflow->getId()); | 401 | $qs = sprintf("action=view&fWorkflowId=%d",$oWorkflow->getId()); |
| 401 | $url = KTUtil::addQueryString($base, $qs); | 402 | $url = KTUtil::addQueryString($base, $qs); |