public function do_execute() { /* Prepare variables */ try { $project_id = $this->getProvidedArgument('projectid'); $project_row = TBGProjectsTable::getTable()->getById($project_id, false); TBGContext::setScope(new TBGScope($project_row[TBGProjectsTable::SCOPE])); $project = new TBGProject($project_id, $project_row); } catch (Exception $e) { throw $e; $this->cliEcho("The project with the ID " . $this->getProvidedArgument('projectid') . " does not exist\n", 'red', 'bold'); exit; } $author = $this->getProvidedArgument('author'); $new_rev = $this->getProvidedArgument('revno'); $commit_msg = $this->getProvidedArgument('log'); $changed = $this->getProvidedArgument('changed'); $old_rev = $this->getProvidedArgument('oldrev', null); $date = $this->getProvidedArgument('date', null); $branch = $this->getProvidedArgument('branch', null); if (TBGSettings::get('access_method_' . $project->getKey()) == TBGVCSIntegration::ACCESS_HTTP) { $this->cliEcho("This project uses the HTTP access method, and so access via the CLI has been disabled\n", 'red', 'bold'); exit; } if ($old_rev === null && !is_integer($new_rev)) { $this->cliEcho("Error: if only the new revision is specified, it must be a number so that old revision can be calculated from it (by substracting 1 from new revision number)."); } else { if ($old_rev === null) { $old_rev = $new_rev - 1; } } $output = TBGVCSIntegration::processCommit($project, $commit_msg, $old_rev, $new_rev, $date, $changed, $author, $branch); $this->cliEcho($output); }
public static function loadFixtures(TBGScope $scope) { $scope_id = $scope->getID(); $admin_group = new TBGGroup(); $admin_group->setName('Administrators'); $admin_group->setScope($scope); $admin_group->save(); TBGSettings::saveSetting('admingroup', $admin_group->getID(), 'core', $scope_id); $user_group = new TBGGroup(); $user_group->setName('Regular users'); $user_group->setScope($scope); $user_group->save(); TBGSettings::saveSetting('defaultgroup', $user_group->getID(), 'core', $scope_id); $guest_group = new TBGGroup(); $guest_group->setName('Guests'); $guest_group->setScope($scope); $guest_group->save(); // Set up initial users, and their permissions if ($scope->isDefault()) { list($guestuser_id, $adminuser_id) = TBGUser::loadFixtures($scope, $admin_group, $user_group, $guest_group); TBGUserScopesTable::getTable()->addUserToScope($guestuser_id, $scope->getID(), $guest_group->getID(), true); TBGUserScopesTable::getTable()->addUserToScope($adminuser_id, $scope->getID(), $admin_group->getID(), true); } else { $default_scope_id = TBGSettings::getDefaultScopeID(); $default_user_id = (int) TBGSettings::get(TBGSettings::SETTING_DEFAULT_USER_ID, 'core', $default_scope_id); TBGUserScopesTable::getTable()->addUserToScope($default_user_id, $scope->getID(), $user_group->getID(), true); TBGUserScopesTable::getTable()->addUserToScope(1, $scope->getID(), $admin_group->getID()); TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_USER_ID, $default_user_id, 'core', $scope->getID()); } TBGPermissionsTable::getTable()->loadFixtures($scope, $admin_group->getID(), $guest_group->getID()); }
public function addUserToScope($user_id, $scope_id, $group_id = null, $confirmed = false) { $group_id = $group_id === null ? TBGSettings::get(TBGSettings::SETTING_USER_GROUP, 'core', $scope_id) : $group_id; $crit = $this->getCriteria(); $crit->addInsert(self::USER_ID, $user_id); $crit->addInsert(self::SCOPE, $scope_id); $crit->addInsert(self::GROUP_ID, $group_id); $crit->addInsert(self::CONFIRMED, $confirmed); $this->doInsert($crit); }
<div id="tab_forgot_pane"<?php if ($selected_tab != 'forgot') { ?> style="display: none;<?php } ?> "> <?php if (TBGSettings::getAuthenticationBackend() != 'tbg' && TBGSettings::getAuthenticationBackend() != null) { echo tbg_parse_text(TBGSettings::get('forgot_message'), null, null, array('embedded' => true)); } else { ?> <div style="vertical-align: middle; padding: 5px;"> <form accept-charset="<?php echo TBGContext::getI18n()->getCharset(); ?> " action="<?php echo make_url('forgot'); ?> " method="post" id="forgot_password_form" onsubmit="resetForgotPassword('<?php echo make_url('forgot'); ?> '); return false;"> <div class="login_boxheader"><?php echo __('Forgot password?'); ?> </div> <p><?php echo __('If you have forgot your password, enter your username here, and we will send you an email that will allow you to change your password'); ?> .</p><br>
/** * Registration logic * * @param TBGRequest $request */ public function runRegister(TBGRequest $request) { TBGContext::loadLibrary('common'); $i18n = TBGContext::getI18n(); try { $username = mb_strtolower(trim($request['fieldusername'])); $buddyname = $request['buddyname']; $email = mb_strtolower(trim($request['email_address'])); $confirmemail = mb_strtolower(trim($request['email_confirm'])); $security = $request['verification_no']; $realname = $request['realname']; $available = TBGUsersTable::getTable()->isUsernameAvailable($username); $fields = array(); if (!$available) { throw new Exception($i18n->__('This username is in use')); } if (!empty($buddyname) && !empty($email) && !empty($confirmemail) && !empty($security)) { if ($email != $confirmemail) { array_push($fields, 'email_address', 'email_confirm'); throw new Exception($i18n->__('The email address must be valid, and must be typed twice.')); } if ($security != $_SESSION['activation_number']) { array_push($fields, 'verification_no'); throw new Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.')); } $email_ok = false; $valid_domain = false; if (tbg_check_syntax($email, "EMAIL")) { $email_ok = true; } if ($email_ok && TBGSettings::get('limit_registration') != '') { $allowed_domains = preg_replace('/[[:space:]]*,[[:space:]]*/', '|', TBGSettings::get('limit_registration')); if (preg_match('/@(' . $allowed_domains . ')$/i', $email) == false) { array_push($fields, 'email_address', 'email_confirm'); throw new Exception($i18n->__('Email adresses from this domain can not be used.')); } /*if (count($allowed_domains) > 0) { foreach ($allowed_domains as $allowed_domain) { $allowed_domain = '@' . trim($allowed_domain); if (mb_strpos($email, $allowed_domain) !== false ) //mb_strpos checks if $to { $valid_domain = true; break; } } } else { $valid_domain = true; }*/ } /*if ($valid_domain == false) { array_push($fields, 'email_address', 'email_confirm'); throw new Exception($i18n->__('Email adresses from this domain can not be used.')); }*/ if ($email_ok == false) { array_push($fields, 'email_address', 'email_confirm'); throw new Exception($i18n->__('The email address must be valid, and must be typed twice.')); } if ($security != $_SESSION['activation_number']) { array_push($fields, 'verification_no'); throw new Exception($i18n->__('To prevent automatic sign-ups, enter the verification number shown below.')); } $password = TBGUser::createPassword(); $user = new TBGUser(); $user->setUsername($username); $user->setRealname($realname); $user->setBuddyname($buddyname); $user->setGroup(TBGSettings::getDefaultGroup()); $user->setEnabled(); $user->setPassword($password); $user->setEmail($email); $user->setJoined(); $user->save(); if ($user->isActivated()) { TBGContext::setMessage('auto_password', $password); return $this->renderJSON(array('loginmessage' => $i18n->__('After pressing %continue, you need to set your password.', array('%continue' => $i18n->__('Continue'))), 'one_time_password' => $password, 'activated' => true)); } return $this->renderJSON(array('loginmessage' => $i18n->__('The account has now been registered - check your email inbox for the activation email. Please be patient - this email can take up to two hours to arrive.'), 'activated' => false)); } else { array_push($fields, 'email_address', 'email_confirm', 'buddyname', 'verification_no'); throw new Exception($i18n->__('You need to fill out all fields correctly.')); } } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $i18n->__($e->getMessage()), 'fields' => $fields)); } }
</li> <?php } ?> <li><a href="javascript:void(0);" onclick="TBG.Main.Helpers.Backdrop.show('<?php echo make_url('get_partial_for_backdrop', array('key' => 'usercard', 'user_id' => $user->getID())); ?> ');$('bud_<?php echo $user->getUsername() . "_12"; ?> ').hide();"><?php echo __('Show user details'); ?> </a></li> <?php if (!in_array($user->getID(), array(1, (int) TBGSettings::get(TBGSettings::SETTING_DEFAULT_USER_ID)))) { ?> <?php if (TBGContext::getScope()->isDefault()) { ?> <li><?php echo javascript_link_tag(__('Delete this user'), array('onclick' => "TBG.Main.Helpers.Dialog.show('" . __('Permanently delete this user?') . "', '" . __('Are you sure you want to remove this user? This will remove the users login data, as well as memberships in (and data in) any scopes the user is a member of.') . "', {yes: {click: function() {TBG.Config.User.remove('" . make_url('configure_users_delete_user', array('user_id' => $user->getID())) . "', " . $user->getID() . "); TBG.Main.Helpers.Dialog.dismiss(); } }, no: {click: TBG.Main.Helpers.Dialog.dismiss}});")); ?> </li> <?php } elseif ($user->isScopeConfirmed()) { ?> <li><?php echo javascript_link_tag(__('Remove user from this scope'), array('onclick' => "TBG.Main.Helpers.Dialog.show('" . __('Remove this user?') . "', '" . __('Are you sure you want to remove this user from the current scope? The users login is kept, and you can re-add the user later.') . "', {yes: {click: function() {TBG.Config.User.remove('" . make_url('configure_users_delete_user', array('user_id' => $user->getID())) . "', " . $user->getID() . "); TBG.Main.Helpers.Dialog.dismiss(); } }, no: {click: TBG.Main.Helpers.Dialog.dismiss}});")); ?> </li>
?> </label></td> <td> <?php include_template('main/textarea', array('area_name' => 'changepw_message', 'area_id' => 'changepw_message', 'height' => '75px', 'width' => '100%', 'value' => TBGSettings::get('changepw_message'), 'hide_hint' => true)); ?> </td> </tr> <tr> <td style="vertical-align: top"><label for="changedetails_message"><?php echo __('Change account details message'); ?> </label></td> <td> <?php include_template('main/textarea', array('area_name' => 'changedetails_message', 'area_id' => 'changedetails_message', 'height' => '75px', 'width' => '100%', 'value' => TBGSettings::get('changedetails_message'), 'hide_hint' => true)); ?> </td> </tr> </table> <?php if ($access_level == TBGSettings::ACCESS_FULL) { ?> <div class="greybox" style="margin: 5px 0px 5px 0px; height: 23px; padding: 5px 10px 5px 10px;"> <div style="float: left; font-size: 13px; padding-top: 2px;"><?php echo __('Click "%save" to save your changes in all categories', array('%save' => __('Save'))); ?> </div> <input type="submit" id="config_auth_button" style="float: right; padding: 0 10px 0 10px; font-size: 14px; font-weight: bold;" value="<?php echo __('Save'); ?>
public function runAddUser(TBGRequest $request) { try { if (!TBGContext::getScope()->hasUsersAvailable()) { throw new Exception($this->getI18n()->__('This instance of The Bug Genie cannot add more users')); } if ($username = trim($request['username'])) { if (!TBGUser::isUsernameAvailable($username)) { if ($request->getParameter('mode') == 'import') { $user = TBGUser::getByUsername($username); $user->addScope(TBGContext::getScope()); return $this->renderJSON(array('imported' => true, 'message' => $this->getI18n()->__('The user was successfully added to this scope (pending user confirmation)'))); } elseif (TBGContext::getScope()->isDefault()) { throw new Exception($this->getI18n()->__('This username already exists')); } else { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('allow_import' => true)); } } $user = new TBGUser(); $user->setUsername($username); $user->setRealname($request->getParameter('realname', $username)); $user->setBuddyname($request->getParameter('buddyname', $username)); $user->setEmail($request->getParameter('email')); $user->setGroup(TBGGroupsTable::getTable()->selectById((int) $request->getParameter('group_id', TBGSettings::get(TBGSettings::SETTING_USER_GROUP)))); $user->setEnabled(); $user->setActivated(); if ($request->hasParameter('password') && !(empty($request['password']) && empty($request['password_repeat']))) { if (empty($request['password']) || $request['password'] != $request['password_repeat']) { throw new Exception($this->getI18n()->__('Please enter the same password twice')); } $password = $request['password']; $user->setPassword($password); } else { $password = TBGUser::createPassword(); $user->setPassword($password); } $user->setJoined(); $user->save(); foreach ((array) $request['teams'] as $team_id) { $user->addToTeam(TBGTeamsTable::getTable()->selectById((int) $team_id)); } TBGEvent::createNew('core', 'config.createuser.save', $user, array('password' => $password))->trigger(); } else { throw new Exception($this->getI18n()->__('Please enter a username')); } $this->getResponse()->setTemplate('configuration/findusers'); $this->too_short = false; $this->created_user = true; $this->users = array($user); $this->total_results = 1; $this->title = $this->getI18n()->__('User %username created', array('%username' => $username)); $this->total_count = TBGUser::getUsersCount(); $this->more_available = TBGContext::getScope()->hasUsersAvailable(); } catch (Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } }
protected function _geshify($matches) { if (!(is_array($matches) && count($matches) > 1)) { return ''; } $codeblock = $matches[2]; $params = $matches[1]; $language = preg_match('/(?<=lang=")(.+?)(?=")/', $params, $matches); if ($language !== 0) { $language = $matches[0]; } else { $language = TBGSettings::get('highlight_default_lang'); } $numbering_startfrom = preg_match('/(?<=line start=")(.+?)(?=")/', $params, $matches); if ($numbering_startfrom !== 0) { $numbering_startfrom = (int) $matches[0]; } else { $numbering_startfrom = 1; } $geshi = new GeSHi($codeblock, $language); $highlighting = preg_match('/(?<=line=")(.+?)(?=")/', $params, $matches); if ($highlighting !== 0) { $highlighting = $matches[0]; } else { $highlighting = false; } $interval = preg_match('/(?<=highlight=")(.+?)(?=")/', $params, $matches); if ($interval !== 0) { $interval = $matches[0]; } else { $interval = TBGSettings::get('highlight_default_interval'); } if ($highlighting === false) { switch (TBGSettings::get('highlight_default_numbering')) { case 1: // Line numbering with a highloght every n rows $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $interval); $geshi->start_line_numbers_at($numbering_startfrom); break; case 2: // Normal line numbering $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 10); $geshi->start_line_numbers_at($numbering_startfrom); break; case 3: break; // No numbering } } else { switch ($highlighting) { case 'highlighted': case 'GESHI_FANCY_LINE_NUMBERS': // Line numbering with a highloght every n rows $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $interval); $geshi->start_line_numbers_at($numbering_startfrom); break; case 'normal': case 'GESHI_NORMAL_LINE_NUMBERS': // Normal line numbering $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS, 10); $geshi->start_line_numbers_at($numbering_startfrom); break; case 3: break; // No numbering } } $codeblock = $geshi->parse_code(); unset($geshi); return '<code>' . $codeblock . '</code>'; }
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; }
</td> </tr> <tr> <td><label for="highlight_default_interval"><?php echo __('Default line highlight interval'); ?> </label></td> <td> <input type="text" name="<?php echo TBGSettings::SETTING_SYNTAX_HIGHLIGHT_DEFAULT_INTERVAL; ?> " style="width: 50px;"<?php if ($access_level != TBGSettings::ACCESS_FULL) { ?> disabled<?php } ?> id="highlight_default_interval" value="<?php echo TBGSettings::get('highlight_default_interval'); ?> " /> </td> </tr> <tr> <td class="config_explanation" colspan="2"><?php echo __('When using fancy numbering, you can have a line highlighted at a regular interval. Set the default interval to use here, if not otherwise specified'); ?> </td> </tr> </table>
public static function processCommit(TBGProject $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null) { $output = ''; TBGContext::setCurrentProject($project); if ($project->isArchived()) { return; } try { TBGContext::getI18n(); } catch (Exception $e) { TBGContext::reinitializeI18n(null); } // Is VCS Integration enabled? if (TBGSettings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::MODE_DISABLED) { $output .= '[VCS ' . $project->getKey() . '] This project does not use VCS Integration' . "\n"; return $output; } // Parse the commit message, and obtain the issues and transitions for issues. $parsed_commit = TBGIssue::getIssuesFromTextByRegex($commit_msg); $issues = $parsed_commit["issues"]; $transitions = $parsed_commit["transitions"]; // If no issues exist, we may not be able to continue // if (count($issues) == 0) // { // $output .= '[VCS '.$project->getKey().'] This project only accepts commits which affect issues' . "\n"; // return $output; // } // Build list of affected files $file_lines = preg_split('/[\\n\\r]+/', $changed); $files = array(); foreach ($file_lines as $aline) { $action = mb_substr($aline, 0, 1); if ($action == "A" || $action == "U" || $action == "D" || $action == "M") { $theline = trim(mb_substr($aline, 1)); $files[] = array($action, $theline); } } // Find author of commit, fallback is guest /* * Some VCSes use a different format of storing the committer's name. Systems like bzr, git and hg use the format * Joe Bloggs <*****@*****.**>, instead of a classic username. Therefore a user will be found via 4 queries: * a) First we extract the email if there is one, and find a user with that email * b) If one is not found - or if no email was specified, then instead test against the real name (using the name part if there was an email) * c) the username or full name is checked against the friendly name field * d) and if we still havent found one, then we check against the username * e) and if we STILL havent found one, we use the guest user */ if (preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) { $email = $matches[0]; // a) $user = TBGUsersTable::getTable()->getByEmail($email); if (!$user instanceof TBGUser) { // Not found by email preg_match("/(?<=^)(.*)(?= <)/", $author, $matches); $author = $matches[0]; } } // b) if (!$user instanceof TBGUser) { $user = TBGUsersTable::getTable()->getByRealname($author); } // c) if (!$user instanceof TBGUser) { $user = TBGUsersTable::getTable()->getByBuddyname($author); } // d) if (!$user instanceof TBGUser) { $user = TBGUsersTable::getTable()->getByUsername($author); } // e) if (!$user instanceof TBGUser) { $user = TBGSettings::getDefaultUser(); } TBGContext::setUser($user); TBGSettings::forceSettingsReload(); TBGContext::cacheAllPermissions(); $output .= '[VCS ' . $project->getKey() . '] Commit to be logged by user ' . $user->getName() . "\n"; if ($date == null) { $date = NOW; } // Create the commit data $commit = new TBGVCSIntegrationCommit(); $commit->setAuthor($user); $commit->setDate($date); $commit->setLog($commit_msg); $commit->setPreviousRevision($old_rev); $commit->setRevision($new_rev); $commit->setProject($project); if ($branch !== null) { $data = 'branch:' . $branch; $commit->setMiscData($data); } $commit->save(); $output .= '[VCS ' . $project->getKey() . '] Commit logged with revision ' . $commit->getRevision() . "\n"; // Iterate over affected issues and update them. foreach ($issues as $issue) { $inst = new TBGVCSIntegrationIssueLink(); $inst->setIssue($issue); $inst->setCommit($commit); $inst->save(); // Process all commit-message transitions for an issue. foreach ($transitions[$issue->getFormattedIssueNo()] as $transition) { if (TBGSettings::get('vcs_workflow_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::WORKFLOW_ENABLED) { TBGContext::setUser($user); TBGSettings::forceSettingsReload(); TBGContext::cacheAllPermissions(); if ($issue->isWorkflowTransitionsAvailable()) { // Go through the list of possible transitions for an issue. Only // process transitions that are applicable to issue's workflow. foreach ($issue->getAvailableWorkflowTransitions() as $possible_transition) { if (mb_strtolower($possible_transition->getName()) == mb_strtolower($transition[0])) { $output .= '[VCS ' . $project->getKey() . '] Running transition ' . $transition[0] . ' on issue ' . $issue->getFormattedIssueNo() . "\n"; // String representation of parameters. Used for log message. $parameters_string = ""; // Iterate over the list of this transition's parameters, and // set them. foreach ($transition[1] as $parameter => $value) { $parameters_string .= "{$parameter}={$value} "; switch ($parameter) { case 'resolution': if (($resolution = TBGResolution::getResolutionByKeyish($value)) instanceof TBGResolution) { TBGContext::getRequest()->setParameter('resolution_id', $resolution->getID()); } break; case 'status': if (($status = TBGStatus::getStatusByKeyish($value)) instanceof TBGStatus) { TBGContext::getRequest()->setParameter('status_id', $status->getID()); } break; } } // Run the transition. $possible_transition->transitionIssueToOutgoingStepWithoutRequest($issue); // Log an informative message about the transition. $output .= '[VCS ' . $project->getKey() . '] Ran transition ' . $possible_transition->getName() . ' with parameters \'' . $parameters_string . '\' on issue ' . $issue->getFormattedIssueNo() . "\n"; } } } } } $issue->addSystemComment(TBGContext::getI18n()->__('This issue has been updated with the latest changes from the code repository.<source>%commit_msg</source>', array('%commit_msg' => $commit_msg)), $user->getID()); $output .= '[VCS ' . $project->getKey() . '] Updated issue ' . $issue->getFormattedIssueNo() . "\n"; } // Create file links foreach ($files as $afile) { // index 0 is action, index 1 is file $inst = new TBGVCSIntegrationFile(); $inst->setAction($afile[0]); $inst->setFile($afile[1]); $inst->setCommit($commit); $inst->save(); $output .= '[VCS ' . $project->getKey() . '] Added with action ' . $afile[0] . ' file ' . $afile[1] . "\n"; } TBGEvent::createNew('vcs_integration', 'new_commit')->trigger(array('commit' => $commit)); return $output; }
protected function _initializeColumns() { if (!is_array($this->_columns)) { if (!strlen($this->_columns)) { if ($columns = TBGSettings::get('search_scs_' . $this->getTemplateName())) { $this->_columns = explode(',', $columns); } else { $this->_columns = self::getDefaultVisibleColumns(); } } else { $this->_columns = explode(',', $this->_columns); } } }
/** * @param \TBGUser $user * @return array */ public function getPlanningColumns(TBGUser $user) { $columns = TBGSettings::get('planning_columns_' . $this->getID(), 'project', TBGContext::getScope()->getID(), $user->getID()); $columns = explode(',', $columns); if (empty($columns) || isset($columns[0]) && empty($columns[0])) { // Default values $columns = array('priority', 'estimated_time', 'spent_time'); } // Set array keys to equal array values $columns = array_combine($columns, $columns); return $columns; }
/** * Get this users timezone * * @return mixed */ public function getTimezone() { if ($this->_timezone == null) { $this->_timezone = TBGSettings::get('timezone', 'core', null, $this->getID()); } return $this->_timezone; }
/** * Shortcut for the global settings function * * @param string $setting the name of the setting * @param integer $uid the uid for the user to check * * @return mixed */ public function getSetting($setting, $uid = 0) { return TBGSettings::get($setting, $this->getName(), TBGContext::getScope()->getID(), $uid); }
public function runAddCommitGitorious(TBGRequest $request) { TBGContext::getResponse()->setContentType('text/plain'); TBGContext::getResponse()->renderHeaders(); $passkey = TBGContext::getRequest()->getParameter('passkey'); $project_id = urldecode(TBGContext::getRequest()->getParameter('project_id')); $project = TBGContext::factory()->TBGProject($project_id); // Validate access if (!$project) { echo 'Error: The project with the ID ' . $project_id . ' does not exist'; exit; } if (TBGSettings::get('access_method_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::ACCESS_DIRECT) { echo 'Error: This project uses the CLI access method, and so access via HTTP has been disabled'; exit; } if (TBGSettings::get('access_passkey_' . $project->getID(), 'vcs_integration') != $passkey) { echo 'Error: The passkey specified does not match the passkey specified for this project'; exit; } // Validate data $data = html_entity_decode(TBGContext::getRequest()->getParameter('payload', null, false)); if (empty($data) || $data == null) { die('Error: No payload was provided'); } $entries = json_decode($data); if ($entries == null) { die('Error: The payload could not be decoded'); } $entries = json_decode($data); $previous = $entries->before; // Branch is stored in the ref $ref = $entries->ref; $parts = explode('/', $ref); if (count($parts) == 3) { $branch = $parts[2]; } else { $branch = null; } // Parse each commit individually foreach (array_reverse($entries->commits) as $commit) { $email = $commit->author->email; $author = $commit->author->name; $new_rev = $commit->id; $old_rev = $previous; $commit_msg = $commit->message; $time = strtotime($commit->timestamp); // Add commit echo TBGVCSIntegration::processCommit($project, $commit_msg, $old_rev, $previous, $time, "", $author, $branch); $previous = $new_rev; exit; } }
?> "> <span id="login_indicator" style="display: none;"><?php echo image_tag('spinning_20.gif'); ?> </span> </div> </form> </div> </div> </div> <?php TBGEvent::createNew('core', 'login_form_pane')->trigger(array_merge(array('selected_tab' => $selected_tab), $options)); ?> <?php if (TBGSettings::get('allowreg') == true) { ?> <?php include_template('main/loginregister', array('selected_tab' => $selected_tab)); ?> <?php } ?> </div> <div id="backdrop_detail_indicator" style="text-align: center; padding: 50px; display: none;"> <?php echo image_tag('spinning_32.gif'); ?> </div> </div> <div class="backdrop_detail_footer">
</label></td> <td style="width: 580px; position: relative;"> <input type="text" name="blob_url" style="width: 100%" id="blob_url" value="<?php echo TBGSettings::get('blob_url_' . $project->getID(), 'vcs_integration'); ?> " style="width: 100;"> </td> </tr> <tr> <td style="width: 200px;"><label for="diff_url"><?php echo __('Diff page'); ?> </label></td> <td style="width: 580px; position: relative;"> <input type="text" name="diff_url" style="width: 100%" id="diff_url" value="<?php echo TBGSettings::get('diff_url_' . $project->getID(), 'vcs_integration'); ?> " style="width: 100;"> </td> </tr> </table> </div> <table style="clear: both; width: 780px;" class="padded_table" cellpadding=0 cellspacing=0> <tr> <td colspan="2" style="padding: 10px 0 10px 10px; text-align: right;"> <div style="float: left; font-size: 13px; padding-top: 2px; font-style: italic;" class="config_explanation"><?php echo __('When you are done, click "%save" to save your changes on all tabs', array('%save' => __('Save'))); ?> </div> <div id="vcs_button" style="float: right; font-size: 14px; font-weight: bold;"> <input type="submit" class="button button-green" value="<?php
public function isKeyboardNavigationEnabled() { $val = TBGSettings::get(TBGSettings::SETTING_USER_KEYBOARD_NAVIGATION, 'core', TBGContext::getScope(), $this->getID()); return $val !== null ? $val : true; }
/** * Reinitialize the i18n object, used only when changing the language in the middle of something * * @param string $language The language code to change to */ public static function reinitializeI18n($language = null) { if (!$language) { self::$_i18n = new TBGI18n(TBGSettings::get('language')); } else { TBGLogging::log('Changing language to ' . $language); self::$_i18n = new TBGI18n($language); self::$_i18n->initialize(); } }
</label></td> <td style="width: 580px;"> <input type="email" name="mailing_from_address" style="width: 300px;" id="mailing_from_address" value="<?php echo TBGSettings::get('project_from_address_' . $project->getID(), 'mailing'); ?> "> </td> </tr> <tr> <td style="width: 200px;"><label for="mailing_from_name"><?php echo __('Project from-name'); ?> </label></td> <td style="width: 580px;"> <input type="text" name="mailing_from_name" style="width: 300px;" id="mailing_from_name" value="<?php echo TBGSettings::get('project_from_name_' . $project->getID(), 'mailing'); ?> "> </td> </tr> <tr> <td class="config_explanation" colspan="2"><?php echo __('By specifying an email address here, users can hit the "Reply" button on email notifications, and replies will be sent to the specified address instead of the usual generic no-reply address.'); ?> </td> </tr> </table> <table style="clear: both; width: 780px;" class="padded_table" cellpadding=0 cellspacing=0> <tr> <td colspan="2" style="padding: 10px 0 10px 10px; text-align: right;"> <div style="float: left; font-size: 13px; padding-top: 2px; font-style: italic;" class="config_explanation"><?php
public function getCharset() { if (TBGContext::isInstallmode()) { return $this->_charset; } return TBGSettings::get('charset') != '' ? TBGSettings::get('charset') : $this->_charset; }
echo image_tag($module->getAccountSettingsLogo(), array('style' => 'float: left;'), false, $module_name) . $module->getAccountSettingsName(); ?> </a></li> <?php } ?> <?php } ?> </ul> </div> <div id="account_tabs_panes"> <div id="tab_profile_pane"> <?php if (TBGSettings::getAuthenticationBackend() != 'tbg' && TBGSettings::getAuthenticationBackend() != null) { echo tbg_parse_text(TBGSettings::get('changedetails_message'), null, null, array('embedded' => true)); } else { ?> <form accept-charset="<?php echo TBGContext::getI18n()->getCharset(); ?> " action="<?php echo make_url('account_save_information'); ?> " onsubmit="updateProfileInformation('<?php echo make_url('account_save_information'); ?> '); return false;" method="post" id="profile_information_form"> <div class="rounded_box borderless lightgrey cut_bottom" style="margin: 5px 0 0 0; width: 690px; border-bottom: 0;"> <p class="content"><?php echo __('Edit your profile details here, including additional information.');
protected function _addProjectEmailAddress(Swift_Mime_Message $message, TBGProject $project = null) { if ($project instanceof TBGProject) { $address = TBGSettings::get(self::SETTING_PROJECT_FROM_ADDRESS . $project->getID(), 'mailing'); $name = TBGSettings::get(self::SETTING_PROJECT_FROM_NAME . $project->getID(), 'mailing'); if ($address != '') { $message->setFrom($address, $name); } } }