mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-14 02:24:31 +00:00
Add duplicate profile fix
This commit is contained in:
parent
955593101b
commit
4eeb1f0247
1 changed files with 75 additions and 0 deletions
75
app/Console/Commands/FixDuplicateProfiles.php
Normal file
75
app/Console/Commands/FixDuplicateProfiles.php
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
use App\{
|
||||||
|
Like,
|
||||||
|
Media,
|
||||||
|
Profile,
|
||||||
|
Status,
|
||||||
|
User
|
||||||
|
};
|
||||||
|
|
||||||
|
class FixDuplicateProfiles extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'fix:profile:duplicates';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Fix duplicate profiles';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$profiles = Profile::selectRaw('count(user_id) as count,user_id,id')->whereNotNull('user_id')->groupBy('user_id')->orderBy('user_id', 'desc')->get()->where('count', '>', 1);
|
||||||
|
$count = $profiles->count();
|
||||||
|
if($count == 0) {
|
||||||
|
$this->info("No duplicate profiles found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->info("Found {$count} accounts with duplicate profiles...");
|
||||||
|
$bar = $this->output->createProgressBar($count);
|
||||||
|
$bar->start();
|
||||||
|
|
||||||
|
foreach ($profiles as $profile) {
|
||||||
|
$dup = Profile::whereUserId($profile->user_id)->get();
|
||||||
|
|
||||||
|
if(
|
||||||
|
$dup->first()->username === $dup->last()->username &&
|
||||||
|
$dup->last()->statuses()->count() == 0 &&
|
||||||
|
$dup->last()->followers()->count() == 0 &&
|
||||||
|
$dup->last()->likes()->count() == 0 &&
|
||||||
|
$dup->last()->media()->count() == 0
|
||||||
|
) {
|
||||||
|
$dup->last()->avatar->forceDelete();
|
||||||
|
$dup->last()->forceDelete();
|
||||||
|
}
|
||||||
|
$bar->advance();
|
||||||
|
}
|
||||||
|
$bar->finish();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue