Add migrations to fix webfinger profiles

This commit is contained in:
Daniel Supernault 2022-09-01 01:13:01 -06:00
parent bc2bbc14ac
commit 66aa8bf9de
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,59 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Profile;
use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline;
class FixWebfingerProfileDuplicateAccounts extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(Profile::count() === 0) {
return;
}
Profile::whereNotNull('domain')
->where('username', 'not like', '@%')
->chunk(200, function($profiles) {
foreach($profiles as $profile) {
$exists = Profile::whereUsername("@{$profile->username}@{$profile->domain}")->first();
if($exists) {
$exists->username = null;
$exists->domain = null;
$exists->webfinger = null;
$exists->save();
DeleteRemoteProfilePipeline::dispatch($exists);
$profile->username = "@{$profile->username}@{$profile->domain}";
if(!$profile->webfinger) {
$profile->webfinger = "@{$profile->username}@{$profile->domain}";
}
$profile->save();
} else {
$profile->username = "@{$profile->username}@{$profile->domain}";
if(!$profile->webfinger) {
$profile->webfinger = "@{$profile->username}@{$profile->domain}";
}
$profile->save();
}
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View file

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Profile;
class GenerateMissingProfileWebfinger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Profile::whereNotNull('domain')
->whereNull('webfinger')
->chunk(200, function($profiles) {
foreach($profiles as $profile) {
if(substr($profile->username, 0, 1) === "@") {
$profile->webfinger = $profile->username;
$profile->save();
}
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}