예제 #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
 public static function loadFixtures(TBGScope $scope, TBGWorkflow $workflow)
 {
     $steps = array();
     $steps['new'] = array('name' => 'New', 'description' => 'A new issue, not yet handled', 'status_id' => TBGStatus::getStatusByKeyish('new')->getID(), 'transitions' => array('investigateissue', 'confirmissue', 'rejectissue', 'acceptissue', 'resolveissue'), 'editable' => true, 'is_closed' => false);
     $steps['investigating'] = array('name' => 'Investigating', 'description' => 'An issue that is being investigated, looked into or is by other means between new and unconfirmed state', 'status_id' => TBGStatus::getStatusByKeyish('investigating')->getID(), 'transitions' => array('requestmoreinformation', 'confirmissue', 'rejectissue', 'acceptissue'), 'editable' => true, 'is_closed' => false);
     $steps['confirmed'] = array('name' => 'Confirmed', 'description' => 'An issue that has been confirmed', 'status_id' => TBGStatus::getStatusByKeyish('confirmed')->getID(), 'transitions' => array('acceptissue', 'assignissue', 'resolveissue'), 'editable' => false, 'is_closed' => false);
     $steps['inprogress'] = array('name' => 'In progress', 'description' => 'An issue that is being adressed', 'status_id' => TBGStatus::getStatusByKeyish('beingworkedon')->getID(), 'transitions' => array('rejectissue', 'markreadyfortesting', 'resolveissue'), 'editable' => false, 'is_closed' => false);
     $steps['readyfortesting'] = array('name' => 'Ready for testing', 'description' => 'An issue that has been marked fixed and is ready for testing', 'status_id' => TBGStatus::getStatusByKeyish('readyfortesting/qa')->getID(), 'transitions' => array('resolveissue', 'testissuesolution'), 'editable' => false, 'is_closed' => false);
     $steps['testing'] = array('name' => 'Testing', 'description' => 'An issue where the proposed or implemented solution is currently being tested or approved', 'status_id' => TBGStatus::getStatusByKeyish('testing/qa')->getID(), 'transitions' => array('acceptissuesolution', 'rejectissuesolution'), 'editable' => false, 'is_closed' => false);
     $steps['rejected'] = array('name' => 'Rejected', 'description' => 'A closed issue that has been rejected', 'status_id' => TBGStatus::getStatusByKeyish('notabug')->getID(), 'transitions' => array('reopenissue'), 'editable' => false, 'is_closed' => true);
     $steps['closed'] = array('name' => 'Closed', 'description' => 'A closed issue', 'status_id' => null, 'transitions' => array('reopenissue'), 'editable' => false, 'is_closed' => true);
     foreach ($steps as $key => $step) {
         $step_object = new TBGWorkflowStep();
         $step_object->setWorkflow($workflow);
         $step_object->setName($step['name']);
         $step_object->setDescription($step['description']);
         $step_object->setLinkedStatusID($step['status_id']);
         $step_object->setIsClosed($step['is_closed']);
         $step_object->setIsEditable($step['editable']);
         $step_object->save();
         $steps[$key]['step'] = $step_object;
     }
     $transitions = TBGWorkflowTransition::loadFixtures($scope, $workflow, $steps);
     $transition = new TBGWorkflowTransition();
     $step = $steps['new']['step'];
     $transition->setOutgoingStep($step);
     $transition->setName('Issue created');
     $transition->setWorkflow($workflow);
     $transition->setDescription('This is the initial transition for issues using this workflow');
     $transition->save();
     $workflow->setInitialTransition($transition);
     $workflow->save();
     foreach ($steps as $step) {
         foreach ($step['transitions'] as $transition) {
             $step['step']->addOutgoingTransition($transitions[$transition]);
         }
     }
 }
 public static function loadFixtures(TBGScope $scope, TBGWorkflow $workflow, $steps)
 {
     $rejected_resolutions = array();
     $rejected_resolutions[] = TBGResolution::getResolutionByKeyish('notanissue')->getID();
     $rejected_resolutions[] = TBGResolution::getResolutionByKeyish('wontfix')->getID();
     $rejected_resolutions[] = TBGResolution::getResolutionByKeyish('cantfix')->getID();
     $rejected_resolutions[] = TBGResolution::getResolutionByKeyish('cantreproduce')->getID();
     $rejected_resolutions[] = TBGResolution::getResolutionByKeyish('duplicate')->getID();
     $resolved_resolutions = array();
     $resolved_resolutions[] = TBGResolution::getResolutionByKeyish('resolved')->getID();
     $resolved_resolutions[] = TBGResolution::getResolutionByKeyish('wontfix')->getID();
     $resolved_resolutions[] = TBGResolution::getResolutionByKeyish('postponed')->getID();
     $resolved_resolutions[] = TBGResolution::getResolutionByKeyish('duplicate')->getID();
     $closed_statuses = array();
     $closed_statuses[] = TBGStatus::getStatusByKeyish('closed')->getID();
     $closed_statuses[] = TBGStatus::getStatusByKeyish('postponed')->getID();
     $closed_statuses[] = TBGStatus::getStatusByKeyish('done')->getID();
     $closed_statuses[] = TBGStatus::getStatusByKeyish('fixed')->getID();
     $transitions = array();
     $transitions['investigateissue'] = array('name' => 'Investigate issue', 'description' => 'Assign the issue to yourself and start investigating it', 'outgoing_step' => 'investigating', 'template' => null, 'pre_validations' => array(TBGWorkflowTransitionValidationRule::RULE_MAX_ASSIGNED_ISSUES => 5), 'actions' => array(TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE_SELF => 0));
     $transitions['requestmoreinformation'] = array('name' => 'Request more information', 'description' => 'Move issue back to new state for more details', 'outgoing_step' => 'new', 'template' => 'main/updateissueproperties', 'actions' => array(TBGWorkflowTransitionAction::ACTION_CLEAR_ASSIGNEE => 0));
     $transitions['confirmissue'] = array('name' => 'Confirm issue', 'description' => 'Confirm that the issue is valid', 'outgoing_step' => 'confirmed', 'template' => null, 'actions' => array(TBGWorkflowTransitionAction::ACTION_SET_PERCENT => 10, TBGWorkflowTransitionAction::ACTION_SET_PRIORITY));
     $transitions['rejectissue'] = array('name' => 'Reject issue', 'description' => 'Reject the issue as invalid', 'outgoing_step' => 'rejected', 'template' => 'main/updateissueproperties', 'post_validations' => array(TBGWorkflowTransitionValidationRule::RULE_RESOLUTION_VALID => join(',', $rejected_resolutions)), 'actions' => array(TBGWorkflowTransitionAction::ACTION_SET_RESOLUTION => 0, TBGWorkflowTransitionAction::ACTION_SET_PERCENT => 100, TBGWorkflowTransitionAction::ACTION_USER_STOP_WORKING => 0));
     $transitions['acceptissue'] = array('name' => 'Accept issue', 'description' => 'Accept the issue and assign it to yourself', 'outgoing_step' => 'inprogress', 'template' => null, 'pre_validations' => array(TBGWorkflowTransitionValidationRule::RULE_MAX_ASSIGNED_ISSUES => 5), 'actions' => array(TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE_SELF => 0, TBGWorkflowTransitionAction::ACTION_USER_START_WORKING => 0));
     $transitions['reopenissue'] = array('name' => 'Reopen issue', 'description' => 'Reopen the issue', 'outgoing_step' => 'new', 'template' => null, 'actions' => array(TBGWorkflowTransitionAction::ACTION_CLEAR_RESOLUTION => 0, TBGWorkflowTransitionAction::ACTION_CLEAR_PERCENT => 0));
     $transitions['assignissue'] = array('name' => 'Assign issue', 'description' => 'Accept the issue and assign it to someone', 'outgoing_step' => 'inprogress', 'template' => 'main/updateissueproperties', 'actions' => array(TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE => 0, TBGWorkflowTransitionAction::ACTION_USER_START_WORKING => 0));
     $transitions['markreadyfortesting'] = array('name' => 'Mark ready for testing', 'description' => 'Mark the issue as ready to be tested', 'outgoing_step' => 'readyfortesting', 'template' => null, 'actions' => array(TBGWorkflowTransitionAction::ACTION_CLEAR_ASSIGNEE => 0, TBGWorkflowTransitionAction::ACTION_USER_STOP_WORKING => 0));
     $transitions['resolveissue'] = array('name' => 'Resolve issue', 'description' => 'Resolve the issue', 'outgoing_step' => 'closed', 'template' => 'main/updateissueproperties', 'post_validations' => array(TBGWorkflowTransitionValidationRule::RULE_STATUS_VALID => join(',', $closed_statuses), TBGWorkflowTransitionValidationRule::RULE_RESOLUTION_VALID => join(',', $resolved_resolutions)), 'actions' => array(TBGWorkflowTransitionAction::ACTION_SET_STATUS => 0, TBGWorkflowTransitionAction::ACTION_SET_PERCENT => 100, TBGWorkflowTransitionAction::ACTION_SET_RESOLUTION => 0, TBGWorkflowTransitionAction::ACTION_USER_STOP_WORKING => 0));
     $transitions['testissuesolution'] = array('name' => 'Test issue solution', 'description' => 'Check whether the solution is valid', 'outgoing_step' => 'testing', 'template' => null, 'actions' => array(TBGWorkflowTransitionAction::ACTION_ASSIGN_ISSUE_SELF => 0, TBGWorkflowTransitionAction::ACTION_USER_START_WORKING => 0));
     $transitions['acceptissuesolution'] = array('name' => 'Accept issue solution', 'description' => 'Mark the issue as resolved', 'outgoing_step' => 'closed', 'template' => 'main/updateissueproperties', 'actions' => array(TBGWorkflowTransitionAction::ACTION_SET_RESOLUTION => 0, TBGWorkflowTransitionAction::ACTION_CLEAR_ASSIGNEE => 0, TBGWorkflowTransitionAction::ACTION_USER_STOP_WORKING => 0));
     $transitions['rejectissuesolution'] = array('name' => 'Reject issue solution', 'description' => 'Reject the proposed solution and mark the issue as in progress', 'outgoing_step' => 'inprogress', 'template' => null, 'actions' => array(TBGWorkflowTransitionAction::ACTION_SET_RESOLUTION => 0, TBGWorkflowTransitionAction::ACTION_CLEAR_ASSIGNEE => 0, TBGWorkflowTransitionAction::ACTION_USER_STOP_WORKING => 0));
     foreach ($transitions as $key => $transition) {
         $transition_object = new TBGWorkflowTransition();
         $transition_object->setName($transition['name']);
         $transition_object->setDescription($transition['description']);
         $transition_object->setOutgoingStep($steps[$transition['outgoing_step']]['step']);
         $transition_object->setTemplate($transition['template']);
         $transition_object->setWorkflow($workflow);
         $transition_object->save();
         $transitions[$key] = $transition_object;
         if (array_key_exists('pre_validations', $transition) && is_array($transition['pre_validations'])) {
             foreach ($transition['pre_validations'] as $type => $validation) {
                 $rule = new TBGWorkflowTransitionValidationRule();
                 $rule->setTransition($transition_object);
                 $rule->setPre();
                 $rule->setRule($type);
                 $rule->setRuleValue($validation);
                 $rule->setWorkflow($workflow);
                 $rule->save();
             }
         }
         if (array_key_exists('post_validations', $transition) && is_array($transition['post_validations'])) {
             foreach ($transition['post_validations'] as $type => $validation) {
                 $rule = new TBGWorkflowTransitionValidationRule();
                 $rule->setTransition($transition_object);
                 $rule->setPost();
                 $rule->setRule($type);
                 $rule->setRuleValue($validation);
                 $rule->setWorkflow($workflow);
                 $rule->save();
             }
         }
         if (array_key_exists('actions', $transition) && is_array($transition['actions'])) {
             foreach ($transition['actions'] as $type => $action) {
                 $action_object = new TBGWorkflowTransitionAction();
                 $action_object->setActionType($type);
                 $action_object->setTransition($transition_object);
                 $action_object->setWorkflow($workflow);
                 if (!is_null($action)) {
                     $action_object->setTargetValue($action);
                 }
                 $action_object->save();
             }
         }
     }
     return $transitions;
 }
