MVP migration

pull/6194/head
Emily Love Watson 3 months ago
parent 6544d269ca
commit 453ae4b32e
No known key found for this signature in database
GPG Key ID: 69981387DE7BC2EE

@ -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!']);
}

@ -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');
}
}

@ -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);
}
}
}

@ -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);
},
]);

@ -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);

@ -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,
];
}

Loading…
Cancel
Save