]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/ChatlibDatabase.php
b95bb64a06a6dbec47b333c2c9248493e0c8492d
[alttp.git] / app / Console / Commands / ChatlibDatabase.php
1 <?php
2
3 namespace App\Console\Commands;
4
5 use App\Models\ChatLib;
6 use App\Models\ChatLog;
7 use Illuminate\Console\Command;
8
9 class ChatlibDatabase extends Command {
10
11         /**
12          * The name and signature of the console command.
13          *
14          * @var string
15          */
16         protected $signature = 'chatlib:database';
17
18         /**
19          * The console command description.
20          *
21          * @var string
22          */
23         protected $description = 'Updates the ChatLib database';
24
25         /**
26          * Execute the console command.
27          *
28          * @return int
29          */
30         public function handle() {
31                 $de = new ChatLib();
32                 $en = new ChatLib();
33
34                 ChatLog::where('type', '=', 'chat')
35                         ->where('banned', '=', false)
36                         ->whereNotNull('evaluated_at')
37                         ->where('created_at', '<', now()->sub(7, 'day'))
38                         ->chunk(5000, function ($msgs) use ($de, $en) {
39                                 foreach ($msgs as $msg) {
40                                         if ($msg->detected_language === 'de') {
41                                                 $de->addMessage($msg);
42                                         } else if ($msg->detected_language === 'en') {
43                                                 $en->addMessage($msg);
44                                         } else if (is_null($msg->detected_language)) {
45                                                 $de->addMessage($msg);
46                                                 $en->addMessage($msg);
47                                         }
48                                 }
49                         });
50
51                 $de->compile();
52                 $de->saveAs('de');
53
54                 $en->compile();
55                 $en->saveAs('en');
56
57                 return 0;
58         }
59
60 }
61
62 ?>