예제 #4
0
 protected function _upgradeFrom3dot2(TBGRequest $request)
 {
     set_time_limit(0);
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'installation' . DS . 'classes' . DS . 'upgrade_3.2');
     foreach (array('publish', 'mailing') as $module) {
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes');
         TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . $module . DS . 'classes' . DS . 'B2DB');
     }
     TBGMilestonesTable::getTable()->upgrade(TBGMilestonesTable3dot2::getTable());
     TBGArticlesTable::getTable()->upgrade(TBGArticlesTable3dot2::getTable());
     TBGProjectsTable::getTable()->upgrade(TBGProjectsTable3dot2::getTable());
     TBGLogTable::getTable()->upgrade(TBGLogTable3dot2::getTable());
     TBGUsersTable::getTable()->upgrade(TBGUsersTable3dot2::getTable());
     TBGIssuesTable::getTable()->upgrade(TBGIssuesTable3dot2::getTable());
     TBGWorkflowsTable::getTable()->upgrade(TBGWorkflowsTable3dot2::getTable());
     TBGIncomingEmailAccountTable::getTable()->upgrade(TBGIncomingEmailAccountTable3dot2::getTable());
     TBGIssueSpentTimesTable::getTable()->upgrade(TBGIssueSpentTimesTable3dot2::getTable());
     TBGCommentsTable::getTable()->upgrade(TBGCommentsTable3dot2::getTable());
     TBGSavedSearchesTable::getTable()->upgrade(TBGSavedSearchesTable3dot2::getTable());
     TBGSettingsTable::getTable()->upgrade(TBGSettingsTable3dot2::getTable());
     TBGNotificationsTable::getTable()->upgrade(TBGNotificationsTable3dot2::getTable());
     TBGPermissionsTable::getTable()->upgrade(TBGPermissionsTable3dot2::getTable());
     TBGUserArticlesTable::getTable()->create();
     TBGApplicationPasswordsTable::getTable()->create();
     TBGUserNotificationSettingsTable::getTable()->create();
     $transaction = \b2db\Core::startTransaction();
     // Upgrade user passwords
     switch ($request['upgrade_passwords']) {
         case 'manual':
             $password = $request['manul_password'];
             foreach (TBGUsersTable::getTable()->selectAll() as $user) {
                 $user->setPassword($password);
                 $user->save();
             }
             break;
         case 'auto':
             $field = $request['upgrade_passwords_pick'] == 'username' ? 'username' : 'email';
             foreach (TBGUsersTable::getTable()->selectAll() as $user) {
                 if ($field == 'username' && trim($user->getUsername())) {
                     $user->setPassword(trim($user->getUsername()));
                     $user->save();
                 } elseif ($field == 'email' && trim($user->getEmail())) {
                     $user->setPassword(trim($user->getEmail()));
                     $user->save();
                 }
             }
             break;
     }
     $adminuser = TBGUsersTable::getTable()->selectById(1);
     $adminuser->setPassword($request['admin_password']);
     $adminuser->save();
     // Add new settings
     TBGSettings::saveSetting(TBGSettings::SETTING_SERVER_TIMEZONE, 'core', date_default_timezone_get(), 0, 1);
     foreach ($request->getParameter('status') as $scope_id => $status_id) {
         $scope = TBGScopesTable::getTable()->selectById((int) $scope_id);
         if ($scope instanceof TBGScope) {
             foreach (TBGWorkflowsTable::getTable()->getAll((int) $scope_id) as $workflow) {
                 $transition = new TBGWorkflowTransition();
                 $steps = $workflow->getSteps();
                 $step = array_shift($steps);
                 $step->setLinkedStatusID((int) $status_id);
                 $step->save();
                 $transition->setOutgoingStep($step);
                 $transition->setName('Issue created');
                 $transition->setWorkflow($workflow);
                 $transition->setScope($scope);
                 $transition->setDescription('This is the initial transition for issues using this workflow');
                 $transition->save();
                 $workflow->setInitialTransition($transition);
                 $workflow->save();
             }
             TBGActivityType::loadFixtures($scope);
         }
     }
     $transaction->commitAndEnd();
     TBGContext::finishUpgrading();
     TBGContext::getModule('mailing')->upgradeFrom3dot2();
     $this->upgrade_complete = true;
 }