Exemplo n.º 1
0
 public function findIssues($filters = array(), $results_per_page = 30, $offset = 0, $groupby = null, $grouporder = null, $sortfields = array(self::LAST_UPDATED => 'asc'))
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::DELETED, false);
     $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID());
     if (count($filters) > 0) {
         $crit->addJoin(TBGIssueCustomFieldsTable::getTable(), TBGIssueCustomFieldsTable::ISSUE_ID, TBGIssuesTable::ID);
         $crit->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
         $crit->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
         $crit->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::ISSUE, self::ID);
         $filter_keys = array_keys($filters);
         foreach ($filters as $filter) {
             self::parseFilter($crit, $filter, $filter_keys);
         }
     }
     $crit->addSelectionColumn(self::ID);
     $crit->setDistinct();
     if ($offset != 0) {
         $crit->setOffset($offset);
     }
     $crit2 = clone $crit;
     $count = $this->doCount($crit2);
     if ($count > 0) {
         $crit3 = $this->getCriteria();
         if ($results_per_page != 0) {
             $crit->setLimit($results_per_page);
         }
         if ($offset != 0) {
             $crit->setOffset($offset);
         }
         if ($groupby !== null) {
             $grouporder = $grouporder !== null ? $grouporder == 'asc' ? Criteria::SORT_ASC : Criteria::SORT_DESC : Criteria::SORT_ASC;
             switch ($groupby) {
                 case 'category':
                     $crit->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::CATEGORY);
                     $crit->addSelectionColumn(TBGListTypesTable::NAME);
                     $crit->addOrderBy(TBGListTypesTable::NAME, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::CATEGORY);
                     $crit3->addOrderBy(TBGListTypesTable::NAME, $grouporder);
                     break;
                 case 'status':
                     $crit->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::STATUS);
                     $crit->addSelectionColumn(self::STATUS);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, Criteria::SORT_DESC);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::STATUS);
                     $crit3->addOrderBy(TBGListTypesTable::ORDER, Criteria::SORT_DESC);
                     break;
                 case 'milestone':
                     $crit->addSelectionColumn(self::MILESTONE);
                     $crit->addSelectionColumn(self::PERCENT_COMPLETE);
                     $crit->addOrderBy(self::MILESTONE, $grouporder);
                     $crit->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     $crit3->addOrderBy(self::MILESTONE, $grouporder);
                     $crit3->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     break;
                 case 'assignee':
                     $crit->addSelectionColumn(self::ASSIGNEE_TEAM);
                     $crit->addSelectionColumn(self::ASSIGNEE_USER);
                     $crit->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     $crit3->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit3->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     break;
                 case 'state':
                     $crit->addSelectionColumn(self::STATE);
                     $crit->addOrderBy(self::STATE, $grouporder);
                     $crit3->addOrderBy(self::STATE, $grouporder);
                     break;
                 case 'severity':
                     $crit->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::SEVERITY);
                     $crit->addSelectionColumn(self::SEVERITY);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::SEVERITY);
                     $crit3->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     break;
                 case 'user_pain':
                     $crit->addSelectionColumn(self::USER_PAIN);
                     $crit->addOrderBy(self::USER_PAIN, $grouporder);
                     $crit3->addOrderBy(self::USER_PAIN, $grouporder);
                     break;
                 case 'votes':
                     $crit->addSelectionColumn(self::VOTES_TOTAL);
                     $crit->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     $crit3->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     break;
                 case 'resolution':
                     $crit->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::RESOLUTION);
                     $crit->addSelectionColumn(self::RESOLUTION);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::RESOLUTION);
                     $crit3->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     break;
                 case 'priority':
                     $crit->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::PRIORITY);
                     $crit->addSelectionColumn(self::PRIORITY);
                     $crit->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     $crit3->addJoin(TBGListTypesTable::getTable(), TBGListTypesTable::ID, self::PRIORITY);
                     $crit3->addOrderBy(TBGListTypesTable::ORDER, $grouporder);
                     break;
                 case 'issuetype':
                     $crit->addJoin(TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID, self::ISSUE_TYPE);
                     $crit->addSelectionColumn(TBGIssueTypesTable::NAME);
                     $crit->addOrderBy(TBGIssueTypesTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID, self::ISSUE_TYPE);
                     $crit3->addOrderBy(TBGIssueTypesTable::NAME, $grouporder);
                     break;
                 case 'edition':
                     $crit->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
                     $crit->addJoin(TBGEditionsTable::getTable(), TBGEditionsTable::ID, TBGIssueAffectsEditionTable::EDITION, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsEditionTable::getTable());
                     $crit->addSelectionColumn(TBGEditionsTable::NAME);
                     $crit->addOrderBy(TBGEditionsTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
                     $crit3->addJoin(TBGEditionsTable::getTable(), TBGEditionsTable::ID, TBGIssueAffectsEditionTable::EDITION, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsEditionTable::getTable());
                     $crit3->addOrderBy(TBGEditionsTable::NAME, $grouporder);
                     break;
                 case 'build':
                     $crit->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::ISSUE, self::ID);
                     $crit->addJoin(TBGBuildsTable::getTable(), TBGBuildsTable::ID, TBGIssueAffectsBuildTable::BUILD, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsBuildTable::getTable());
                     $crit->addSelectionColumn(TBGBuildsTable::NAME);
                     $crit->addOrderBy(TBGBuildsTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::ISSUE, self::ID);
                     $crit3->addJoin(TBGBuildsTable::getTable(), TBGBuildsTable::ID, TBGIssueAffectsBuildTable::BUILD, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsBuildTable::getTable());
                     $crit3->addOrderBy(TBGBuildsTable::NAME, $grouporder);
                     break;
                 case 'component':
                     $crit->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
                     $crit->addJoin(TBGComponentsTable::getTable(), TBGComponentsTable::ID, TBGIssueAffectsComponentTable::COMPONENT, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsComponentTable::getTable());
                     $crit->addSelectionColumn(TBGComponentsTable::NAME);
                     $crit->addOrderBy(TBGComponentsTable::NAME, $grouporder);
                     $crit3->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
                     $crit3->addJoin(TBGComponentsTable::getTable(), TBGComponentsTable::ID, TBGIssueAffectsComponentTable::COMPONENT, array(), Criteria::DB_LEFT_JOIN, TBGIssueAffectsComponentTable::getTable());
                     $crit3->addOrderBy(TBGComponentsTable::NAME, $grouporder);
                     break;
             }
         }
         foreach ($sortfields as $field => $sortorder) {
             $crit->addSelectionColumn($field);
             $crit->addOrderBy($field, $sortorder);
         }
         $res = $this->doSelect($crit, 'none');
         $ids = array();
         if ($res) {
             while ($row = $res->getNextRow()) {
                 $ids[] = $row->get(self::ID);
             }
             $ids = array_reverse($ids);
             $crit3->addWhere(self::ID, $ids, Criteria::DB_IN);
             foreach ($sortfields as $field => $sortorder) {
                 $crit3->addOrderBy($field, $sortorder);
             }
             $res = $this->doSelect($crit3);
             $rows = $res->getAllRows();
         } else {
             $rows = array();
         }
         unset($res);
         return array($rows, $count, $ids);
     } else {
         return array(null, 0, array());
     }
 }
