コード例 #1
0
 public function runConfigureWorkflowTransition(TBGRequest $request)
 {
     $this->workflow = null;
     $this->transition = null;
     try {
         $this->workflow = TBGContext::factory()->TBGWorkflow($request->getParameter('workflow_id'));
         if ($request->hasParameter('transition_id')) {
             $mode = $request->getParameter('mode');
             $this->transition = TBGContext::factory()->TBGWorkflowTransition($request->getParameter('transition_id'));
             if ($request->isMethod(TBGRequest::POST)) {
                 if ($mode == 'delete') {
                     $this->transition->deleteTransition($request->getParameter('direction'));
                     return $this->renderJSON(array('failed' => false));
                 } elseif ($mode == 'delete_action') {
                     $this->action = TBGContext::factory()->TBGWorkflowTransitionAction($request->getParameter('action_id'));
                     $this->action->delete();
                     return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The action has been deleted')));
                 } elseif ($mode == 'new_action') {
                     $action = new TBGWorkflowTransitionAction();
                     $action->setActionType($request->getParameter('action_type'));
                     $action->setTransition($this->transition);
                     $action->setWorkflow($this->workflow);
                     $action->setTargetValue('');
                     $action->save();
                     return $this->renderJSON(array('failed' => false, 'content' => $this->getComponentHTML('configuration/workflowtransitionaction', array('action' => $action))));
                 } elseif ($mode == 'update_action') {
                     $this->action = TBGContext::factory()->TBGWorkflowTransitionAction($request->getParameter('action_id'));
                     $this->action->setTargetValue($request->getParameter('target_value'));
                     $this->action->save();
                     $text = $request->getParameter('target_value');
                     switch ($this->action->getActionType()) {
                         case TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGUser((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('User specified during transition');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_RESOLUTION:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGResolution((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Resolution specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_REPRODUCABILITY:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGReproducability((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Reproducability specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_STATUS:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGStatus((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Status specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_MILESTONE:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGMilestone((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Milestone specified by user');
                             break;
                         case TBGWorkflowTransitionAction::ACTION_SET_PRIORITY:
                             $text = $this->action->getTargetValue() ? TBGContext::factory()->TBGPriority((int) $this->action->getTargetValue())->getName() : TBGContext::getI18n()->__('Priority specified by user');
                             break;
                     }
                     return $this->renderJSON(array('failed' => false, 'content' => $text));
                 } elseif ($mode == 'delete_validation_rule') {
                     $this->rule = TBGContext::factory()->TBGWorkflowTransitionValidationRule($request->getParameter('rule_id'));
                     $this->rule->delete();
                     return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The validation rule has been deleted')));
                 } elseif ($mode == 'new_validation_rule') {
                     $rule = new TBGWorkflowTransitionValidationRule();
                     if ($request->getParameter('postorpre') == 'post') {
                         $exists = (bool) $this->transition->hasPostValidationRule($request->getParameter('rule'));
                         if (!$exists) {
                             $rule->setPost();
                         }
                     } elseif ($request->getParameter('postorpre') == 'pre') {
                         $exists = (bool) $this->transition->hasPreValidationRule($request->getParameter('rule'));
                         if (!$exists) {
                             $rule->setPre();
                         }
                     }
                     if ($exists) {
                         $this->getResponse()->setHttpStatus(400);
                         return $this->renderJSON(array('failed' => true, 'message' => TBGContext::getI18n()->__('This validation rule already exist')));
                     }
                     $rule->setRule($request->getParameter('rule'));
                     $rule->setRuleValue('');
                     $rule->setTransition($this->transition);
                     $rule->setWorkflow($this->workflow);
                     $rule->save();
                     return $this->renderJSON(array('failed' => false, 'content' => $this->getTemplateHTML('configuration/workflowtransitionvalidationrule', array('rule' => $rule))));
                 } elseif ($mode == 'update_validation_rule') {
                     $this->rule = TBGContext::factory()->TBGWorkflowTransitionValidationRule($request->getParameter('rule_id'));
                     $text = null;
                     switch ($this->rule->getRule()) {
                         case TBGWorkflowTransitionValidationRule::RULE_MAX_ASSIGNED_ISSUES:
                             $this->rule->setRuleValue($request->getParameter('rule_value'));
                             $text = $this->rule->getRuleValue() ? $this->rule->getRuleValue() : TBGContext::getI18n()->__('Unlimited');
                             break;
                         case TBGWorkflowTransitionValidationRule::RULE_PRIORITY_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_REPRODUCABILITY_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_RESOLUTION_VALID:
                         case TBGWorkflowTransitionValidationRule::RULE_STATUS_VALID:
                             $this->rule->setRuleValue(join(',', $request->getParameter('rule_value')));
                             $text = $this->rule->getRuleValue() ? $this->rule->getRuleValueAsJoinedString() : TBGContext::getI18n()->__('Any valid value');
                             break;
                             //case TBGWorkflowTransitionValidationRule::RULE_:
                             //	$text = ($this->rule->getRuleValue()) ? $this->rule->getRuleValue() : TBGContext::getI18n()->__('Unlimited');
                             //	break;
                     }
                     $this->rule->save();
                     return $this->renderJSON(array('failed' => false, 'content' => $text));
                 } elseif ($request->getParameter('transition_name') && $request->getParameter('outgoing_step_id') && $request->hasParameter('template')) {
                     $this->transition->setName($request->getParameter('transition_name'));
                     $this->transition->setDescription($request->getParameter('transition_description'));
                     if ($request->getParameter('template')) {
                         $this->transition->setTemplate($request->getParameter('template'));
                     } else {
                         $this->transition->setTemplate(null);
                     }
                     try {
                         $step = TBGContext::factory()->TBGWorkflowStep($request->getParameter('outgoing_step_id'));
                     } catch (Exception $e) {
                     }
                     $this->transition->setOutgoingStep($step);
                     $this->transition->save();
                     $transition = $this->transition;
                     $redirect_transition = true;
                 }
             }
         } elseif ($request->isMethod(TBGRequest::POST) && $request->hasParameter('step_id')) {
             $step = TBGContext::factory()->TBGWorkflowStep($request->getParameter('step_id'));
             /*if ($step->isCore() || $workflow->isCore())
             		{
             			throw new InvalidArgumentException("The default workflow cannot be edited");
             		}*/
             if ($request->getParameter('add_transition_type') == 'existing' && $request->hasParameter('existing_transition_id')) {
                 $transition = TBGContext::factory()->TBGWorkflowTransition($request->getParameter('existing_transition_id'));
                 $redirect_transition = false;
             } else {
                 if ($request->getParameter('transition_name') && $request->getParameter('outgoing_step_id') && $request->hasParameter('template')) {
                     if (($outgoing_step = TBGContext::factory()->TBGWorkflowStep((int) $request->getParameter('outgoing_step_id'))) && $step instanceof TBGWorkflowStep) {
                         if (array_key_exists($request->getParameter('template'), TBGWorkflowTransition::getTemplates())) {
                             $transition = new TBGWorkflowTransition();
                             $transition->setWorkflow($this->workflow);
                             $transition->setName($request->getParameter('transition_name'));
                             $transition->setDescription($request->getParameter('transition_description'));
                             $transition->setOutgoingStep($outgoing_step);
                             $transition->setTemplate($request->getParameter('template'));
                             $transition->save();
                             $step->addOutgoingTransition($transition);
                             $redirect_transition = true;
                         } else {
                             throw new InvalidArgumentException(TBGContext::getI18n()->__('Please select a valid template'));
                         }
                     } else {
                         throw new InvalidArgumentException(TBGContext::getI18n()->__('Please select a valid outgoing step'));
                     }
                 } else {
                     throw new InvalidArgumentException(TBGContext::getI18n()->__('Please fill in all required fields'));
                 }
             }
             $step->addOutgoingTransition($transition);
         } else {
             throw new InvalidArgumentException('Invalid action');
         }
     } catch (InvalidArgumentException $e) {
         //throw $e;
         $this->error = $e->getMessage();
     } catch (Exception $e) {
         throw $e;
         $this->error = TBGContext::getI18n()->__('This workflow / transition does not exist');
     }
     if (isset($redirect_transition) && $redirect_transition) {
         $this->forward(TBGContext::getRouting()->generate('configure_workflow_transition', array('workflow_id' => $this->workflow->getID(), 'transition_id' => $transition->getID())));
     } elseif (isset($redirect_transition)) {
         $this->forward(TBGContext::getRouting()->generate('configure_workflow_steps', array('workflow_id' => $this->workflow->getID())));
     }
 }
コード例 #2
0
 protected function _populateActions()
 {
     if ($this->_actions === null) {
         $this->_actions = TBGWorkflowTransitionAction::getByTransitionID($this->getID());
     }
 }