Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

pixelfed/pixelfed

6813 stars
1 code files
View pixelfed/pixelfed on GitHub

app/Console/Commands/FixLikes.php

Open in GitHub
use Illuminate\Console\Command;
use App\{Like, Status};
use DB;
 
class FixLikes extends Command
{
//
public function handle()
{
$chunk = 100;
$limit = Like::select('status_id')->groupBy('status_id')->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','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(' ');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.