Exemplo n.º 2
0
 /**
  *
  * @param \b2db\Criteria $crit
  * @param array|TBGSearchFilter $filters
  * @param \b2db\Criterion $ctn
  * @return null
  */
 public function addToCriteria($crit, $filters, $ctn = null)
 {
     $filter_key = $this->getFilterKey();
     if (in_array($this['operator'], array('=', '!=', '<=', '>=', '<', '>'))) {
         if ($filter_key == 'text') {
             if ($this['value'] != '') {
                 $searchterm = mb_strpos($this['value'], '%') !== false ? $this['value'] : "%{$this['value']}%";
                 if ($this['operator'] == '=') {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(TBGIssuesTable::TITLE, $searchterm, Criteria::DB_LIKE);
                     }
                     $ctn->addOr(TBGIssuesTable::DESCRIPTION, $searchterm, Criteria::DB_LIKE);
                     $ctn->addOr(TBGIssuesTable::REPRODUCTION_STEPS, $searchterm, Criteria::DB_LIKE);
                     $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, Criteria::DB_LIKE);
                 } else {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(TBGIssuesTable::TITLE, $searchterm, Criteria::DB_NOT_LIKE);
                     }
                     $ctn->addWhere(TBGIssuesTable::DESCRIPTION, $searchterm, Criteria::DB_NOT_LIKE);
                     $ctn->addWhere(TBGIssuesTable::REPRODUCTION_STEPS, $searchterm, Criteria::DB_NOT_LIKE);
                     $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, Criteria::DB_NOT_LIKE);
                 }
                 return $ctn;
             }
         } elseif (in_array($filter_key, self::getValidSearchFilters())) {
             if ($filter_key == 'subprojects') {
                 if (TBGContext::isProjectContext()) {
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion(TBGIssuesTable::PROJECT_ID, TBGContext::getCurrentProject()->getID());
                     }
                     if ($this->hasValue()) {
                         foreach ($this->getValues() as $value) {
                             switch ($value) {
                                 case 'all':
                                     $subprojects = TBGProject::getIncludingAllSubprojectsAsArray(TBGContext::getCurrentProject());
                                     foreach ($subprojects as $subproject) {
                                         if ($subproject->getID() == TBGContext::getCurrentProject()->getID()) {
                                             continue;
                                         }
                                         $ctn->addOr(TBGIssuesTable::PROJECT_ID, $subproject->getID());
                                     }
                                     break;
                                 case 'none':
                                 case '':
                                     break;
                                 default:
                                     $ctn->addOr(TBGIssuesTable::PROJECT_ID, (int) $value);
                                     break;
                             }
                         }
                     }
                     return $ctn;
                 }
             } elseif (in_array($filter_key, array('build', 'edition', 'component'))) {
                 switch ($filter_key) {
                     case 'component':
                         $tbl = TBGIssueAffectsComponentTable::getTable();
                         $fk = TBGIssueAffectsComponentTable::ISSUE;
                         break;
                     case 'edition':
                         $tbl = TBGIssueAffectsEditionTable::getTable();
                         $fk = TBGIssueAffectsEditionTable::ISSUE;
                         break;
                     case 'build':
                         $tbl = TBGIssueAffectsBuildTable::getTable();
                         $fk = TBGIssueAffectsBuildTable::ISSUE;
                         break;
                 }
                 $crit->addJoin($tbl, $fk, TBGIssuesTable::ID, array(array($tbl->getB2DBAlias() . '.' . $filter_key, $this->getValues())), \b2db\Criteria::DB_INNER_JOIN);
                 return null;
             } else {
                 if ($filter_key == 'project_id' && in_array('subprojects', $filters)) {
                     return null;
                 }
                 $values = $this->getValues();
                 $num_values = 0;
                 if ($filter_key == 'status') {
                     if ($this->hasValue('open')) {
                         $c = $crit->returnCriterion(TBGIssuesTable::STATE, TBGIssue::STATE_OPEN);
                         $num_values++;
                     }
                     if ($this->hasValue('closed')) {
                         $num_values++;
                         if (isset($c)) {
                             $c->addWhere(TBGIssuesTable::STATE, TBGIssue::STATE_CLOSED);
                         } else {
                             $c = $crit->returnCriterion(TBGIssuesTable::STATE, TBGIssue::STATE_CLOSED);
                         }
                     }
                     if (isset($c)) {
                         if (count($values) == $num_values) {
                             return $c;
                         } else {
                             $crit->addWhere($c);
                         }
                     }
                 }
                 $dbname = TBGIssuesTable::getTable()->getB2DBName();
                 foreach ($values as $value) {
                     $operator = $this['operator'];
                     $or = true;
                     if ($filter_key == 'status' && in_array($value, array('open', 'closed'))) {
                         continue;
                     } else {
                         $field = $dbname . '.' . $filter_key;
                         if ($operator == '!=' || in_array($filter_key, array('posted', 'last_updated'))) {
                             $or = false;
                         }
                     }
                     if ($ctn === null) {
                         $ctn = $crit->returnCriterion($field, $value, urldecode($operator));
                     } elseif ($or) {
                         $ctn->addOr($field, $value, urldecode($operator));
                     } else {
                         $ctn->addWhere($field, $value, urldecode($operator));
                     }
                 }
                 return $ctn;
             }
         } elseif (TBGCustomDatatype::doesKeyExist($filter_key)) {
             $customdatatype = TBGCustomDatatype::getByKey($filter_key);
             if (in_array($this->getFilterType(), TBGCustomDatatype::getInternalChoiceFieldsAsArray())) {
                 $tbl = clone TBGIssueCustomFieldsTable::getTable();
                 $crit->addJoin($tbl, TBGIssueCustomFieldsTable::ISSUE_ID, TBGIssuesTable::ID, array(array($tbl->getB2DBAlias() . '.customfields_id', $customdatatype->getID()), array($tbl->getB2DBAlias() . '.customfieldoption_id', $this->getValues())), \b2db\Criteria::DB_INNER_JOIN);
                 return null;
             } else {
                 foreach ($this->getValues() as $value) {
                     if ($customdatatype->hasCustomOptions()) {
                         if ($ctn === null) {
                             $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                             $ctn->addWhere(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID, $value, $this['operator']);
                         } else {
                             $ctn->addOr(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID, $value, $this['operator']);
                         }
                     } else {
                         if ($ctn === null) {
                             $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                             $ctn->addWhere(TBGIssueCustomFieldsTable::OPTION_VALUE, $value, $this['operator']);
                         } else {
                             $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $value, $this['operator']);
                         }
                     }
                 }
                 return $ctn;
             }
         }
     }
 }
