/**
  * Deletes all exiting conditions then saves the new condition.
  * @param Transition $transition
  * @param int $field_id
  * @return int The ID of the newly created condition
  */
 public function addCondition(Transition $transition, $field_id)
 {
     $this->getFieldNotEmptyDao()->deleteByTransitionId($transition->getId());
     if ($field_id) {
         return $this->getFieldNotEmptyDao()->create($transition->getId(), $field_id);
     }
 }
Example #2
0
 function testImpossibleCondition()
 {
     $transition = new Transition('A', 'B');
     $transition->setStates(array('A', 'C', 'D', 'F'));
     $transition->addGuard('atLeast', 4, array('C', 'D', 'E'));
     $this->assertEquals(array(array('class' => 'invalid', 'count' => 4, 'set' => array('C', 'D', 'E'))), $transition->explain());
 }
	function triggerTransition( $transitionId, $object, $type = null )
	{
		// Make sure the transition exists
		if ( ! $transition = $this->getTransition($transitionId) ) {
			return false;
		}

		// Make sure the user can use it
		$perms = Perms::get(array('type' => 'transition', 'object' => $transitionId));
		if ( ! $perms->trigger_transition ) {
			return false;
		}

		// Verify that the states are consistent
		$states = $this->getCurrentStates($object, $type);

		$tr = new Transition($transition['from'], $transition['to']);
		$tr->setStates($states);

		foreach ( $transition['guards'] as $guard ) {
			call_user_func_array(array($tr, 'addGuard'), $guard);
		}

		if ( ! $tr->isReady() ) {
			return false;
		}

		$this->addState($transition['to'], $object, $type);
		if ( ! $transition['preserve'] ) {
			$this->removeState($transition['from'], $object, $type);
		}

		return true;
	}
Example #4
0
 function testUnder()
 {
     $transition = new Transition('A', 'B');
     $transition->setStates(array('A', 'C', 'D', 'F'));
     $transition->addGuard('atMost', 4, array('C', 'D', 'E', 'F', 'G'));
     $this->assertEquals(array(), $transition->explain());
 }
Example #5
0
 public function itDelegatesDuplicateToPermissionsManager()
 {
     $new_transition_id = 2;
     $field_mapping = array('some fields mapping');
     $ugroup_mapping = array('some ugroups mapping');
     $duplicate_type = PermissionsDao::DUPLICATE_NEW_PROJECT;
     expect($this->permissions_manager)->duplicatePermissions($this->transition->getId(), $new_transition_id, array(Workflow_Transition_Condition_Permissions::PERMISSION_TRANSITION), $ugroup_mapping, $duplicate_type)->once();
     $this->permissions_factory->duplicate($this->transition, $new_transition_id, $field_mapping, $ugroup_mapping, $duplicate_type);
 }
