-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathUpdateAchievementsForPostWithComments.php
executable file
·46 lines (40 loc) · 1.27 KB
/
UpdateAchievementsForPostWithComments.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace App\Console\Commands;
use App\Achievements\Contents\AuthorCommentInteraction;
use App\Achievements\Contents\AuthorHighCommentInteraction;
use App\Models\Post;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Collection;
class UpdateAchievementsForPostWithComments extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:achievements-post-comments';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update achievements for authors based on the comments on their posts.';
/**
* Execute the console command.
*/
public function handle()
{
Post::with(['author'])
->has('comments', '>=', 10)
->withCount('comments')
->where('created_at', '>=', now()->subWeek())
->chunk(100, function (Collection $posts) {
$posts->each(function (Post $post) {
if ($post->comments_count >= 30) {
$post->author->reward(AuthorHighCommentInteraction::class);
}
$post->author->reward(AuthorCommentInteraction::class);
});
});
}
}