diff --git a/app/Http/Controllers/ScorePinsController.php b/app/Http/Controllers/ScorePinsController.php index 3270bfdd568..ed12cefdf96 100644 --- a/app/Http/Controllers/ScorePinsController.php +++ b/app/Http/Controllers/ScorePinsController.php @@ -91,9 +91,16 @@ public function store() $rulesetId = Beatmap::MODES[$score->getMode()]; $currentMinDisplayOrder = $user->scorePins()->where('ruleset_id', $rulesetId)->min('display_order') ?? 2500; + $soloScore = $score instanceof Solo\Score + ? $score + : Solo\Score::firstWhere(['ruleset_id' => $rulesetId, 'legacy_score_id' => $score->getKey()]); + try { - (new ScorePin(['display_order' => $currentMinDisplayOrder - 100, 'ruleset_id' => $rulesetId])) - ->user()->associate($user) + (new ScorePin([ + 'display_order' => $currentMinDisplayOrder - 100, + 'ruleset_id' => $rulesetId, + 'new_score_id' => $soloScore?->getKey(), + ]))->user()->associate($user) ->score()->associate($score) ->saveOrExplode(); } catch (Exception $ex) { diff --git a/database/migrations/2024_02_15_115214_add_new_score_id_to_score_pins.php b/database/migrations/2024_02_15_115214_add_new_score_id_to_score_pins.php new file mode 100644 index 00000000000..c394c50d63e --- /dev/null +++ b/database/migrations/2024_02_15_115214_add_new_score_id_to_score_pins.php @@ -0,0 +1,27 @@ +. Licensed under the GNU Affero General Public License v3.0. +// See the LICENCE file in the repository root for full licence text. + +declare(strict_types=1); + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class extends Migration +{ + public function up(): void + { + Schema::table('score_pins', function (Blueprint $table) { + $table->unsignedBigInteger('new_score_id')->after('score_id')->nullable(true); + }); + } + + public function down(): void + { + Schema::table('score_pins', function (Blueprint $table) { + $table->dropColumn('new_score_id'); + }); + } +};