Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically create beatmap set description topic on edit if missing #11706

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ SLACK_ENDPOINT=https://myconan.net/null/
# INITIAL_HELP_FORUM_IDS="5 47 85"
# ISSUE_FORUM_IDS=
# FORUM_POST_MINIMUM_PLAYS=200
# BEATMAP_DESCRIPTION_FORUM_ID=6

PUSHER_APP_ID=
PUSHER_KEY=
Expand Down
55 changes: 32 additions & 23 deletions app/Models/Beatmapset.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use App\Libraries\ImageProcessorService;
use App\Libraries\StorageUrl;
use App\Libraries\Transactions\AfterCommit;
use App\Models\Forum\Post;
use App\Traits\Memoizes;
use App\Traits\Validatable;
use App\Transformers\BeatmapsetTransformer;
Expand Down Expand Up @@ -1406,27 +1407,40 @@ public function editableDescription()

public function updateDescription($bbcode, $user)
{
$post = $this->descriptionPost;
if ($post === null) {
return;
}
return DB::transaction(function () use ($bbcode, $user) {
$post = $this->descriptionPost;

$split = preg_split('/-{15}/', $post->post_text, 2);
if ($post === null) {
$forum = Forum\Forum::findOrFail($GLOBALS['cfg']['osu']['forum']['beatmap_description_forum_id']);
$title = $this->artist.' - '.$this->title;

$options = [
'withGallery' => true,
'ignoreLineHeight' => true,
];
$topic = Forum\Topic::createNew($forum, [
'title' => $title,
'user' => $user,
'body' => '---------------',
]);
$topic->lock();
$this->update(['thread_id' => $topic->getKey()]);
$post = $topic->firstPost;
}

$header = new BBCodeFromDB($split[0], $post->bbcode_uid, $options);
$newBody = $header->toEditor()."---------------\n".ltrim($bbcode);
$split = preg_split('/-{15}/', $post->post_text, 2);

return $post
->skipBeatmapPostRestrictions()
->update([
'post_text' => $newBody,
'post_edit_user' => $user === null ? null : $user->getKey(),
]);
$options = [
'withGallery' => true,
'ignoreLineHeight' => true,
];

$header = new BBCodeFromDB($split[0], $post->bbcode_uid, $options);
$newBody = $header->toEditor()."---------------\n".ltrim($bbcode);

return $post
->skipBeatmapPostRestrictions()
->update([
'post_text' => $newBody,
'post_edit_user' => $user === null ? null : $user->getKey(),
]);
});
}

private function extractDescription($post)
Expand All @@ -1443,12 +1457,7 @@ private function extractDescription($post)

private function getBBCode()
{
$post = $this->descriptionPost;

if ($post === null) {
return;
}

$post = $this->descriptionPost ?? new Post();
$description = $this->extractDescription($post);

$options = [
Expand Down
1 change: 1 addition & 0 deletions config/osu.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
'issue_forum_ids' => array_map('intval', explode(' ', env('ISSUE_FORUM_IDS', '4 5 29 30 101'))),
'max_post_length' => get_int(env('FORUM_POST_MAX_LENGTH')) ?? 60000,
'minimum_plays' => get_int(env('FORUM_POST_MINIMUM_PLAYS')) ?? 200,
'beatmap_description_forum_id' => get_int(env('BEATMAP_DESCRIPTION_FORUM_ID')) ?? 6,
'necropost_months' => 6,
'old_months' => 1,
'poll_edit_hours' => get_int(env('FORUM_POLL_EDIT_HOURS')) ?? 1,
Expand Down
Loading