Revert "User profile linking can get stuck with null profile_id after partial observer failure"

This reverts commit f52ffe292b.
w5
Your Name 2 months ago
parent 796f978a94
commit ae59dc3d37

@ -61,24 +61,11 @@ class UserObserver
return;
}
if (empty($user->profile)) {
// Check if an orphaned profile exists (created but never linked)
$existingProfile = Profile::whereUsername($user->username)->first();
if ($existingProfile) {
// Link orphaned profile to user if profile_id is not set
if (! $user->profile_id) {
DB::transaction(function () use ($user, $existingProfile) {
$user = User::findOrFail($user->id);
$user->profile_id = $existingProfile->id;
$user->save();
});
}
return;
}
if (Profile::whereUsername($user->username)->exists()) {
return;
}
// Create profile and link to user in a single atomic transaction
if (empty($user->profile)) {
$profile = DB::transaction(function () use ($user) {
$profile = new Profile;
$profile->user_id = $user->id;
@ -99,14 +86,21 @@ class UserObserver
$profile->save();
$this->applyDefaultDomainBlocks($user);
return $profile;
});
DB::transaction(function () use ($user, $profile) {
$user = User::findOrFail($user->id);
$user->profile_id = $profile->id;
$user->save();
return $profile;
});
// UserNotify::updateOrCreate([
// 'profile_id' => $profile->id,
// 'user_id' => $user->id,
// ]);
CreateAvatar::dispatch($profile);
CreateAvatar::dispatch($profile);
});
if ((bool) config_cache('account.autofollow') == true) {
$names = config_cache('account.autofollow_usernames');

Loading…
Cancel
Save