From 453ae4b32efec06b4040c7f7e578b3f86257ac7d Mon Sep 17 00:00:00 2001 From: Emily Love Watson Date: Wed, 8 Oct 2025 14:15:34 -0500 Subject: [PATCH] MVP migration --- .../ProfileMigrationController.php | 8 ++++-- .../MoveMigrateFollowersPipeline.php | 17 ++++++------ .../MovePipeline/MoveSendFollowPipeline.php | 3 ++- ...leMigrationDeliverMoveActivityPipeline.php | 5 ++-- .../ProfileMigrationMoveFollowersPipeline.php | 27 +++++++++++++------ app/Transformer/ActivityPub/Verb/Move.php | 8 +++--- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/ProfileMigrationController.php b/app/Http/Controllers/ProfileMigrationController.php index 9ac90531c..48f5b4a2a 100644 --- a/app/Http/Controllers/ProfileMigrationController.php +++ b/app/Http/Controllers/ProfileMigrationController.php @@ -5,11 +5,13 @@ namespace App\Http\Controllers; use App\Http\Requests\ProfileMigrationStoreRequest; use App\Jobs\ProfilePipeline\ProfileMigrationDeliverMoveActivityPipeline; use App\Jobs\ProfilePipeline\ProfileMigrationMoveFollowersPipeline; +use App\Jobs\MovePipeline\MoveMigrateFollowersPipeline; use App\Models\ProfileAlias; use App\Models\ProfileMigration; use App\Services\AccountService; use App\Services\WebfingerService; use App\Util\ActivityPub\Helpers; +use Cache; use Illuminate\Http\Request; use Illuminate\Support\Facades\Bus; @@ -61,15 +63,17 @@ class ProfileMigrationController extends Controller 'indexable' => false, ]); AccountService::del($user->profile_id); + Cache::forget('pfc:cached-user:wt:'.strtolower($user->profile->username)); + Cache::forget('pfc:cached-user:wot:'.strtolower($user->profile->username)); Bus::batch([ [ new ProfileMigrationDeliverMoveActivityPipeline($migration, $user->profile, $newAccount), ], [ - new ProfileMigrationMoveFollowersPipeline($user->profile_id, $newAccount->id), + new ProfileMigrationMoveFollowersPipeline($user->profile_id, $newAccount->id, $request->safe()->acct, $newAccount->permalink()), ] - ])->onQueue('follow')->dispatch(); + ])->onQueue('move')->dispatch(); return redirect()->back()->with(['status' => 'Succesfully migrated account!']); } diff --git a/app/Jobs/MovePipeline/MoveMigrateFollowersPipeline.php b/app/Jobs/MovePipeline/MoveMigrateFollowersPipeline.php index 1cde3818e..021cae1e0 100644 --- a/app/Jobs/MovePipeline/MoveMigrateFollowersPipeline.php +++ b/app/Jobs/MovePipeline/MoveMigrateFollowersPipeline.php @@ -118,14 +118,15 @@ class MoveMigrateFollowersPipeline implements ShouldQueue if (! $follower->private_key || ! $follower->username || ! $follower->user_id || $follower->status === 'delete') { continue; } - - Follower::updateOrCreate([ - 'profile_id' => $follower->id, - 'following_id' => $targetPid, - ]); - - MoveSendFollowPipeline::dispatch($follower, $targetInbox, $targetPid, $target)->onQueue('follow'); + if ($targetInbox) { + MoveSendFollowPipeline::dispatch($follower, $targetInbox, $targetPid, $target)->onQueue('follow'); + } else { + Follower::updateOrCreate([ + 'profile_id' => $follower->id, + 'following_id' => $targetPid, + ]); + } } - }, 'id'); + }, 'profiles.id'); } } diff --git a/app/Jobs/MovePipeline/MoveSendFollowPipeline.php b/app/Jobs/MovePipeline/MoveSendFollowPipeline.php index 6d1cef5e1..bdf9def62 100644 --- a/app/Jobs/MovePipeline/MoveSendFollowPipeline.php +++ b/app/Jobs/MovePipeline/MoveSendFollowPipeline.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; use Illuminate\Queue\Middleware\ThrottlesExceptions; use Illuminate\Queue\Middleware\WithoutOverlapping; +use Illuminate\Support\Facades\Log; class MoveSendFollowPipeline implements ShouldQueue { @@ -107,7 +108,7 @@ class MoveSendFollowPipeline implements ShouldQueue ], ]); } catch (ClientException $e) { - + Log::error($e); } } } diff --git a/app/Jobs/ProfilePipeline/ProfileMigrationDeliverMoveActivityPipeline.php b/app/Jobs/ProfilePipeline/ProfileMigrationDeliverMoveActivityPipeline.php index 5fa27c33d..fd5882cab 100644 --- a/app/Jobs/ProfilePipeline/ProfileMigrationDeliverMoveActivityPipeline.php +++ b/app/Jobs/ProfilePipeline/ProfileMigrationDeliverMoveActivityPipeline.php @@ -14,6 +14,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\Log; use League\Fractal; use League\Fractal\Serializer\ArraySerializer; @@ -128,8 +129,8 @@ class ProfileMigrationDeliverMoveActivityPipeline implements ShouldBeUniqueUntil $pool = new Pool($client, $requests($audience), [ 'concurrency' => config('federation.activitypub.delivery.concurrency'), 'fulfilled' => function ($response, $index) { - }, - 'rejected' => function ($reason, $index) { + }, 'rejected' => function ($reason, $index) { + Log::error($reason); }, ]); diff --git a/app/Jobs/ProfilePipeline/ProfileMigrationMoveFollowersPipeline.php b/app/Jobs/ProfilePipeline/ProfileMigrationMoveFollowersPipeline.php index c3d825ec9..4b64a3039 100644 --- a/app/Jobs/ProfilePipeline/ProfileMigrationMoveFollowersPipeline.php +++ b/app/Jobs/ProfilePipeline/ProfileMigrationMoveFollowersPipeline.php @@ -3,6 +3,7 @@ namespace App\Jobs\ProfilePipeline; use App\Follower; +use App\Http\Controllers\FollowerController; use App\Profile; use App\Services\AccountService; use Illuminate\Bus\Batchable; @@ -13,6 +14,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\Log; class ProfileMigrationMoveFollowersPipeline implements ShouldBeUniqueUntilProcessing, ShouldQueue { @@ -77,16 +79,25 @@ class ProfileMigrationMoveFollowersPipeline implements ShouldBeUniqueUntilProces if (! $og || ! $ne || $og == $ne) { return; } - $ne->followers_count = $og->followers_count; - $ne->save(); - $og->followers_count = 0; - $og->save(); - foreach (Follower::whereFollowingId($this->oldPid)->lazyById(200, 'id') as $follower) { + + $targetInbox = $ne['sharedInbox'] ?? $ne['inbox_url']; + foreach (Follower::whereFollowingId($this->oldPid)->where('local_profile', true)->lazyById(200, 'id') as $follower) { try { - $follower->following_id = $this->newPid; - $follower->save(); + if ($targetInbox) { + $followerProfile = Profile::find($follower->profile_id); + Follower::updateOrCreate([ + 'profile_id' => $follower->profile_id, + 'following_id' => $this->newPid, + ]); + (new FollowerController)->sendFollow($followerProfile, $ne); + } else { + Follower::updateOrCreate([ + 'profile_id' => $follower->profile_id, + 'following_id' => $this->newPid, + ]); + } } catch (Exception $e) { - $follower->delete(); + Log::error($e); } } AccountService::del($this->oldPid); diff --git a/app/Transformer/ActivityPub/Verb/Move.php b/app/Transformer/ActivityPub/Verb/Move.php index 2460914be..aedb32e59 100644 --- a/app/Transformer/ActivityPub/Verb/Move.php +++ b/app/Transformer/ActivityPub/Verb/Move.php @@ -9,9 +9,9 @@ class Move extends Fractal\TransformerAbstract { public function transform(ProfileMigration $migration) { - $objUrl = $migration->target->permalink(); - $id = $migration->target->permalink('#moves/'.$migration->id); - $to = $migration->target->permalink('/followers'); + $objUrl = $migration->profile->permalink(); + $id = $migration->profile->permalink('#moves/'.$migration->id); + $to = $migration->profile->permalink('/followers'); return [ '@context' => 'https://www.w3.org/ns/activitystreams', @@ -19,7 +19,7 @@ class Move extends Fractal\TransformerAbstract 'actor' => $objUrl, 'type' => 'Move', 'object' => $objUrl, - 'target' => $migration->profile->permalink(), + 'target' => $migration->target->permalink(), 'to' => $to, ]; }