Skip to content

Commit

Permalink
feat: replace legacy Activity table (#1937)
Browse files Browse the repository at this point in the history
* feat: replace legacy Activity table

* remove dead code

* cleanup

* cleanup

* cleanup

* change member since date on history page

* update award achievement test

* update tests

* web api user summary

* update UserRecentlyPlayedGamesTest

* cleanup
  • Loading branch information
luchaos committed Nov 1, 2023
1 parent 42bf6a4 commit 07e8456
Show file tree
Hide file tree
Showing 29 changed files with 62 additions and 559 deletions.
5 changes: 2 additions & 3 deletions app/Community/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
use App\Community\Models\Ticket;
use App\Community\Models\TriggerTicket;
use App\Community\Models\TriggerTicketComment;
use App\Community\Models\UserActivityLegacy;
use App\Community\Models\UserActivity;
use App\Community\Models\UserComment;
use App\Community\Models\UserGameListEntry;
use App\Community\Models\UserRelation;
Expand Down Expand Up @@ -86,8 +86,7 @@ public function boot(): void
'trigger.ticket' => TriggerTicket::class,
'trigger.ticket.comment' => TriggerTicketComment::class,
'user.comment' => UserComment::class,
'user-activity' => UserActivityLegacy::class,
// TODO 'user-activity' => UserActivity::class,
'user-activity' => UserActivity::class,
'user-game-list-entry' => UserGameListEntry::class,
'user-relation' => UserRelation::class,
'vote' => Vote::class,
Expand Down
3 changes: 0 additions & 3 deletions app/Community/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use App\Community\Models\NewsComment;
use App\Community\Models\TriggerTicket;
use App\Community\Models\UserActivity;
use App\Community\Models\UserActivityLegacy;
use App\Community\Models\UserComment;
use App\Community\Policies\AchievementCommentPolicy;
use App\Community\Policies\AchievementSetClaimPolicy;
Expand All @@ -31,7 +30,6 @@
use App\Community\Policies\NewsCommentPolicy;
use App\Community\Policies\NewsPolicy;
use App\Community\Policies\TriggerTicketPolicy;
use App\Community\Policies\UserActivityLegacyPolicy;
use App\Community\Policies\UserActivityPolicy;
use App\Community\Policies\UserCommentPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
Expand All @@ -52,7 +50,6 @@ class AuthServiceProvider extends ServiceProvider
NewsComment::class => NewsCommentPolicy::class,
TriggerTicket::class => TriggerTicketPolicy::class,
UserActivity::class => UserActivityPolicy::class,
UserActivityLegacy::class => UserActivityLegacyPolicy::class,
UserComment::class => UserCommentPolicy::class,
];

Expand Down
9 changes: 0 additions & 9 deletions app/Community/Concerns/ActsAsCommunityMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Community\Models\Message;
use App\Community\Models\UserActivity;
use App\Community\Models\UserActivityLegacy;
use App\Community\Models\UserComment;
use App\Community\Models\UserGameListEntry;
use App\Site\Models\User;
Expand All @@ -22,14 +21,6 @@ public static function bootActsAsCommunityMember(): void
{
}

/**
* @return HasMany<UserActivityLegacy>
*/
public function legacyActivities(): HasMany
{
return $this->hasMany(UserActivityLegacy::class, 'User', 'User');
}

/**
* @return HasMany<UserActivity>
*/
Expand Down
46 changes: 3 additions & 43 deletions app/Community/Enums/ActivityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,10 @@

namespace App\Community\Enums;

/**
* @deprecated kept for connect api postactivity request only
*/
abstract class ActivityType
{
// TODO remove - activity types can be derived from respective tables; user activity log will work differently
public const UnlockedAchievement = 1;

public const Login = 2;

public const StartedPlaying = 3;

public const UploadAchievement = 4;

public const EditAchievement = 5;

public const CompleteGame = 6;

public const NewLeaderboardEntry = 7;

public const ImprovedLeaderboardEntry = 8;

public const OpenedTicket = 9;

public const ClosedTicket = 10;

public const BeatGame = 11;

public static function cases(): array
{
return [
self::UnlockedAchievement,
self::Login,
self::StartedPlaying,
self::UploadAchievement,
self::EditAchievement,
self::CompleteGame,
self::NewLeaderboardEntry,
self::ImprovedLeaderboardEntry,
self::OpenedTicket,
self::ClosedTicket,
self::BeatGame,
];
}

public static function isValid(int $value): bool
{
return in_array($value, self::cases());
}
}
3 changes: 1 addition & 2 deletions app/Community/Enums/ArticleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class ArticleType

