diff --git a/app/Console/Commands/FixLikes.php b/app/Console/Commands/FixLikes.php new file mode 100644 index 000000000..adb4ee454 --- /dev/null +++ b/app/Console/Commands/FixLikes.php @@ -0,0 +1,75 @@ +get()->count(); + + if($limit > 1000) { + if($this->confirm('We have found more than 1000 records to update, this may take a few moments. Are you sure you want to continue?') == false) { + $this->error('Cancelling command...'); + return; + } + } + + $bar = $this->output->createProgressBar($limit); + $this->line(' '); + $this->info(' Starting like count fix ...'); + $this->line(' '); + $bar->start(); + + Like::selectRaw('count(id) as count, status_id') + ->groupBy('status_id') + ->chunk($chunk, function($likes) use($bar) { + foreach($likes as $like) { + $s = Status::find($like['status_id']); + if($s && $s->likes_count == 0) { + $s->likes_count = $like['count']; + $s->save(); + } + $bar->advance(); + } + }); + + $bar->finish(); + $this->line(' '); + $this->line(' '); + } +}