/** * Add or delete an issue field option * * @param TBGRequest $request */ public function runConfigureIssuefieldsAction(TBGRequest $request) { $i18n = TBGContext::getI18n(); $this->forward403unless($this->access_level == TBGSettings::ACCESS_FULL); $types = TBGDatatype::getTypes(); switch ($request['mode']) { case 'saveorder': $itemtype = $request['type']; if (array_key_exists($itemtype, $types)) { TBGListTypesTable::getTable()->saveOptionOrder($request[$itemtype . '_list'], $itemtype); } else { $customtype = TBGCustomDatatype::getByKey($request['type']); TBGCustomFieldOptionsTable::getTable()->saveOptionOrder($request[$itemtype . '_list'], $customtype->getID()); } return $this->renderJSON('ok'); break; case 'add': if ($request['name']) { if (array_key_exists($request['type'], $types)) { $type_name = $types[$request['type']]; $item = new $type_name(); $item->setName($request['name']); $item->setItemdata($request['itemdata']); $item->save(); } else { $customtype = TBGCustomDatatype::getByKey($request['type']); $item = $customtype->createNewOption($request['name'], $request['value'], $request['itemdata']); } return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The option was added'), 'content' => $this->getTemplateHTML('issuefield', array('item' => $item, 'access_level' => $this->access_level, 'type' => $request['type'])))); } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name'))); case 'edit': if ($request['name']) { if (array_key_exists($request['type'], $types)) { $labname = $types[$request['type']]; $item = TBGContext::factory()->{$labname}($request['id']); } else { $customtype = TBGCustomDatatype::getByKey($request['type']); $item = TBGContext::factory()->TBGCustomDatatypeOption($request['id']); } if ($item instanceof TBGDatatypeBase) { $item->setName($request['name']); $item->setItemdata($request['itemdata']); if (!$item->isBuiltin()) { $item->setValue($request['value']); } $item->save(); return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The option was updated'))); } else { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid id'))); } } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name'))); case 'delete': if ($request->hasParameter('id')) { if (array_key_exists($request['type'], $types)) { $classname = 'TBG' . ucfirst($request['type']); $item = TBGContext::factory()->{$classname}($request['id'])->delete(); return $this->renderJSON(array('title' => $i18n->__('The option was deleted'))); } else { \b2db\Core::getTable('TBGCustomFieldOptionsTable')->doDeleteById($request['id']); return $this->renderJSON(array('title' => $i18n->__('The option was deleted'))); } } $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $i18n->__('Invalid id or type'))); break; } }
public function _migrateData(\b2db\Table $old_table) { switch ($old_table->getVersion()) { case 1: if ($res = $old_table->doSelectAll()) { $customfields = TBGCustomDatatype::getB2DBTable()->selectAll(); while ($row = $res->getNextRow()) { $customfield_id = $row->get(self::CUSTOMFIELDS_ID); $customfield = array_key_exists($customfield_id, $customfields) ? $customfields[$customfield_id] : null; if ($customfield instanceof TBGCustomDatatype && $customfield->hasCustomOptions()) { $customfieldoption = TBGCustomFieldOptionsTable::getTable()->getByValueAndCustomfieldID((int) $row->get(self::OPTION_VALUE), $customfield->getID()); if ($customfieldoption instanceof TBGCustomDatatypeOption) { $crit = $this->getCriteria(); $crit->addUpdate(self::CUSTOMFIELDOPTION_ID, $customfieldoption->getID()); $crit->addUpdate(self::OPTION_VALUE, null); $this->doUpdateById($crit, $row->get(self::ID)); } elseif ($row->get(self::ID)) { $this->doDeleteById($row->get(self::ID)); } } } } break; } }
/** * Delete a custom type by id * * @param integer $id */ protected function _preDelete() { TBGCustomFieldOptionsTable::getTable()->deleteCustomFieldOptions($this->getID()); \b2db\Core::getTable('TBGIssueFieldsTable')->deleteByIssueFieldKey($this->getKey()); }
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; }
protected function _initializeCustomfields() { foreach (TBGCustomDatatype::getAll() as $key => $customdatatype) { $var_name = "_customfield" . $key; $this->{$var_name} = null; } if ($rows = TBGIssueCustomFieldsTable::getTable()->getAllValuesByIssueID($this->getID())) { foreach ($rows as $row) { $datatype = new TBGCustomDatatype($row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID)); $var_name = "_customfield" . $datatype->getKey(); if ($datatype->hasCustomOptions()) { $option = TBGCustomFieldOptionsTable::getTable()->selectById((int) $row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID)); if ($option instanceof TBGCustomDatatypeOption) { $this->{$var_name} = $option; } } else { if ($datatype->hasPredefinedOptions()) { $this->{$var_name} = $row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDOPTION_ID); } else { $this->{$var_name} = $row->get(TBGIssueCustomFieldsTable::OPTION_VALUE); } } } } }
/** * Populates all the custom field values */ protected function _populateCustomfields() { if (!$this->_custom_populated) { $this->_custom_populated = true; foreach (TBGCustomDatatype::getAll() as $key => $customdatatype) { $var_name = "_customfield" . $key; $this->{$var_name} = null; } if ($res = TBGIssueCustomFieldsTable::getTable()->getAllValuesByIssueID($this->getID())) { while ($row = $res->getNextRow()) { $datatype = new TBGCustomDatatype($row->get(TBGIssueCustomFieldsTable::CUSTOMFIELDS_ID)); $var_name = "_customfield" . $datatype->getKey(); if ($datatype->hasCustomOptions()) { if ($optionrow = TBGCustomFieldOptionsTable::getTable()->doSelectById($row->get(TBGIssueCustomFieldsTable::OPTION_VALUE))) { $this->{$var_name} = $optionrow->get(TBGCustomFieldOptionsTable::OPTION_VALUE); } } else { $this->{$var_name} = $row->get(TBGIssueCustomFieldsTable::OPTION_VALUE); } } } $this->_mergeChangedProperties(); } }