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

fix: move achievement migration tool to Filament, update achievement_sets #2728

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wescopeland
Copy link
Member

This PR moves the admin achievement migration tool to the "Admin Tools" page in Filament. Additionally, migrating an achievement now also updates achievement_sets.

Screenshot 2024-09-30 at 4 39 54 PM

@wescopeland wescopeland requested a review from a team September 30, 2024 20:59
return [$achievement->id => "ID: {$achievement->id} - Title: {$achievement->title} - Game: {$achievement->game->title}"];
})
->toArray();
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that this feature gets used all that often, but I imagine that when it is used, people just paste in a CSV of achievements to move. CSVs don't seem to work with the new component. You have to enter each ID individually, and select the matching result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest to use a CSV input field.

'Server',
ArticleType::GameModification,
$gameId,
"$user migrated " . Str::plural('achievement', count($achievementIds)) . ' ' .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be {$user->display_name}:

{"ID":...} migrated achievements 458393,458394,458392 from games 29978,4068.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But wouldn't it be better to put the GameID modifications in the audit logs for the individual achievements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied both in latest. GameID changes are now correctly recorded in the audit log.

dispatch(new UpdateGameMetricsJob($gameId))->onQueue('game-metrics');
foreach ($oldGameIds as $oldGameId) {
dispatch(new UpdateGameMetricsJob($oldGameId))->onQueue('game-metrics');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an AchievementMoved event that notifies the DispatchUpdateGameMetricsJob that seems like it should be used here. The trade-off is that it has to be raised for each achievement, and relies on the queue to de-dup the old/new game updates.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this event. I believe with my fix for the audit log, AchievementMoved is now being correctly automatically dispatched.

if (!PlayerGame::where('game_id', $gameId)->where('user_id', $userId)->exists()) {
$playerGame = new PlayerGame(['user_id' => $userId, 'game_id' => $gameId]);
$playerGame->save();
dispatch(new UpdatePlayerGameMetricsJob($userId, $gameId));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PlayerGameMetrics should be updated for the user whether or not they've previously played the game. The player metrics for the old game(s) should also be updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest:

// Update all affected player game metrics.
$affectedUserIds = PlayerAchievement::whereIn('achievement_id', $achievementIds)
    ->select(['user_id'])
    ->distinct()
    ->pluck('user_id');
foreach ($affectedUserIds as $userId) {
    // Ensure player_game entries exist for the new game for all affected users.
    if (!PlayerGame::where('game_id', $gameId)->where('user_id', $userId)->exists()) {
        $playerGame = new PlayerGame(['user_id' => $userId, 'game_id' => $gameId]);
        $playerGame->save();
    }

    dispatch(new UpdatePlayerGameMetricsJob($userId, $gameId));
    foreach ($oldGameIds as $oldGameId) {
        dispatch(new UpdatePlayerGameMetricsJob($userId, $oldGameId));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants