This commit is contained in:
Doar Mihai
2026-05-30 18:56:17 +03:00
parent 17a2211952
commit afc49488a9
5 changed files with 93 additions and 33 deletions
+23 -9
View File
@@ -12,22 +12,36 @@ use Illuminate\Console\Command;
class ImportGamesCommand extends Command
{
protected $signature = 'games:import {--limit=100} {--offset=0} {--popular} {--new}';
protected $signature = 'games:import {--limit=100} {--offset=0} {--popular} {--new} {--year=} {--platform=}';
protected $description = 'Import games from IGDB into the local database';
public function handle(IgdbService $igdb): int
{
$limit = (int) $this->option('limit');
$offset = (int) $this->option('offset');
$limit = (int) $this->option('limit');
$offset = (int) $this->option('offset');
$year = $this->option('year') ? (int) $this->option('year') : null;
$platform = $this->option('platform') ? (int) $this->option('platform') : null;
$this->info("Fetching {$limit} games from IGDB (offset: {$offset})…");
if ($year && $platform) {
$this->error('Use --year or --platform, not both.');
return self::FAILURE;
}
$label = match (true) {
$year !== null => "year {$year}",
$platform !== null => "platform IGDB ID {$platform}",
$this->option('new') => 'new releases',
default => "popular (offset: {$offset})",
};
$this->info("Fetching {$limit} games from IGDB ({$label})…");
try {
if ($this->option('new')) {
$results = $igdb->getNewReleases($limit);
} else {
$results = $igdb->getPopularGames($limit, $offset);
}
$results = match (true) {
$year !== null => $igdb->getGamesByYear($year, $limit, $offset),
$platform !== null => $igdb->getGamesByPlatform($platform, $limit, $offset),
$this->option('new') => $igdb->getNewReleases($limit),
default => $igdb->getPopularGames($limit, $offset),
};
} catch (\Exception $e) {
$this->error('IGDB request failed: ' . $e->getMessage());
return self::FAILURE;