public const News = 4; // TODO commentable_type = news

public const Activity = 5;
// public const Activity = 5; // deprecated

public const Leaderboard = 6; // TODO commentable_type = leaderboard

Expand All @@ -37,7 +37,6 @@ public static function cases(): array
self::Achievement,
self::User,
self::News,
self::Activity,
self::Leaderboard,
self::AchievementTicket,
self::Forum,
Expand Down
20 changes: 0 additions & 20 deletions app/Community/Listeners/WriteUserActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace App\Community\Listeners;

use App\Community\Enums\ActivityType;
use App\Community\Enums\UserActivityType;
use App\Community\Models\UserActivity;
use App\Community\Models\UserActivityLegacy;
use App\Platform\Events\AchievementSetBeaten;
use App\Platform\Events\AchievementSetCompleted;
use App\Platform\Events\LeaderboardEntryCreated;
Expand All @@ -32,11 +30,6 @@ public function handle(object $event): void
$subjectId = null;
$context = null;

$storeLegacyActivity = true;
$legacyActivityType = null;
$data = null;
$data2 = null;

/** @var User $user */
$user = $event->user;

Expand All @@ -46,11 +39,6 @@ public function handle(object $event): void
* login will only be called when user was logged out in-between
* ignore login activity within 6 hours after the last login activity
*/
$legacyActivityType = ActivityType::Login;
$storeLegacyActivity = $user->legacyActivities()
->where('activitytype', '=', $legacyActivityType)
->where('timestamp', '>', Carbon::now()->subHours(6))
->doesntExist();
$userActivityType = UserActivityType::Login;
$storeActivity = $user->activities()
->where('type', '=', $userActivityType)
Expand Down Expand Up @@ -97,14 +85,6 @@ public function handle(object $event): void
default:
}

if ($legacyActivityType && $storeLegacyActivity) {
$user->legacyActivities()->save(new UserActivityLegacy([
'activitytype' => $legacyActivityType,
'data' => $data,
'data2' => $data2,
]));
}

