diff --git a/.env.example b/.env.example index 4875ae3057e..81e8bb81bfa 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=6 PUSHER_APP_ID= PUSHER_KEY= diff --git a/app/Models/Beatmapset.php b/app/Models/Beatmapset.php index 354155d33e7..853e1a36ddf 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 App\Transformers\BeatmapsetTransformer; @@ -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) @@ -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 = [ diff --git a/config/osu.php b/config/osu.php index de037d65fbd..c0b52b2dee5 100644 --- a/config/osu.php +++ b/config/osu.php @@ -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,