mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Add migrations to fix webfinger profiles
This commit is contained in:
parent
bc2bbc14ac
commit
66aa8bf9de
2 changed files with 97 additions and 0 deletions
|
@ -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()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue