Skip to content

Commit

Permalink
Merge pull request #11706 from bdach/bss2-editable-description
Browse files Browse the repository at this point in the history
Automatically create beatmap set description topic on edit if missing
  • Loading branch information
nanaya authored Jan 29, 2025
2 parents 4a1d92a + 223d72c commit f80b526
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
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

0 comments on commit f80b526

Please sign in to comment.