Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: drop Author from the Achievements table #2450

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/Helpers/database/achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ function UploadNewAchievement(
$achievement->Points = $points;
$achievement->Flags = $flag;
$achievement->type = ($typeValue == 'NULL') ? null : $type;
$achievement->Author = $author->User; // TODO remove
$achievement->user_id = $author->id;
$achievement->BadgeName = $badge;

Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/database/game.php
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ function GetPatchData(int $gameID, ?User $user, int $flag): array
'Title' => $achievement->Title,
'Description' => $achievement->Description,
'Points' => $achievement->Points,
'Author' => $achievement->developer->User,
'Author' => $achievement->developer?->User,
'Modified' => $achievement->DateModified->unix(),
'Created' => $achievement->DateCreated->unix(),
'BadgeName' => $achievement->BadgeName,
Expand Down
13 changes: 2 additions & 11 deletions app/Models/Achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class Achievement extends BaseModel implements HasComments
// TODO drop MemAddr, migrate to triggerable morph
// TODO drop Progress, ProgressMax, ProgressFormat migrate to triggerable morph
// TODO drop Flags, derived from being included in an achievement set
// TODO drop Author, migrate to user_id
// TODO drop VotesPos, migrate to votable/ratable morph
// TODO drop VotesNeg, migrate to votable/ratable morph
// TODO drop BadgeName, derived from badge set
Expand Down Expand Up @@ -97,7 +96,6 @@ class Achievement extends BaseModel implements HasComments
];

protected $visible = [
'Author',
'BadgeName',
'DateCreated',
'DateModified',
Expand Down Expand Up @@ -210,11 +208,9 @@ public function getCreatedAtAttribute(): ?Carbon
return $this->attributes['DateCreated'] ? Carbon::parse($this->attributes['DateCreated']) : null;
}

public function getCanDelegateUnlocks(User|string $user): bool
public function getCanDelegateUnlocks(User $user): bool
{
$username = $user instanceof User ? $user->User : $user;

return $this->game->getIsStandalone() && $this->getAuthorAttribute() === $username;
return $this->game->getIsStandalone() && $this->user_id === $user->id;
}

public function getPermalinkAttribute(): string
Expand Down Expand Up @@ -294,11 +290,6 @@ public function getUpdatedAtAttribute(): ?Carbon
return $this->attributes['Updated'] ? Carbon::parse($this->attributes['Updated']) : null;
}

public function getAuthorAttribute(): string
{
return $this->attributes['Author'];
}

// TODO remove after rename
public function getPointsWeightedAttribute(): int
{
Expand Down
1 change: 0 additions & 1 deletion database/factories/AchievementFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function definition(): array
'Title' => ucwords(fake()->words(2, true)),
'Description' => fake()->sentence(),
'MemAddr' => '0x000000',
'Author' => $user?->username ?? $this->fakeUsername(),
'user_id' => $user?->id ?? 1,
'Flags' => AchievementFlag::Unofficial,
'type' => null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

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('Achievements', function (Blueprint $table) {
$table->dropColumn('Author');
});
}

