Files
HeimerdingerLoL/database/seeders/ChampionImageSeeder.php
Rico van Zelst b4c827e391 fix: Update existing champion images
- Fixes issue that made it so champion images would store duplicate champion images no matter what.
2024-08-07 00:06:01 +02:00

50 lines
1.6 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\Champion;
use App\Models\ChampionImage;
use Illuminate\Database\Seeder;
class ChampionImageSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Champion::all()->each(function ($champion) {
$dataJson = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/v1/champions/'.$champion->champion_id.'.json';
$data = json_decode(file_get_contents($dataJson), true);
$championSkins = $data['skins'];
foreach ($championSkins as $skin) {
$this->updateOrCreateImage($skin, $champion, 'splash', $skin['splashPath']);
$this->updateOrCreateImage($skin, $champion, 'uncentered_splash', $skin['uncenteredSplashPath']);
$this->updateOrCreateImage($skin, $champion, 'loading', $skin['loadScreenPath']);
$this->updateOrCreateImage($skin, $champion, 'tile', $skin['tilePath']);
}
});
}
/**
* Update or create a ChampionImage entry.
*/
private function updateOrCreateImage($skin, $champion, $type, $path): void
{
$url = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/'.strtolower(substr($path, strpos($path, 'ASSETS')));
ChampionImage::updateOrCreate(
[
'full_id' => $skin['id'],
'type' => $type,
],
[
'champion_id' => $champion->champion_id,
'url' => $url,
]
);
}
}