Exemplo n.º 3
0
 public function runAddAffected(TBGRequest $request)
 {
     TBGContext::loadLibrary('ui');
     try {
         $issue = TBGContext::factory()->TBGIssue($request['issue_id']);
         $statuses = TBGStatus::getAll();
         switch ($request['item_type']) {
             case 'edition':
                 if (!$issue->getProject()->isEditionsEnabled()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Editions are disabled')));
                 } elseif (!$issue->canEditAffectedEditions()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You are not allowed to do this')));
                 }
                 $edition = TBGContext::factory()->TBGEdition($request['which_item_edition']);
                 if (TBGIssueAffectsEditionTable::getTable()->getByIssueIDandEditionID($issue->getID(), $edition->getID())) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('%item is already affected by this issue', array('%item' => $edition->getName()))));
                 }
                 $edition = $issue->addAffectedEdition($edition);
                 $item = $edition;
                 $itemtype = 'edition';
                 $itemtypename = TBGContext::getI18n()->__('Edition');
                 $content = get_template_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses));
                 $message = TBGContext::getI18n()->__('Edition <b>%edition</b> is now affected by this issue', array('%edition' => $edition['edition']->getName()));
                 break;
             case 'component':
                 if (!$issue->getProject()->isComponentsEnabled()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Components are disabled')));
                 } elseif (!$issue->canEditAffectedComponents()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You are not allowed to do this')));
                 }
                 $component = TBGContext::factory()->TBGComponent($request['which_item_component']);
                 if (TBGIssueAffectsComponentTable::getTable()->getByIssueIDandComponentID($issue->getID(), $component->getID())) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('%item is already affected by this issue', array('%item' => $component->getName()))));
                 }
                 $component = $issue->addAffectedComponent($component);
                 $item = $component;
                 $itemtype = 'component';
                 $itemtypename = TBGContext::getI18n()->__('Component');
                 $content = get_template_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses));
                 $message = TBGContext::getI18n()->__('Component <b>%component</b> is now affected by this issue', array('%component' => $component['component']->getName()));
                 break;
             case 'build':
                 if (!$issue->getProject()->isBuildsEnabled()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Releases are disabled')));
                 } elseif (!$issue->canEditAffectedBuilds()) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You are not allowed to do this')));
                 }
                 $build = TBGContext::factory()->TBGBuild($request['which_item_build']);
                 if (TBGIssueAffectsBuildTable::getTable()->getByIssueIDandBuildID($issue->getID(), $build->getID())) {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('%item is already affected by this issue', array('%item' => $build->getName()))));
                 }
                 $build = $issue->addAffectedBuild($build);
                 $item = $build;
                 $itemtype = 'build';
                 $itemtypename = TBGContext::getI18n()->__('Release');
                 $content = get_template_html('main/affecteditem', array('item' => $item, 'itemtype' => $itemtype, 'itemtypename' => $itemtypename, 'issue' => $issue, 'statuses' => $statuses));
                 $message = TBGContext::getI18n()->__('Release <b>%build</b> is now affected by this issue', array('%build' => $build['build']->getName()));
                 break;
             default:
                 throw new Exception('Internal error');
                 break;
         }
         $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()));
     }
 }
