the browser-facing portion of osu!

Merge pull request #11706 from bdach/bss2-editable-description

Automatically create beatmap set description topic on edit if missing

authored by Edho Arief and committed by GitHub f80b526a 4a1d92a5

Changed files
+34 -23
app
config
+1
.env.example
··· 101 101 # INITIAL_HELP_FORUM_IDS="5 47 85" 102 102 # ISSUE_FORUM_IDS= 103 103 # FORUM_POST_MINIMUM_PLAYS=200 104 + # BEATMAP_DESCRIPTION_FORUM_ID=6 104 105 105 106 PUSHER_APP_ID= 106 107 PUSHER_KEY=
+32 -23
app/Models/Beatmapset.php
··· 29 29 use App\Libraries\ImageProcessorService; 30 30 use App\Libraries\StorageUrl; 31 31 use App\Libraries\Transactions\AfterCommit; 32 + use App\Models\Forum\Post; 32 33 use App\Traits\Memoizes; 33 34 use App\Traits\Validatable; 34 35 use App\Transformers\BeatmapsetTransformer; ··· 1406 1407 1407 1408 public function updateDescription($bbcode, $user) 1408 1409 { 1409 - $post = $this->descriptionPost; 1410 - if ($post === null) { 1411 - return; 1412 - } 1410 + return DB::transaction(function () use ($bbcode, $user) { 1411 + $post = $this->descriptionPost; 1413 1412 1414 - $split = preg_split('/-{15}/', $post->post_text, 2); 1413 + if ($post === null) { 1414 + $forum = Forum\Forum::findOrFail($GLOBALS['cfg']['osu']['forum']['beatmap_description_forum_id']); 1415 + $title = $this->artist.' - '.$this->title; 1415 1416 1416 - $options = [ 1417 - 'withGallery' => true, 1418 - 'ignoreLineHeight' => true, 1419 - ]; 1417 + $topic = Forum\Topic::createNew($forum, [ 1418 + 'title' => $title, 1419 + 'user' => $user, 1420 + 'body' => '---------------', 1421 + ]); 1422 + $topic->lock(); 1423 + $this->update(['thread_id' => $topic->getKey()]); 1424 + $post = $topic->firstPost; 1425 + } 1420 1426 1421 - $header = new BBCodeFromDB($split[0], $post->bbcode_uid, $options); 1422 - $newBody = $header->toEditor()."---------------\n".ltrim($bbcode); 1427 + $split = preg_split('/-{15}/', $post->post_text, 2); 1423 1428 1424 - return $post 1425 - ->skipBeatmapPostRestrictions() 1426 - ->update([ 1427 - 'post_text' => $newBody, 1428 - 'post_edit_user' => $user === null ? null : $user->getKey(), 1429 - ]); 1429 + $options = [ 1430 + 'withGallery' => true, 1431 + 'ignoreLineHeight' => true, 1432 + ]; 1433 + 1434 + $header = new BBCodeFromDB($split[0], $post->bbcode_uid, $options); 1435 + $newBody = $header->toEditor()."---------------\n".ltrim($bbcode); 1436 + 1437 + return $post 1438 + ->skipBeatmapPostRestrictions() 1439 + ->update([ 1440 + 'post_text' => $newBody, 1441 + 'post_edit_user' => $user === null ? null : $user->getKey(), 1442 + ]); 1443 + }); 1430 1444 } 1431 1445 1432 1446 private function extractDescription($post) ··· 1443 1457 1444 1458 private function getBBCode() 1445 1459 { 1446 - $post = $this->descriptionPost; 1447 - 1448 - if ($post === null) { 1449 - return; 1450 - } 1451 - 1460 + $post = $this->descriptionPost ?? new Post(); 1452 1461 $description = $this->extractDescription($post); 1453 1462 1454 1463 $options = [
+1
config/osu.php
··· 127 127 'issue_forum_ids' => array_map('intval', explode(' ', env('ISSUE_FORUM_IDS', '4 5 29 30 101'))), 128 128 'max_post_length' => get_int(env('FORUM_POST_MAX_LENGTH')) ?? 60000, 129 129 'minimum_plays' => get_int(env('FORUM_POST_MINIMUM_PLAYS')) ?? 200, 130 + 'beatmap_description_forum_id' => get_int(env('BEATMAP_DESCRIPTION_FORUM_ID')) ?? 6, 130 131 'necropost_months' => 6, 131 132 'old_months' => 1, 132 133 'poll_edit_hours' => get_int(env('FORUM_POLL_EDIT_HOURS')) ?? 1,