]> git.localhorst.tv Git - alttp.git/blob - app/Console/Commands/GuessingClean.php
clean up forgotten guessing games
[alttp.git] / app / Console / Commands / GuessingClean.php
1 <?php
2
3 namespace App\Console\Commands;
4
5 use App\Models\Channel;
6 use Illuminate\Console\Command;
7 use Illuminate\Http\Client\RequestException;
8 use Illuminate\Support\Facades\Http;
9
10 class GuessingClean extends Command {
11
12         /**
13          * The name and signature of the console command.
14          *
15          * @var string
16          */
17         protected $signature = 'guessing:clean';
18
19         /**
20          * The console command description.
21          *
22          * @var string
23          */
24         protected $description = 'Cancel orphaned guessing games';
25
26         /**
27          * Execute the console command.
28          *
29          * @return int
30          */
31         public function handle()
32         {
33                 $channels = Channel
34                         ::whereNotNull('guessing_start')
35                         ->where('guessing_start', '<', now()
36                         ->sub(4, 'hour'))
37                         ->get();
38                 foreach ($channels as $channel) {
39                         $this->line($channel->title);
40                         $channel->guessing_start = null;
41                         $channel->guessing_end = null;
42                         $channel->save();
43                 }
44                 return Command::SUCCESS;
45         }
46
47 }