if ($userActivityType && $storeActivity) {
$user->activities()->save(new UserActivity([
'type' => $userActivityType,
Expand Down
26 changes: 13 additions & 13 deletions app/Community/Models/UserActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Community\Models;

use App\Community\Enums\ActivityType;
use App\Community\Enums\UserActivityType;
use App\Platform\Models\Achievement;
use App\Platform\Models\Game;
use App\Site\Models\User;
Expand Down Expand Up @@ -38,11 +38,11 @@ protected static function newFactory(): UserActivityFactory
public function isAchievementActivity(): bool
{
return in_array($this->type, [
ActivityType::UnlockedAchievement,
ActivityType::UploadAchievement,
ActivityType::EditAchievement,
ActivityType::OpenedTicket,
ActivityType::ClosedTicket,
UserActivityType::UnlockedAchievement,
UserActivityType::UploadAchievement,
UserActivityType::EditAchievement,
UserActivityType::OpenedTicket,
UserActivityType::ClosedTicket,
]);
}

Expand All @@ -52,27 +52,27 @@ public function isAchievementActivity(): bool
public function isGameActivity(): bool
{
return in_array($this->type, [
ActivityType::StartedPlaying,
ActivityType::CompleteGame,
ActivityType::NewLeaderboardEntry,
ActivityType::ImprovedLeaderboardEntry,
UserActivityType::StartedPlaying,
UserActivityType::CompleteAchievementSet,
UserActivityType::NewLeaderboardEntry,
UserActivityType::ImprovedLeaderboardEntry,
]);
}

public function getIconAttribute(): ?string
{
$icon = null;
switch ($this->activitytype) {
case ActivityType::UnlockedAchievement:
case UserActivityType::UnlockedAchievement:
/*
* TODO
* $this->achievement->badge
*/
break;
case ActivityType::Login:
case UserActivityType::Login:
$icon = 'assets/images/activity/login.webp';
break;
case ActivityType::StartedPlaying:
case UserActivityType::StartedPlaying:
$icon = 'assets/images/activity/playing.webp';
break;
}
Expand Down
27 changes: 0 additions & 27 deletions app/Community/Models/UserActivityLegacy.php

This file was deleted.

23 changes: 0 additions & 23 deletions app/Community/Policies/UserActivityLegacyPolicy.php

This file was deleted.

4 changes: 0 additions & 4 deletions app/Helpers/database/achievement.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use App\Community\Enums\ActivityType;
use App\Community\Enums\ArticleType;
use App\Platform\Enums\AchievementFlag;
use App\Platform\Enums\AchievementPoints;
Expand Down Expand Up @@ -236,7 +235,6 @@ function UploadNewAchievement(

$achievement->save();
$idInOut = $achievement->ID;
postActivity($author, ActivityType::UploadAchievement, $idInOut);

static_addnewachievement($idInOut);
addArticleComment(
Expand Down Expand Up @@ -323,8 +321,6 @@ function UploadNewAchievement(
static_setlastupdatedgame($gameID);
static_setlastupdatedachievement($idInOut);

postActivity($author, ActivityType::EditAchievement, $idInOut);

if ($changingAchSet) {
if ($flag === AchievementFlag::OfficialCore) {
addArticleComment(
Expand Down
3 changes: 0 additions & 3 deletions app/Helpers/database/leaderboard.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use App\Community\Enums\ActivityType;
use App\Community\Enums\ArticleType;
use App\Site\Enums\Permissions;
use App\Site\Models\User;
Expand Down Expand Up @@ -64,11 +63,9 @@ function SubmitLeaderboardEntry(
} elseif ($numRowsAffected == 1) {
// (New) Entry added!
$retVal['BestScore'] = $newEntry;
postActivity($user, ActivityType::NewLeaderboardEntry, $lbID, $newEntry);
} else { // if ( $numRowsAffected == 2 )
// Improved Entry added!
$retVal['BestScore'] = $newEntry;
postActivity($user, ActivityType::ImprovedLeaderboardEntry, $lbID, $newEntry);
}

// If you fall through to here, populate $dataOut with some juicy info :)
Expand Down
3 changes: 0 additions & 3 deletions app/Helpers/database/player-achievement.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use App\Community\Enums\ActivityType;
use App\Platform\Enums\AchievementFlag;
use App\Platform\Models\Achievement;
use App\Platform\Models\Game;
Expand Down Expand Up @@ -78,8 +77,6 @@ function unlockAchievement(User $user, int $achievementId, bool $isHardcore): ar
$playerGame->save();
}
}

postActivity($user, ActivityType::UnlockedAchievement, $achievement->ID, (int) $isHardcore);
}

if ($playerGame) {
Expand Down
5 changes: 0 additions & 5 deletions app/Helpers/database/ticket.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use App\Community\Enums\ActivityType;
use App\Community\Enums\ArticleType;
use App\Community\Enums\SubscriptionSubjectType;
use App\Community\Enums\TicketFilters;
Expand Down Expand Up @@ -151,7 +150,6 @@ function _createTicket(User $user, int $achID, int $reportType, ?int $hardcore,
[user=$username] would like to report a bug with an achievement you've created:
$bugReportDetails";
CreateNewMessage($username, $achAuthor, "Bug Report ($gameTitle)", $bugReportMessage);
postActivity($username, ActivityType::OpenedTicket, $achID);

// notify subscribers other than the achievement's author
// TODO dry it. why is this not (1 << 1) like in submitNewTicketsJSON?
Expand Down Expand Up @@ -344,21 +342,18 @@ function updateTicket(string $user, int $ticketID, int $ticketVal, ?string $reas
addArticleComment("Server", ArticleType::Achievement, $achID, "$user demoted this achievement to Unofficial.", $user);
}
$comment = "Ticket closed by $user. Reason: \"$reason\".";
postActivity($user, ActivityType::ClosedTicket, $achID);
break;

case TicketState::Open:
if ($ticketData['ReportState'] == TicketState::Request) {
$comment = "Ticket reassigned to author by $user.";
} else {
$comment = "Ticket reopened by $user.";
postActivity($user, ActivityType::OpenedTicket, $achID);
}
break;

case TicketState::Resolved:
$comment = "Ticket resolved as fixed by $user.";
postActivity($user, ActivityType::ClosedTicket, $achID);
break;

case TicketState::Request:
Expand Down
Loading

0 comments on commit 07e8456

Please sign in to comment.