本文整理汇总了PHP中thebuggenie\core\entities\Issue::getIssuesFromTextByRegex方法的典型用法代码示例。如果您正苦于以下问题:PHP Issue::getIssuesFromTextByRegex方法的具体用法?PHP Issue::getIssuesFromTextByRegex怎么用?PHP Issue::getIssuesFromTextByRegex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thebuggenie\core\entities\Issue
的用法示例。
在下文中一共展示了Issue::getIssuesFromTextByRegex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processIncomingEmailAccount
public function processIncomingEmailAccount(IncomingEmailAccount $account)
{
$count = 0;
if ($emails = $account->getUnprocessedEmails()) {
try {
$current_user = framework\Context::getUser();
foreach ($emails as $email) {
$user = $this->getOrCreateUserFromEmailString($email->from);
if ($user instanceof User) {
if (framework\Context::getUser()->getID() != $user->getID()) {
framework\Context::switchUserContext($user);
}
$message = $account->getMessage($email);
$data = $message->getBodyPlain() ? $message->getBodyPlain() : strip_tags($message->getBodyHTML());
if ($data) {
if (mb_detect_encoding($data, 'UTF-8', true) === false) {
$data = utf8_encode($data);
}
$new_data = '';
foreach (explode("\n", $data) as $line) {
$line = trim($line);
if ($line) {
$line = preg_replace('/^(_{2,}|-{2,})$/', "<hr>", $line);
$new_data .= $line . "\n";
} else {
$new_data .= "\n";
}
}
$data = nl2br($new_data, false);
}
// Parse the subject, and obtain the issues.
$parsed_commit = Issue::getIssuesFromTextByRegex(mb_decode_mimeheader($email->subject));
$issues = $parsed_commit["issues"];
// If any issues were found, add new comment to each issue.
if ($issues) {
foreach ($issues as $issue) {
$text = preg_replace('#(^\\w.+:\\n)?(^>.*(\\n|$))+#mi', "", $data);
$text = trim($text);
if (!$this->processIncomingEmailCommand($text, $issue) && $user->canPostComments()) {
$comment = new Comment();
$comment->setContent($text);
$comment->setPostedBy($user);
$comment->setTargetID($issue->getID());
$comment->setTargetType(Comment::TYPE_ISSUE);
$comment->save();
}
}
} else {
if ($user->canReportIssues($account->getProject())) {
$issue = new Issue();
$issue->setProject($account->getProject());
$issue->setTitle(mb_decode_mimeheader($email->subject));
$issue->setDescription($data);
$issue->setPostedBy($user);
$issue->setIssuetype($account->getIssuetype());
$issue->save();
// Append the new issue to the list of affected issues. This
// is necessary in order to process the attachments properly.
$issues[] = $issue;
}
}
// If there was at least a single affected issue, and mail
// contains attachments, add those attachments to related issues.
if ($issues && $message->hasAttachments()) {
foreach ($message->getAttachments() as $attachment_no => $attachment) {
echo 'saving attachment ' . $attachment_no;
$name = $attachment['filename'];
$new_filename = framework\Context::getUser()->getID() . '_' . NOW . '_' . basename($name);
if (framework\Settings::getUploadStorage() == 'files') {
$files_dir = framework\Settings::getUploadsLocalpath();
$filename = $files_dir . $new_filename;
} else {
$filename = $name;
}
Logging::log('Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no);
echo 'Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no;
$content_type = $attachment['type'] . '/' . $attachment['subtype'];
$file = new File();
$file->setRealFilename($new_filename);
$file->setOriginalFilename(basename($name));
$file->setContentType($content_type);
$file->setDescription($name);
$file->setUploadedBy(framework\Context::getUser());
if (framework\Settings::getUploadStorage() == 'database') {
$file->setContent($attachment['data']);
} else {
Logging::log('Saving file ' . $new_filename . ' with content from attachment ' . $attachment_no);
file_put_contents($new_filename, $attachment['data']);
}
$file->save();
// Attach file to each related issue.
foreach ($issues as $issue) {
$issue->attachFile($file);
}
}
}
$count++;
}
}
} catch (\Exception $e) {
//.........这里部分代码省略.........
示例2: processCommit
public static function processCommit(\thebuggenie\core\entities\Project $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null, \Closure $callback = null)
{
$output = '';
framework\Context::setCurrentProject($project);
if ($project->isArchived()) {
return;
}
if (Commits::getTable()->isProjectCommitProcessed($new_rev, $project->getID())) {
return;
}
try {
framework\Context::getI18n();
} catch (\Exception $e) {
framework\Context::reinitializeI18n(null);
}
// Is VCS Integration enabled?
if (framework\Settings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == self::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 = \thebuggenie\core\entities\Issue::getIssuesFromTextByRegex($commit_msg);
$issues = $parsed_commit["issues"];
$transitions = $parsed_commit["transitions"];
// 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 <me@example.com>, 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
*/
// a)
$user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($author);
if (!$user instanceof \thebuggenie\core\entities\User && preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
$email = $matches[0];
// a2)
$user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($email);
if (!$user instanceof \thebuggenie\core\entities\User) {
// Not found by email
preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
$author = $matches[0];
}
}
// b)
if (!$user instanceof \thebuggenie\core\entities\User) {
$user = \thebuggenie\core\entities\tables\Users::getTable()->getByRealname($author);
}
// c)
if (!$user instanceof \thebuggenie\core\entities\User) {
$user = \thebuggenie\core\entities\tables\Users::getTable()->getByBuddyname($author);
}
// d)
if (!$user instanceof \thebuggenie\core\entities\User) {
$user = \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($author);
}
// e)
if (!$user instanceof \thebuggenie\core\entities\User) {
$user = framework\Settings::getDefaultUser();
}
framework\Context::setUser($user);
framework\Settings::forceSettingsReload();
framework\Context::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 Commit();
$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);
}
if ($callback !== null) {
$commit = $callback($commit);
}
$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 IssueLink();
$inst->setIssue($issue);
//.........这里部分代码省略.........