Skip to content

Commit 7eb9d67

Browse files
committed
Check mod type
- Check on scanning archive paths - Check when game changes its mod types definition
1 parent a808606 commit 7eb9d67

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Jobs;
4+
5+
use App\Models\Game;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Foundation\Queue\Queueable;
8+
use Illuminate\Support\Collection;
9+
10+
class DetectGameFileModTypes implements ShouldQueue
11+
{
12+
use Queueable;
13+
14+
/**
15+
* Create a new job instance.
16+
*/
17+
public function __construct(public Game $game){ }
18+
19+
/**
20+
* Execute the job.
21+
*/
22+
public function handle(): void
23+
{
24+
ini_set('memory_limit', '2G');
25+
26+
$this->game->mods()->chunk(250, function(Collection $mods) {
27+
foreach ($mods as $mod) {
28+
foreach ($mod->files as $file) {
29+
$file->mod_type = $file->detectFileModType();
30+
$file->timestamps = false;
31+
$file->save();
32+
}
33+
}
34+
});
35+
36+
}
37+
}
38+

backend/app/Jobs/ScanArchivePaths.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function handle(): void
4040
$file->archive_paths = self::scanPathsInArchive($file);
4141
$file->timestamps = false;
4242

43+
$file->mod_type = $file->detectFileModType();
44+
4345
$file->save();
4446
}
4547

backend/app/Models/Game.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Http\Controllers\UserController;
66
use App\Http\Resources\UserResource;
7+
use App\Jobs\DetectGameFileModTypes;
78
use App\Services\APIService;
89
use App\Services\ModService;
910
use Arr;
@@ -102,7 +103,7 @@ class Game extends Model
102103
protected $guarded = [
103104
'game_sdk_key'
104105
];
105-
protected $hidden = ['webhook_url', 'viewable_mods_count', 'game_sdk_key'];
106+
protected $hidden = ['webhook_url', 'viewable_mods_count', 'game_sdk_key', 'mod_types_definition'];
106107
protected $appends = [];
107108
public const WITH_USER_PERFS = ['followed', 'ignored'];
108109
protected $with = [];
@@ -310,6 +311,12 @@ public static function booted()
310311
static::saving(fn(Game $game) => $game->ensureForumExists());
311312
static::created(fn(Game $game) => $game->ensureForumExists());
312313

314+
static::saved(function(Game $game) {
315+
if ($game->id && $game->isDirty('mod_types_definition')) {
316+
DetectGameFileModTypes::dispatch($game);
317+
}
318+
});
319+
313320
static::deleting(function(Game $game) {
314321
Storage::delete('games/images/'.$game->banner);
315322
Storage::delete('games/images/'.$game->thumbnail);

0 commit comments

Comments
 (0)