Exemplo n.º 4
0
 protected function _upgradeFrom3dot1()
 {
     // Add classpath for existing old tables used for upgrade
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'installation' . DS . 'classes' . DS . 'upgrade_3.1');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'mailing' . DS . 'classes' . DS . 'B2DB');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'mailing' . DS . 'classes');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes' . DS . 'B2DB');
     TBGContext::addAutoloaderClassPath(THEBUGGENIE_MODULES_PATH . 'publish' . DS . 'classes');
     // Create new tables
     TBGDashboardViewsTable::getTable()->create();
     TBGOpenIdAccountsTable::getTable()->create();
     TBGProjectAssignedUsersTable::getTable()->create();
     TBGProjectAssignedTeamsTable::getTable()->create();
     TBGEditionAssignedUsersTable::getTable()->create();
     TBGEditionAssignedTeamsTable::getTable()->create();
     TBGComponentAssignedUsersTable::getTable()->create();
     TBGComponentAssignedTeamsTable::getTable()->create();
     TBGRolePermissionsTable::getTable()->create();
     TBGUserScopesTable::getTable()->create();
     // Upgrade existing tables
     TBGProjectsTable::getTable()->upgrade(TBGProjectsTable3dot1::getTable());
     TBGUsersTable::getTable()->upgrade(TBGUsersTable3dot1::getTable());
     TBGIssuesTable::getTable()->upgrade(TBGIssuesTable3dot1::getTable());
     TBGIssueTypesTable::getTable()->upgrade(TBGIssueTypesTable3dot1::getTable());
     TBGListTypesTable::getTable()->upgrade(TBGListTypesTable3dot1::getTable());
     TBGEditionsTable::getTable()->upgrade(TBGEditionsTable3dot1::getTable());
     TBGBuildsTable::getTable()->upgrade(TBGBuildsTable3dot1::getTable());
     TBGCommentsTable::getTable()->upgrade(TBGCommentsTable3dot1::getTable());
     TBGComponentsTable::getTable()->upgrade(TBGComponentsTable3dot1::getTable());
     TBGCustomFieldsTable::getTable()->upgrade(TBGCustomFieldsTable3dot1::getTable());
     TBGCustomFieldOptionsTable::getTable()->upgrade(TBGCustomFieldOptionsTable3dot1::getTable());
     TBGIssueCustomFieldsTable::getTable()->upgrade(TBGIssueCustomFieldsTable3dot1::getTable());
     // Create new module tables
     TBGIncomingEmailAccountTable::getTable()->create();
     // Add new indexes
     TBGArticlesTable::getTable()->createIndexes();
     TBGCommentsTable::getTable()->createIndexes();
     TBGIssueAffectsBuildTable::getTable()->createIndexes();
     TBGIssueAffectsComponentTable::getTable()->createIndexes();
     TBGIssueAffectsEditionTable::getTable()->createIndexes();
     TBGIssueFieldsTable::getTable()->createIndexes();
     TBGIssueFilesTable::getTable()->createIndexes();
     TBGIssuesTable::getTable()->createIndexes();
     TBGIssuetypeSchemesTable::getTable()->createIndexes();
     TBGPermissionsTable::getTable()->createIndexes();
     TBGProjectsTable::getTable()->createIndexes();
     TBGSettingsTable::getTable()->createIndexes();
     TBGTeamMembersTable::getTable()->createIndexes();
     TBGUserIssuesTable::getTable()->createIndexes();
     TBGUsersTable::getTable()->createIndexes();
     TBGUserScopesTable::getTable()->createIndexes();
     if (TBGContext::getRequest()->getParameter('fix_my_timestamps', false)) {
         $this->_fixTimestamps();
     }
     foreach (TBGScope::getAll() as $scope) {
         TBGRole::loadFixtures($scope);
         foreach (TBGDatatype::getTypes() as $type => $class) {
             TBGContext::setPermission('set_datatype_' . $type, 0, 'core', 0, 0, 0, true, $scope->getID());
         }
         TBGContext::setPermission('page_confirm_scope_access', 0, 'core', 0, 0, 0, true, $scope->getID());
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_WORKFLOW, 'core', $scope->getID())) {
             $workflow_id = TBGWorkflowsTable::getTable()->getFirstIdByScope($scope->getID());
             if ($workflow_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_WORKFLOW, $workflow_id, 'core', $scope->getID());
             } else {
                 TBGWorkflow::loadFixtures($scope);
             }
         }
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_WORKFLOWSCHEME, 'core', $scope->getID())) {
             $workflow_scheme_id = TBGWorkflowSchemesTable::getTable()->getFirstIdByScope($scope->getID());
             if ($workflow_scheme_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_WORKFLOWSCHEME, $workflow_scheme_id, 'core', $scope->getID());
             } else {
                 TBGWorkflowScheme::loadFixtures($scope);
             }
         }
         if (!TBGSettings::get(TBGSettings::SETTING_DEFAULT_ISSUETYPESCHEME, 'core', $scope->getID())) {
             $issuetype_scheme_id = TBGIssuetypeSchemesTable::getTable()->getFirstIdByScope($scope->getID());
             if ($issuetype_scheme_id) {
                 TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_ISSUETYPESCHEME, $issuetype_scheme_id, 'core', $scope->getID());
             } else {
                 TBGIssuetypeScheme::loadFixtures($scope);
             }
         }
         TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_ID, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_TYPE, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_ID, 0, 'core', $scope->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_TYPE, 0, 'core', $scope->getID());
     }
     $linkstable = TBGLinksTable::getTable();
     $crit = $linkstable->getCriteria();
     $crit->addUpdate(TBGLinksTable::URL, 'http://issues.thebuggenie.com');
     $crit->addWhere(TBGLinksTable::URL, 'http://thebuggenie.com/thebuggenie');
     $crit->addOr(TBGLinksTable::URL, 'http://www.thebuggenie.com/thebuggenie');
     $linkstable->doUpdate($crit);
     $listtypestable = TBGListTypesTable::getTable();
     $crit = $listtypestable->getCriteria();
     $crit->addUpdate(TBGListTypesTable::ITEMTYPE, 'role');
     $crit->addWhere(TBGListTypesTable::ITEMTYPE, 'projectrole');
     $listtypestable->doUpdate($crit);
     $crit = $listtypestable->getCriteria();
     $crit->addUpdate(TBGListTypesTable::ITEMTYPE, 'priority');
     $crit->addWhere(TBGListTypesTable::ITEMTYPE, 'b2_prioritytypes');
     $listtypestable->doUpdate($crit);
     TBGWorkflowTransitionsTable::getTable()->upgradeFrom3dot1();
     TBGSettings::saveSetting(TBGSettings::SETTING_ICONSET, TBGSettings::get(TBGSettings::SETTING_THEME_NAME));
     TBGContext::setPermission('readarticle', 0, 'publish', 0, 0, 0, true);
     foreach (TBGProject::getAll() as $project) {
         TBGDashboardViewsTable::getTable()->setDefaultViews($project->getID(), TBGDashboardViewsTable::TYPE_PROJECT);
         if (!$project->getKey()) {
             $project->setName($project->getName());
         }
     }
     $this->upgrade_complete = true;
 }
