]> git.localhorst.tv Git - alttp.git/blobdiff - app/Console/Commands/GuessingClean.php
clean up forgotten guessing games
[alttp.git] / app / Console / Commands / GuessingClean.php
diff --git a/app/Console/Commands/GuessingClean.php b/app/Console/Commands/GuessingClean.php
new file mode 100644 (file)
index 0000000..d26b3e9
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Channel;
+use Illuminate\Console\Command;
+use Illuminate\Http\Client\RequestException;
+use Illuminate\Support\Facades\Http;
+
+class GuessingClean extends Command {
+
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'guessing:clean';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Cancel orphaned guessing games';
+
+       /**
+        * Execute the console command.
+        *
+        * @return int
+        */
+       public function handle()
+       {
+               $channels = Channel
+                       ::whereNotNull('guessing_start')
+                       ->where('guessing_start', '<', now()
+                       ->sub(4, 'hour'))
+                       ->get();
+               foreach ($channels as $channel) {
+                       $this->line($channel->title);
+                       $channel->guessing_start = null;
+                       $channel->guessing_end = null;
+                       $channel->save();
+               }
+               return Command::SUCCESS;
+       }
+
+}