Example #6
0
 function deck()
 {
     $deck_id = $_GET['deck'];
     $user_id = $this->getCurrentUserID();
     $deck = new Deck();
     $deck->createFromIDLite($deck_id);
     //show error if deck does not exist
     if (!isset($deck->deck_id)) {
         header('Location: ' . BASE_PATH . 'error/404');
         die;
     }
     $style = isset($_GET['style']) ? $_GET['style'] : $deck->default_theme;
     $transition = isset($_GET['transition']) ? $_GET['transition'] : $deck->default_transition;
     if ($user_id) {
         $user = new User();
         $user->createFromID($user_id);
         if (!isset($_GET['style']) && $deck_id) {
             $style = $user->getPreferenceValue('deck-' . $deck_id . '-theme');
         } else {
             $user->setPreferenceValueNoPass('deck-' . $deck_id . '-theme', $_GET['style']);
         }
         if (!isset($_GET['transition']) && $deck_id) {
             $transition = $user->getPreferenceValue('deck-' . $deck_id . '-transition');
         } else {
             $user->setPreferenceValueNoPass('deck-' . $deck_id . '-transition', $_GET['transition']);
         }
     }
     $deck->last_revision_id = $deck->getLastRevisionID();
     $deck->getTranslatedFromChanged();
     $brand = $deck->getBrand();
     $styleObj = new Style();
     $styles = $styleObj->getAll();
     $transitionObj = new Transition();
     $transitions = $transitionObj->getAll();
     $current_user = new User();
     $current_user->createFromID($this->getCurrentUserID());
     $this->set('isFollowing', $current_user->isFollowing('deck', $deck->deck_id));
     $this->set('styles', $styles);
     $this->set('transitions', $transitions);
     $this->set('deck', $deck);
     $this->set('page_title', $deck->title . ' - SlideWiki');
     $this->set('page_keywords', join(',', $deck->getTags($deck->id)));
     $this->set('page_description', $deck->abstract);
     if (!$style) {
         $style = $deck->default_theme;
     }
     $this->set('style', $style);
     if (!$transition) {
         $transition = $deck->default_transition;
     }
     $this->set('transition', $transition);
     $this->set('brand', $brand);
     $this->set('page_additional_footer', '<p><a href="static/deck/' . $deck->id . '_' . $deck->slug_title . '">( Plain Deck )</a></p>');
 }
Example #7
0
 function testBeforeShouldTriggerActions()
 {
     $current_user = new MockUser();
     $field_value_new = new MockTracker_FormElement_Field_List_Value();
     $field_value_new->setReturnValue('getId', 2066);
     //'old_id' => null,
     //'field_id' => 2707,
     //'value' => 'New',
     //'description' => 'The bug has been submitted',
     //'rank' => '10');
     $field_value_analyzed = new MockTracker_FormElement_Field_List_Value();
     $field_value_analyzed->setReturnValue('getId', 2067);
     //'old_id' => null,
     //'field_id' => 2707,
     //'value' => 'Analyzed',
     //'description' => 'The bug is analyzed',
     //'rank' => '20');
     $fields_data = array('field_id' => 'value');
     $t1 = new Transition(1, 2, $field_value_new, $field_value_analyzed);
     $a1 = new MockTransition_PostAction();
     $a2 = new MockTransition_PostAction();
     $t1->setPostActions(array($a1, $a2));
     $a1->expectOnce('before', array($fields_data, $current_user));
     $a2->expectOnce('before', array($fields_data, $current_user));
     $t1->before($fields_data, $current_user);
 }
 private function displayTransitionDetails(TrackerManager $engine, Codendi_Request $request, PFUser $current_user, Transition $transition)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $this->displayHeader($engine);
     if ($transition->getFieldValueFrom()) {
         $from_label = $transition->getFieldValueFrom()->getLabel();
     } else {
         $from_label = $GLOBALS['Language']->getText('workflow_admin', 'new_artifact');
     }
     $to_label = $transition->getFieldValueTo()->getLabel();
     echo '<h3>';
     echo $GLOBALS['Language']->getText('workflow_admin', 'title_define_transition_details', array($hp->purify($from_label), $hp->purify($to_label)));
     echo '</h3>';
     $form_action = TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => (int) $this->tracker->id, 'func' => Workflow::FUNC_ADMIN_TRANSITIONS, 'transition' => $transition->getId()));
     echo '<form action="' . $form_action . '" method="POST">';
     echo '<table><tr><td>';
     $section_conditions = new Widget_Static($GLOBALS['Language']->getText('workflow_admin', 'under_the_following_condition'));
     $section_conditions->setContent($transition->fetchConditions());
     $section_conditions->display();
     $actions = '';
     $actions .= $transition->fetchPostActions();
     $actions .= $this->post_action_factory->fetchPostActions();
     $section_postactions = new Widget_Static($GLOBALS['Language']->getText('workflow_admin', 'following_action_performed'));
     $section_postactions->setContent($actions);
     $section_postactions->display();
     $back_to_transitions_link = TRACKER_BASE_URL . '/?' . http_build_query(array('tracker' => (int) $this->tracker->id, 'func' => Workflow::FUNC_ADMIN_TRANSITIONS));
     echo '<p>';
     echo '<a href="' . $back_to_transitions_link . '">←' . $GLOBALS['Language']->getText('plugin_tracker_admin', 'clean_cancel') . '</a>';
     echo '&nbsp;';
     echo '<input type="submit" name="workflow_details" value="' . $GLOBALS['Language']->getText('global', 'btn_submit') . '" />';
     echo '</p>';
     echo '</td></tr></table>';
     echo '</form>';
     $this->displayFooter($engine);
 }
 /**
  * Creates transition in the database
  *
  * @param int $workflow_id The workflow_id of the transitions to save
  * @param Transition          $transition The transition
  *
  * @return void
  */
 public function saveObject($workflow_id, $transition)
 {
     $dao = $this->getDao();
     if ($transition->getFieldValueFrom() == null) {
         $from_id = null;
     } else {
         $from_id = $transition->getFieldValueFrom()->getId();
     }
     $to_id = $transition->getFieldValueTo()->getId();
     $transition_id = $dao->addTransition($workflow_id, $from_id, $to_id);
     $transition->setTransitionId($transition_id);
     //Save postactions
     $postactions = $transition->getAllPostActions();
     foreach ($postactions as $postaction) {
         $tpaf = $this->getPostActionFactory();
         $tpaf->saveObject($postaction);
     }
     //Save conditions
     $transition->getConditions()->saveObject();
 }
