From b8b08a9b4cc631d53c91207baa4754e8ea313e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 11 Nov 2024 14:26:30 +0100 Subject: [PATCH 1/2] Automatically create beatmap set description topic on edit if missing This is a solution to the problem of the new beatmap submission server not creating a description topic for the set like the old one did. Notably, this solution implies several shortcuts: - If the main metadata of the set (artist, title) don't change, the forum thread will not be renamed - The forum thread will be posted in a hardcoded forum and never moved, while old BSS would move the thread between forums 6 and 10 depending on whether the beatmap is pending or WIP. Not doing this saves a whole bunch of busy work. - There is no actual body in the forum thread OP, contrary to what old submission did. The aforementioned simplifications were made with the assumption that subforums 6 and 10 on production were going to be hidden away from users due to not containing any actual content that anyone would ever want to see. (Same thing applies to forum 19, which is graveyard.) The *one and only goal* here is that descriptions should be editable for maps submitted using new BSS. Thus I am taking pretty much the same shortcuts that places like the profile page already seem to be. --- .env.example | 1 + app/Models/Beatmapset.php | 55 +++++++++++++++++++++++---------------- config/osu.php | 1 + 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/.env.example b/.env.example index 9c2392c9089..2fa91a6be12 100644 --- a/.env.example +++ b/.env.example @@ -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=10 PUSHER_APP_ID= PUSHER_KEY= diff --git a/app/Models/Beatmapset.php b/app/Models/Beatmapset.php index 185dc6c1c95..09adff9dd50 100644 --- a/app/Models/Beatmapset.php +++ b/app/Models/Beatmapset.php @@ -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 Cache; @@ -1389,27 +1390,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) @@ -1426,12 +1440,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 = [ diff --git a/config/osu.php b/config/osu.php index 9d067a60fe7..28859f87aa7 100644 --- a/config/osu.php +++ b/config/osu.php @@ -126,6 +126,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')) ?? 10, 'necropost_months' => 6, 'old_months' => 1, 'poll_edit_hours' => get_int(env('FORUM_POLL_EDIT_HOURS')) ?? 1, From 6f8dadeacc4c2b4f2f5e64095cb4310e82d10283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 31 Dec 2024 09:01:46 +0100 Subject: [PATCH 2/2] Change default forum for description topics to pending forum (id:6) --- .env.example | 2 +- config/osu.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 8d10ba74ab5..81e8bb81bfa 100644 --- a/.env.example +++ b/.env.example @@ -101,7 +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=10 +# BEATMAP_DESCRIPTION_FORUM_ID=6 PUSHER_APP_ID= PUSHER_KEY= diff --git a/config/osu.php b/config/osu.php index 41b0414cc16..c0b52b2dee5 100644 --- a/config/osu.php +++ b/config/osu.php @@ -127,7 +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')) ?? 10, + '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,