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\Build;
9use App\Models\BuildPropagationHistory;
10use Carbon\Carbon;
11use DB;
12use Illuminate\Console\Command;
13
14class BuildsUpdatePropagationHistory extends Command
15{
16 /**
17 * The name and signature of the console command.
18 *
19 * @var string
20 */
21 protected $signature = 'builds:update-propagation-history';
22
23 /**
24 * The console command description.
25 *
26 * @var string
27 */
28 protected $description = 'Updates the build propagation history based on current data.';
29
30 /**
31 * Create a new command instance.
32 *
33 * @return void
34 */
35 public function __construct()
36 {
37 parent::__construct();
38 }
39
40 /**
41 * Execute the console command.
42 *
43 * @return mixed
44 */
45 public function handle()
46 {
47 DB::transaction(function () {
48 $date = Carbon::now();
49
50 $builds = Build::propagationHistory()
51 ->whereIn('stream_id', $GLOBALS['cfg']['osu']['changelog']['update_streams'])
52 ->get();
53
54 foreach ($builds as $build) {
55 BuildPropagationHistory::create([
56 'build_id' => $build->build_id,
57 'user_count' => $build->users,
58 'created_at' => $date,
59 ]);
60 }
61 }, 3);
62 }
63}