Example #10
0
 /**
  * Return permission form for the transition
  *
  * @param Transition $transition The transition
  *
  * @return string html
  */
 protected function fetchWorkflowPermissions($transition)
 {
     $html = '';
     $html .= '<ul class="workflow_conditions">';
     $html .= '<li class="workflow_conditions_perms">';
     $html .= $GLOBALS['Language']->getText('workflow_admin', 'label_define_transition_permissions');
     $html .= '<br />';
     $html .= '<p>';
     $html .= plugin_tracker_permission_fetch_selection_field('PLUGIN_TRACKER_WORKFLOW_TRANSITION', $transition->getTransitionId(), $this->tracker->group_id);
     $html .= '</p>';
     $html .= '</li></ul>';
     return $html;
 }
Example #11
0
 /**
  * Duplicate the conditions
  */
 public function duplicate(Transition $from_transition, $new_transition_id, $field_mapping, $ugroup_mapping, $duplicate_type)
 {
     $this->dao->duplicate($from_transition->getId(), $new_transition_id, $field_mapping);
 }
Example #12
0
 /**
  * Executes the transition.
  * After a successful transition this function will not work again for this object.
  *
  * @return bool
  */
 public function doTransition()
 {
     // do not transition if this was already executed
     if ($this->transitionCompleted) {
         return TRUE;
     }
     // only execute transition if id is given
     if (empty($this->transition->getId())) {
         return FALSE;
     }
     // issue of this transition must be set and persistent
     if (empty($this->issue) || !$this->issue->isPersistent()) {
         return FALSE;
     }
     // this transition must be the issue's active one
     if ($this->issue->getActiveTransition() !== $this) {
         return FALSE;
     }
     // get transition's issue's key or id
     if (!empty($this->issue->getKey())) {
         $issue_identifier = $this->issue->getKey();
     } elseif (!empty($this->issue->getId())) {
         $issue_identifier = $this->issue->getId();
     } else {
         return FALSE;
     }
     // get currently available transitions for this issue in this status
     $transitions = Transition::getTransitions($this->issue);
     if (empty($transitions[$this->transition->getId()])) {
         return FALSE;
     }
     $this->createDiffObject(true);
     $path = 'issue/' . $issue_identifier . '/transitions';
     $response = $this->issue->getCommunicationService()->post($path, $this->getDiffObject(), 204);
     if ($response === FALSE) {
         return FALSE;
     }
     // update associated issue
     $this->issue->fields->status = $transitions[$this->transition->getId()];
     $this->transitionCompleted = TRUE;
     $this->issue->deleteActiveTransition($this);
     return TRUE;
 }
 protected function _onCheckCanTransition(Transition $transition)
 {
     //only block a specific transition
     if ($transition->getName() == 'b_to_c') {
         return false;
     }
     return true;
 }
