From afc724b9651f2ed89ea796673c6af050473b023a Mon Sep 17 00:00:00 2001 From: clayton Date: Tue, 15 Aug 2023 12:05:38 -0700 Subject: [PATCH 1/3] Move WIP/pending beatmaps to graveyard when approving their beatmapset --- app/Models/Beatmapset.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Models/Beatmapset.php b/app/Models/Beatmapset.php index f3e8f3f859a..3bd7f67f44f 100644 --- a/app/Models/Beatmapset.php +++ b/app/Models/Beatmapset.php @@ -558,11 +558,23 @@ public function setApproved($state, $user, ?array $beatmapIds = null) $approvedState = static::STATES[$state]; $beatmaps = $this->beatmaps(); - if (isset($beatmapIds)) { - if ($beatmaps->whereKey($beatmapIds)->count() === count($beatmapIds)) { - $beatmaps = $beatmaps->whereIn('beatmap_id', $beatmapIds); - } else { - throw new InvariantException('beatmap_ids contains invalid id'); + if ($beatmapIds !== null) { + $beatmaps->whereKey($beatmapIds); + + if ($beatmaps->count() !== count($beatmapIds)) { + throw new InvariantException('Invalid beatmap IDs'); + } + + // If the beatmapset will be scoreable, set all of the unspecified + // beatmaps currently "WIP" or "pending" to "graveyard". It doesn't + // make sense for any beatmaps to be in those states when they + // cannot be updated. + if ($approvedState > 0) { + $this + ->beatmaps() + ->whereKeyNot($beatmapIds) + ->whereIn('approved', [static::STATES['wip'], static::STATES['pending']]) + ->update(['approved' => static::STATES['graveyard']]); } } From 5e9e39a03a77b4d6b6ee6ad84e50d61a6be18bb5 Mon Sep 17 00:00:00 2001 From: clayton Date: Wed, 13 Sep 2023 10:56:17 -0700 Subject: [PATCH 2/3] Add test for setting beatmap approved states --- tests/Models/BeatmapsetTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Models/BeatmapsetTest.php b/tests/Models/BeatmapsetTest.php index 65f8b274622..2d318be6256 100644 --- a/tests/Models/BeatmapsetTest.php +++ b/tests/Models/BeatmapsetTest.php @@ -40,6 +40,29 @@ public function testLove() $this->assertTrue($beatmapset->fresh()->isLoved()); } + public function testLoveBeatmapApprovedStates(): void + { + $user = User::factory()->create(); + $beatmapset = $this->createBeatmapset(); + + $specifiedBeatmap = $beatmapset->beatmaps()->first(); + $beatmapset->beatmaps()->saveMany([ + $graveyardBeatmap = Beatmap::factory()->make(['approved' => Beatmapset::STATES['graveyard']]), + $pendingBeatmap = Beatmap::factory()->make(['approved' => Beatmapset::STATES['pending']]), + $wipBeatmap = Beatmap::factory()->make(['approved' => Beatmapset::STATES['wip']]), + $rankedBeatmap = Beatmap::factory()->make(['approved' => Beatmapset::STATES['ranked']]), + ]); + + $beatmapset->love($user, [$specifiedBeatmap->getKey()]); + + $this->assertTrue($beatmapset->fresh()->isLoved()); + $this->assertSame('loved', $specifiedBeatmap->fresh()->status()); + $this->assertSame('graveyard', $graveyardBeatmap->fresh()->status()); + $this->assertSame('graveyard', $pendingBeatmap->fresh()->status()); + $this->assertSame('graveyard', $wipBeatmap->fresh()->status()); + $this->assertSame('ranked', $rankedBeatmap->fresh()->status()); + } + // region single-playmode beatmap sets public function testNominate() { From 2951ff074d9bd10b9ef7f076e07a0bc1bbb5e05b Mon Sep 17 00:00:00 2001 From: clayton Date: Wed, 13 Sep 2023 10:56:46 -0700 Subject: [PATCH 3/3] Check beatmap approved state in testLove --- tests/Models/BeatmapsetTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Models/BeatmapsetTest.php b/tests/Models/BeatmapsetTest.php index 2d318be6256..fc8e12ee806 100644 --- a/tests/Models/BeatmapsetTest.php +++ b/tests/Models/BeatmapsetTest.php @@ -38,6 +38,7 @@ public function testLove() $this->assertSame($notifications + 1, Notification::count()); $this->assertSame($userNotifications + 1, UserNotification::count()); $this->assertTrue($beatmapset->fresh()->isLoved()); + $this->assertSame('loved', $beatmapset->beatmaps()->first()->status()); } public function testLoveBeatmapApprovedStates(): void