1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Console\Commands;
7
8use App\Models\User;
9use Illuminate\Console\Command;
10
11class UserForumStatSyncCommand extends Command
12{
13 /**
14 * The console command name.
15 *
16 * @var string
17 */
18 protected $signature = 'user:forumsync';
19
20 /**
21 * The console command description.
22 *
23 * @var string
24 */
25 protected $description = 'Synchronises forum post counts for all users.';
26
27 /**
28 * Create a new command instance.
29 */
30 public function __construct()
31 {
32 parent::__construct();
33 }
34
35 private $progress;
36
37 /**
38 * Execute the console command.
39 *
40 * @return mixed
41 */
42 public function handle()
43 {
44 $this->info('Synchronising user post counts...');
45
46 $this->progress = $this->output->createProgressBar(User::count());
47
48 User::chunkById(1000, function ($users) {
49 foreach ($users as $u) {
50 $u->refreshForumCache();
51 $this->progress->advance();
52 }
53 });
54
55 $this->progress->finish();
56 }
57
58 /**
59 * Get the console command arguments.
60 *
61 * @return array
62 */
63 protected function getArguments()
64 {
65 return [];
66 }
67
68 /**
69 * Get the console command options.
70 *
71 * @return array
72 */
73 protected function getOptions()
74 {
75 return [];
76 }
77}