|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\IgdbBundle\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
8
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
13
|
|
|
use VideoGamesRecords\IgdbBundle\Entity\PlatformLogo; |
|
14
|
|
|
use VideoGamesRecords\IgdbBundle\Client\IgdbClient; |
|
15
|
|
|
|
|
16
|
|
|
#[AsCommand( |
|
17
|
|
|
name: 'igdb:import:platform-logos', |
|
18
|
|
|
description: 'Import all platform logos from IGDB API into database' |
|
19
|
|
|
)] |
|
20
|
|
|
class ImportPlatformLogosCommand extends Command |
|
21
|
|
|
{ |
|
22
|
|
|
public function __construct( |
|
23
|
|
|
private IgdbClient $igdbClient, |
|
24
|
|
|
private EntityManagerInterface $entityManager |
|
25
|
|
|
) { |
|
26
|
|
|
parent::__construct(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
30
|
|
|
{ |
|
31
|
|
|
$io = new SymfonyStyle($input, $output); |
|
32
|
|
|
|
|
33
|
|
|
$io->title('Importing platform logos from IGDB API'); |
|
34
|
|
|
|
|
35
|
|
|
try { |
|
36
|
|
|
$platformLogos = $this->igdbClient->getAllPlatformLogos(); |
|
37
|
|
|
$io->progressStart(count($platformLogos)); |
|
38
|
|
|
|
|
39
|
|
|
$insertedCount = 0; |
|
40
|
|
|
$updatedCount = 0; |
|
41
|
|
|
|
|
42
|
|
|
foreach ($platformLogos as $platformLogoData) { |
|
43
|
|
|
$existingPlatformLogo = $this->entityManager |
|
44
|
|
|
->getRepository(PlatformLogo::class) |
|
45
|
|
|
->find($platformLogoData['id']); |
|
46
|
|
|
|
|
47
|
|
|
if ($existingPlatformLogo) { |
|
48
|
|
|
// Pas de timestamps dans l'API, on met toujours à jour |
|
49
|
|
|
$existingPlatformLogo->setAlphaChannel($platformLogoData['alpha_channel'] ?? false); |
|
50
|
|
|
$existingPlatformLogo->setAnimated($platformLogoData['animated'] ?? false); |
|
51
|
|
|
$existingPlatformLogo->setChecksum($platformLogoData['checksum'] ?? null); |
|
52
|
|
|
$existingPlatformLogo->setHeight($platformLogoData['height'] ?? 0); |
|
53
|
|
|
$existingPlatformLogo->setImageId($platformLogoData['image_id'] ?? ''); |
|
54
|
|
|
$existingPlatformLogo->setUrl($platformLogoData['url'] ?? null); |
|
55
|
|
|
$existingPlatformLogo->setWidth($platformLogoData['width'] ?? 0); |
|
56
|
|
|
$existingPlatformLogo->setUpdatedAt(new \DateTimeImmutable()); |
|
57
|
|
|
$updatedCount++; |
|
58
|
|
|
} else { |
|
59
|
|
|
$platformLogo = new PlatformLogo(); |
|
60
|
|
|
$platformLogo->setId($platformLogoData['id']); |
|
61
|
|
|
$platformLogo->setAlphaChannel($platformLogoData['alpha_channel'] ?? false); |
|
62
|
|
|
$platformLogo->setAnimated($platformLogoData['animated'] ?? false); |
|
63
|
|
|
$platformLogo->setChecksum($platformLogoData['checksum'] ?? null); |
|
64
|
|
|
$platformLogo->setHeight($platformLogoData['height'] ?? 0); |
|
65
|
|
|
$platformLogo->setImageId($platformLogoData['image_id'] ?? ''); |
|
66
|
|
|
$platformLogo->setUrl($platformLogoData['url'] ?? null); |
|
67
|
|
|
$platformLogo->setWidth($platformLogoData['width'] ?? 0); |
|
68
|
|
|
|
|
69
|
|
|
$this->entityManager->persist($platformLogo); |
|
70
|
|
|
$insertedCount++; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$io->progressAdvance(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$this->entityManager->flush(); |
|
77
|
|
|
$io->progressFinish(); |
|
78
|
|
|
|
|
79
|
|
|
$io->success([ |
|
80
|
|
|
"Platform logos imported successfully!", |
|
81
|
|
|
"Inserted: $insertedCount platform logos", |
|
82
|
|
|
"Updated: $updatedCount platform logos", |
|
83
|
|
|
"Total processed: " . ($insertedCount + $updatedCount) . " platform logos" |
|
84
|
|
|
]); |
|
85
|
|
|
|
|
86
|
|
|
return Command::SUCCESS; |
|
87
|
|
|
} catch (\Exception $e) { |
|
88
|
|
|
$io->error('Failed to import platform logos: ' . $e->getMessage()); |
|
89
|
|
|
return Command::FAILURE; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|