From 4eeb1f02472a689b868508ae6ab83954212c0c12 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 12 Feb 2019 01:10:29 -0700 Subject: [PATCH] Add duplicate profile fix --- app/Console/Commands/FixDuplicateProfiles.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 app/Console/Commands/FixDuplicateProfiles.php diff --git a/app/Console/Commands/FixDuplicateProfiles.php b/app/Console/Commands/FixDuplicateProfiles.php new file mode 100644 index 00000000..a9cab3ec --- /dev/null +++ b/app/Console/Commands/FixDuplicateProfiles.php @@ -0,0 +1,75 @@ +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(); + } +}