public function down(): void
{
Schema::table('Achievements', function (Blueprint $table) {
$table->string('Author', 32)->after('type');
});
}
};
2 changes: 1 addition & 1 deletion public/API/API_GetGameExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
'Description' => $am->Description,
'Points' => $am->Points,
'TrueRatio' => $am->TrueRatio,
'Author' => $am->developer->display_name,
'Author' => $am->developer?->display_name,
'DateModified' => Carbon::parse($am->DateModified)->format('Y-m-d H:i:s'),
'DateCreated' => Carbon::parse($am->DateCreated)->format('Y-m-d H:i:s'),
'BadgeName' => $am->BadgeName,
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Api/V1/GameExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testGetGame(): void
'Points' => $achievement1->Points,
'BadgeName' => $achievement1->BadgeName,
'DisplayOrder' => $achievement1->DisplayOrder,
'Author' => $achievement1->Author,
'Author' => $achievement1->developer->User,
'DateCreated' => $achievement1->DateCreated->__toString(),
'DateModified' => $achievement1->DateModified->__toString(),
'NumAwarded' => 4,
Expand All @@ -126,7 +126,7 @@ public function testGetGame(): void
'Points' => $achievement3->Points,
'BadgeName' => $achievement3->BadgeName,
'DisplayOrder' => $achievement3->DisplayOrder,
'Author' => $achievement3->Author,
'Author' => $achievement3->developer->User,
'DateCreated' => $achievement3->DateCreated->__toString(),
'DateModified' => $achievement3->DateModified->__toString(),
'NumAwarded' => 3,
Expand All @@ -139,7 +139,7 @@ public function testGetGame(): void
'Points' => $achievement2->Points,
'BadgeName' => $achievement2->BadgeName,
'DisplayOrder' => $achievement2->DisplayOrder,
'Author' => $achievement2->Author,
'Author' => $achievement2->developer->User,
'DateCreated' => $achievement2->DateCreated->__toString(),
'DateModified' => $achievement2->DateModified->__toString(),
'NumAwarded' => 4,
Expand All @@ -159,7 +159,7 @@ public function testGetGame(): void
'Points' => $achievement4->Points,
'BadgeName' => $achievement4->BadgeName,
'DisplayOrder' => $achievement4->DisplayOrder,
'Author' => $achievement4->Author,
'Author' => $achievement4->developer->User,
'DateCreated' => $achievement4->DateCreated->__toString(),
'DateModified' => $achievement4->DateModified->__toString(),
'NumAwarded' => 0,
Expand Down
30 changes: 15 additions & 15 deletions tests/Feature/Api/V1/GameInfoAndUserProgressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testGetGameInfoAndUserProgress(): void
'Points' => $achievement1->Points,
'BadgeName' => $achievement1->BadgeName,
'DisplayOrder' => $achievement1->DisplayOrder,
'Author' => $achievement1->Author,
'Author' => $achievement1->developer->User,
'DateCreated' => $achievement1->DateCreated->__toString(),
'DateModified' => $achievement1->DateModified->__toString(),
'NumAwarded' => 4,
Expand All @@ -126,7 +126,7 @@ public function testGetGameInfoAndUserProgress(): void
'Points' => $achievement3->Points,
'BadgeName' => $achievement3->BadgeName,
'DisplayOrder' => $achievement3->DisplayOrder,
'Author' => $achievement3->Author,
'Author' => $achievement3->developer->User,
'DateCreated' => $achievement3->DateCreated->__toString(),
'DateModified' => $achievement3->DateModified->__toString(),
'NumAwarded' => 3,
Expand All @@ -139,7 +139,7 @@ public function testGetGameInfoAndUserProgress(): void
'Points' => $achievement2->Points,
'BadgeName' => $achievement2->BadgeName,
'DisplayOrder' => $achievement2->DisplayOrder,
'Author' => $achievement2->Author,
'Author' => $achievement2->developer->User,
'DateCreated' => $achievement2->DateCreated->__toString(),
'DateModified' => $achievement2->DateModified->__toString(),
'NumAwarded' => 4,
Expand Down Expand Up @@ -285,7 +285,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement1->Points,
'BadgeName' => $achievement1->BadgeName,
'DisplayOrder' => $achievement1->DisplayOrder,
'Author' => $achievement1->Author,
'Author' => $achievement1->developer->User,
'DateCreated' => $achievement1->DateCreated->__toString(),
'DateModified' => $achievement1->DateModified->__toString(),
'NumAwarded' => 3,
Expand All @@ -298,7 +298,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement3->Points,
'BadgeName' => $achievement3->BadgeName,
'DisplayOrder' => $achievement3->DisplayOrder,
'Author' => $achievement3->Author,
'Author' => $achievement3->developer->User,
'DateCreated' => $achievement3->DateCreated->__toString(),
'DateModified' => $achievement3->DateModified->__toString(),
'NumAwarded' => 2,
Expand All @@ -311,7 +311,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement2->Points,
'BadgeName' => $achievement2->BadgeName,
'DisplayOrder' => $achievement2->DisplayOrder,
'Author' => $achievement2->Author,
'Author' => $achievement2->developer->User,
'DateCreated' => $achievement2->DateCreated->__toString(),
'DateModified' => $achievement2->DateModified->__toString(),
'NumAwarded' => 3,
Expand Down Expand Up @@ -357,7 +357,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement1->Points,
'BadgeName' => $achievement1->BadgeName,
'DisplayOrder' => $achievement1->DisplayOrder,
'Author' => $achievement1->Author,
'Author' => $achievement1->developer->User,
'DateCreated' => $achievement1->DateCreated->__toString(),
'DateModified' => $achievement1->DateModified->__toString(),
'NumAwarded' => 3,
Expand All @@ -370,7 +370,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement3->Points,
'BadgeName' => $achievement3->BadgeName,
'DisplayOrder' => $achievement3->DisplayOrder,
'Author' => $achievement3->Author,
'Author' => $achievement3->developer->User,
'DateCreated' => $achievement3->DateCreated->__toString(),
'DateModified' => $achievement3->DateModified->__toString(),
'NumAwarded' => 2,
Expand All @@ -383,7 +383,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement2->Points,
'BadgeName' => $achievement2->BadgeName,
'DisplayOrder' => $achievement2->DisplayOrder,
'Author' => $achievement2->Author,
'Author' => $achievement2->developer->User,
'DateCreated' => $achievement2->DateCreated->__toString(),
'DateModified' => $achievement2->DateModified->__toString(),
'NumAwarded' => 3,
Expand Down Expand Up @@ -429,7 +429,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement1->Points,
'BadgeName' => $achievement1->BadgeName,
'DisplayOrder' => $achievement1->DisplayOrder,
'Author' => $achievement1->Author,
'Author' => $achievement1->developer->User,
'DateCreated' => $achievement1->DateCreated->__toString(),
'DateModified' => $achievement1->DateModified->__toString(),
'NumAwarded' => 3,
Expand All @@ -442,7 +442,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement3->Points,
'BadgeName' => $achievement3->BadgeName,
'DisplayOrder' => $achievement3->DisplayOrder,
'Author' => $achievement3->Author,
'Author' => $achievement3->developer->User,
'DateCreated' => $achievement3->DateCreated->__toString(),
'DateModified' => $achievement3->DateModified->__toString(),
'NumAwarded' => 2,
Expand All @@ -455,7 +455,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement2->Points,
'BadgeName' => $achievement2->BadgeName,
'DisplayOrder' => $achievement2->DisplayOrder,
'Author' => $achievement2->Author,
'Author' => $achievement2->developer->User,
'DateCreated' => $achievement2->DateCreated->__toString(),
'DateModified' => $achievement2->DateModified->__toString(),
'NumAwarded' => 3,
Expand Down Expand Up @@ -501,7 +501,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement1->Points,
'BadgeName' => $achievement1->BadgeName,
'DisplayOrder' => $achievement1->DisplayOrder,
'Author' => $achievement1->Author,
'Author' => $achievement1->developer->User,
'DateCreated' => $achievement1->DateCreated->__toString(),
'DateModified' => $achievement1->DateModified->__toString(),
'NumAwarded' => 3,
Expand All @@ -514,7 +514,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement3->Points,
'BadgeName' => $achievement3->BadgeName,
'DisplayOrder' => $achievement3->DisplayOrder,
'Author' => $achievement3->Author,
'Author' => $achievement3->developer->User,
'DateCreated' => $achievement3->DateCreated->__toString(),
'DateModified' => $achievement3->DateModified->__toString(),
'NumAwarded' => 2,
Expand All @@ -527,7 +527,7 @@ public function testGetGameInfoAndUserProgressWithHighestAwardMetadata(): void
'Points' => $achievement2->Points,
'BadgeName' => $achievement2->BadgeName,
'DisplayOrder' => $achievement2->DisplayOrder,
'Author' => $achievement2->Author,
'Author' => $achievement2->developer->User,
'DateCreated' => $achievement2->DateCreated->__toString(),
'DateModified' => $achievement2->DateModified->__toString(),
'NumAwarded' => 3,
Expand Down
Loading
Loading