Skip to content
Snippets Groups Projects
Commit ed3c8881 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

Fix forum entries

parent 395d7254
No related branches found
No related tags found
1 merge request!6Fix forum entries
......@@ -4,8 +4,16 @@ final class IssuesController extends TracToGitlab\EventController
const SECRET_ISSUE_OPEN = 'N]<d5V/6tn/sYNMy';
const LABEL_MAPPING = [
'TIC' => ['1927f2b86d6b185aa6c6697810ad42f1', 'a65dd807699b7b3b3d182b674042b70e', 'TIC #%1$u: %2$s'],
'StEP' => ['1927f2b86d6b185aa6c6697810ad42f1', '93c84607e687030b249a69cd30ca7bd9', 'StEP00%1$u: %2$s'],
'TIC' => [
'course_id' => '1927f2b86d6b185aa6c6697810ad42f1',
'subject' => 'TIC #%1$u: %2$s',
'body' => "%1\$s\n\n----\nZum [gitlab-Issue #%2\$u](%3\$s)",
],
'StEP' => [
'course_id' => '1927f2b86d6b185aa6c6697810ad42f1',
'subject' => 'StEP00%1$u: %2$s',
'body' => "Zum [gitlab-Issue #%2\$u](%3\$s)",
],
];
public function create_action()
......@@ -33,14 +41,14 @@ final class IssuesController extends TracToGitlab\EventController
continue;
}
$title = sprintf(
$definition[2],
$definition['subject'],
$this->getFromPayload('object_attributes', 'iid'),
$this->getFromPayload('object_attributes', 'title')
);
$body = Studip\Markup::markAsHtml(
$this->parsedown->text(
sprintf(
"%s\n\n----\nZum [gitlab-Issue #%u](%s)",
$definition['body'],
$this->getFromPayload('object_attributes', 'description'),
$this->getFromPayload('object_attributes', 'iid'),
$this->getFromPayload('object_attributes', 'url')
......@@ -49,19 +57,22 @@ final class IssuesController extends TracToGitlab\EventController
);
$url = $this->createForumEntry(
$label,
$user,
$title,
$body,
$definition[0],
$definition[1]
$definition['course_id']
);
if ($url) {
$this->gitlab->issues()->addNote(
$this->getFromPayload('project', 'id'),
$this->getFromPayload('object_attributes', 'iid'),
"[Zum Forenbeitrag auf dem Entwicklungsserver]({$url})"
);
}
}
}
}
$this->render_nothing();
......@@ -79,29 +90,51 @@ final class IssuesController extends TracToGitlab\EventController
}
/**
* @return string Absolute URL to forum posting
* @return ?string Absolute URL to forum posting
*/
private function createForumEntry(\User $user, string $subject, string $body, string $course_id, string $parent_id)
private function createForumEntry(string $type, \User $user, string $subject, string $body, string $course_id)
{
require_once "{$GLOBALS['STUDIP_BASE_PATH']}/public/plugins_packages/core/Forum/models/ForumEntry.php";
if (!PluginEngine::getPlugin('CoreForum')) {
return null;
}
$query = "SELECT category_id
FROM forum_categories
WHERE seminar_id = ?
AND entry_name LIKE CONCAT('Aktive ', ?, '%')";
$category_id = DBManager::get()->fetchColumn($query, [$course_id, $type]);
$topic_id = md5(uniqid('CoreForum'));
ForumEntry::insert([
'topic_id' => $topic_id,
'seminar_id' => $course_id,
'user_id' => $user->id,
'name' => $subject,
'content' => $subject,
'author' => $user->getFullName(),
'author_host' => $_SERVER['REMOTE_ADDR']
], $course_id);
$id = md5(uniqid('forum-entry', true));
if ($category_id) {
ForumCat::addArea($category_id, $topic_id);
}
\ForumEntry::insert([
'topic_id' => $id,
$topic_id2 = md5(uniqid('CoreForum'));
ForumEntry::insert([
'topic_id' => $topic_id2,
'seminar_id' => $course_id,
'user_id' => $user->id,
'name' => $subject,
'content' => $body,
'author' => $user->getFullName(),
'author_host' => '',
], $parent_id);
'author_host' => $_SERVER['REMOTE_ADDR']
], $topic_id);
$old_base = \URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']);
$url = \PluginEngine::getURL(
'CoreForum',
['cid' => $course_id],
"index/index/{$id}#{$id}"
"index/index/{$topic_id2}#{$topic_id2}"
);
\URLHelper::setBaseURL($old_base);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment