Skip to content

Commit

Permalink
Merge pull request #11003 from nanaya/score-pin-id
Browse files Browse the repository at this point in the history
Record new score id when pinning
  • Loading branch information
notbakaneko authored Apr 2, 2024
2 parents 28bfe59 + 0e706c9 commit 8268b7d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/Http/Controllers/ScorePinsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. 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');
});
}
};

0 comments on commit 8268b7d

Please sign in to comment.