Exemplo n.º 5
0
 /**
  * Set status for affected edition
  * 
  * @see setAffectedItemStatus()
  * @see setAffectedBuildStatus()
  * @see setAffectedComponentStatus()
  * 
  * @param TBGEdition $item The edition to set status for
  * @param TBGDatatype $status The status to set
  * 
  * @return boolean
  */
 public function setAffectedEditionStatus($item, $status)
 {
     if (TBGIssueAffectsEditionTable::getTable()->setStatusByIssueIDandEditionID($this->getID(), $item->getID(), $status->getID())) {
         $this->addLogEntry(TBGLogTable::LOG_AFF_DELETE, TBGContext::getI18n()->__("'%item_name' -> '%status_name", array('%item_name' => $item->getName(), '%status_name' => $status->getName())));
         return true;
     }
     return false;
 }
 public function findIssues($filters = array(), $results_per_page = 30, $offset = 0, $groupby = null, $grouporder = null)
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::DELETED, false);
     if (count($filters) > 0) {
         $crit->addJoin(TBGIssueCustomFieldsTable::getTable(), TBGIssueCustomFieldsTable::ISSUE_ID, TBGIssuesTable::ID);
         foreach ($filters as $filter => $filter_info) {
             if (array_key_exists('value', $filter_info) && in_array($filter_info['operator'], array('=', '!=', '<=', '>=', '<', '>'))) {
                 if ($filter == 'text') {
                     if ($filter_info['value'] != '') {
                         $searchterm = strpos($filter_info['value'], '%') !== false ? $filter_info['value'] : "%{$filter_info['value']}%";
                         if ($filter_info['operator'] == '=') {
                             $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_LIKE);
                             $ctn->addOr(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_LIKE);
                             $ctn->addOr(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_LIKE);
                             $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, B2DBCriteria::DB_LIKE);
                         } else {
                             $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             $ctn->addWhere(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             $ctn->addWhere(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                         }
                         $crit->addWhere($ctn);
                     }
                 } elseif (in_array($filter, self::getValidSearchFilters())) {
                     $crit->addWhere($this->getB2DBName() . '.' . $filter, $filter_info['value'], $filter_info['operator']);
                 } elseif (TBGCustomDatatype::doesKeyExist($filter)) {
                     $customdatatype = TBGCustomDatatype::getByKey($filter);
                     $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                     $ctn->addWhere(TBGIssueCustomFieldsTable::OPTION_VALUE, $filter_info['value'], $filter_info['operator']);
                     $crit->addWhere($ctn);
                 }
             } else {
                 if (in_array($filter, self::getValidSearchFilters())) {
                     $first_val = array_shift($filter_info);
                     if ($filter == 'text') {
                         $filter_info = $first_val;
                         if ($filter_info['value'] != '') {
                             $searchterm = strpos($filter_info['value'], '%') !== false ? $filter_info['value'] : "%{$filter_info['value']}%";
                             if ($filter_info['operator'] == '=') {
                                 $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_LIKE);
                                 $ctn->addOr(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_LIKE);
                                 $ctn->addOr(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_LIKE);
                             } else {
                                 $ctn = $crit->returnCriterion(self::TITLE, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                                 $ctn->addWhere(self::DESCRIPTION, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                                 $ctn->addWhere(self::REPRODUCTION_STEPS, $searchterm, B2DBCriteria::DB_NOT_LIKE);
                             }
                             $crit->addWhere($ctn);
                         }
                     } else {
                         $ctn = $crit->returnCriterion($this->getB2DBName() . '.' . $filter, $first_val['value'], $first_val['operator']);
                         if (count($filter_info) > 0) {
                             foreach ($filter_info as $single_filter) {
                                 if (in_array($single_filter['operator'], array('=', '<=', '>=', '<', '>'))) {
                                     $ctn->addOr($this->getB2DBName() . '.' . $filter, $single_filter['value'], $single_filter['operator']);
                                 } elseif ($single_filter['operator'] == '!=') {
                                     $ctn->addWhere($this->getB2DBName() . '.' . $filter, $single_filter['value'], $single_filter['operator']);
                                 }
                             }
                         }
                         $crit->addWhere($ctn);
                     }
                 } elseif (TBGCustomDatatype::doesKeyExist($filter)) {
                     $customdatatype = TBGCustomDatatype::getByKey($filter);
                     $first_val = array_shift($filter_info);
                     $ctn = $crit->returnCriterion(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID, $customdatatype->getID());
                     $ctn->addWhere(TBGIssueCustomFieldsTable::OPTION_VALUE, $first_val['value'], $first_val['operator']);
                     if (count($filter_info) > 0) {
                         foreach ($filter_info as $single_filter) {
                             if (in_array($single_filter['operator'], array('=', '!=', '<=', '>=', '<', '>'))) {
                                 $ctn->addOr(TBGIssueCustomFieldsTable::OPTION_VALUE, $single_filter['value'], $single_filter['operator']);
                             }
                         }
                     }
                     $crit->addWhere($ctn);
                 }
             }
         }
     }
     $crit->addSelectionColumn(self::ID);
     $crit->setDistinct();
     if ($offset != 0) {
         $crit->setOffset($offset);
     }
     $crit2 = clone $crit;
     $count = $this->doCount($crit2);
     if ($count > 0) {
         if ($results_per_page != 0) {
             $crit->setLimit($results_per_page);
         }
         if ($offset != 0) {
             $crit->setOffset($offset);
         }
         if ($groupby !== null) {
             $grouporder = $grouporder !== null ? $grouporder == 'asc' ? B2DBCriteria::SORT_ASC : B2DBCriteria::SORT_DESC : B2DBCriteria::SORT_ASC;
             switch ($groupby) {
                 case 'category':
                     $crit->addSelectionColumn(TBGListTypesTable::NAME);
                     $crit->addOrderBy(TBGListTypesTable::NAME, $grouporder);
                     break;
                 case 'status':
                     $crit->addSelectionColumn(self::STATUS);
                     $crit->addOrderBy(self::STATUS, $grouporder);
                     break;
                 case 'milestone':
                     $crit->addSelectionColumn(self::MILESTONE);
                     $crit->addSelectionColumn(self::PERCENT_COMPLETE);
                     $crit->addOrderBy(self::MILESTONE, $grouporder);
                     $crit->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     break;
                 case 'assignee':
                     $crit->addSelectionColumn(self::ASSIGNED_TYPE);
                     $crit->addSelectionColumn(self::ASSIGNED_TO);
                     $crit->addOrderBy(self::ASSIGNED_TYPE);
                     $crit->addOrderBy(self::ASSIGNED_TO, $grouporder);
                     break;
                 case 'state':
                     $crit->addSelectionColumn(self::STATE);
                     $crit->addOrderBy(self::STATE, $grouporder);
                     break;
                 case 'severity':
                     $crit->addSelectionColumn(self::SEVERITY);
                     $crit->addOrderBy(self::SEVERITY, $grouporder);
                     break;
                 case 'user_pain':
                     $crit->addSelectionColumn(self::USER_PAIN);
                     $crit->addOrderBy(self::USER_PAIN, $grouporder);
                     break;
                 case 'votes':
                     $crit->addSelectionColumn(self::VOTES_TOTAL);
                     $crit->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     break;
                 case 'resolution':
                     $crit->addSelectionColumn(self::RESOLUTION);
                     $crit->addOrderBy(self::RESOLUTION, $grouporder);
                     break;
                 case 'priority':
                     $crit->addSelectionColumn(self::PRIORITY);
                     $crit->addOrderBy(self::PRIORITY, $grouporder);
                     break;
                 case 'issuetype':
                     $crit->addJoin(TBGIssueTypesTable::getTable(), TBGIssueTypesTable::ID, self::ISSUE_TYPE);
                     $crit->addSelectionColumn(TBGIssueTypesTable::NAME);
                     $crit->addOrderBy(TBGIssueTypesTable::NAME, $grouporder);
                     break;
                 case 'edition':
                     $crit->addJoin(TBGIssueAffectsEditionTable::getTable(), TBGIssueAffectsEditionTable::ISSUE, self::ID);
                     $crit->addJoin(TBGEditionsTable::getTable(), TBGEditionsTable::ID, TBGIssueAffectsEditionTable::EDITION, array(), B2DBCriteria::DB_LEFT_JOIN, TBGIssueAffectsEditionTable::getTable());
                     $crit->addSelectionColumn(TBGEditionsTable::NAME);
                     $crit->addOrderBy(TBGEditionsTable::NAME, $grouporder);
                     break;
                 case 'build':
                     $crit->addJoin(TBGIssueAffectsBuildTable::getTable(), TBGIssueAffectsBuildTable::ISSUE, self::ID);
                     $crit->addJoin(TBGBuildsTable::getTable(), TBGBuildsTable::ID, TBGIssueAffectsBuildTable::BUILD, array(), B2DBCriteria::DB_LEFT_JOIN, TBGIssueAffectsBuildTable::getTable());
                     $crit->addSelectionColumn(TBGBuildsTable::NAME);
                     $crit->addOrderBy(TBGBuildsTable::NAME, $grouporder);
                     break;
                 case 'component':
                     $crit->addJoin(TBGIssueAffectsComponentTable::getTable(), TBGIssueAffectsComponentTable::ISSUE, self::ID);
                     $crit->addJoin(TBGComponentsTable::getTable(), TBGComponentsTable::ID, TBGIssueAffectsComponentTable::COMPONENT, array(), B2DBCriteria::DB_LEFT_JOIN, TBGIssueAffectsComponentTable::getTable());
                     $crit->addSelectionColumn(TBGComponentsTable::NAME);
                     $crit->addOrderBy(TBGComponentsTable::NAME, $grouporder);
                     break;
             }
         }
         $crit->addSelectionColumn(self::LAST_UPDATED);
         $crit->addOrderBy(self::LAST_UPDATED, 'asc');
         $res = $this->doSelect($crit, 'none');
         $ids = array();
         while ($row = $res->getNextRow()) {
             $ids[] = $row->get(self::ID);
         }
         $ids = array_reverse($ids);
         $crit2 = $this->getCriteria();
         $crit2->addWhere(self::ID, $ids, B2DBCriteria::DB_IN);
         $crit2->addOrderBy(self::ID, $ids);
         $res = $this->doSelect($crit2);
         return array($res, $count);
     } else {
         return array(null, 0);
     }
 }