]> git.localhorst.tv Git - alttp.git/blobdiff - app/Console/Commands/ReevaluateChatCommand.php
more classification
[alttp.git] / app / Console / Commands / ReevaluateChatCommand.php
diff --git a/app/Console/Commands/ReevaluateChatCommand.php b/app/Console/Commands/ReevaluateChatCommand.php
new file mode 100644 (file)
index 0000000..69a8374
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\ChatLog;
+use Illuminate\Console\Command;
+
+class EvaluateChatCommand extends Command {
+
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'chat:reevaluate';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Reevaluate chat log entries';
+
+       /**
+        * Execute the console command.
+        *
+        * @return int
+        */
+       public function handle() {
+               $good = 0;
+               $bad = 0;
+               ChatLog::where('type', '=', 'chat')
+                       ->where('banned', false)
+                       ->orderBy('created_at')
+                       ->chunk(10000, function ($logs) use (&$good, &$bad) {
+                               foreach ($logs as $line) {
+                                       try {
+                                               $line->evaluate();
+                                               $line->evaluated_at = now();
+                                               $line->save();
+                                               ++$good;
+                                       } catch (\Exception $e) {
+                                               ++$bad;
+                                               $this->error('unable to evaluate line '.$line->id.': '.$e->getMessage());
+                                               $line->type = 'error';
+                                               $line->text_content = $e->getMessage();
+                                               $line->evaluated_at = now();
+                                               $line->save();
+                                       }
+                               }
+                               echo $good;
+                               if ($bad) {
+                                       echo ' +', $bad, ' errors';
+                               }
+                               echo PHP_EOL;
+                       });
+
+               return Command::SUCCESS;
+       }
+
+}