From 521b5b5b073bd60579d60563e19aaab237e3b569 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 7 Jul 2019 23:45:21 -0600 Subject: [PATCH] Add FixHashtags command --- app/Console/Commands/FixHashtags.php | 109 +++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 app/Console/Commands/FixHashtags.php diff --git a/app/Console/Commands/FixHashtags.php b/app/Console/Commands/FixHashtags.php new file mode 100644 index 000000000..3b51bb407 --- /dev/null +++ b/app/Console/Commands/FixHashtags.php @@ -0,0 +1,109 @@ +info(' ____ _ ______ __ '); + $this->info(' / __ \(_) _____ / / __/__ ____/ / '); + $this->info(' / /_/ / / |/_/ _ \/ / /_/ _ \/ __ / '); + $this->info(' / ____/ /> info(' /_/ /_/_/|_|\___/_/_/ \___/\__,_/ '); + $this->info(' '); + $this->info(' '); + $this->info('Pixelfed version: ' . config('pixelfed.version')); + $this->info(' '); + $this->info('Running Fix Hashtags command'); + $this->info(' '); + + $missingCount = StatusHashtag::doesntHave('status')->count(); + if($missingCount > 0) { + $this->info("Found {$missingCount} orphaned StatusHashtag records to delete ..."); + $this->info(' '); + $bar = $this->output->createProgressBar($missingCount); + $bar->start(); + foreach(StatusHashtag::doesntHave('status')->get() as $tag) { + $tag->delete(); + $bar->advance(); + } + $bar->finish(); + $this->info(' '); + } else { + $this->info(' '); + $this->info('Found no orphaned hashtags to delete!'); + } + + + $this->info(' '); + + $count = StatusHashtag::whereNull('status_visibility')->count(); + if($count > 0) { + $this->info("Found {$count} hashtags to fix ..."); + $this->info(' '); + } else { + $this->info('Found no hashtags to fix!'); + $this->info(' '); + return; + } + + $bar = $this->output->createProgressBar($count); + $bar->start(); + + StatusHashtag::with('status') + ->whereNull('status_visibility') + ->chunk(50, function($tags) use($bar) { + foreach($tags as $tag) { + if(!$tag->status || !$tag->status->scope) { + continue; + } + $tag->status_visibility = $tag->status->scope; + $tag->save(); + $bar->advance(); + } + }); + + $bar->finish(); + $this->info(' '); + $this->info(' '); + } +}