Skip to content

Commit d39a7ba

Browse files
authored
Merge pull request #36 from helldivers-2/main
Put fix into production
2 parents a10f206 + feceaa5 commit d39a7ba

File tree

18 files changed

+1817
-121
lines changed

18 files changed

+1817
-121
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\PlanetHistory;
6+
use Carbon\Carbon;
7+
use Illuminate\Console\Command;
8+
9+
class migrate_planet_history_fix extends Command
10+
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
16+
protected $signature = 'app:migrate_planet_history_fix {id?}';
17+
18+
/**
19+
* The console command description.
20+
*
21+
* @var string
22+
*/
23+
protected $description = 'Command description';
24+
25+
/**
26+
* Execute the console command.
27+
*/
28+
public function handle()
29+
{
30+
31+
if ($this->argument('id') == null)
32+
{
33+
34+
PlanetHistory::where('id', '>=', 0)->chunk(100, function($models) {
35+
36+
foreach($models as $model) {
37+
$p = PlanetHistory::where('id', '>', $model->id)->where('index', $model->index)->orderBy('id', 'ASC')->first();
38+
if ($p != null)
39+
{
40+
$model->last_valid = $p->created_at->subSeconds(1)->getTimestamp();
41+
$this->info($p->id);
42+
} else
43+
{
44+
$model->last_valid = 0;
45+
$this->info('null');
46+
}
47+
$model->valid_start = $model->created_at->getTimestamp();
48+
$model->save();
49+
$this->info($model->id.' | '.$model->valid_start.' | '.$model->last_valid);
50+
}
51+
52+
});
53+
54+
} else if ($this->argument('id') > 0)
55+
{
56+
$model = PlanetHistory::find($this->argument('id'));
57+
$p = PlanetHistory::where('id', '>', $model->id)->where('index', $model->index)->orderBy('id', 'ASC')->first();
58+
if ($p != null)
59+
{
60+
$model->last_valid = $p->created_at->subSeconds(1)->getTimestamp();
61+
$this->info($p->id);
62+
} else
63+
{
64+
$model->last_valid = 0;
65+
$this->info('null');
66+
}
67+
$model->valid_start = $model->created_at->getTimestamp();
68+
$model->save();
69+
$this->info($model->id.' | '.$model->valid_start.' | '.$model->last_valid);
70+
} else if ($this->argument('id') == 0)
71+
{
72+
73+
74+
PlanetHistory::where('last_valid', 0)->chunk(100, function($models) {
75+
76+
foreach($models as $model) {
77+
$p = PlanetHistory::where('id', '>', $model->id)->where('index', $model->index)->orderBy('id', 'ASC')->first();
78+
if ($p != null)
79+
{
80+
$model->last_valid = $p->created_at->subSeconds(1)->getTimestamp();
81+
$this->info($p->id);
82+
} else
83+
{
84+
$model->last_valid = 0;
85+
$this->info('null');
86+
}
87+
$model->valid_start = $model->created_at->getTimestamp();
88+
$model->save();
89+
$this->info($model->id.' | '.$model->valid_start.' | '.$model->last_valid);
90+
}
91+
});
92+
}
93+
}
94+
}

app/Http/Controllers/PlanetCampaignController.php renamed to app/Http/Controllers/Api/PlanetCampaignController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace App\Http\Controllers;
3+
namespace App\Http\Controllers\Api;
44

5+
use App\Http\Controllers\Controller;
56
use App\Models\PlanetCampaign;
67
use Illuminate\Http\Request;
78

0 commit comments

Comments
 (0)