Example #14
0
 /**
  * Apply Transition
  *
  * @param Transition $candidate
  *
  * @return mixed[]|null
  */
 private function apply($candidate)
 {
     if (($output = $candidate->apply($this->input, $this->context, $this)) !== null) {
         $this->output[] = $output;
     }
     return $this->backtrack();
 }
Example #15
0
 /**
  * Duplicate the conditions
  */
 public function duplicate(Transition $from_transition, $new_transition_id, $field_mapping, $ugroup_mapping, $duplicate_type)
 {
     PermissionsManager::instance()->duplicatePermissions($from_transition->getId(), $new_transition_id, array(Workflow_Transition_Condition_Permissions::PERMISSION_TRANSITION), $ugroup_mapping, $duplicate_type);
 }
Example #16
0
 /**
  * Says if this transition is equals to another transtion
  *
  * @param Transition $transition The transition to compare
  *
  * @return bool
  */
 public function equals(Transition $transition)
 {
     $source_from = $this->getFieldValueFrom();
     $source_to = $this->getFieldValueTo();
     $target_from = $transition->getFieldValueFrom();
     $target_to = $transition->getFieldValueTo();
     return is_null($source_from) && is_null($target_from) && is_null($source_to) && is_null($target_to) || is_null($source_from) && is_null($target_from) && !is_null($source_to) && !is_null($target_to) && $source_to->getId() === $target_to->getId() || !is_null($source_from) && !is_null($target_from) && is_null($source_to) && is_null($target_to) && $source_from->getId() === $target_from->getId() || !is_null($source_from) && !is_null($target_from) && !is_null($source_to) && !is_null($target_to) && $source_from->getId() === $target_from->getId() && $source_to->getId() === $target_to->getId();
 }
 /**
  *
  * @param Transition $transition
  *
  * @return Tuleap\Tracker\REST\WorkflowTransitionRepresentation
  */
 private function getWorkflowTransitionRepresentation(Transition $transition)
 {
     $workflow_representation = new WorkflowTransitionRepresentation();
     $workflow_representation->build($transition->getIdFrom(), $transition->getIdTo());
     return $workflow_representation;
 }
Example #18
0
 public function itReturnsFalseWhenConditionsAreNotValid()
 {
     $transition = new Transition($this->id, $this->workflow_id, $this->from, $this->to);
     $fields_data = array();
     $artifact = mock('Tracker_Artifact');
     $conditions = stub('Workflow_Transition_ConditionsCollection')->validate()->returns(false);
     $transition->setConditions($conditions);
     $this->assertFalse($transition->validate($fields_data, $artifact));
 }
 /**
  * Retrieves matching PostAction database records.
  *
  * @param Transition $transition The Transition to which the PostActions must be associated
  * @param string     $shortname  The PostAction type (short name, not class name)
  *
  * @return DataAccessResult
  */
 private function loadPostActionRows(Transition $transition, $shortname)
 {
     $dao = $this->getDao($shortname);
     return $dao->searchByTransitionId($transition->getId());
 }
 /**
  * Retrieves matching PostAction database records.
  *
  * @param Transition $transition The Transition to which the PostActions must be associated
  * @param string     $shortname  The PostAction type (short name, not class name)
  *
  * @return DataAccessResult
  */
 private function loadPostActionRows(Transition $transition)
 {
     return $this->dao->searchByTransitionId($transition->getId());
 }