public function addNewCommit($project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author) { /* Find issues to update */ $fixes_grep = "#((bug|issue|ticket|fix|fixes|fixed|fixing|applies to|closes|references|ref|addresses|re|see|according to|also see)\\s\\#?(([A-Z0-9]+\\-)?\\d+))#ie"; $output = ''; $f_issues = array(); try { TBGContext::getI18n(); } catch (Exception $e) { TBGContext::reinitializei18n(); } try { $project = new TBGProject($project); } catch (Exception $e) { return TBGContext::getI18n()->__('Error: Invalid project ID'); } if (preg_match_all($fixes_grep, $commit_msg, $f_issues)) { // Github if (is_array($changed)) { $entries = $changed; $changed = ''; // Now handle changed files foreach ($entries[0] as $file) { $changed .= 'M' . $file . "\n"; } // Now handle new files foreach ($entries[1] as $file) { $changed .= 'A' . $file . "\n"; } // Now handle deleted files foreach ($entries[2] as $file) { $changed .= 'D' . $file . "\n"; } } $f_issues = array_unique($f_issues[3]); $file_lines = preg_split('/[\\n\\r]+/', $changed); $files = array(); foreach ($file_lines as $aline) { $action = substr($aline, 0, 1); if ($action == "A" || $action == "U" || $action == "D" || $action == "M") { $theline = trim(substr($aline, 1)); $files[] = array($action, $theline); } } foreach ($f_issues as $issue_no) { TBGContext::setCurrentProject($project); $theIssue = TBGIssue::getIssueFromLink($issue_no, true); if ($theIssue instanceof TBGIssue) { $uid = 0; /* * 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 just say the user is id 0 (unknown user). */ if (preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) { $email = $matches[0]; // a) $crit = new B2DBCriteria(); $crit->setFromTable(TBGUsersTable::getTable()); $crit->addSelectionColumn(TBGUsersTable::ID); $crit->addWhere(TBGUsersTable::EMAIL, $email); $row = TBGUsersTable::getTable()->doSelectOne($crit); if ($row != null) { $uid = $row->get(TBGUsersTable::ID); } else { // Not found by email preg_match("/(?<=^)(.*)(?= <)/", $author, $matches); $author = $matches[0]; } } // b) if ($uid == 0) { $crit = new B2DBCriteria(); $crit->setFromTable(TBGUsersTable::getTable()); $crit->addSelectionColumn(TBGUsersTable::ID); $crit->addWhere(TBGUsersTable::REALNAME, $author); $row = TBGUsersTable::getTable()->doSelectOne($crit); if ($row != null) { $uid = $row->get(TBGUsersTable::ID); } } // c) if ($uid == 0) { $crit = new B2DBCriteria(); $crit->setFromTable(TBGUsersTable::getTable()); $crit->addSelectionColumn(TBGUsersTable::ID); $crit->addWhere(TBGUsersTable::BUDDYNAME, $author); $row = TBGUsersTable::getTable()->doSelectOne($crit); if ($row != null) { $uid = $row->get(TBGUsersTable::ID); } } // d) if ($uid == 0) { $crit = new B2DBCriteria(); $crit->setFromTable(TBGUsersTable::getTable()); $crit->addSelectionColumn(TBGUsersTable::ID); $crit->addWhere(TBGUsersTable::UNAME, $author); $row = TBGUsersTable::getTable()->doSelectOne($crit); if ($row != null) { $uid = $row->get(TBGUsersTable::ID); } } $theIssue->addSystemComment(TBGContext::getI18n()->__('Issue updated from code repository'), TBGContext::getI18n()->__('This issue has been updated with the latest changes from the code repository.<source>%commit_msg%</source>', array('%commit_msg%' => $commit_msg)), $uid); foreach ($files as $afile) { if ($date == null) { $date = time(); } TBGVCSIntegrationTable::addEntry($theIssue->getID(), $afile[0], $commit_msg, $afile[1], $new_rev, $old_rev, $uid, $date); } $output .= 'Updated ' . $theIssue->getFormattedIssueNo() . "\n"; } else { $output .= 'Can\'t find ' . $issue_no . ' so not updating that one.' . "\n"; } } } return $output; }
/** * Return the time when the issue was reopened * * @return false if closed, otherwise a timestamp */ public function whenReopened() { if ($this->isClosed()) { return false; } $crit = new B2DBCriteria(); $crit->addSelectionColumn(TBGLogTable::TIME); $crit->addWhere(TBGLogTable::TARGET, $this->_id); $crit->addWhere(TBGLogTable::TARGET_TYPE, 1); $crit->addWhere(TBGLogTable::CHANGE_TYPE, 22); $crit->addOrderBy(TBGLogTable::TIME, 'desc'); $res = TBGLogTable::getTable()->doSelect($crit); $ret_arr = array(); if ($res->getNumberOfRows() == 0) { return false; } $row = $res->getNextRow(); return $row->get(TBGLogTable::TIME); }