public function runConfigureProjectEdition(framework\Request $request) { if ($this->getUser()->canManageProject($this->selected_project) || $this->getUser()->canManageProjectReleases($this->selected_project)) { try { if ($edition_id = $request['edition_id']) { $edition = entities\Edition::getB2DBTable()->selectById($edition_id); if ($request->isPost()) { $release_date = null; if ($request['has_release_date']) { $release_date = mktime(0, 0, 1, $request['release_month'], $request['release_day'], $request['release_year']); } $edition->setReleaseDate($release_date); if (($e_name = $request['edition_name']) && trim($e_name) != '') { if ($e_name != $edition->getName()) { if (in_array($e_name, $edition->getProject()->getEditions())) { throw new \Exception(framework\Context::getI18n()->__('This edition already exists for this project')); } $edition->setName($e_name); } } else { throw new \Exception(framework\Context::getI18n()->__('You need to specify a name for this edition')); } $edition->setDescription($request->getParameter('description', null, false)); $edition->setDocumentationURL($request['doc_url']); $edition->setReleased((int) $request['released']); $edition->setLocked((bool) $request['locked']); $edition->save(); return $this->renderJSON(array('edition_name' => $edition->getName(), 'message' => framework\Context::getI18n()->__('Edition details saved'))); } else { switch ($request['mode']) { case 'releases': case 'components': $this->selected_section = $request['mode']; break; default: $this->selected_section = 'general'; } $content = $this->getComponentHTML('project/projectedition', array('edition' => $edition, 'access_level' => $this->access_level, 'selected_section' => $this->selected_section)); return $this->renderJSON(array('content' => $content)); } } else { throw new \Exception(framework\Context::getI18n()->__('Invalid edition id')); } } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array("error" => $this->getI18n()->__("You don't have access to modify edition"))); }
case \thebuggenie\core\entities\CustomDatatype::COMPONENTS_CHOICE: $old_object = \thebuggenie\core\entities\Component::getB2DBTable()->selectById($old_value); break; case \thebuggenie\core\entities\CustomDatatype::RELEASES_CHOICE: $old_object = \thebuggenie\core\entities\Build::getB2DBTable()->selectById($old_value); break; case \thebuggenie\core\entities\CustomDatatype::STATUS_CHOICE: $old_object = \thebuggenie\core\entities\Status::getB2DBTable()->selectById($old_value); break; } } catch (\Exception $e) { } try { switch ($customdatatype->getType()) { case \thebuggenie\core\entities\CustomDatatype::EDITIONS_CHOICE: $new_object = \thebuggenie\core\entities\Edition::getB2DBTable()->selectById($new_value); break; case \thebuggenie\core\entities\CustomDatatype::COMPONENTS_CHOICE: $new_object = \thebuggenie\core\entities\Component::getB2DBTable()->selectById($new_value); break; case \thebuggenie\core\entities\CustomDatatype::RELEASES_CHOICE: $new_object = \thebuggenie\core\entities\Build::getB2DBTable()->selectById($new_value); break; case \thebuggenie\core\entities\CustomDatatype::STATUS_CHOICE: $new_object = \thebuggenie\core\entities\Status::getB2DBTable()->selectById($new_value); break; } } catch (\Exception $e) { } $old_value = is_object($old_object) ? $old_object->getName() : \thebuggenie\core\framework\Context::getI18n()->__('Unknown'); $new_value = is_object($new_object) ? $new_object->getName() : \thebuggenie\core\framework\Context::getI18n()->__('Unknown');
protected function _processChanges() { $related_issues_to_save = array(); $changed_properties = $this->_getChangedProperties(); if (count($changed_properties)) { $is_saved_estimated = false; $is_saved_spent = false; $is_saved_assignee = false; $is_saved_owner = false; foreach ($changed_properties as $property => $value) { $compare_value = is_object($this->{$property}) ? $this->{$property}->getID() : $this->{$property}; $original_value = $value['original_value']; if ($original_value != $compare_value) { switch ($property) { case '_title': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_TITLE, framework\Context::getI18n()->__("Title updated"), $original_value, $compare_value); break; case '_shortname': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_SHORTNAME, framework\Context::getI18n()->__("Issue label updated"), $original_value, $compare_value); break; case '_description': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_DESCRIPTION, framework\Context::getI18n()->__("Description updated"), $original_value, $compare_value); break; case '_reproduction_steps': $this->addLogEntry(tables\Log::LOG_ISSUE_UPDATE_REPRODUCTIONSTEPS, framework\Context::getI18n()->__("Reproduction steps updated"), $original_value, $compare_value); break; case '_category': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Category::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getCategory() instanceof Datatype ? $this->getCategory()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_CATEGORY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_bug_type': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_bug_type', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_bug_type', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_BUG_TYPE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_effect': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_effect', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_effect', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_EFFECT, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_pain_likelihood': if ($original_value != 0) { $old_name = ($old_item = self::getPainTypesOrLabel('pain_likelihood', $original_value)) ? $old_item : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = ($new_item = self::getPainTypesOrLabel('pain_likelihood', $value['current_value'])) ? $new_item : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_LIKELIHOOD, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_user_pain': $this->addLogEntry(tables\Log::LOG_ISSUE_PAIN_CALCULATED, $original_value . ' ⇒ ' . $value['current_value']); break; case '_status': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Status::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getStatus() instanceof Datatype ? $this->getStatus()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_STATUS, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_reproducability': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Reproducability::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getReproducability() instanceof Datatype ? $this->getReproducability()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_REPRODUCABILITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_priority': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Priority::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getPriority() instanceof Datatype ? $this->getPriority()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_PRIORITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_assignee_team': case '_assignee_user': if (!$is_saved_assignee) { $new_name = $this->getAssignee() instanceof \thebuggenie\core\entities\common\Identifiable ? $this->getAssignee()->getName() : framework\Context::getI18n()->__('Not assigned'); if ($this->getAssignee() instanceof \thebuggenie\core\entities\User) { $this->startWorkingOnIssue($this->getAssignee()); } $this->addLogEntry(tables\Log::LOG_ISSUE_ASSIGNED, $new_name); $is_saved_assignee = true; } break; case '_posted_by': $old_identifiable = $original_value ? \thebuggenie\core\entities\User::getB2DBTable()->selectById($original_value) : framework\Context::getI18n()->__('Unknown'); $old_name = $old_identifiable instanceof \thebuggenie\core\entities\User ? $old_identifiable->getName() : framework\Context::getI18n()->__('Unknown'); $new_name = $this->getPostedBy()->getName(); $this->addLogEntry(tables\Log::LOG_ISSUE_POSTED, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_being_worked_on_by_user': if ($original_value != 0) { $old_identifiable = \thebuggenie\core\entities\User::getB2DBTable()->selectById($original_value); $old_name = $old_identifiable instanceof \thebuggenie\core\entities\User ? $old_identifiable->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not being worked on'); } $new_name = $this->getUserWorkingOnIssue() instanceof \thebuggenie\core\entities\User ? $this->getUserWorkingOnIssue()->getName() : framework\Context::getI18n()->__('Not being worked on'); $this->addLogEntry(tables\Log::LOG_ISSUE_USERS, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_owner_team': case '_owner_user': if (!$is_saved_owner) { $new_name = $this->getOwner() instanceof \thebuggenie\core\entities\common\Identifiable ? $this->getOwner()->getName() : framework\Context::getI18n()->__('Not owned by anyone'); $this->addLogEntry(tables\Log::LOG_ISSUE_OWNED, $new_name); $is_saved_owner = true; } break; case '_percent_complete': $this->addLogEntry(tables\Log::LOG_ISSUE_PERCENT, $original_value . '% ⇒ ' . $this->getPercentCompleted() . '', $original_value, $compare_value); break; case '_resolution': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Resolution::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getResolution() instanceof Datatype ? $this->getResolution()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_RESOLUTION, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_severity': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Severity::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getSeverity() instanceof Datatype ? $this->getSeverity()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_SEVERITY, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_milestone': if ($original_value != 0) { $old_name = ($old_item = \thebuggenie\core\entities\Milestone::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Not determined'); } else { $old_name = framework\Context::getI18n()->__('Not determined'); } $new_name = $this->getMilestone() instanceof \thebuggenie\core\entities\Milestone ? $this->getMilestone()->getName() : framework\Context::getI18n()->__('Not determined'); $this->addLogEntry(tables\Log::LOG_ISSUE_MILESTONE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); $this->_milestone_order = 0; break; case '_issuetype': if ($original_value != 0) { $old_name = ($old_item = Issuetype::getB2DBTable()->selectById($original_value)) ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); } else { $old_name = framework\Context::getI18n()->__('Unknown'); } $new_name = $this->getIssuetype() instanceof \thebuggenie\core\entities\Issuetype ? $this->getIssuetype()->getName() : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_ISSUETYPE, $old_name . ' ⇒ ' . $new_name, $original_value, $compare_value); break; case '_estimated_months': case '_estimated_weeks': case '_estimated_days': case '_estimated_hours': case '_estimated_points': if (!$is_saved_estimated) { $old_time = array('months' => $this->getChangedPropertyOriginal('_estimated_months'), 'weeks' => $this->getChangedPropertyOriginal('_estimated_weeks'), 'days' => $this->getChangedPropertyOriginal('_estimated_days'), 'hours' => $this->getChangedPropertyOriginal('_estimated_hours'), 'points' => $this->getChangedPropertyOriginal('_estimated_points')); $old_formatted_time = array_sum($old_time) > 0 ? Issue::getFormattedTime($old_time) : framework\Context::getI18n()->__('Not estimated'); $new_formatted_time = $this->hasEstimatedTime() ? Issue::getFormattedTime($this->getEstimatedTime()) : framework\Context::getI18n()->__('Not estimated'); $this->addLogEntry(tables\Log::LOG_ISSUE_TIME_ESTIMATED, $old_formatted_time . ' ⇒ ' . $new_formatted_time, serialize($old_time), serialize($this->getEstimatedTime())); $is_saved_estimated = true; } break; case '_spent_months': case '_spent_weeks': case '_spent_days': case '_spent_hours': case '_spent_points': if (!$is_saved_spent) { $old_time = array('months' => $this->getChangedPropertyOriginal('_spent_months'), 'weeks' => $this->getChangedPropertyOriginal('_spent_weeks'), 'days' => $this->getChangedPropertyOriginal('_spent_days'), 'hours' => round($this->getChangedPropertyOriginal('_spent_hours') / 100, 2), 'points' => $this->getChangedPropertyOriginal('_spent_points')); $old_formatted_time = array_sum($old_time) > 0 ? Issue::getFormattedTime($old_time) : framework\Context::getI18n()->__('No time spent'); $new_formatted_time = $this->hasSpentTime() ? Issue::getFormattedTime($this->getSpentTime()) : framework\Context::getI18n()->__('No time spent'); $this->addLogEntry(tables\Log::LOG_ISSUE_TIME_SPENT, $old_formatted_time . ' ⇒ ' . $new_formatted_time, serialize($old_time), serialize($this->getSpentTime())); $is_saved_spent = true; } break; case '_state': if ($this->isClosed()) { $this->addLogEntry(tables\Log::LOG_ISSUE_CLOSE); if ($this->getMilestone() instanceof \thebuggenie\core\entities\Milestone) { if ($this->getMilestone()->isSprint()) { if (!$this->getIssueType()->isTask()) { $this->setSpentPoints($this->getEstimatedPoints()); } else { if ($this->getSpentHours() < $this->getEstimatedHours()) { $this->setSpentHours($this->getEstimatedHours()); } foreach ($this->getParentIssues() as $parent_issue) { if ($parent_issue->checkTaskStates()) { $related_issues_to_save[$parent_issue->getID()] = true; } } } } $this->getMilestone()->updateStatus(); $this->getMilestone()->save(); } } else { $this->addLogEntry(tables\Log::LOG_ISSUE_REOPEN); } break; case '_blocking': if ($this->isBlocking()) { $this->addLogEntry(tables\Log::LOG_ISSUE_BLOCKED); } else { $this->addLogEntry(tables\Log::LOG_ISSUE_UNBLOCKED); } break; default: if (mb_substr($property, 0, 12) == '_customfield') { $key = mb_substr($property, 12); $customdatatype = CustomDatatype::getByKey($key); switch ($customdatatype->getType()) { case CustomDatatype::INPUT_TEXT: $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value); break; case CustomDatatype::INPUT_TEXTAREA_SMALL: case CustomDatatype::INPUT_TEXTAREA_MAIN: $new_value = $this->getCustomField($key) != '' ? $this->getCustomField($key) : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $new_value, $original_value, $compare_value); break; case CustomDatatype::EDITIONS_CHOICE: case CustomDatatype::COMPONENTS_CHOICE: case CustomDatatype::RELEASES_CHOICE: case CustomDatatype::MILESTONE_CHOICE: case CustomDatatype::STATUS_CHOICE: case CustomDatatype::TEAM_CHOICE: case CustomDatatype::USER_CHOICE: case CustomDatatype::CLIENT_CHOICE: $old_object = null; $new_object = null; try { switch ($customdatatype->getType()) { case CustomDatatype::EDITIONS_CHOICE: $old_object = Edition::getB2DBTable()->selectById($original_value); break; case CustomDatatype::COMPONENTS_CHOICE: $old_object = Component::getB2DBTable()->selectById($original_value); break; case CustomDatatype::RELEASES_CHOICE: $old_object = Build::getB2DBTable()->selectById($original_value); break; case CustomDatatype::MILESTONE_CHOICE: $old_object = Milestone::getB2DBTable()->selectById($original_value); break; case CustomDatatype::STATUS_CHOICE: $old_object = Status::getB2DBTable()->selectById($original_value); break; case CustomDatatype::TEAM_CHOICE: $old_object = Team::getB2DBTable()->selectById($original_value); break; case CustomDatatype::USER_CHOICE: $old_object = User::getB2DBTable()->selectById($original_value); break; case CustomDatatype::CLIENT_CHOICE: $old_object = Client::getB2DBTable()->selectById($original_value); break; } } catch (\Exception $e) { } try { switch ($customdatatype->getType()) { case CustomDatatype::EDITIONS_CHOICE: case CustomDatatype::COMPONENTS_CHOICE: case CustomDatatype::RELEASES_CHOICE: case CustomDatatype::MILESTONE_CHOICE: case CustomDatatype::STATUS_CHOICE: case CustomDatatype::TEAM_CHOICE: case CustomDatatype::USER_CHOICE: case CustomDatatype::CLIENT_CHOICE: $new_object = $this->getCustomField($key); break; } } catch (\Exception $e) { } $old_value = is_object($old_object) ? $old_object->getName() : framework\Context::getI18n()->__('Unknown'); $new_value = is_object($new_object) ? $new_object->getName() : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' ⇒ ' . $new_value, $original_value, $compare_value); break; default: $old_item = null; try { $old_item = $original_value ? new CustomDatatypeOption($original_value) : null; } catch (\Exception $e) { } $old_value = $old_item instanceof \thebuggenie\core\entities\CustomDatatypeOption ? $old_item->getName() : framework\Context::getI18n()->__('Unknown'); $new_value = $this->getCustomField($key) instanceof \thebuggenie\core\entities\CustomDatatypeOption ? $this->getCustomField($key)->getName() : framework\Context::getI18n()->__('Unknown'); $this->addLogEntry(tables\Log::LOG_ISSUE_CUSTOMFIELD_CHANGED, $key . ': ' . $old_value . ' ⇒ ' . $new_value, $original_value, $compare_value); break; } } break; } } } if ($is_saved_estimated) { tables\IssueEstimates::getTable()->saveEstimate($this->getID(), $this->_estimated_months, $this->_estimated_weeks, $this->_estimated_days, $this->_estimated_hours, $this->_estimated_points); } } return $related_issues_to_save; }
/** * Set status for affected edition * * @see setAffectedItemStatus() * @see setAffectedBuildStatus() * @see setAffectedComponentStatus() * * @param \thebuggenie\core\entities\Edition $item The edition to set status for * @param \thebuggenie\core\entities\Datatype $status The status to set * * @return boolean */ public function setAffectedEditionStatus($item, $status) { if (tables\IssueAffectsEdition::getTable()->setStatusByIssueIDandEditionID($this->getID(), $item->getID(), $status->getID())) { $this->touch(); $this->addLogEntry(tables\Log::LOG_AFF_DELETE, framework\Context::getI18n()->__("'%item_name' -> '%status_name", array('%item_name' => $item->getName(), '%status_name' => $status->getName()))); return true; } return false; }
public function getEditionID() { return $this->_edition instanceof \thebuggenie\core\entities\Edition ? $this->_edition->getID() : (int) $this->_edition; }
public function componentBuild() { if (!isset($this->build)) { $this->build = new entities\Build(); $this->build->setProject(framework\Context::getCurrentProject()); $this->build->setName(framework\Context::getI18n()->__('%project_name version 0.0.0', array('%project_name' => $this->project->getName()))); if (framework\Context::getRequest()->getParameter('edition_id') && ($edition = entities\Edition::getB2DBTable()->selectById(framework\Context::getRequest()->getParameter('edition_id')))) { $this->build->setEdition($edition); } } }
public function runAddAffected(framework\Request $request) { framework\Context::loadLibrary('ui'); try { $issue = entities\Issue::getB2DBTable()->selectById($request['issue_id']); $statuses = entities\Status::getAll(); switch ($request['item_type']) { case 'edition': if (!$issue->getProject()->isEditionsEnabled()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Editions are disabled'))); } elseif (!$issue->canEditAffectedEditions()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You are not allowed to do this'))); } $edition = entities\Edition::getB2DBTable()->selectById($request['which_item_edition']); if (tables\IssueAffectsEdition::getTable()->getByIssueIDandEditionID($issue->getID(), $edition->getID())) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('%item is already affected by this issue', array('%item' => $edition->getName())))); } $result = $issue->addAffectedEdition($edition); if ($result !== false) { $itemtype = 'edition'; $item = $result; $itemtypename = framework\Context::getI18n()->__('Edition'); $content = get_component_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses)); } $message = framework\Context::getI18n()->__('Edition <b>%edition</b> is now affected by this issue', array('%edition' => $edition->getName()), true); break; case 'component': if (!$issue->getProject()->isComponentsEnabled()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Components are disabled'))); } elseif (!$issue->canEditAffectedComponents()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You are not allowed to do this'))); } $component = entities\Component::getB2DBTable()->selectById($request['which_item_component']); if (tables\IssueAffectsComponent::getTable()->getByIssueIDandComponentID($issue->getID(), $component->getID())) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('%item is already affected by this issue', array('%item' => $component->getName())))); } $result = $issue->addAffectedComponent($component); if ($result !== false) { $itemtype = 'component'; $item = $result; $itemtypename = framework\Context::getI18n()->__('Component'); $content = get_component_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses)); } $message = framework\Context::getI18n()->__('Component <b>%component</b> is now affected by this issue', array('%component' => $component->getName()), true); break; case 'build': if (!$issue->getProject()->isBuildsEnabled()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('Releases are disabled'))); } elseif (!$issue->canEditAffectedBuilds()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('You are not allowed to do this'))); } $build = entities\Build::getB2DBTable()->selectById($request['which_item_build']); if (tables\IssueAffectsBuild::getTable()->getByIssueIDandBuildID($issue->getID(), $build->getID())) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => framework\Context::getI18n()->__('%item is already affected by this issue', array('%item' => $build->getName())))); } $result = $issue->addAffectedBuild($build); if ($result !== false) { $itemtype = 'build'; $item = $result; $itemtypename = framework\Context::getI18n()->__('Release'); $content = get_component_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses)); } $message = framework\Context::getI18n()->__('Release <b>%build</b> is now affected by this issue', array('%build' => $build->getName()), true); break; default: throw new \Exception('Internal error'); } $editions = array(); $components = array(); $builds = array(); if ($issue->getProject()->isEditionsEnabled()) { $editions = $issue->getEditions(); } if ($issue->getProject()->isComponentsEnabled()) { $components = $issue->getComponents(); } if ($issue->getProject()->isBuildsEnabled()) { $builds = $issue->getBuilds(); } $count = count($editions) + count($components) + count($builds); return $this->renderJSON(array('content' => $content, 'message' => $message, 'itemcount' => $count)); } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } }