diff --git a/app/Jobs/Import/ImportHubDataJob.php b/app/Jobs/Import/ImportHubDataJob.php index 57006d0..3815ace 100644 --- a/app/Jobs/Import/ImportHubDataJob.php +++ b/app/Jobs/Import/ImportHubDataJob.php @@ -49,6 +49,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue // Begin to import the data into the permanent local database tables. $this->importUsers(); + $this->importUserFollows(); $this->importLicenses(); $this->importSptVersions(); $this->importMods(); @@ -608,6 +609,37 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue ]; } + protected function importUserFollows(): void + { + $followsGroupedByFollower = []; + + DB::connection('mysql_hub') + ->table('wcf1_user_follow') + ->select(['followID', 'userID', 'followUserID', 'time']) + ->chunkById(100, function (Collection $follows) use (&$followsGroupedByFollower) { + foreach ($follows as $follow) { + $followerId = User::whereHubId($follow->userID)->value('id'); + $followingId = User::whereHubId($follow->followUserID)->value('id'); + + if (! $followerId || ! $followingId) { + continue; + } + + $followsGroupedByFollower[$followerId][$followingId] = [ + 'created_at' => Carbon::parse($follow->time, 'UTC'), + 'updated_at' => Carbon::parse($follow->time, 'UTC'), + ]; + } + }, 'followID'); + + foreach ($followsGroupedByFollower as $followerId => $followings) { + $user = User::find($followerId); + if ($user) { + $user->following()->sync($followings); + } + } + } + /** * Import the licenses from the Hub database to the local database. */